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';
18 import { getResource, ResourcesState } from 'store/resources/resources';
19 import { ProjectResource } from 'models/project';
20 import { UserResource } from 'models/user';
22 export const WORKFLOW_PANEL_ID = "workflowPanel";
23 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
24 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
25 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
27 export const loadWorkflowPanel = () =>
28 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
29 dispatch(workflowPanelActions.REQUEST_ITEMS());
30 const response = await services.workflowService.list();
31 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
34 export const setUuidPrefix = (uuidPrefix: string) =>
35 propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
37 export const getUuidPrefix = (state: RootState) => {
38 return state.properties.uuidPrefix;
41 export const openRunProcess = (workflowUuid: string, ownerUuid?: string, name?: string, inputObj?: { [key: string]: any }) =>
42 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
43 const response = await services.workflowService.list();
44 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
46 const workflows = getState().runProcessPanel.searchWorkflows;
47 const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
49 dispatch<any>(navigateToRunProcess);
50 dispatch<any>(goToStep(1));
51 dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
52 dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
53 dispatch<any>(loadPresets(workflow.uuid));
55 dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
58 dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(ownerUuid));
59 owner = getResource<ProjectResource | UserResource>(ownerUuid)(getState().resources);
62 dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name, owner }));
65 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
68 dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
72 export const getPublicUserUuid = (state: RootState) => {
73 const prefix = state.auth.localCluster;
74 return `${prefix}-tpzed-anonymouspublic`;
76 export const getPublicGroupUuid = (state: RootState) => {
77 const prefix = state.auth.localCluster;
78 return `${prefix}-j7d0g-anonymouspublic`;
81 export const showWorkflowDetails = (uuid: string) =>
82 propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
84 export const getWorkflowDetails = (state: RootState) => {
85 const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
86 const workflows = state.runProcessPanel.workflows;
87 const workflow = workflows.find(workflow => workflow.uuid === uuid);
88 return workflow || undefined;