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, navigateTo } from 'store/navigation/navigation-action';
14 runProcessPanelActions,
16 getWorkflowRunnerSettings
17 } from 'store/run-process-panel/run-process-panel-actions';
18 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
19 import { initialize } from 'redux-form';
20 import { RUN_PROCESS_BASIC_FORM } from 'views/run-process-panel/run-process-basic-form';
21 import { RUN_PROCESS_INPUTS_FORM } from 'views/run-process-panel/run-process-inputs-form';
22 import { RUN_PROCESS_ADVANCED_FORM } from 'views/run-process-panel/run-process-advanced-form';
23 import { getResource } from 'store/resources/resources';
24 import { ProjectResource } from 'models/project';
25 import { UserResource } from 'models/user';
26 import { getWorkflowInputs, parseWorkflowDefinition } from 'models/workflow';
28 export const WORKFLOW_PANEL_ID = "workflowPanel";
29 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
30 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
31 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
33 export const WORKFLOW_PROCESSES_PANEL_ID = "workflowProcessesPanel";
34 export const workflowProcessesPanelActions = bindDataExplorerActions(WORKFLOW_PROCESSES_PANEL_ID);
36 export const loadWorkflowPanel = () =>
37 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
38 dispatch(workflowPanelActions.REQUEST_ITEMS());
39 const response = await services.workflowService.list();
40 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
43 export const setUuidPrefix = (uuidPrefix: string) =>
44 propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
46 export const getUuidPrefix = (state: RootState) => {
47 return state.properties.uuidPrefix;
50 export const openRunProcess = (workflowUuid: string, ownerUuid?: string, name?: string, inputObj?: { [key: string]: any }) =>
51 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
52 const response = await services.workflowService.list();
53 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
55 const workflows = getState().runProcessPanel.searchWorkflows;
56 const listedWorkflow = workflows.find(workflow => workflow.uuid === workflowUuid);
57 const workflow = listedWorkflow || await services.workflowService.get(workflowUuid);
59 dispatch<any>(navigateToRunProcess);
60 dispatch<any>(goToStep(1));
61 dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
62 dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
63 dispatch<any>(loadPresets(workflow.uuid));
65 dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
69 owner = getResource<ProjectResource | UserResource>(ownerUuid)(getState().resources);
70 if (!owner || !owner.canWrite) {
75 dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(owner.uuid));
78 dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name, owner }));
80 const definition = parseWorkflowDefinition(workflow);
82 const inputs = getWorkflowInputs(definition);
84 const values = inputs.reduce((values, input) => ({
86 [input.id]: input.default,
88 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, values));
93 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
96 dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
100 export const getPublicUserUuid = (state: RootState) => {
101 const prefix = state.auth.localCluster;
102 return `${prefix}-tpzed-anonymouspublic`;
104 export const getPublicGroupUuid = (state: RootState) => {
105 const prefix = state.auth.localCluster;
106 return `${prefix}-j7d0g-anonymouspublic`;
108 export const getAllUsersGroupUuid = (state: RootState) => {
109 const prefix = state.auth.localCluster;
110 return `${prefix}-j7d0g-fffffffffffffff`;
113 export const showWorkflowDetails = (uuid: string) =>
114 propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
116 export const getWorkflowDetails = (state: RootState) => {
117 const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
118 const workflows = state.runProcessPanel.workflows;
119 const workflow = workflows.find(workflow => workflow.uuid === uuid);
120 return workflow || undefined;
123 export const deleteWorkflow = (workflowUuid: string, ownerUuid: string) =>
124 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
125 dispatch<any>(navigateTo(ownerUuid));
126 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removing ...', kind: SnackbarKind.INFO }));
127 await services.workflowService.delete(workflowUuid);
128 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'Removed.', hideDuration: 2000, kind: SnackbarKind.SUCCESS }));