15672: Adds filtering by name on subprocess panel by using the search field.
[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 { getProperty } from '~/store/properties/properties';
11 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
12 import { goToStep, runProcessPanelActions, loadPresets, DEFAULT_ADVANCED_FORM_VALUES } 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_ADVANCED_FORM } from '~/views/run-process-panel/run-process-advanced-form';
16
17 export const WORKFLOW_PANEL_ID = "workflowPanel";
18 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
19 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
20 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
21
22 export const loadWorkflowPanel = () =>
23     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
24         dispatch(workflowPanelActions.REQUEST_ITEMS());
25         const response = await services.workflowService.list();
26         dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
27     };
28
29 export const setUuidPrefix = (uuidPrefix: string) =>
30     propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
31
32 export const getUuidPrefix = (state: RootState) => {
33     return state.properties.uuidPrefix;
34 };
35
36 export const openRunProcess = (uuid: string) =>
37     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
38         const workflows = getState().runProcessPanel.searchWorkflows;
39         const workflow = workflows.find(workflow => workflow.uuid === uuid);
40         if (workflow) {
41             dispatch<any>(navigateToRunProcess);
42             dispatch<any>(goToStep(1));
43             dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
44             dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
45             dispatch<any>(loadPresets(workflow.uuid));
46             dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, DEFAULT_ADVANCED_FORM_VALUES));
47         } else {
48             dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
49         }
50     };
51
52 export const getPublicUserUuid = (state: RootState) => {
53     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
54     return `${prefix}-tpzed-anonymouspublic`;
55 };
56 export const getPublicGroupUuid = (state: RootState) => {
57     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
58     return `${prefix}-j7d0g-anonymouspublic`;
59 };
60
61 export const showWorkflowDetails = (uuid: string) =>
62     propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
63
64 export const getWorkflowDetails = (state: RootState) => {
65     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
66     const workflows = state.runProcessPanel.workflows;
67     const workflow = workflows.find(workflow => workflow.uuid === uuid);
68     return workflow || undefined;
69 };