add-option-to-run-a-process-from-workflow-view
[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 { getResource } from '../resources/resources';
11 import { getProperty } from '~/store/properties/properties';
12 import { WorkflowResource } from '~/models/workflow';
13 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
14 import { goToStep, runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
15
16 export const WORKFLOW_PANEL_ID = "workflowPanel";
17 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
18 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
19 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
20
21 export const loadWorkflowPanel = () =>
22     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
23         dispatch(workflowPanelActions.REQUEST_ITEMS());
24         const response = await services.workflowService.list();
25         dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
26     };
27
28 export const setUuidPrefix = (uuidPrefix: string) =>
29     propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
30
31 export const getUuidPrefix = (state: RootState) => {
32     return state.properties.uuidPrefix;
33 };
34
35 export const openRunProcess = (uuid: string) =>
36     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {  
37         const workflows = getState().runProcessPanel.searchWorkflows;
38         const workflow = workflows.find(workflow => workflow.uuid === uuid);
39         dispatch<any>(navigateToRunProcess);
40         dispatch(runProcessPanelActions.RESET_RUN_PROCESS_PANEL()); 
41         dispatch<any>(goToStep(1));
42         dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
43         dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow!));       
44     };
45
46 export const getPublicUserUuid = (state: RootState) => {
47     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
48     return `${prefix}-tpzed-anonymouspublic`;
49 };
50 export const getPublicGroupUuid = (state: RootState) => {
51     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
52     return `${prefix}-j7d0g-anonymouspublic`;
53 };
54
55 export const showWorkflowDetails = (uuid: string) =>
56     propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
57
58 export const getWorkflowDetails = (state: RootState) => {
59     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
60     return uuid ? getResource<WorkflowResource>(uuid)(state.resources) : undefined;
61 };