Skip to content

Commit c54e341

Browse files
Merge pull request #943 from pnp/feature/attachments-label
Feature/attachments label
2 parents c91987a + ca8c752 commit c54e341

File tree

5 files changed

+38
-30
lines changed

5 files changed

+38
-30
lines changed

docs/documentation/docs/controls/ListItemAttachments.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ The `ListItemAttachments` control can be configured with the following propertie
5959
| itemId | number | no | List Item Id |
6060
| listId | string | yes | Guid of the list. |
6161
| webUrl | string | no | URL of the site. By default it uses the current site URL. |
62+
| label | string | no | Main text to display on the placeholder, next to the icon. |
63+
| description | string | no | Description text to display on the placeholder, below the main text and icon. |
6264
| disabled | boolean | no | Specifies if the control is disabled or not. |
6365
| openAttachmentsInNewWindow | boolean | no | Specifies if the attachment should be openend in a separate browser tab. Use this property set to `true` if you plan to use the component in Microsoft Teams. |
6466

src/controls/listItemAttachments/IListItemAttachmentsProps.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ export interface IListItemAttachmentsProps {
88
disabled?: boolean;
99
context: BaseComponentContext;
1010
openAttachmentsInNewWindow?: boolean; // JJ - 20200613 - needed to support Microsoft Teams
11+
/**
12+
* Main text to display on the placeholder, next to the icon
13+
*/
14+
label?:string;
15+
/**
16+
* Description text to display on the placeholder, below the main text and icon
17+
*/
18+
description?:string;
1119
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
export interface IUploadAttachmentState {
3-
file: any;
43
hideDialog: boolean;
54
dialogMessage: string;
65
isLoading: boolean;
7-
6+
87
}

src/controls/listItemAttachments/ListItemAttachments.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,22 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
120120
dialogMessage: strings.ListItemAttachmentserrorLoadAttachments.replace('{0}', error.message)
121121
});
122122
});
123-
}
124-
else if(this.state.filesToUpload && this.state.filesToUpload.length > 0){
125-
let files = this.state.filesToUpload.map(file=>({
126-
FileName: file.name,
127-
ServerRelativeUrl: undefined
128-
}));
129-
await this.loadAttachmentsPreview(files);
130-
}
131-
else{
132-
this.setState({
133-
fireUpload: false,
134-
hideDialog: true,
135-
dialogMessage: '',
136-
showPlaceHolder: true
137-
});
138-
}
123+
}
124+
else if(this.state.filesToUpload && this.state.filesToUpload.length > 0){
125+
let files = this.state.filesToUpload.map(file=>({
126+
FileName: file.name,
127+
ServerRelativeUrl: undefined
128+
}));
129+
await this.loadAttachmentsPreview(files);
130+
}
131+
else{
132+
this.setState({
133+
fireUpload: false,
134+
hideDialog: true,
135+
dialogMessage: '',
136+
showPlaceHolder: true
137+
});
138+
}
139139
}
140140

141141
/**
@@ -255,8 +255,8 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
255255
this.state.showPlaceHolder ?
256256
<Placeholder
257257
iconName='Upload'
258-
iconText={strings.ListItemAttachmentslPlaceHolderIconText}
259-
description={strings.ListItemAttachmentslPlaceHolderDescription}
258+
iconText={this.props.label || strings.ListItemAttachmentslPlaceHolderIconText}
259+
description={this.props.description || strings.ListItemAttachmentslPlaceHolderDescription}
260260
buttonLabel={strings.ListItemAttachmentslPlaceHolderButtonLabel}
261261
hideButton={this.props.disabled}
262262
onConfigure={() => this.setState({ fireUpload: true })} />
@@ -304,7 +304,7 @@ export class ListItemAttachments extends React.Component<IListItemAttachmentsPro
304304
</div>
305305
);
306306
})}
307-
{
307+
{ !this.state.hideDialog &&
308308

309309
<Dialog
310310
hidden={this.state.hideDialog}

src/controls/listItemAttachments/UploadAttachment.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import styles from './ListItemAttachments.module.scss';
1212
export class UploadAttachment extends React.Component<IUploadAttachmentProps, IUploadAttachmentState> {
1313
private _spservice: SPservice;
1414
private fileInput;
15+
private _isFileExplorerOpen = false;
1516

1617
constructor(props: IUploadAttachmentProps) {
1718
super(props);
1819

1920
this.state = {
20-
file: null,
2121
hideDialog: true,
2222
dialogMessage: '',
2323
isLoading: false,
@@ -35,9 +35,10 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
3535
* @param prevState
3636
*/
3737
public componentDidUpdate(prevProps: IUploadAttachmentProps, prevState: IUploadAttachmentState): void {
38-
if (this.props.fireUpload) {
38+
if (this.props.fireUpload && !this._isFileExplorerOpen) {
3939
this.fileInput.current.value = '';
4040
this.fileInput.current.click();
41+
this._isFileExplorerOpen = true;
4142
}
4243
}
4344

@@ -62,19 +63,16 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
6263
const file = e.target.files[0];
6364
return new Promise<void>((resolve,errorCallback)=>{
6465
reader.onloadend = async () => {
65-
this.setState({
66-
file: file
67-
});
68-
66+
6967
try {
7068
if(this.props.itemId && this.props.itemId > 0){
7169
await this._spservice.addAttachment(this.props.listId, this.props.itemId, file.name, file, this.props.webUrl);
7270
}
73-
71+
72+
this.props.onAttachmentUpload(file);
7473
this.setState({
7574
isLoading: false
7675
});
77-
this.props.onAttachmentUpload(file);
7876
resolve();
7977
} catch (error) {
8078
this.setState({
@@ -84,10 +82,11 @@ export class UploadAttachment extends React.Component<IUploadAttachmentProps, IU
8482
});
8583
errorCallback(error);
8684
}
85+
this._isFileExplorerOpen = false;
8786
};
8887
reader.readAsDataURL(file);
8988
});
90-
89+
9190
}
9291

9392
/**

0 commit comments

Comments
 (0)