Add generic trash action
authorDaniel Kos <daniel.kos@contractors.roche.com>
Tue, 4 Sep 2018 05:38:49 +0000 (07:38 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Tue, 4 Sep 2018 05:38:49 +0000 (07:38 +0200)
Feature #13828

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>

src/store/trash/trash-actions.ts
src/views-components/context-menu/action-sets/trash-action-set.ts
src/views/trash-panel/trash-panel.tsx

index 06e1648323e754444437dfb114e0fb15cdb0e586..cd6df55670d322044c5d386a3c597cc19f0db3e0 100644 (file)
@@ -9,6 +9,7 @@ import { snackbarActions } from "~/store/snackbar/snackbar-actions";
 import { trashPanelActions } from "~/store/trash-panel/trash-panel-action";
 import { activateSidePanelTreeItem, loadSidePanelTreeProjects } from "~/store/side-panel-tree/side-panel-tree-actions";
 import { projectPanelActions } from "~/store/project-panel/project-panel-action";
+import { ResourceKind, TrashableResource } from "~/models/resource";
 
 export const toggleProjectTrashed = (uuid: string, ownerUuid: string, isTrashed: boolean) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<any> => {
@@ -54,3 +55,12 @@ export const toggleCollectionTrashed = (uuid: string, isTrashed: boolean) =>
             }));
         }
     };
+
+export const toggleTrashed = (kind: ResourceKind, uuid: string, ownerUuid: string, isTrashed: boolean) =>
+    (dispatch: Dispatch) => {
+        if (kind === ResourceKind.PROJECT) {
+            dispatch<any>(toggleProjectTrashed(uuid, ownerUuid, isTrashed!!));
+        } else if (kind === ResourceKind.COLLECTION) {
+            dispatch<any>(toggleCollectionTrashed(uuid, isTrashed!!));
+        }
+    };
index 3a5c53070e20f4355139b41136061a410158bd2e..fafd5feb2246fe5bf9900a7f2e9c9a3e4a7d0561 100644 (file)
@@ -4,13 +4,13 @@
 
 import { ContextMenuActionSet } from "../context-menu-action-set";
 import { ToggleTrashAction } from "~/views-components/context-menu/actions/trash-action";
-import { toggleCollectionTrashed } from "~/store/trash/trash-actions";
+import { toggleTrashed } from "~/store/trash/trash-actions";
 
 export const trashActionSet: ContextMenuActionSet = [[
     {
         component: ToggleTrashAction,
         execute: (dispatch, resource) => {
-            dispatch<any>(toggleCollectionTrashed(resource.uuid, resource.isTrashed!!));
+            dispatch<any>(toggleTrashed(resource.kind, resource.uuid, resource.ownerUuid, resource.isTrashed!!));
         }
     },
 ]];
index dadfabb0d6e0fcafee0b361125a8624b78997cd2..08df05c247b61b8be75874ba87c4adbaa7834d71 100644 (file)
@@ -17,7 +17,7 @@ import { RestoreFromTrashIcon, TrashIcon } from '~/components/icon/icon';
 import { TRASH_PANEL_ID } from "~/store/trash-panel/trash-panel-action";
 import { getProperty } from "~/store/properties/properties";
 import { PROJECT_PANEL_CURRENT_UUID } from "~/store/project-panel/project-panel-action";
-import { ContextMenuResource, openContextMenu } from "~/store/context-menu/context-menu-actions";
+import { openContextMenu } from "~/store/context-menu/context-menu-actions";
 import { getResource, ResourcesState } from "~/store/resources/resources";
 import {
     ResourceDeleteDate,
@@ -28,7 +28,7 @@ import {
 } from "~/views-components/data-explorer/renderers";
 import { navigateTo } from "~/store/navigation/navigation-action";
 import { loadDetailsPanel } from "~/store/details-panel/details-panel-action";
-import { toggleCollectionTrashed, toggleProjectTrashed } from "~/store/trash/trash-actions";
+import { toggleCollectionTrashed, toggleProjectTrashed, toggleTrashed } from "~/store/trash/trash-actions";
 import { ContextMenuKind } from "~/views-components/context-menu/context-menu";
 import { Dispatch } from "redux";
 
@@ -63,13 +63,12 @@ export const ResourceRestore =
     })((props: { resource?: TrashableResource, dispatch?: Dispatch<any> }) =>
         <IconButton onClick={() => {
             if (props.resource && props.dispatch) {
-                const res = props.resource;
-
-                if (props.resource.kind === ResourceKind.PROJECT) {
-                    props.dispatch(toggleProjectTrashed(res.uuid, res.ownerUuid, res.isTrashed));
-                } else if (props.resource.kind === ResourceKind.COLLECTION) {
-                    props.dispatch(toggleCollectionTrashed(res.uuid, res.isTrashed));
-                }
+                props.dispatch(toggleTrashed(
+                    props.resource.kind,
+                    props.resource.uuid,
+                    props.resource.ownerUuid,
+                    props.resource.isTrashed
+                ));
             }
         }}>
             <RestoreFromTrashIcon/>