From 746094957b7321ce19f82574e71e66120c726ea3 Mon Sep 17 00:00:00 2001 From: Aleksandr Lushkin Date: Thu, 13 Jun 2024 14:45:33 +0200 Subject: [PATCH] Client: Add showing error if trying export index before previous one has completed --- packages/client/public/locales/en/Files.json | 1 + .../client/src/store/ContextOptionsStore.js | 69 +------------- .../client/src/store/FilesActionsStore.js | 91 ++++++++++++++++++- 3 files changed, 94 insertions(+), 67 deletions(-) diff --git a/packages/client/public/locales/en/Files.json b/packages/client/public/locales/en/Files.json index 014c7ff0d5..13b91652b2 100644 --- a/packages/client/public/locales/en/Files.json +++ b/packages/client/public/locales/en/Files.json @@ -68,6 +68,7 @@ "EnableNotifications": "Enable notifications", "ExcludeSubfolders": "Exclude subfolders", "ExportRoomIndex": "Export room index", + "ExportRoomIndexAlreadyInProgressError": "Room index export is already in progress. Please wait until the current export is completed to start the new one.", "FavoritesEmptyContainerDescription": "To mark files as favorites or remove them from this list, use the context menu.", "FileContents": "File contents", "FileDownloadingIsRestricted": "File downloading is restricted in this room.", diff --git a/packages/client/src/store/ContextOptionsStore.js b/packages/client/src/store/ContextOptionsStore.js index 4459473531..00d3b6a8aa 100644 --- a/packages/client/src/store/ContextOptionsStore.js +++ b/packages/client/src/store/ContextOptionsStore.js @@ -96,11 +96,7 @@ import { getDefaultAccessUser } from "@docspace/shared/utils/getDefaultAccessUse import { copyShareLink } from "@docspace/shared/utils/copy"; import { connectedCloudsTypeTitleTranslation } from "@docspace/client/src/helpers/filesUtils"; -import { - getOAuthToken, - hideLoader, - showLoader, -} from "@docspace/shared/utils/common"; +import { getOAuthToken } from "@docspace/shared/utils/common"; import api from "@docspace/shared/api"; import { RoomsType, @@ -109,14 +105,12 @@ import { UrlActionType, EmployeeType, FilesSelectorFilterTypes, - ExportRoomIndexTaskStatus, } from "@docspace/shared/enums"; import FilesFilter from "@docspace/shared/api/files/filter"; import { getFileLink, getFolderLink } from "@docspace/shared/api/files"; import { resendInvitesAgain } from "@docspace/shared/api/people"; import { checkDialogsOpen } from "@docspace/shared/utils/checkDialogsOpen"; import { PRODUCT_NAME } from "@docspace/shared/constants"; -import { showSuccessExportRoomIndexToast } from "SRC_DIR/helpers/toast-helpers"; const LOADER_TIMER = 500; let loadingTime; @@ -899,65 +893,8 @@ class ContextOptionsStore { this.filesActionsStore.setMuteAction(action, item, t); }; - checkExportRoomIndexProgress = async () => { - return await new Promise((resolve, reject) => { - setTimeout(async () => { - try { - const res = await api.rooms.getExportRoomIndexProgress(); - - resolve(res); - } catch (e) { - reject(e); - } - }, 1000); - }); - }; - - loopExportRoomIndexStatusChecking = async () => { - let isCompleted = false; - let res; - - while (!isCompleted) { - res = await this.checkExportRoomIndexProgress(); - - if (res?.isCompleted) { - isCompleted = true; - } - } - - return res; - }; - - onSuccessExportRoomIndex = (t, fileName, fileUrl) => { - const { openOnNewPage } = this.filesSettingsStore; - const urlWithProxy = combineUrl(window.DocSpaceConfig?.proxy?.url, fileUrl); - - showSuccessExportRoomIndexToast(t, fileName, urlWithProxy, openOnNewPage); - }; - - onExportRoomIndex = async (t, roomId) => { - try { - showLoader(); - - let res = await api.rooms.exportRoomIndex(roomId); - - if (!res.isCompleted) { - res = await this.loopExportRoomIndexStatusChecking(); - } - - if (res.status === ExportRoomIndexTaskStatus.Failed) { - toastr.error(res.error); - return; - } - - if (res.status === ExportRoomIndexTaskStatus.Completed) { - this.onSuccessExportRoomIndex(t, res.resultFileName, res.resultFileUrl); - } - } catch (e) { - toastr.error(e); - } finally { - hideLoader(); - } + onExportRoomIndex = (t, roomId) => { + this.filesActionsStore.exportRoomIndex(t, roomId); }; onClickRemoveFromRecent = (item) => { diff --git a/packages/client/src/store/FilesActionsStore.js b/packages/client/src/store/FilesActionsStore.js index 48116dcb1c..c03b94ff88 100644 --- a/packages/client/src/store/FilesActionsStore.js +++ b/packages/client/src/store/FilesActionsStore.js @@ -58,6 +58,7 @@ import { import { ConflictResolveType, Events, + ExportRoomIndexTaskStatus, FileAction, FileStatus, FolderType, @@ -78,7 +79,11 @@ import { CategoryType } from "SRC_DIR/helpers/constants"; import RoomsFilter from "@docspace/shared/api/rooms/filter"; import AccountsFilter from "@docspace/shared/api/people/filter"; import { RoomSearchArea, UrlActionType } from "@docspace/shared/enums"; -import { getObjectByLocation } from "@docspace/shared/utils/common"; +import { + getObjectByLocation, + hideLoader, + showLoader, +} from "@docspace/shared/utils/common"; import uniqueid from "lodash/uniqueId"; import FilesFilter from "@docspace/shared/api/files/filter"; import { @@ -87,6 +92,8 @@ import { } from "SRC_DIR/helpers/utils"; import { MEDIA_VIEW_URL } from "@docspace/shared/constants"; import { openingNewTab } from "@docspace/shared/utils/openingNewTab"; +import api from "@docspace/shared/api"; +import { showSuccessExportRoomIndexToast } from "SRC_DIR/helpers/toast-helpers"; class FilesActionStore { settingsStore; @@ -110,6 +117,7 @@ class FilesActionStore { isGroupMenuBlocked = false; emptyTrashInProgress = false; processCreatingRoomFromData = false; + alreadyExportingRoomIndex = false; constructor( settingsStore, @@ -2745,6 +2753,87 @@ class FilesActionStore { .itemOperationToFolder(operationData) .catch((error) => toastr.error(error)); }; + + checkExportRoomIndexProgress = async () => { + return await new Promise((resolve, reject) => { + setTimeout(async () => { + try { + const res = await api.rooms.getExportRoomIndexProgress(); + + resolve(res); + } catch (e) { + reject(e); + } + }, 1000); + }); + }; + + loopExportRoomIndexStatusChecking = async () => { + let isCompleted = false; + let res; + + while (!isCompleted) { + res = await this.checkExportRoomIndexProgress(); + + if (res?.isCompleted) { + isCompleted = true; + } + } + + return res; + }; + + checkPreviousExportRoomIndexInProgress = async () => { + if (this.alreadyExportingRoomIndex) { + return true; + } + + const previousExport = await api.rooms.getExportRoomIndexProgress(); + + return previousExport && !previousExport.isCompleted; + }; + + onSuccessExportRoomIndex = (t, fileName, fileUrl) => { + const { openOnNewPage } = this.filesSettingsStore; + const urlWithProxy = combineUrl(window.DocSpaceConfig?.proxy?.url, fileUrl); + + showSuccessExportRoomIndexToast(t, fileName, urlWithProxy, openOnNewPage); + }; + + exportRoomIndex = async (t, roomId) => { + try { + showLoader(); + + const previousExportInProgress = + await this.checkPreviousExportRoomIndexInProgress(); + + if (previousExportInProgress) { + return toastr.error(t("Files:ExportRoomIndexAlreadyInProgressError")); + } + + this.alreadyExportingRoomIndex = true; + + let res = await api.rooms.exportRoomIndex(roomId); + + if (!res.isCompleted) { + res = await this.loopExportRoomIndexStatusChecking(); + } + + if (res.status === ExportRoomIndexTaskStatus.Failed) { + toastr.error(res.error); + return; + } + + if (res.status === ExportRoomIndexTaskStatus.Completed) { + this.onSuccessExportRoomIndex(t, res.resultFileName, res.resultFileUrl); + } + } catch (e) { + toastr.error(e); + } finally { + this.alreadyExportingRoomIndex = false; + hideLoader(); + } + }; } export default FilesActionStore;