[arvados-workbench2] updated: 2.6.0-17-gf3d18482

git repository hosting git at public.arvados.org
Tue May 23 23:43:02 UTC 2023


Summary of changes:
 src/components/icon/icon.tsx                       |   9 ++
 .../collection-panel-files-state.ts                |  16 +++
 .../collections/collection-partial-copy-actions.ts | 154 +++++++++++---------
 .../collections/collection-partial-move-actions.ts | 160 ++++++++++++---------
 .../action-sets/collection-files-action-set.ts     |  14 +-
 .../collection-files-item-action-set.ts            |  34 ++++-
 .../partial-copy-to-existing-collection-dialog.ts  |   4 +-
 .../partial-copy-to-new-collection-dialog.ts       |   5 +-
 .../partial-copy-to-separate-collections-dialog.ts |   4 +-
 .../partial-move-to-existing-collection-dialog.ts  |   4 +-
 .../partial-move-to-new-collection-dialog.ts       |   4 +-
 .../partial-move-to-separate-collections-dialog.ts |   4 +-
 12 files changed, 257 insertions(+), 155 deletions(-)

       via  f3d184828b69929818603bd1e88ef8cb98a472df (commit)
      from  7d3e2f9561e8cebfa7c3d4fddd8d2c586aadccd8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f3d184828b69929818603bd1e88ef8cb98a472df
Author: Stephen Smith <stephen at curii.com>
Date:   Tue May 23 19:41:25 2023 -0400

    20031: Add single file context menu move/copy actions
    
    Refactors copy/move actions to pass file selection through dialog.data to allow
    single selected file to be passed from context menu
    
    Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen at curii.com>

diff --git a/src/components/icon/icon.tsx b/src/components/icon/icon.tsx
index 20b87b20..157fb44b 100644
--- a/src/components/icon/icon.tsx
+++ b/src/components/icon/icon.tsx
@@ -18,6 +18,7 @@ import ImportContacts from '@material-ui/icons/ImportContacts';
 import ChevronRight from '@material-ui/icons/ChevronRight';
 import Close from '@material-ui/icons/Close';
 import ContentCopy from '@material-ui/icons/FileCopyOutlined';
+import FileCopy from '@material-ui/icons/FileCopy';
 import CreateNewFolder from '@material-ui/icons/CreateNewFolder';
 import Delete from '@material-ui/icons/Delete';
 import DeviceHub from '@material-ui/icons/DeviceHub';
@@ -135,8 +136,15 @@ export const OutputIcon: IconType = (props: any) =>
         <path d="M14,14H10V11H8L12,7L16,11H14V14M16,11M5,15V5H19V15H15A3,3 0 0,1 12,18A3,3 0 0,1 9,15H5M19,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3" />
     </SvgIcon>;
 
+// https://pictogrammers.com/library/mdi/icon/file-move/
+export const FileMoveIcon: IconType = (props: any) =>
+    <SvgIcon {...props}>
+        <path d="M14,17H18V14L23,18.5L18,23V20H14V17M13,9H18.5L13,3.5V9M6,2H14L20,8V12.34C19.37,12.12 18.7,12 18,12A6,6 0 0,0 12,18C12,19.54 12.58,20.94 13.53,22H6C4.89,22 4,21.1 4,20V4A2,2 0 0,1 6,2Z" />
+    </SvgIcon>;
+
 export type IconType = React.SFC<{ className?: string, style?: object }>;
 
+// https://v4.mui.com/components/material-icons/
 export const AddIcon: IconType = (props) => <Add {...props} />;
 export const AddFavoriteIcon: IconType = (props) => <StarBorder {...props} />;
 export const AdminMenuIcon: IconType = (props) => <Build {...props} />;
@@ -146,6 +154,7 @@ export const BackIcon: IconType = (props) => <ArrowBack {...props} />;
 export const CustomizeTableIcon: IconType = (props) => <Menu {...props} />;
 export const CommandIcon: IconType = (props) => <LastPage {...props} />;
 export const CopyIcon: IconType = (props) => <ContentCopy {...props} />;
+export const FileCopyIcon: IconType = (props) => <FileCopy {...props} />;
 export const CollectionIcon: IconType = (props) => <LibraryBooks {...props} />;
 export const CloseIcon: IconType = (props) => <Close {...props} />;
 export const CloudUploadIcon: IconType = (props) => <CloudUpload {...props} />;
diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts
index d987c84a..298a5a1e 100644
--- a/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts
+++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts
@@ -4,6 +4,8 @@
 
 import { Tree, TreeNode, mapTreeValues, getNodeValue, getNodeDescendants } from 'models/tree';
 import { CollectionFile, CollectionDirectory, CollectionFileType } from 'models/collection-file';
+import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
+import { CollectionResource } from 'models/collection';
 
 export type CollectionPanelFilesState = Tree<CollectionPanelDirectory | CollectionPanelFile>;
 
@@ -16,6 +18,11 @@ export interface CollectionPanelFile extends CollectionFile {
     selected: boolean;
 }
 
+export interface CollectionFileSelection {
+    collection: CollectionResource;
+    selectedPaths: string[];
+}
+
 export const mapCollectionFileToCollectionPanelFile = (node: TreeNode<CollectionDirectory | CollectionFile>): TreeNode<CollectionPanelDirectory | CollectionPanelFile> => {
     return {
         ...node,
@@ -45,3 +52,12 @@ export const filterCollectionFilesBySelection = (tree: CollectionPanelFilesState
             array.indexOf(value) === index
         ));
 };
+
+export const getCollectionSelection = (sourceCollection: CollectionResource, selectedItems: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)[]) => ({
+    collection: sourceCollection,
+    selectedPaths: selectedItems.map(itemsToPaths).map(trimPathUuids(sourceCollection.uuid)),
+})
+
+const itemsToPaths = (item: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)): string => ('uuid' in item) ? item.uuid : item.id;
+
+const trimPathUuids = (parentCollectionUuid: string) => (path: string) => path.replace(new RegExp(`(^${parentCollectionUuid})`), '');
diff --git a/src/store/collections/collection-partial-copy-actions.ts b/src/store/collections/collection-partial-copy-actions.ts
index 899f87c9..8a3340b3 100644
--- a/src/store/collections/collection-partial-copy-actions.ts
+++ b/src/store/collections/collection-partial-copy-actions.ts
@@ -8,13 +8,15 @@ import { FormErrors, initialize, startSubmit, stopSubmit } from 'redux-form';
 import { resetPickerProjectTree } from 'store/project-tree-picker/project-tree-picker-actions';
 import { dialogActions } from 'store/dialog/dialog-actions';
 import { ServiceRepository } from 'services/services';
-import { filterCollectionFilesBySelection } from '../collection-panel/collection-panel-files/collection-panel-files-state';
+import { CollectionFileSelection, CollectionPanelDirectory, CollectionPanelFile, filterCollectionFilesBySelection, getCollectionSelection } from '../collection-panel/collection-panel-files/collection-panel-files-state';
 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
 import { getCommonResourceServiceError, CommonResourceServiceError } from 'services/common-service/common-resource-service';
 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
 import { FileOperationLocation } from "store/tree-picker/tree-picker-actions";
 import { updateResources } from 'store/resources/resources-actions';
 import { navigateTo } from 'store/navigation/navigation-action';
+import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
+import { CollectionResource } from 'models/collection';
 
 export const COLLECTION_PARTIAL_COPY_FORM_NAME = 'COLLECTION_PARTIAL_COPY_DIALOG';
 export const COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION = 'COLLECTION_PARTIAL_COPY_TO_SELECTED_DIALOG';
@@ -35,44 +37,54 @@ export interface CollectionPartialCopyToSeparateCollectionsFormData {
     projectUuid: string;
 }
 
-export const openCollectionPartialCopyToNewCollectionDialog = () =>
+export const openCollectionPartialCopyToNewCollectionDialog = (resource: ContextMenuResource) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            const initialData = {
-                name: `Files extracted from: ${currentCollection.name}`,
-                description: currentCollection.description,
-                projectUuid: undefined
-            };
-            dispatch(initialize(COLLECTION_PARTIAL_COPY_FORM_NAME, initialData));
-            dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_FORM_NAME, data: {} }));
+        const sourceCollection = getState().collectionPanel.item;
+
+        if (sourceCollection) {
+            openCopyToNewDialog(dispatch, sourceCollection, [resource]);
         }
     };
 
-export const copyCollectionPartialToNewCollection = ({ name, description, projectUuid }: CollectionPartialCopyToNewCollectionFormData) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
+export const openCollectionPartialCopyMultipleToNewCollectionDialog = () =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
 
