From ea8d5b471d5bb4492b2c1171f9b72bab20757c63 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 23 Dec 2020 12:09:30 +0300 Subject: [PATCH] Web: Files: Fixed document type definitions in download us dialog --- .../dialogs/DownloadDialog/index.js | 40 ++++--------------- .../Client/src/store/files/selectors.js | 36 +++++++++++++++++ 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/products/ASC.Files/Client/src/components/dialogs/DownloadDialog/index.js b/products/ASC.Files/Client/src/components/dialogs/DownloadDialog/index.js index 3963d14c91..e7ed371917 100644 --- a/products/ASC.Files/Client/src/components/dialogs/DownloadDialog/index.js +++ b/products/ASC.Files/Client/src/components/dialogs/DownloadDialog/index.js @@ -16,10 +16,7 @@ import { utils, api, toastr } from "asc-web-common"; import { getFileIcon, getFolderIcon, - isSpreadsheet, - isPresentation, - isDocument, - getSelection, + getSortedFiles, } from "../../../store/files/selectors"; import { setSecondaryProgressBarData, @@ -52,38 +49,15 @@ const formatKeys = Object.freeze({ class DownloadDialogComponent extends React.Component { constructor(props) { super(props); + const { sortedFiles } = this.props; changeLanguage(i18n); - const documents = []; - const spreadsheets = []; - const presentations = []; - const other = []; - - for (let item of props.items) { - item.checked = true; - item.format = formatKeys.OriginalFormat; - - if (item.fileExst) { - if (isSpreadsheet(item.fileExst)) { - spreadsheets.push(item); - } else if (isPresentation(item.fileExst)) { - presentations.push(item); - } else if (item.fileExst !== ".pdf" && isDocument(item.fileExst)) { - documents.push(item); - } else { - other.push(item); - } - } else { - other.push(item); - } - } - this.state = { - documents, - spreadsheets, - presentations, - other, + documents: sortedFiles.documents, + spreadsheets: sortedFiles.spreadsheets, + presentations: sortedFiles.presentations, + other: sortedFiles.other, documentsTitleFormat: formatKeys.OriginalFormat, spreadsheetsTitleFormat: formatKeys.OriginalFormat, @@ -631,7 +605,7 @@ const DownloadDialog = (props) => ( const mapStateToProps = (state) => { return { - items: getSelection(state), + sortedFiles: getSortedFiles(state), }; }; diff --git a/products/ASC.Files/Client/src/store/files/selectors.js b/products/ASC.Files/Client/src/store/files/selectors.js index 921a2038cd..6b54d5138f 100644 --- a/products/ASC.Files/Client/src/store/files/selectors.js +++ b/products/ASC.Files/Client/src/store/files/selectors.js @@ -1239,3 +1239,39 @@ export const isSecondaryProgressFinished = createSelector( return data && data.percent === 100; } ); + +export const getSortedFiles = (state) => { + const formatKeys = Object.freeze({ + OriginalFormat: 0, + }); + + const items = getSelection(state); + + let sortedFiles = { + documents: [], + spreadsheets: [], + presentations: [], + other: [], + }; + + for (let item of items) { + item.checked = true; + item.format = formatKeys.OriginalFormat; + + if (item.fileExst) { + if (isSpreadsheet(item.fileExst)(state)) { + sortedFiles.spreadsheets.push(item); + } else if (isPresentation(item.fileExst)(state)) { + sortedFiles.presentations.push(item); + } else if (item.fileExst !== ".pdf" && canWebEdit(item.fileExst)(state)) { + sortedFiles.documents.push(item); + } else { + sortedFiles.other.push(item); + } + } else { + sortedFiles.other.push(item); + } + } + + return sortedFiles; +};