UI Improvements
[arvados-workbench2.git] / src / store / compute-nodes / compute-nodes-actions.ts
index 659b1e8674c7c63138d76c106c3cc23941665e02..7a76c1296b45fbd187b47a5d76c0ea5797a10f23 100644 (file)
@@ -3,21 +3,18 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { Dispatch } from "redux";
-import { unionize, ofType, UnionOf } from "~/common/unionize";
 import { RootState } from '~/store/store';
 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
-import { ServiceRepository } from "~/services/services";
-import { NodeResource } from '~/models/node';
 import { dialogActions } from '~/store/dialog/dialog-actions';
-import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions';
 import { navigateToRootProject } from '~/store/navigation/navigation-action';
+import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
+import { getResource } from '~/store/resources/resources';
+import { ServiceRepository } from "~/services/services";
+import { NodeResource } from '~/models/node';
 
-export const computeNodesActions = unionize({
-    SET_COMPUTE_NODES: ofType<NodeResource[]>(),
-    REMOVE_COMPUTE_NODE: ofType<string>()
-});
-
-export type ComputeNodesActions = UnionOf<typeof computeNodesActions>;
+export const COMPUTE_NODE_PANEL_ID = "computeNodeId";
+export const computeNodesActions = bindDataExplorerActions(COMPUTE_NODE_PANEL_ID);
 
 export const COMPUTE_NODE_REMOVE_DIALOG = 'computeNodeRemoveDialog';
 export const COMPUTE_NODE_ATTRIBUTES_DIALOG = 'computeNodeAttributesDialog';
@@ -28,20 +25,20 @@ export const loadComputeNodesPanel = () =>
         if (user && user.isAdmin) {
             try {
                 dispatch(setBreadcrumbs([{ label: 'Compute Nodes' }]));
-                const response = await services.nodeService.list();
-                dispatch(computeNodesActions.SET_COMPUTE_NODES(response.items));
+                dispatch(computeNodesActions.REQUEST_ITEMS());
             } catch (e) {
                 return;
             }
         } else {
             dispatch(navigateToRootProject);
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000 }));
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000, kind: SnackbarKind.ERROR }));
         }
     };
 
 export const openComputeNodeAttributesDialog = (uuid: string) =>
     (dispatch: Dispatch, getState: () => RootState) => {
-        const computeNode = getState().computeNodes.find(node => node.uuid === uuid);
+        const { resources } = getState();
+        const computeNode = getResource<NodeResource>(uuid)(resources);
         dispatch(dialogActions.OPEN_DIALOG({ id: COMPUTE_NODE_ATTRIBUTES_DIALOG, data: { computeNode } }));
     };
 
@@ -60,11 +57,11 @@ export const openComputeNodeRemoveDialog = (uuid: string) =>
 
 export const removeComputeNode = (uuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...' }));
+        dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
         try {
             await services.nodeService.delete(uuid);
-            dispatch(computeNodesActions.REMOVE_COMPUTE_NODE(uuid));
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Compute node has been successfully removed.', hideDuration: 2000 }));
+            dispatch(computeNodesActions.REQUEST_ITEMS());
+            dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Compute node has been successfully removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
         } catch (e) {
             return;
         }