-        if (sourceCollection) {
+        if (sourceCollection && selectedItems.length) {
+            openCopyToNewDialog(dispatch, sourceCollection, selectedItems);
+        }
+    };
+
+const openCopyToNewDialog = (dispatch: Dispatch, sourceCollection: CollectionResource, selectedItems: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)[]) => {
+    // Get selected files
+    const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+    // Populate form initial state
+    const initialFormData = {
+        name: `Files extracted from: ${sourceCollection.name}`,
+        description: sourceCollection.description,
+        projectUuid: undefined
+    };
+    dispatch(initialize(COLLECTION_PARTIAL_COPY_FORM_NAME, initialFormData));
+    dispatch<any>(resetPickerProjectTree());
+    dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_FORM_NAME, data: collectionFileSelection }));
+};
+
+export const copyCollectionPartialToNewCollection = (fileSelection: CollectionFileSelection, formData: CollectionPartialCopyToNewCollectionFormData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        if (fileSelection.collection) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_COPY_FORM_NAME));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_COPY_FORM_NAME));
 
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
-
                 // Copy files
                 const updatedCollection = await services.collectionService.copyFiles(
-                    sourceCollection.portableDataHash,
-                    paths,
+                    fileSelection.collection.portableDataHash,
+                    fileSelection.selectedPaths,
                     {
-                        name,
-                        description,
-                        ownerUuid: projectUuid,
+                        name: formData.name,
+                        description: formData.description,
+                        ownerUuid: formData.projectUuid,
                         uuid: undefined,
                     },
                     '/',
@@ -104,35 +116,46 @@ export const copyCollectionPartialToNewCollection = ({ name, description, projec
         }
     };
 
-export const openCollectionPartialCopyToExistingCollectionDialog = () =>
+export const openCollectionPartialCopyToExistingCollectionDialog = (resource: ContextMenuResource) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            const initialData = {
-                destination: {uuid: currentCollection.uuid, destinationPath: ''}
-            };
-            dispatch(initialize(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION, initialData));
-            dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION, data: {} }));
+        const sourceCollection = getState().collectionPanel.item;
+
+        if (sourceCollection) {
+            openCopyToExistingDialog(dispatch, sourceCollection, [resource]);
         }
     };
 
-export const copyCollectionPartialToExistingCollection = ({ destination }: CollectionPartialCopyToExistingCollectionFormData) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
+export const openCollectionPartialCopyMultipleToExistingCollectionDialog = () =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
+
+        if (sourceCollection && selectedItems.length) {
+            openCopyToExistingDialog(dispatch, sourceCollection, selectedItems);
+        }
+    };
 
-        if (sourceCollection && destination && destination.uuid) {
+const openCopyToExistingDialog = (dispatch: Dispatch, sourceCollection: CollectionResource, selectedItems: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)[]) => {
+    // Get selected files
+    const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+    // Populate form initial state
+    const initialFormData = {
+        destination: {uuid: sourceCollection.uuid, destinationPath: ''}
+    };
+    dispatch(initialize(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION, initialFormData));
+    dispatch<any>(resetPickerProjectTree());
+    dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION, data: collectionFileSelection }));
+}
+
+export const copyCollectionPartialToExistingCollection = (fileSelection: CollectionFileSelection, formData: CollectionPartialCopyToExistingCollectionFormData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        if (fileSelection.collection && formData.destination && formData.destination.uuid) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION));
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
 
                 // Copy files
-                const updatedCollection = await services.collectionService.copyFiles(sourceCollection.portableDataHash, paths, {uuid: destination.uuid}, destination.path || '/', false);
+                const updatedCollection = await services.collectionService.copyFiles(fileSelection.collection.portableDataHash, fileSelection.selectedPaths, {uuid: formData.destination.uuid}, formData.destination.path || '/', false);
                 dispatch(updateResources([updatedCollection]));
 
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION }));
@@ -155,41 +178,38 @@ export const copyCollectionPartialToExistingCollection = ({ destination }: Colle
 
 export const openCollectionPartialCopyToSeparateCollectionsDialog = () =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            const initialData = {
-                name: currentCollection.name,
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
+
+        if (sourceCollection && selectedItems.length) {
+            // Get selected files
+            const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+            // Populate form initial state
+            const initialFormData = {
+                name: sourceCollection.name,
                 projectUuid: undefined
             };
-            dispatch(initialize(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS, initialData));
+            dispatch(initialize(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS, initialFormData));
             dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS, data: {} }));
+            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS, data: collectionFileSelection }));
         }
     };
 
