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';
14 runProcessPanelActions,
16 getWorkflowRunnerSettings
17 } from 'store/run-process-panel/run-process-panel-actions';
18 import { snackbarActions } 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 { getUserUuid } from "common/getuser";
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 loadWorkflowPanel = () =>
34 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
35 dispatch(workflowPanelActions.REQUEST_ITEMS());
36 const response = await services.workflowService.list();
37 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
40 export const setUuidPrefix = (uuidPrefix: string) =>
41 propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
43 export const getUuidPrefix = (state: RootState) => {
44 return state.properties.uuidPrefix;
47 export const openRunProcess = (workflowUuid: string, ownerUuid?: string, name?: string, inputObj?: { [key: string]: any }) =>
48 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
49 const response = await services.workflowService.list();
50 dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
52 const workflows = getState().runProcessPanel.searchWorkflows;
53 const workflow = workflows.find(workflow => workflow.uuid === workflowUuid);
55 dispatch<any>(navigateToRunProcess);
56 dispatch<any>(goToStep(1));
57 dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
58 dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
59 dispatch<any>(loadPresets(workflow.uuid));
61 dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
65 const userUuid = getUserUuid(getState());
66 owner = getResource<ProjectResource | UserResource>(ownerUuid)(getState().resources);
67 if (!owner || !userUuid || owner.writableBy.indexOf(userUuid) === -1) {
72 dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(owner.uuid));
75 dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name, owner }));
78 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
81 dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
85 export const getPublicUserUuid = (state: RootState) => {
86 const prefix = state.auth.localCluster;
87 return `${prefix}-tpzed-anonymouspublic`;
89 export const getPublicGroupUuid = (state: RootState) => {
90 const prefix = state.auth.localCluster;
91 return `${prefix}-j7d0g-anonymouspublic`;
94 export const showWorkflowDetails = (uuid: string) =>
95 propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
97 export const getWorkflowDetails = (state: RootState) => {
98 const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
99 const workflows = state.runProcessPanel.workflows;
100 const workflow = workflows.find(workflow => workflow.uuid === uuid);
101 return workflow || undefined;