Merge branch 'master' into 13902-ui-move-to-popup
[arvados-workbench2.git] / src / store / collection-panel / collection-panel-files / collection-panel-files-actions.ts
index 12e64138a4089c7f1ed8dd1ae4e3c7478ba47ad3..cedfbebef5aded305b3237e125ee80857c96361b 100644 (file)
@@ -4,12 +4,13 @@
 
 import { default as unionize, ofType, UnionOf } from "unionize";
 import { Dispatch } from "redux";
-import { CollectionFilesTree, CollectionFileType } from "../../../models/collection-file";
-import { ServiceRepository } from "../../../services/services";
+import { CollectionFilesTree, CollectionFileType } from "~/models/collection-file";
+import { ServiceRepository } from "~/services/services";
 import { RootState } from "../../store";
 import { snackbarActions } from "../../snackbar/snackbar-actions";
 import { dialogActions } from "../../dialog/dialog-actions";
-import { getNodeValue } from "../../../models/tree";
+import { getNodeValue, getNodeDescendants } from "~/models/tree";
+import { CollectionPanelDirectory, CollectionPanelFile } from "./collection-panel-files-state";
 
 export const collectionPanelFilesAction = unionize({
     SET_COLLECTION_FILES: ofType<CollectionFilesTree>(),
@@ -39,6 +40,19 @@ export const removeCollectionFiles = (filePaths: string[]) =>
         }
     };
 
+export const removeCollectionsSelectedFiles = () =>
+    (dispatch: Dispatch, getState: () => RootState) => {
+        const tree = getState().collectionPanelFiles;
+        const allFiles = getNodeDescendants('')(tree)
+            .map(id => getNodeValue(id)(tree))
+            .filter(file => file !== undefined) as Array<CollectionPanelDirectory | CollectionPanelFile>;
+
+        const selectedDirectories = allFiles.filter(file => file.selected && file.type === CollectionFileType.DIRECTORY);
+        const selectedFiles = allFiles.filter(file => file.selected && !selectedDirectories.some(dir => dir.id === file.path));
+        const paths = [...selectedDirectories, ...selectedFiles].map(file => file.id);
+        dispatch<any>(removeCollectionFiles(paths));
+    };
+
 export const FILE_REMOVE_DIALOG = 'fileRemoveDialog';
 export const openFileRemoveDialog = (filePath: string) =>
     (dispatch: Dispatch, getState: () => RootState) => {
@@ -61,4 +75,15 @@ export const openFileRemoveDialog = (filePath: string) =>
                 }
             }));
         }
-    };
\ No newline at end of file
+    };
+
+export const MULTIPLE_FILES_REMOVE_DIALOG = 'multipleFilesRemoveDialog';
+export const openMultipleFilesRemoveDialog = () =>
+    dialogActions.OPEN_DIALOG({
+        id: MULTIPLE_FILES_REMOVE_DIALOG,
+        data: {
+            title: 'Removing files',
+            text: 'Are you sure you want to remove selected files?',
+            confirmButtonLabel: 'Remove'
+        }
+    });