-export const copyCollectionPartialToSeparateCollections = ({ name, projectUuid }: CollectionPartialCopyToSeparateCollectionsFormData) =>
+export const copyCollectionPartialToSeparateCollections = (fileSelection: CollectionFileSelection, formData: CollectionPartialCopyToSeparateCollectionsFormData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
-
-        if (sourceCollection) {
+        if (fileSelection.collection) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS));
 
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
-
                 // Copy files
-                const collections = await Promise.all(paths.map((path) =>
+                const collections = await Promise.all(fileSelection.selectedPaths.map((path) =>
                     services.collectionService.copyFiles(
-                        sourceCollection.portableDataHash,
+                        fileSelection.collection.portableDataHash,
                         [path],
                         {
-                            name: `File copied from collection ${name}${path}`,
-                            ownerUuid: projectUuid,
+                            name: `File copied from collection ${formData.name}${path}`,
+                            ownerUuid: formData.projectUuid,
                             uuid: undefined,
                         },
                         '/',
@@ -197,7 +217,7 @@ export const copyCollectionPartialToSeparateCollections = ({ name, projectUuid }
                     )
                 ));
                 dispatch(updateResources(collections));
-                dispatch<any>(navigateTo(projectUuid));
+                dispatch<any>(navigateTo(formData.projectUuid));
 
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS }));
                 dispatch(snackbarActions.OPEN_SNACKBAR({
diff --git a/src/store/collections/collection-partial-move-actions.ts b/src/store/collections/collection-partial-move-actions.ts
index 206f8335..318971a0 100644
--- a/src/store/collections/collection-partial-move-actions.ts
+++ b/src/store/collections/collection-partial-move-actions.ts
@@ -6,7 +6,8 @@ import { Dispatch } from "redux";
 import { initialize, startSubmit } from "redux-form";
 import { CommonResourceServiceError, getCommonResourceServiceError } from "services/common-service/common-resource-service";
 import { ServiceRepository } from "services/services";
-import { filterCollectionFilesBySelection } from "store/collection-panel/collection-panel-files/collection-panel-files-state";
+import { CollectionFileSelection, CollectionPanelDirectory, CollectionPanelFile, filterCollectionFilesBySelection, getCollectionSelection } from "store/collection-panel/collection-panel-files/collection-panel-files-state";
+import { ContextMenuResource } from "store/context-menu/context-menu-actions";
 import { dialogActions } from "store/dialog/dialog-actions";
 import { navigateTo } from "store/navigation/navigation-action";
 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
@@ -15,6 +16,7 @@ import { updateResources } from "store/resources/resources-actions";
 import { SnackbarKind, snackbarActions } from "store/snackbar/snackbar-actions";
 import { RootState } from "store/store";
 import { FileOperationLocation } from "store/tree-picker/tree-picker-actions";
+import { CollectionResource } from "models/collection";
 
 export const COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION = 'COLLECTION_PARTIAL_MOVE_TO_NEW_DIALOG';
 export const COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION = 'COLLECTION_PARTIAL_MOVE_TO_SELECTED_DIALOG';
@@ -35,45 +37,55 @@ export interface CollectionPartialMoveToSeparateCollectionsFormData {
     projectUuid: string;
 }
 
-export const openCollectionPartialMoveToNewCollectionDialog = () =>
+export const openCollectionPartialMoveToNewCollectionDialog = (resource: ContextMenuResource) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            const initialData = {
-                name: `Files moved from: ${currentCollection.name}`,
-                description: currentCollection.description,
-                projectUuid: undefined
-            };
-            dispatch(initialize(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION, initialData));
-            dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION, data: {} }));
+        const sourceCollection = getState().collectionPanel.item;
+
+        if (sourceCollection) {
+            openMoveToNewDialog(dispatch, sourceCollection, [resource]);
         }
     };
 
-export const moveCollectionPartialToNewCollection = ({ name, description, projectUuid }: CollectionPartialMoveToNewCollectionFormData) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
+export const openCollectionPartialMoveMultipleToNewCollectionDialog = () =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
 
