Web: Files: SelectFolderInput/SelectFileInput: Extended the component by adding a reset function to default values.

This commit is contained in:
Tatiana Lopaeva 2021-10-11 09:38:08 +03:00
parent d83a400e0c
commit 965153850c
2 changed files with 70 additions and 22 deletions

View File

@ -71,13 +71,17 @@ class SelectFolderModalDialog extends React.Component {
}
componentDidUpdate(prevProps) {
const { storeFolderId, canCreate, showButtons } = this.props;
const { storeFolderId, canCreate, showButtons, isReset } = this.props;
if (showButtons && storeFolderId !== prevProps.storeFolderId) {
this.setState({
canCreate: canCreate,
isLoading: false,
});
}
if (isReset && isReset !== prevProps.isReset) {
this.onResetInfo();
}
}
trySwitch = async () => {
const {
@ -347,9 +351,18 @@ class SelectFolderModalDialog extends React.Component {
};
onSelect = async (folder) => {
const { onSelectFolder, onClose, showButtons, onSetFullPath } = this.props;
const { folderId } = this.state;
const {
onSelectFolder,
onClose,
showButtons,
onSetFullPath,
onSetLoadingData,
onSetLoadingInput,
} = this.props;
const { folderId } = this.state;
onSetLoadingData && onSetLoadingData(true);
onSetLoadingInput && onSetLoadingInput(true);
let requests = [];
if (isArrayEqual([folder[0]], [folderId])) {
@ -414,6 +427,57 @@ class SelectFolderModalDialog extends React.Component {
onSave && onSave(e, folderId);
onClose && onClose();
};
onResetInfo = async () => {
//debugger;
const { id, foldersType, onSelectFolder, onSetFullPath } = this.props;
switch (foldersType) {
case "common":
try {
if (!id) {
folderList = await SelectFolderDialog.getCommonFolders();
}
onSelectFolder && onSelectFolder(`${id ? id : folderList[0].id}`);
this.setState({
folderId: `${id ? id : folderList[0].id}`,
});
onSetFullPath("");
this.loadersCompletes();
} catch (err) {
console.error(err);
this.loadersCompletes();
}
break;
case "third-party":
try {
if (!id) {
folderList = await SelectFolderDialog.getCommonThirdPartyList();
}
onSelectFolder && onSelectFolder(`${id ? id : folderList[0].id}`);
this.setState({
folderId: `${id ? id : folderList[0].id}`,
});
onSetFullPath("");
this.loadersCompletes();
} catch (err) {
console.error(err);
this.loadersCompletes();
}
break;
}
};
render() {
const {
t,
@ -622,6 +686,7 @@ class SelectFolderDialog extends React.Component {
}
return newArray;
};
render() {
return (
<MobxProvider auth={authStore} {...stores}>

View File

@ -33,25 +33,6 @@ class SelectFolderInputBody extends React.PureComponent {
setFirstLoad(false);
}
componentDidUpdate(prevProps) {
const { isSetDefaultFolderPath, folderPath } = this.props;
if (
isSetDefaultFolderPath &&
isSetDefaultFolderPath !== prevProps.isSetDefaultFolderPath
) {
this.setState({
fullFolderPath: this.state.fullFolderPathDefault,
});
}
if (folderPath !== prevProps.folderPath) {
this.setState({
fullFolderPath: folderPath,
fullFolderPathDefault: folderPath,
});
}
}
onSetFullPath = (pathName) => {
this.setState({
fullFolderPath: pathName,
@ -98,6 +79,7 @@ class SelectFolderInputBody extends React.PureComponent {
footer,
fontSizeInput,
maxInputWidth,
isReset,
} = this.props;
const { isLoading, baseFolderPath, fullFolderPath } = this.state;
@ -138,6 +120,7 @@ class SelectFolderInputBody extends React.PureComponent {
header={header}
headerName={headerName}
footer={footer}
isReset={isReset}
/>
</StyledComponent>
);