14841: Add inactive user page.
[arvados.git] / src / store / workflow-panel / workflow-panel-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from 'redux';
6 import { RootState } from '~/store/store';
7 import { ServiceRepository } from '~/services/services';
8 import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
9 import { propertiesActions } from '~/store/properties/properties-actions';
10 import { getResource } from '~/store/resources/resources';
11 import { getProperty } from '~/store/properties/properties';
12 import { WorkflowResource } from '~/models/workflow';
13 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
14 import { goToStep, runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
15 import { snackbarActions } from '~/store/snackbar/snackbar-actions';
16
17 export const WORKFLOW_PANEL_ID = "workflowPanel";
18 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
19 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
20 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
21
22 export const loadWorkflowPanel = () =>
23     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24         dispatch(workflowPanelActions.REQUEST_ITEMS());
25         const response = await services.workflowService.list();
26         dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
27     };
28
29 export const setUuidPrefix = (uuidPrefix: string) =>
30     propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
31
32 export const getUuidPrefix = (state: RootState) => {
33     return state.properties.uuidPrefix;
34 };
35
36 export const openRunProcess = (uuid: string) =>
37     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
38         const workflows = getState().runProcessPanel.searchWorkflows;
39         const workflow = workflows.find(workflow => workflow.uuid === uuid);
40         if (workflow) {
41             dispatch<any>(navigateToRunProcess);
42             dispatch<any>(goToStep(1));
43             dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
44             dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
45         } else {
46             dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
47         }
48     };
49
50 export const getPublicUserUuid = (state: RootState) => {
51     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
52     return `${prefix}-tpzed-anonymouspublic`;
53 };
54 export const getPublicGroupUuid = (state: RootState) => {
55     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
56     return `${prefix}-j7d0g-anonymouspublic`;
57 };
58
59 export const showWorkflowDetails = (uuid: string) =>
60     propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
61
62 export const getWorkflowDetails = (state: RootState) => {
63     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
64     const workflows = state.runProcessPanel.workflows;
65     const workflow = workflows.find(workflow => workflow.uuid === uuid);
66     return workflow || undefined;
67 };