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 { Breadcrumb } from '~/components/breadcrumbs/breadcrumbs';
8 import { getResource } from '~/store/resources/resources';
9 import { TreePicker } from '../tree-picker/tree-picker';
10 import { getSidePanelTreeBranch } from '../side-panel-tree/side-panel-tree-actions';
11 import { propertiesActions } from '../properties/properties-actions';
12 import { getProcess } from '~/store/processes/process';
14 export const BREADCRUMBS = 'breadcrumbs';
16 export interface ResourceBreadcrumb extends Breadcrumb {
20 export const setBreadcrumbs = (breadcrumbs: Breadcrumb[]) =>
21 propertiesActions.SET_PROPERTY({ key: BREADCRUMBS, value: breadcrumbs });
23 const getSidePanelTreeBreadcrumbs = (uuid: string) => (treePicker: TreePicker): ResourceBreadcrumb[] => {
24 const nodes = getSidePanelTreeBranch(uuid)(treePicker);
25 return nodes.map(node =>
26 typeof node.value === 'string'
27 ? { label: node.value, uuid: node.nodeId }
28 : { label: node.value.name, uuid: node.value.uuid });
31 export const setSidePanelBreadcrumbs = (uuid: string) =>
32 (dispatch: Dispatch, getState: () => RootState) => {
33 const { treePicker } = getState();
34 const breadcrumbs = getSidePanelTreeBreadcrumbs(uuid)(treePicker);
35 dispatch(setBreadcrumbs(breadcrumbs));
38 export const setProjectBreadcrumbs = setSidePanelBreadcrumbs;
40 export const setCollectionBreadcrumbs = (collectionUuid: string) =>
41 (dispatch: Dispatch, getState: () => RootState) => {
42 const { resources } = getState();
43 const collection = getResource(collectionUuid)(resources);
45 dispatch<any>(setProjectBreadcrumbs(collection.ownerUuid));
48 export const setProcessBreadcrumbs = (processUuid: string) =>
49 (dispatch: Dispatch, getState: () => RootState) => {
50 const { resources } = getState();
51 const process = getProcess(processUuid)(resources);
53 dispatch<any>(setProjectBreadcrumbs(process.containerRequest.ownerUuid));