20031: Add single file context menu move/copy actions
authorStephen Smith <stephen@curii.com>
Tue, 23 May 2023 23:41:25 +0000 (19:41 -0400)
committerStephen Smith <stephen@curii.com>
Tue, 23 May 2023 23:41:25 +0000 (19:41 -0400)
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@curii.com>

12 files changed:
src/components/icon/icon.tsx
src/store/collection-panel/collection-panel-files/collection-panel-files-state.ts
src/store/collections/collection-partial-copy-actions.ts
src/store/collections/collection-partial-move-actions.ts
src/views-components/context-menu/action-sets/collection-files-action-set.ts
src/views-components/context-menu/action-sets/collection-files-item-action-set.ts
src/views-components/dialog-forms/partial-copy-to-existing-collection-dialog.ts
src/views-components/dialog-forms/partial-copy-to-new-collection-dialog.ts
src/views-components/dialog-forms/partial-copy-to-separate-collections-dialog.ts
src/views-components/dialog-forms/partial-move-to-existing-collection-dialog.ts
src/views-components/dialog-forms/partial-move-to-new-collection-dialog.ts
src/views-components/dialog-forms/partial-move-to-separate-collections-dialog.ts

index 20b87b20515e90de0fdaf281a5d9b75b25a789a1..157fb44b3c12d796a887065d8eeb4da01fd8c152 100644 (file)
@@ -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} />;
index d987c84a98061438c1f03a6d2f8a6c896ad739dc..298a5a1efe4a21be6f3be936ab353a001bc7d97d 100644 (file)
@@ -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})`), '');
index 899f87c968459ff8a7e3c1d4ed20d8a9431a88a7..8a3340b34d373f346c3c9e4b521301aac6692711 100644 (file)
@@ -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({
index 206f8335a33948f3c24cd5e0a831fefd44fe02ca..318971a0e24dcb661aa9dad724a006629ce47298 100644 (file)
@@ -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({
index 06f7789e36c20aae9ea8b7849492d45698bda8d9..681ca5b3c05dd272576f4e1a7c7ae9bff9dadde6 100644 (file)
@@ -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());
         }
     },
 ];
index 4cb9ebda4c02a4c421a6aa9f44bd92cf05255b84..d0758d700a578d98caf1b437ddc8dcab829fb2d4 100644 (file)
@@ -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);
index 8fe57f2dc367d89925e4ed538a377e5b5d1beee7..dd0d0cb47d203642230556dd207845fc0da0e950 100644 (file)
@@ -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),
index 40bb1478a3e50d0d9a3b056b23cbb01db6f18a31..65b65db40104cc4713467bd943ee8b212b2252aa 100644 (file)
@@ -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),
index e2687cbf60415e34c6a9c4d3c3d80a4516d0c296..78fdd3a1d1032be9fe55a137456d4762a3be9bb4 100644 (file)
@@ -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),
index cb18a6632ebac2457a20ca3c0b67f141361a2b82..e8d51f1a31de36f9aa6d73be18541103e2fa794e 100644 (file)
@@ -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),
index d7251c8a7e4f1a24f77659fd9b4db9582ef38b30..103e1e19e3429bb7c0a303d69a09af9b7485ca10 100644 (file)
@@ -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),
index 8346709b78db50dd0573d35810d01aff0336b1a4..8f7ea594365080f708bf81acb3ce3dc7393270eb 100644 (file)
@@ -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),