-        if (sourceCollection) {
+        if (sourceCollection && selectedItems.length) {
+            openMoveToNewDialog(dispatch, sourceCollection, selectedItems);
+        }
+    };
+
+const openMoveToNewDialog = (dispatch: Dispatch, sourceCollection: CollectionResource, selectedItems: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)[]) => {
+    // Get selected files
+    const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+    // Populate form initial state
+    const initialFormData = {
+        name: `Files moved from: ${sourceCollection.name}`,
+        description: sourceCollection.description,
+        projectUuid: undefined
+    };
+    dispatch(initialize(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION, initialFormData));
+    dispatch<any>(resetPickerProjectTree());
+    dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION, data: collectionFileSelection }));
+}
+
+export const moveCollectionPartialToNewCollection = (fileSelection: CollectionFileSelection, formData: CollectionPartialMoveToNewCollectionFormData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        if (fileSelection.collection) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION));
 
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
-
                 // Move files
                 const updatedCollection = await services.collectionService.moveFiles(
-                    sourceCollection.uuid,
-                    sourceCollection.portableDataHash,
-                    paths,
+                    fileSelection.collection.uuid,
+                    fileSelection.collection.portableDataHash,
+                    fileSelection.selectedPaths,
                     {
-                        name,
-                        description,
-                        ownerUuid: projectUuid,
+                        name: formData.name,
+                        description: formData.description,
+                        ownerUuid: formData.projectUuid,
                         uuid: undefined,
                     },
                     '/',
@@ -100,35 +112,52 @@ export const moveCollectionPartialToNewCollection = ({ name, description, projec
         }
     };
 
-export const openCollectionPartialMoveToExistingCollectionDialog = () =>
+export const openCollectionPartialMoveToExistingCollectionDialog = (resource: ContextMenuResource) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
-            const initialData = {
-                destination: {uuid: currentCollection.uuid, path: ''}
-            };
-            dispatch(initialize(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION, initialData));
-            dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION, data: {} }));
+        const sourceCollection = getState().collectionPanel.item;
+
+        if (sourceCollection) {
+            openMoveToExistingDialog(dispatch, sourceCollection, [resource]);
         }
     };
 
-export const moveCollectionPartialToExistingCollection = ({ destination }: CollectionPartialMoveToExistingCollectionFormData) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
+export const openCollectionPartialMoveMultipleToExistingCollectionDialog = () =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
+
+        if (sourceCollection && selectedItems.length) {
+            openMoveToExistingDialog(dispatch, sourceCollection, selectedItems);
+        }
+    };
+
+const openMoveToExistingDialog = (dispatch: Dispatch, sourceCollection: CollectionResource, selectedItems: (CollectionPanelDirectory | CollectionPanelFile | ContextMenuResource)[]) => {
+    // Get selected files
+    const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+    // Populate form initial state
+    const initialFormData = {
+        destination: {uuid: sourceCollection.uuid, path: ''}
+    };
+    dispatch(initialize(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION, initialFormData));
+    dispatch<any>(resetPickerProjectTree());
+    dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION, data: collectionFileSelection }));
+}
 
-        if (sourceCollection && destination && destination.uuid) {
+export const moveCollectionPartialToExistingCollection = (fileSelection: CollectionFileSelection, formData: CollectionPartialMoveToExistingCollectionFormData) =>
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+        if (fileSelection.collection && formData.destination && formData.destination.uuid) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION));
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
 
                 // Move files
-                const updatedCollection = await services.collectionService.moveFiles(sourceCollection.uuid, sourceCollection.portableDataHash, paths, {uuid: destination.uuid}, destination.path || '/', false);
+                const updatedCollection = await services.collectionService.moveFiles(
+                    fileSelection.collection.uuid,
+                    fileSelection.collection.portableDataHash,
+                    fileSelection.selectedPaths,
+                    {uuid: formData.destination.uuid},
+                    formData.destination.path || '/', false
+                );
                 dispatch(updateResources([updatedCollection]));
 
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION }));
@@ -151,42 +180,39 @@ export const moveCollectionPartialToExistingCollection = ({ destination }: Colle
 
 export const openCollectionPartialMoveToSeparateCollectionsDialog = () =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const currentCollection = getState().collectionPanel.item;
-        if (currentCollection) {
+        const sourceCollection = getState().collectionPanel.item;
+        const selectedItems = filterCollectionFilesBySelection(getState().collectionPanelFiles, true);
+
+        if (sourceCollection && selectedItems.length) {
+            // Get selected files
+            const collectionFileSelection = getCollectionSelection(sourceCollection, selectedItems);
+            // Populate form initial state
             const initialData = {
-                name: currentCollection.name,
+                name: sourceCollection.name,
                 projectUuid: undefined
             };
             dispatch(initialize(COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS, initialData));
             dispatch<any>(resetPickerProjectTree());
-            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS, data: {} }));
+            dispatch(dialogActions.OPEN_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS, data: collectionFileSelection }));
         }
     };
 
