1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from '~/store/store';
7 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
8 import { dialogActions } from '~/store/dialog/dialog-actions';
9 import {snackbarActions, SnackbarKind} from '~/store/snackbar/snackbar-actions';
10 import { navigateToRootProject } from '~/store/navigation/navigation-action';
11 import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
12 import { getResource } from '~/store/resources/resources';
13 import { ServiceRepository } from "~/services/services";
14 import { NodeResource } from '~/models/node';
16 export const COMPUTE_NODE_PANEL_ID = "computeNodeId";
17 export const computeNodesActions = bindDataExplorerActions(COMPUTE_NODE_PANEL_ID);
19 export const COMPUTE_NODE_REMOVE_DIALOG = 'computeNodeRemoveDialog';
20 export const COMPUTE_NODE_ATTRIBUTES_DIALOG = 'computeNodeAttributesDialog';
22 export const loadComputeNodesPanel = () =>
23 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
24 const user = getState().auth.user;
25 if (user && user.isAdmin) {
27 dispatch(setBreadcrumbs([{ label: 'Compute Nodes' }]));
28 dispatch(computeNodesActions.REQUEST_ITEMS());
33 dispatch(navigateToRootProject);
34 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "You don't have permissions to view this page", hideDuration: 2000, kind: SnackbarKind.ERROR }));
38 export const openComputeNodeAttributesDialog = (uuid: string) =>
39 (dispatch: Dispatch, getState: () => RootState) => {
40 const { resources } = getState();
41 const computeNode = getResource<NodeResource>(uuid)(resources);
42 dispatch(dialogActions.OPEN_DIALOG({ id: COMPUTE_NODE_ATTRIBUTES_DIALOG, data: { computeNode } }));
45 export const openComputeNodeRemoveDialog = (uuid: string) =>
46 (dispatch: Dispatch, getState: () => RootState) => {
47 dispatch(dialogActions.OPEN_DIALOG({
48 id: COMPUTE_NODE_REMOVE_DIALOG,
50 title: 'Remove compute node',
51 text: 'Are you sure you want to remove this compute node?',
52 confirmButtonLabel: 'Remove',
58 export const removeComputeNode = (uuid: string) =>
59 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
60 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
62 await services.nodeService.delete(uuid);
63 dispatch(computeNodesActions.REQUEST_ITEMS());
64 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Compute node has been successfully removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));