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 { 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';
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);
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));
31 export const setUuidPrefix = (uuidPrefix: string) =>
32 propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
34 export const getUuidPrefix = (state: RootState) => {
35 return state.properties.uuidPrefix;
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));
43 const workflows = getState().runProcessPanel.searchWorkflows;
44 const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
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));
52 dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
54 dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(ownerUuid));
57 dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name }));
60 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
63 dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
67 export const getPublicUserUuid = (state: RootState) => {
68 const prefix = state.auth.localCluster;
69 return `${prefix}-tpzed-anonymouspublic`;
71 export const getPublicGroupUuid = (state: RootState) => {
72 const prefix = state.auth.localCluster;
73 return `${prefix}-j7d0g-anonymouspublic`;
76 export const showWorkflowDetails = (uuid: string) =>
77 propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
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;