-export const moveCollectionPartialToSeparateCollections = ({ name, projectUuid }: CollectionPartialMoveToSeparateCollectionsFormData) =>
+export const moveCollectionPartialToSeparateCollections = (fileSelection: CollectionFileSelection, formData: CollectionPartialMoveToSeparateCollectionsFormData) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const state = getState();
-        // Get current collection
-        const sourceCollection = state.collectionPanel.item;
-
-        if (sourceCollection) {
+        if (fileSelection.collection) {
             try {
                 dispatch(startSubmit(COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS));
                 dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS));
 
-                // Get selected files
-                const paths = filterCollectionFilesBySelection(state.collectionPanelFiles, true)
-                    .map(file => file.id.replace(new RegExp(`(^${sourceCollection.uuid})`), ''));
-
                 // Move files
-                const collections = await Promise.all(paths.map((path) =>
+                const collections = await Promise.all(fileSelection.selectedPaths.map((path) =>
                     services.collectionService.moveFiles(
-                        sourceCollection.uuid,
-                        sourceCollection.portableDataHash,
+                        fileSelection.collection.uuid,
+                        fileSelection.collection.portableDataHash,
                         [path],
                         {
-                            name: `File moved from collection ${name}${path}`,
-                            ownerUuid: projectUuid,
+                            name: `File moved from collection ${formData.name}${path}`,
+                            ownerUuid: formData.projectUuid,
                             uuid: undefined,
                         },
                         '/',
@@ -194,7 +220,7 @@ export const moveCollectionPartialToSeparateCollections = ({ name, projectUuid }
                     )
                 ));
                 dispatch(updateResources(collections));
-                dispatch<any>(navigateTo(projectUuid));
+                dispatch<any>(navigateTo(formData.projectUuid));
 
                 dispatch(dialogActions.CLOSE_DIALOG({ id: COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS }));
                 dispatch(snackbarActions.OPEN_SNACKBAR({
diff --git a/src/views-components/context-menu/action-sets/collection-files-action-set.ts b/src/views-components/context-menu/action-sets/collection-files-action-set.ts
index 06f7789e..681ca5b3 100644
--- a/src/views-components/context-menu/action-sets/collection-files-action-set.ts
+++ b/src/views-components/context-menu/action-sets/collection-files-action-set.ts
@@ -5,23 +5,23 @@
 import { ContextMenuAction, ContextMenuActionSet } from "views-components/context-menu/context-menu-action-set";
 import { collectionPanelFilesAction, openMultipleFilesRemoveDialog } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
 import {
-    openCollectionPartialCopyToNewCollectionDialog,
-    openCollectionPartialCopyToExistingCollectionDialog,
+    openCollectionPartialCopyMultipleToNewCollectionDialog,
+    openCollectionPartialCopyMultipleToExistingCollectionDialog,
     openCollectionPartialCopyToSeparateCollectionsDialog
 } from 'store/collections/collection-partial-copy-actions';
-import { openCollectionPartialMoveToExistingCollectionDialog, openCollectionPartialMoveToNewCollectionDialog, openCollectionPartialMoveToSeparateCollectionsDialog } from "store/collections/collection-partial-move-actions";
+import { openCollectionPartialMoveMultipleToExistingCollectionDialog, openCollectionPartialMoveMultipleToNewCollectionDialog, openCollectionPartialMoveToSeparateCollectionsDialog } from "store/collections/collection-partial-move-actions";
 
 const copyActions: ContextMenuAction[] = [
     {
         name: "Copy selected into new collection",
         execute: dispatch => {
-            dispatch<any>(openCollectionPartialCopyToNewCollectionDialog());
+            dispatch<any>(openCollectionPartialCopyMultipleToNewCollectionDialog());
         }
     },
     {
         name: "Copy selected into existing collection",
         execute: dispatch => {
-            dispatch<any>(openCollectionPartialCopyToExistingCollectionDialog());
+            dispatch<any>(openCollectionPartialCopyMultipleToExistingCollectionDialog());
         }
     },
 ];
@@ -40,13 +40,13 @@ const moveActions: ContextMenuAction[] = [
     {
         name: "Move selected into new collection",
         execute: dispatch => {
-            dispatch<any>(openCollectionPartialMoveToNewCollectionDialog());
+            dispatch<any>(openCollectionPartialMoveMultipleToNewCollectionDialog());
         }
     },
     {
         name: "Move selected into existing collection",
         execute: dispatch => {
-            dispatch<any>(openCollectionPartialMoveToExistingCollectionDialog());
+            dispatch<any>(openCollectionPartialMoveMultipleToExistingCollectionDialog());
         }
     },
 ];
diff --git a/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts b/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts
index 4cb9ebda..d0758d70 100644
--- a/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts
+++ b/src/views-components/context-menu/action-sets/collection-files-item-action-set.ts
@@ -3,13 +3,29 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { ContextMenuActionSet } from "../context-menu-action-set";
-import { RemoveIcon, RenameIcon } from "components/icon/icon";
+import { FileCopyIcon, FileMoveIcon, RemoveIcon, RenameIcon } from "components/icon/icon";
 import { DownloadCollectionFileAction } from "../actions/download-collection-file-action";
 import { openFileRemoveDialog, openRenameFileDialog } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions';
 import { CollectionFileViewerAction } from 'views-components/context-menu/actions/collection-file-viewer-action';
 import { CollectionCopyToClipboardAction } from "../actions/collection-copy-to-clipboard-action";
+import { openCollectionPartialMoveToExistingCollectionDialog, openCollectionPartialMoveToNewCollectionDialog } from "store/collections/collection-partial-move-actions";
+import { openCollectionPartialCopyToExistingCollectionDialog, openCollectionPartialCopyToNewCollectionDialog } from "store/collections/collection-partial-copy-actions";
 
 export const readOnlyCollectionDirectoryItemActionSet: ContextMenuActionSet = [[
+    {
+        name: "Copy item into new collection",
+        icon: FileCopyIcon,
+        execute: (dispatch, resource) => {
+            dispatch<any>(openCollectionPartialCopyToNewCollectionDialog(resource));
+        }
+    },
+    {
+        name: "Copy item into existing collection",
+        icon: FileCopyIcon,
+        execute: (dispatch, resource) => {
+            dispatch<any>(openCollectionPartialCopyToExistingCollectionDialog(resource));
+        }
+    },
     {
         component: CollectionFileViewerAction,
         execute: () => { return; },
@@ -29,6 +45,20 @@ export const readOnlyCollectionFileItemActionSet: ContextMenuActionSet = [[
 ]];
 
 const writableActionSet: ContextMenuActionSet = [[
+    {
+        name: "Move item into new collection",
+        icon: FileMoveIcon,
+        execute: (dispatch, resource) => {
+            dispatch<any>(openCollectionPartialMoveToNewCollectionDialog(resource));
+        }
+    },
+    {
+        name: "Move item into existing collection",
+        icon: FileMoveIcon,
+        execute: (dispatch, resource) => {
+            dispatch<any>(openCollectionPartialMoveToExistingCollectionDialog(resource));
+        }
+    },
     {
         name: "Rename",
         icon: RenameIcon,
@@ -50,4 +80,4 @@ const writableActionSet: ContextMenuActionSet = [[
 
 export const collectionDirectoryItemActionSet: ContextMenuActionSet = readOnlyCollectionDirectoryItemActionSet.concat(writableActionSet);
 
-export const collectionFileItemActionSet: ContextMenuActionSet = readOnlyCollectionFileItemActionSet.concat(writableActionSet);
\ No newline at end of file
+export const collectionFileItemActionSet: ContextMenuActionSet = readOnlyCollectionFileItemActionSet.concat(writableActionSet);
diff --git a/src/views-components/dialog-forms/partial-copy-to-existing-collection-dialog.ts b/src/views-components/dialog-forms/partial-copy-to-existing-collection-dialog.ts
index 8fe57f2d..dd0d0cb4 100644
--- a/src/views-components/dialog-forms/partial-copy-to-existing-collection-dialog.ts
+++ b/src/views-components/dialog-forms/partial-copy-to-existing-collection-dialog.ts
@@ -13,8 +13,8 @@ export const PartialCopyToExistingCollectionDialog = compose(
     withDialog(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION),
     reduxForm<CollectionPartialCopyToExistingCollectionFormData>({
         form: COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION,
-        onSubmit: (data, dispatch) => {
-            dispatch(copyCollectionPartialToExistingCollection(data));
+        onSubmit: (data, dispatch, dialog) => {
+            dispatch(copyCollectionPartialToExistingCollection(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION),
diff --git a/src/views-components/dialog-forms/partial-copy-to-new-collection-dialog.ts b/src/views-components/dialog-forms/partial-copy-to-new-collection-dialog.ts
index 40bb1478..65b65db4 100644
--- a/src/views-components/dialog-forms/partial-copy-to-new-collection-dialog.ts
+++ b/src/views-components/dialog-forms/partial-copy-to-new-collection-dialog.ts
@@ -13,8 +13,9 @@ export const PartialCopyToNewCollectionDialog = compose(
     withDialog(COLLECTION_PARTIAL_COPY_FORM_NAME),
     reduxForm<CollectionPartialCopyToNewCollectionFormData>({
         form: COLLECTION_PARTIAL_COPY_FORM_NAME,
-        onSubmit: (data, dispatch) => {
-            dispatch(copyCollectionPartialToNewCollection(data));
+        onSubmit: (data, dispatch, dialog) => {
+            console.log(dialog.data);
+            dispatch(copyCollectionPartialToNewCollection(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_COPY_FORM_NAME),
diff --git a/src/views-components/dialog-forms/partial-copy-to-separate-collections-dialog.ts b/src/views-components/dialog-forms/partial-copy-to-separate-collections-dialog.ts
index e2687cbf..78fdd3a1 100644
--- a/src/views-components/dialog-forms/partial-copy-to-separate-collections-dialog.ts
+++ b/src/views-components/dialog-forms/partial-copy-to-separate-collections-dialog.ts
@@ -13,8 +13,8 @@ export const PartialCopyToSeparateCollectionsDialog = compose(
     withDialog(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS),
     reduxForm<CollectionPartialCopyToSeparateCollectionsFormData>({
         form: COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS,
-        onSubmit: (data, dispatch) => {
-            dispatch(copyCollectionPartialToSeparateCollections(data));
+        onSubmit: (data, dispatch, dialog) => {
+            dispatch(copyCollectionPartialToSeparateCollections(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_COPY_TO_SEPARATE_COLLECTIONS),
diff --git a/src/views-components/dialog-forms/partial-move-to-existing-collection-dialog.ts b/src/views-components/dialog-forms/partial-move-to-existing-collection-dialog.ts
index cb18a663..e8d51f1a 100644
--- a/src/views-components/dialog-forms/partial-move-to-existing-collection-dialog.ts
+++ b/src/views-components/dialog-forms/partial-move-to-existing-collection-dialog.ts
@@ -13,8 +13,8 @@ export const PartialMoveToExistingCollectionDialog = compose(
     withDialog(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION),
     reduxForm<CollectionPartialMoveToExistingCollectionFormData>({
         form: COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION,
-        onSubmit: (data, dispatch) => {
-            dispatch(moveCollectionPartialToExistingCollection(data));
+        onSubmit: (data, dispatch, dialog) => {
+            dispatch(moveCollectionPartialToExistingCollection(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION),
diff --git a/src/views-components/dialog-forms/partial-move-to-new-collection-dialog.ts b/src/views-components/dialog-forms/partial-move-to-new-collection-dialog.ts
index d7251c8a..103e1e19 100644
--- a/src/views-components/dialog-forms/partial-move-to-new-collection-dialog.ts
+++ b/src/views-components/dialog-forms/partial-move-to-new-collection-dialog.ts
@@ -13,8 +13,8 @@ export const PartialMoveToNewCollectionDialog = compose(
     withDialog(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION),
     reduxForm<CollectionPartialMoveToNewCollectionFormData>({
         form: COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION,
-        onSubmit: (data, dispatch) => {
-            dispatch(moveCollectionPartialToNewCollection(data));
+        onSubmit: (data, dispatch, dialog) => {
+            dispatch(moveCollectionPartialToNewCollection(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION),
diff --git a/src/views-components/dialog-forms/partial-move-to-separate-collections-dialog.ts b/src/views-components/dialog-forms/partial-move-to-separate-collections-dialog.ts
index 8346709b..8f7ea594 100644
--- a/src/views-components/dialog-forms/partial-move-to-separate-collections-dialog.ts
+++ b/src/views-components/dialog-forms/partial-move-to-separate-collections-dialog.ts
@@ -13,8 +13,8 @@ export const PartialMoveToSeparateCollectionsDialog = compose(
     withDialog(COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS),
     reduxForm<CollectionPartialMoveToSeparateCollectionsFormData>({
         form: COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS,
-        onSubmit: (data, dispatch) => {
-            dispatch(moveCollectionPartialToSeparateCollections(data));
+        onSubmit: (data, dispatch, dialog) => {
+            dispatch(moveCollectionPartialToSeparateCollections(dialog.data, data));
         }
     }),
     pickerId(COLLECTION_PARTIAL_MOVE_TO_SEPARATE_COLLECTIONS),

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list