Merge branch 'master' into 13864-Virtual-machines
[arvados.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
14 export const WORKFLOW_PANEL_ID = "workflowPanel";
15 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
16 const WORKFLOW_PANEL_DETAILS_UUID = 'workflowPanelDetailsUuid';
17 export const workflowPanelActions = bindDataExplorerActions(WORKFLOW_PANEL_ID);
18
19 export const loadWorkflowPanel = () =>
20     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
21         dispatch(workflowPanelActions.REQUEST_ITEMS());
22     };
23
24 export const setUuidPrefix = (uuidPrefix: string) =>
25     propertiesActions.SET_PROPERTY({ key: UUID_PREFIX_PROPERTY_NAME, value: uuidPrefix });
26
27 export const getUuidPrefix = (state: RootState) => {
28     return state.properties.uuidPrefix;
29 };
30
31 export const getPublicUserUuid = (state: RootState) => {
32     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
33     return `${prefix}-tpzed-anonymouspublic`;
34 };
35 export const getPublicGroupUuid = (state: RootState) => {
36     const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
37     return `${prefix}-j7d0g-anonymouspublic`;
38 };
39
40 export const showWorkflowDetails = (uuid: string) =>
41     propertiesActions.SET_PROPERTY({ key: WORKFLOW_PANEL_DETAILS_UUID, value: uuid });
42
43 export const getWorkflowDetails = (state: RootState) => {
44     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
45     return uuid ? getResource<WorkflowResource>(uuid)(state.resources) : undefined;
46 };