From 950eaf2d4340cfd80863282d6aa90f60ef4a06ad Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Fri, 10 Jul 2020 11:39:55 +0300 Subject: [PATCH] Web: Files: Home: Fixed init styled RowContent outside render --- .../Home/Section/Body/FilesRowContent.js | 479 +++++++++--------- 1 file changed, 239 insertions(+), 240 deletions(-) diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Body/FilesRowContent.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Body/FilesRowContent.js index 35a81b6219..7731ff75d9 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Body/FilesRowContent.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Body/FilesRowContent.js @@ -15,6 +15,43 @@ import EditingWrapperComponent from "./EditingWrapperComponent"; const { FileAction } = constants; +const SimpleFilesRowContent = styled(RowContent)` +.badge-ext { + margin-left: -8px; + margin-right: 8px; +} + +.badge { + height: 14px; + width: 14px; + margin-right: 8px; +} + +.badges { + display: flex; + align-items: center; +} + +.share-icon { + margin-top: -4px; + padding-right: 8px; +} +`; + +const okIcon = ; + +const cancelIcon = ; + class FilesRowContent extends React.PureComponent { constructor(props) { @@ -191,15 +228,15 @@ class FilesRowContent extends React.PureComponent { const { item, treeFolders, setTreeFolders, rootFolderId, newItems, filter } = this.props; if (item.fileExst) { api.files - .markAsRead([], [item.id]) - .then(() => { - const data = treeFolders; - const dataItem = data.find((x) => x.id === rootFolderId); - dataItem.newItems = newItems ? dataItem.newItems - 1 : 0;//////newItems - setTreeFolders(data); - fetchFiles(this.props.selectedFolder.id, filter.clone(), store.dispatch); - }) - .catch((err) => toastr.error(err)) + .markAsRead([], [item.id]) + .then(() => { + const data = treeFolders; + const dataItem = data.find((x) => x.id === rootFolderId); + dataItem.newItems = newItems ? dataItem.newItems - 1 : 0;//////newItems + setTreeFolders(data); + fetchFiles(this.props.selectedFolder.id, filter.clone(), store.dispatch); + }) + .catch((err) => toastr.error(err)) } else { const newFolderId = this.props.selectedFolder.pathParts; newFolderId.push(item.id); @@ -212,39 +249,39 @@ class FilesRowContent extends React.PureComponent { onShowNewFilesPanel = () => { const { showNewFilesPanel } = this.state; - this.setState({showNewFilesPanel: !showNewFilesPanel}); + this.setState({ showNewFilesPanel: !showNewFilesPanel }); }; setConvertDialogVisible = () => this.setState({ showConvertDialog: !this.state.showConvertDialog }); - getConvertProgress = fileId => { - api.files.getConvertFile(fileId).then(res => { - if(res && res[0] && res[0].progress !== 100) { - this.props.setProgressValue(res[0].progress); - setTimeout(() => this.getConvertProgress(fileId), 1000); + getConvertProgress = fileId => { + api.files.getConvertFile(fileId).then(res => { + if (res && res[0] && res[0].progress !== 100) { + this.props.setProgressValue(res[0].progress); + setTimeout(() => this.getConvertProgress(fileId), 1000); + } else { + const { selectedFolder, filter, onLoading, setProgressValue, finishFilesOperations } = this.props; + if (res[0].error) { + finishFilesOperations(res[0].error); } else { - const { selectedFolder, filter, onLoading, setProgressValue, finishFilesOperations } = this.props; - if(res[0].error) { - finishFilesOperations(res[0].error); - } else { - setProgressValue(100); - finishFilesOperations(); - const newFilter = filter.clone(); - fetchFiles(selectedFolder.id, newFilter, store.dispatch) - .catch(err => toastr.error(err)) - .finally(() => onLoading(false)); - } + setProgressValue(100); + finishFilesOperations(); + const newFilter = filter.clone(); + fetchFiles(selectedFolder.id, newFilter, store.dispatch) + .catch(err => toastr.error(err)) + .finally(() => onLoading(false)); } - }); - } - + } + }); + } + onConvert = () => { const { item, startFilesOperations, t } = this.props; startFilesOperations(t("Convert")); - this.setState({showConvertDialog: false}, () => + this.setState({ showConvertDialog: false }, () => api.files.convertFile(item.id).then(convertRes => { - if(convertRes && convertRes[0] && convertRes[0].progress !== 100) { + if (convertRes && convertRes[0] && convertRes[0].progress !== 100) { this.getConvertProgress(item.id); } }) @@ -266,49 +303,12 @@ class FilesRowContent extends React.PureComponent { versionGroup } = item; - const SimpleFilesRowContent = styled(RowContent)` - .badge-ext { - margin-left: -8px; - margin-right: 8px; - } - - .badge { - height: 14px; - width: 14px; - margin-right: 8px; - } - - .badges { - display: flex; - align-items: center; - } - - .share-icon { - margin-top: -4px; - padding-right: 8px; - } - `; - const titleWithoutExt = getTitleWithoutExst(item); const fileOwner = createdBy && ((this.props.viewer.id === createdBy.id && t("AuthorMe")) || createdBy.displayName); const updatedDate = updated && this.getStatusByDate(); const canEditFile = fileExst && canWebEdit(fileExst); const canConvertFile = fileExst && canConvert(fileExst); - const okIcon = ; - - const cancelIcon = ; - const isEdit = (id === editingId) && (fileExst === fileAction.extension); const linkStyles = isTrashFolder ? { noHover: true } : { onClick: this.onFilesClick }; const showNew = item.new && item.new > 0; @@ -325,179 +325,178 @@ class FilesRowContent extends React.PureComponent { cancelUpdateItem={this.cancelUpdateItem} /> : ( - <> - {showConvertDialog && ( - - )} - {showNewFilesPanel && ( - - )} - - + {showConvertDialog && ( + + )} + {showNewFilesPanel && ( + + )} + - {titleWithoutExt} - - <> - {fileExst ? -
- - {fileExst} - - {canConvertFile && - - } - {canEditFile && - - } - {fileStatus === 1 && - - } - {false && - - } - {versionGroup > 1 && - - } - {fileStatus === 2 && - - } -
- : -
- { !!showNew && - - } -
- } - - - {fileOwner} - - { }} - isTextOverflow={true} - > - {updatedDate && updatedDate} - - - {fileExst - ? contentLength - : `${t("TitleDocuments")}: ${filesCount} / ${t("TitleSubfolders")}: ${foldersCount}`} - -
+ + {titleWithoutExt} + + <> + {fileExst ? +
+ + {fileExst} + + {canConvertFile && + + } + {canEditFile && + + } + {fileStatus === 1 && + + } + {false && + + } + {versionGroup > 1 && + + } + {fileStatus === 2 && + + } +
+ : +
+ {!!showNew && + + } +
+ } + + + {fileOwner} + + + {updatedDate && updatedDate} + + + {fileExst + ? contentLength + : `${t("TitleDocuments")}: ${filesCount} / ${t("TitleSubfolders")}: ${foldersCount}`} + +
) }