X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/859bae14d31fe063ed1204be7300083b3216de60..b831639582bf6ffc96566424dc5b5168a5c54a0f:/src/views-components/context-menu/action-sets/collection-action-set.ts diff --git a/src/views-components/context-menu/action-sets/collection-action-set.ts b/src/views-components/context-menu/action-sets/collection-action-set.ts index fec40794..264ca5c0 100644 --- a/src/views-components/context-menu/action-sets/collection-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-action-set.ts @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { ContextMenuAction, ContextMenuActionSet } from '../context-menu-action-set'; -import { ToggleFavoriteAction } from '../actions/favorite-action'; -import { toggleFavorite } from 'store/favorites/favorites-actions'; +import { ContextMenuActionItem, ContextMenuActionItemSet } from "../context-menu-action-set"; +import { ToggleFavoriteAction } from "../actions/favorite-action"; +import { toggleFavorite } from "store/favorites/favorites-actions"; import { RenameIcon, ShareIcon, @@ -16,148 +16,151 @@ import { Link, RestoreVersionIcon, FolderSharedIcon, -} from 'components/icon/icon'; -import { openCollectionUpdateDialog } from 'store/collections/collection-update-actions'; -import { favoritePanelActions } from 'store/favorite-panel/favorite-panel-action'; -import { openMoveCollectionDialog } from 'store/collections/collection-move-actions'; -import { openCollectionCopyDialog } from 'store/collections/collection-copy-actions'; -import { openWebDavS3InfoDialog } from 'store/collections/collection-info-actions'; -import { ToggleTrashAction } from 'views-components/context-menu/actions/trash-action'; -import { toggleCollectionTrashed } from 'store/trash/trash-actions'; -import { openSharingDialog } from 'store/sharing-dialog/sharing-dialog-actions'; -import { openAdvancedTabDialog } from 'store/advanced-tab/advanced-tab'; -import { toggleDetailsPanel } from 'store/details-panel/details-panel-action'; -import { copyToClipboardAction, openInNewTabAction } from 'store/open-in-new-tab/open-in-new-tab.actions'; -import { openRestoreCollectionVersionDialog } from 'store/collections/collection-version-actions'; -import { TogglePublicFavoriteAction } from '../actions/public-favorite-action'; -import { togglePublicFavorite } from 'store/public-favorites/public-favorites-actions'; -import { publicFavoritePanelActions } from 'store/public-favorites-panel/public-favorites-action'; -import { ContextMenuResource } from 'store/context-menu/context-menu-actions'; +} from "components/icon/icon"; +import { openCollectionUpdateDialog } from "store/collections/collection-update-actions"; +import { favoritePanelActions } from "store/favorite-panel/favorite-panel-action"; +import { openMoveCollectionDialog } from "store/collections/collection-move-actions"; +import { openCollectionCopyDialog, openMultiCollectionCopyDialog } from "store/collections/collection-copy-actions"; +import { openWebDavS3InfoDialog } from "store/collections/collection-info-actions"; +import { ToggleTrashAction } from "views-components/context-menu/actions/trash-action"; +import { toggleCollectionTrashed } from "store/trash/trash-actions"; +import { openSharingDialog } from "store/sharing-dialog/sharing-dialog-actions"; +import { openAdvancedTabDialog } from "store/advanced-tab/advanced-tab"; +import { toggleDetailsPanel } from "store/details-panel/details-panel-action"; +import { copyToClipboardAction, openInNewTabAction } from "store/open-in-new-tab/open-in-new-tab.actions"; +import { openRestoreCollectionVersionDialog } from "store/collections/collection-version-actions"; +import { TogglePublicFavoriteAction } from "../actions/public-favorite-action"; +import { togglePublicFavorite } from "store/public-favorites/public-favorites-actions"; +import { publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action"; +import { ContextMenuResource } from "store/context-menu/context-menu-actions"; -const toggleFavoriteAction: ContextMenuAction = { +const toggleFavoriteAction: ContextMenuActionItem = { component: ToggleFavoriteAction, - name: 'ToggleFavoriteAction', + name: "ToggleFavoriteAction", execute: (dispatch, resources) => { - resources.forEach((resource) => + for (const resource of [...resources]) { dispatch(toggleFavorite(resource)).then(() => { dispatch(favoritePanelActions.REQUEST_ITEMS()); - }) - ); + }); + } }, }; - -const commonActionSet: ContextMenuActionSet = [ +const commonActionSet: ContextMenuActionItemSet = [ [ { icon: OpenIcon, - name: 'Open in new tab', - execute: (dispatch, resource) => { - dispatch(openInNewTabAction(resource)); + name: "Open in new tab", + execute: (dispatch, resources) => { + dispatch(openInNewTabAction(resources[0])); }, }, { icon: Link, - name: 'Copy to clipboard', - execute: (dispatch, resource) => { - dispatch(copyToClipboardAction(resource)); + name: "Copy to clipboard", + execute: (dispatch, resources) => { + dispatch(copyToClipboardAction(resources)); }, }, { icon: CopyIcon, - name: 'Make a copy', + name: "Make a copy", execute: (dispatch, resources) => { - resources.forEach((resource) => dispatch(openCollectionCopyDialog(resource))); + if (resources[0].fromContextMenu || resources.length === 1) dispatch(openCollectionCopyDialog(resources[0])); + else dispatch(openMultiCollectionCopyDialog(resources[0])); }, }, { icon: DetailsIcon, - name: 'View details', - execute: (dispatch) => { + name: "View details", + execute: dispatch => { dispatch(toggleDetailsPanel()); }, }, { icon: AdvancedIcon, - name: 'API Details', + name: "API Details", execute: (dispatch, resources) => { - resources.forEach((resource) => dispatch(openAdvancedTabDialog(resource.uuid))); + dispatch(openAdvancedTabDialog(resources[0].uuid)); }, }, ], ]; -export const readOnlyCollectionActionSet: ContextMenuActionSet = [ +export const readOnlyCollectionActionSet: ContextMenuActionItemSet = [ [ ...commonActionSet.reduce((prev, next) => prev.concat(next), []), toggleFavoriteAction, { icon: FolderSharedIcon, - name: 'Open with 3rd party client', + name: "Open with 3rd party client", execute: (dispatch, resources) => { - resources.forEach((resource) => dispatch(openWebDavS3InfoDialog(resource.uuid))); + dispatch(openWebDavS3InfoDialog(resources[0].uuid)); }, }, ], ]; -export const collectionActionSet: ContextMenuActionSet = [ +export const collectionActionSet: ContextMenuActionItemSet = [ [ ...readOnlyCollectionActionSet.reduce((prev, next) => prev.concat(next), []), { icon: RenameIcon, - name: 'Edit collection', + name: "Edit collection", execute: (dispatch, resources) => { - resources.forEach((resource) => dispatch(openCollectionUpdateDialog(resource))); + dispatch(openCollectionUpdateDialog(resources[0])); }, }, { icon: ShareIcon, - name: 'Share', + name: "Share", execute: (dispatch, resources) => { - resources.forEach(({ uuid }) => dispatch(openSharingDialog(uuid))); + dispatch(openSharingDialog(resources[0].uuid)); }, }, { icon: MoveToIcon, - name: 'Move to', - execute: (dispatch, resources) => resources.forEach((resource) => dispatch(openMoveCollectionDialog(resource))), + name: "Move to", + execute: (dispatch, resources) => dispatch(openMoveCollectionDialog(resources[0])), }, { component: ToggleTrashAction, - name: 'ToggleTrashAction', - // execute: (dispatch, resource) => { + name: "ToggleTrashAction", execute: (dispatch, resources: ContextMenuResource[]) => { - resources.forEach((resource) => dispatch(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!))); + for (const resource of [...resources]) { + dispatch(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!)); + } }, }, ], ]; -export const collectionAdminActionSet: ContextMenuActionSet = [ +export const collectionAdminActionSet: ContextMenuActionItemSet = [ [ ...collectionActionSet.reduce((prev, next) => prev.concat(next), []), { component: TogglePublicFavoriteAction, - name: 'TogglePublicFavoriteAction', + name: "TogglePublicFavoriteAction", execute: (dispatch, resources) => { - resources.forEach((resource) => + for (const resource of [...resources]) { dispatch(togglePublicFavorite(resource)).then(() => { dispatch(publicFavoritePanelActions.REQUEST_ITEMS()); - }) - ); + }); + } }, }, ], ]; -export const oldCollectionVersionActionSet: ContextMenuActionSet = [ +export const oldCollectionVersionActionSet: ContextMenuActionItemSet = [ [ ...commonActionSet.reduce((prev, next) => prev.concat(next), []), { icon: RestoreVersionIcon, - name: 'Restore version', + name: "Restore version", execute: (dispatch, resources) => { - resources.forEach(({ uuid }) => dispatch(openRestoreCollectionVersionDialog(uuid))); + for (const resource of [...resources]) { + dispatch(openRestoreCollectionVersionDialog(resource.uuid)); + } }, }, ],