19069: Fix create workflow test
[arvados-workbench2.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 { getProperty } from 'store/properties/properties';
11 import { navigateToRunProcess } from 'store/navigation/navigation-action';
12 import { goToStep, runProcessPanelActions, loadPresets, getWorkflowRunnerSettings } from 'store/run-process-panel/run-process-panel-actions';
13 import { snackbarActions } from 'store/snackbar/snackbar-actions';
14 import { initialize } from 'redux-form';
15 import { RUN_PROCESS_BASIC_FORM } from 'views/run-process-panel/run-process-basic-form';
16 import { RUN_PROCESS_INPUTS_FORM } from 'views/run-process-panel/run-process-inputs-form';
17 import { RUN_PROCESS_ADVANCED_FORM } from 'views/run-process-panel/run-process-advanced-form';
18
19 export const WORKFLOW_PANEL_ID = "workflowPanel";
20 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
21 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
22 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
23
24 export const loadWorkflowPanel = () =>
25     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
26         dispatch(workflowPanelActions.REQUEST_ITEMS());
27         const response = await services.workflowService.list();
28         dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
29     };
30
31 export const setUuidPrefix = (uuidPrefix: string) =>
32     propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
33
34 export const getUuidPrefix = (state: RootState) => {
35     return state.properties.uuidPrefix;
36 };
37
38 export const openRunProcess = (workflowUuid: string, ownerUuid?: string, name?: string, inputObj?: { [key: string]: any }) =>
39     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
40         const response = await services.workflowService.list();
41         dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
42
43         const workflows = getState().runProcessPanel.searchWorkflows;
44         const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
45         if (workflow) {
46             dispatch<any>(navigateToRunProcess);
47             dispatch<any>(goToStep(1));
48             dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
49             dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
50             dispatch<any>(loadPresets(workflow.uuid));
51
52             dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
53             if (ownerUuid) {
54                 dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(ownerUuid));
55             }
56             if (name) {
57                 dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name }));
58             }
59             if (inputObj) {
60                 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
61             }
62         } else {
63             dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
64         }
65     };
66
67 export const getPublicUserUuid = (state: RootState) => {
68     const prefix = state.auth.localCluster;
69     return `${prefix}-tpzed-anonymouspublic`;
70 };
71 export const getPublicGroupUuid = (state: RootState) => {
72     const prefix = state.auth.localCluster;
73     return `${prefix}-j7d0g-anonymouspublic`;
74 };
75
76 export const showWorkflowDetails = (uuid: string) =>
77     propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
78
79 export const getWorkflowDetails = (state: RootState) => {
80     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
81     const workflows = state.runProcessPanel.workflows;
82     const workflow = workflows.find(workflow => workflow.uuid === uuid);
83     return workflow || undefined;
84 };