Fix attachment not cleared after submit issue

This commit is contained in:
Ari Gunawan 2021-05-06 14:23:33 +07:00
parent be1b788c4b
commit 558b5411e8
1 changed files with 21 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import { Separator } from 'office-ui-fabric-react/lib/Separator';
import { IconButton } from 'office-ui-fabric-react/lib/Button'; import { IconButton } from 'office-ui-fabric-react/lib/Button';
import { mergeStyles } from 'office-ui-fabric-react/lib/Styling'; import { mergeStyles } from 'office-ui-fabric-react/lib/Styling';
import { IconNames } from '@uifabric/icons'; import { IconNames } from '@uifabric/icons';
import { isEqual } from '@microsoft/sp-lodash-subset';
import { IAttachment } from "../../../../types/IAttachment"; import { IAttachment } from "../../../../types/IAttachment";
import { ControlMode } from '../../../../common/datatypes/ControlMode'; import { ControlMode } from '../../../../common/datatypes/ControlMode';
@ -36,14 +37,27 @@ export class AttachmentRender extends React.Component<IAttachmentProps, IAttachm
} }
public componentDidUpdate(prevProps: IAttachmentProps, prevState: IAttachmentState) { public componentDidUpdate(prevProps: IAttachmentProps, prevState: IAttachmentState) {
//Component Value property got updated from List State switch (this.props.controlMode) {
if (this.props.value case ControlMode.New:
&& this.props.value.Attachments if (!isEqual(prevProps.value, this.props.value)) {
&& this.props.value.Attachments.length > 0 this.setState({
&& this.state.attachments.length == 0 attachments: this.props.value || [],
&& prevState.attachments.length == 0) { });
this.setState({ attachments: this.props.value.Attachments }); }
break;
case ControlMode.Display:
case ControlMode.Edit:
//Component Value property got updated from List State
if (this.props.value
&& this.props.value.Attachments
&& this.props.value.Attachments.length > 0
&& this.state.attachments.length == 0
&& prevState.attachments.length == 0) {
this.setState({ attachments: this.props.value.Attachments });
}
break;
} }
if (this.state.attachments.length < prevState.attachments.length) { if (this.state.attachments.length < prevState.attachments.length) {
this.props.valueChanged(this.state.attachments); this.props.valueChanged(this.state.attachments);
} }