From 21cec41c5bbdb37260f5be2e69cc247f5766e3d4 Mon Sep 17 00:00:00 2001 From: Lisa Knox Date: Mon, 4 Dec 2023 11:45:50 -0500 Subject: [PATCH 1/1] 21128: disabled trash button during async op Arvados-DCO-1.1-Signed-off-by: Lisa Knox --- src/store/favorites/favorites-actions.ts | 4 ++ src/store/multiselect/multiselect-actions.tsx | 4 +- .../project-panel-middleware-service.ts | 7 +++- .../public-favorites-actions.ts | 4 +- .../trash-panel-middleware-service.ts | 4 +- src/store/trash/trash-actions.ts | 9 +++-- .../multiselect-toolbar/ms-menu-actions.ts | 38 +++++++++---------- 7 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/store/favorites/favorites-actions.ts b/src/store/favorites/favorites-actions.ts index bd4d878e..a1667326 100644 --- a/src/store/favorites/favorites-actions.ts +++ b/src/store/favorites/favorites-actions.ts @@ -10,6 +10,8 @@ import { checkFavorite } from "./favorites-reducer"; import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions"; import { ServiceRepository } from "services/services"; import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions"; +import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { addDisabledButton, removeDisabledButton } from "store/multiselect/multiselect-actions"; export const favoritesActions = unionize({ TOGGLE_FAVORITE: ofType<{ resourceUuid: string }>(), @@ -26,6 +28,7 @@ export const toggleFavorite = (resource: { uuid: string; name: string }) => return Promise.reject("No user"); } dispatch(progressIndicatorActions.START_WORKING("toggleFavorite")); + dispatch(addDisabledButton(MultiSelectMenuActionNames.ADD_TO_FAVORITES)) dispatch(favoritesActions.TOGGLE_FAVORITE({ resourceUuid: resource.uuid })); const isFavorite = checkFavorite(resource.uuid, getState().favorites); dispatch(snackbarActions.OPEN_SNACKBAR({ @@ -50,6 +53,7 @@ export const toggleFavorite = (resource: { uuid: string; name: string }) => hideDuration: 2000, kind: SnackbarKind.SUCCESS })); + dispatch(removeDisabledButton(MultiSelectMenuActionNames.ADD_TO_FAVORITES)) dispatch(progressIndicatorActions.STOP_WORKING("toggleFavorite")); }) .catch((e: any) => { diff --git a/src/store/multiselect/multiselect-actions.tsx b/src/store/multiselect/multiselect-actions.tsx index 091d3ef6..9b564486 100644 --- a/src/store/multiselect/multiselect-actions.tsx +++ b/src/store/multiselect/multiselect-actions.tsx @@ -53,7 +53,7 @@ export const setSelectedUuid = (uuid: string | null) => { }; }; -export const setDisabledButton = (buttonName: string) => { +export const addDisabledButton = (buttonName: string) => { return dispatch => { dispatch({ type: multiselectActionContants.ADD_DISABLED, payload: buttonName }); }; @@ -72,6 +72,6 @@ export const multiselectActions = { deselectOne, toggleOne, setSelectedUuid, - setDisabledButton, + addDisabledButton, removeDisabledButton, }; diff --git a/src/store/project-panel/project-panel-middleware-service.ts b/src/store/project-panel/project-panel-middleware-service.ts index b72058d5..08eead97 100644 --- a/src/store/project-panel/project-panel-middleware-service.ts +++ b/src/store/project-panel/project-panel-middleware-service.ts @@ -35,6 +35,8 @@ import { updatePublicFavorites } from "store/public-favorites/public-favorites-a import { selectedFieldsOfGroup } from "models/group"; import { defaultCollectionSelectedFields } from "models/collection"; import { containerRequestFieldsNoMounts } from "models/container-request"; +import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { removeDisabledButton } from "store/multiselect/multiselect-actions"; export class ProjectPanelMiddlewareService extends DataExplorerMiddlewareService { constructor(private services: ServiceRepository, id: string) { @@ -76,7 +78,10 @@ export class ProjectPanelMiddlewareService extends DataExplorerMiddlewareService api.dispatch(couldNotFetchProjectContents()); } } finally { - if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); } + if (!background) { + api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); + api.dispatch(removeDisabledButton(MultiSelectMenuActionNames.ADD_TO_TRASH)) + } } } } diff --git a/src/store/public-favorites/public-favorites-actions.ts b/src/store/public-favorites/public-favorites-actions.ts index 7fb08788..5bf5078d 100644 --- a/src/store/public-favorites/public-favorites-actions.ts +++ b/src/store/public-favorites/public-favorites-actions.ts @@ -9,7 +9,7 @@ import { checkPublicFavorite } from "./public-favorites-reducer"; import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions"; import { ServiceRepository } from "services/services"; import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions"; -import { setDisabledButton, removeDisabledButton } from "store/multiselect/multiselect-actions"; +import { addDisabledButton, removeDisabledButton } from "store/multiselect/multiselect-actions"; import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; export const publicFavoritesActions = unionize({ @@ -23,7 +23,7 @@ export type PublicFavoritesAction = UnionOf; export const togglePublicFavorite = (resource: { uuid: string; name: string }) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise => { dispatch(progressIndicatorActions.START_WORKING("togglePublicFavorite")); - dispatch(setDisabledButton(MultiSelectMenuActionNames.ADD_TO_PUBLIC_FAVORITES)) + dispatch(addDisabledButton(MultiSelectMenuActionNames.ADD_TO_PUBLIC_FAVORITES)) const uuidPrefix = getState().auth.config.uuidPrefix; const uuid = `${uuidPrefix}-j7d0g-publicfavorites`; dispatch(publicFavoritesActions.TOGGLE_PUBLIC_FAVORITE({ resourceUuid: resource.uuid })); diff --git a/src/store/trash-panel/trash-panel-middleware-service.ts b/src/store/trash-panel/trash-panel-middleware-service.ts index d72b6ad7..8b760ebb 100644 --- a/src/store/trash-panel/trash-panel-middleware-service.ts +++ b/src/store/trash-panel/trash-panel-middleware-service.ts @@ -27,7 +27,8 @@ import { serializeResourceTypeFilters } from 'store//resource-type-filters/resou import { getDataExplorerColumnFilters } from 'store/data-explorer/data-explorer-middleware-service'; import { joinFilters } from 'services/api/filter-builder'; import { CollectionResource } from "models/collection"; - +import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { removeDisabledButton } from "store/multiselect/multiselect-actions"; export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService { constructor(private services: ServiceRepository, id: string) { super(id); @@ -84,6 +85,7 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService { })); api.dispatch(couldNotFetchTrashContents()); } + api.dispatch(removeDisabledButton(MultiSelectMenuActionNames.ADD_TO_TRASH)) } } diff --git a/src/store/trash/trash-actions.ts b/src/store/trash/trash-actions.ts index 62b66922..50ac31c8 100644 --- a/src/store/trash/trash-actions.ts +++ b/src/store/trash/trash-actions.ts @@ -13,6 +13,8 @@ import { sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with import { ResourceKind } from "models/resource"; import { navigateTo, navigateToTrash } from "store/navigation/navigation-action"; import { matchCollectionRoute, matchSharedWithMeRoute } from "routes/routes"; +import { MultiSelectMenuActionNames } from "views-components/multiselect-toolbar/ms-menu-actions"; +import { addDisabledButton } from "store/multiselect/multiselect-actions"; export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean, isMulti: boolean) => @@ -20,11 +22,12 @@ export const toggleProjectTrashed = let errorMessage = ""; let successMessage = ""; let untrashedResource; + dispatch(addDisabledButton(MultiSelectMenuActionNames.ADD_TO_TRASH)) try { if (isTrashed) { errorMessage = "Could not restore project from trash"; successMessage = "Restored project from trash"; - untrashedResource = await services.groupsService.untrash(uuid); + untrashedResource = await services.groupsService.untrash(uuid); dispatch(isMulti || !untrashedResource ? navigateToTrash : navigateTo(uuid)); dispatch(activateSidePanelTreeItem(uuid)); } else { @@ -32,7 +35,7 @@ export const toggleProjectTrashed = successMessage = "Added project to trash"; await services.groupsService.trash(uuid); dispatch(loadSidePanelTreeProjects(ownerUuid)); - + const { location } = getState().router; if (matchSharedWithMeRoute(location ? location.pathname : "")) { dispatch(sharedWithMePanelActions.REQUEST_ITEMS()); @@ -42,7 +45,7 @@ export const toggleProjectTrashed = } } if (untrashedResource) { - dispatch( + dispatch( snackbarActions.OPEN_SNACKBAR({ message: successMessage, hideDuration: 2000, diff --git a/src/views-components/multiselect-toolbar/ms-menu-actions.ts b/src/views-components/multiselect-toolbar/ms-menu-actions.ts index e5673453..b01a5e17 100644 --- a/src/views-components/multiselect-toolbar/ms-menu-actions.ts +++ b/src/views-components/multiselect-toolbar/ms-menu-actions.ts @@ -20,25 +20,25 @@ import { togglePublicFavorite } from "store/public-favorites/public-favorites-ac import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action"; import { PublicFavoritesState } from 'store/public-favorites/public-favorites-reducer'; -export const MultiSelectMenuActionNames: Record = { - ADD_TO_FAVORITES: 'Add to Favorites', - ADD_TO_TRASH: 'Add to Trash', - ADD_TO_PUBLIC_FAVORITES: 'Add to public favorites', - API_DETAILS: 'API Details', - COPY_AND_RERUN_PROCESS: 'Copy and re-run process', - COPY_TO_CLIPBOARD: 'Copy to clipboard', - DELETE_WORKFLOW: 'Delete Worflow', - EDIT_PPROJECT: 'Edit project', - FREEZE_PROJECT: 'Freeze Project', - MAKE_A_COPY: 'Make a copy', - MOVE_TO: 'Move to', - NEW_PROJECT: 'New project', - OPEN_IN_NEW_TAB: 'Open in new tab', - OPEN_W_3RD_PARTY_CLIENT: 'Open with 3rd party client', - REMOVE: 'Remove', - RUN_WORKFLOW: 'Run Workflow', - SHARE: 'Share', - VIEW_DETAILS: 'View details', +export enum MultiSelectMenuActionNames { + ADD_TO_FAVORITES = 'Add to Favorites', + ADD_TO_TRASH = 'Add to Trash', + ADD_TO_PUBLIC_FAVORITES = 'Add to public favorites', + API_DETAILS = 'API Details', + COPY_AND_RERUN_PROCESS = 'Copy and re-run process', + COPY_TO_CLIPBOARD = 'Copy to clipboard', + DELETE_WORKFLOW = 'Delete Worflow', + EDIT_PPROJECT = 'Edit project', + FREEZE_PROJECT = 'Freeze Project', + MAKE_A_COPY = 'Make a copy', + MOVE_TO = 'Move to', + NEW_PROJECT = 'New project', + OPEN_IN_NEW_TAB = 'Open in new tab', + OPEN_W_3RD_PARTY_CLIENT = 'Open with 3rd party client', + REMOVE = 'Remove', + RUN_WORKFLOW = 'Run Workflow', + SHARE = 'Share', + VIEW_DETAILS = 'View details', }; export type MultiSelectMenuAction = { -- 2.30.2