Merge branch '17109-keepweb-urls-pdh-support'
[arvados.git] / src / views-components / breadcrumbs / breadcrumbs.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { connect } from "react-redux";
6 import { Breadcrumbs as BreadcrumbsComponent, BreadcrumbsProps } from '~/components/breadcrumbs/breadcrumbs';
7 import { RootState } from '~/store/store';
8 import { Dispatch } from 'redux';
9 import { navigateTo } from '~/store/navigation/navigation-action';
10 import { getProperty } from '../../store/properties/properties';
11 import { ResourceBreadcrumb, BREADCRUMBS } from '../../store/breadcrumbs/breadcrumbs-actions';
12 import { openSidePanelContextMenu } from '~/store/context-menu/context-menu-actions';
13
14 type BreadcrumbsDataProps = Pick<BreadcrumbsProps, 'items'>;
15 type BreadcrumbsActionProps = Pick<BreadcrumbsProps, 'onClick' | 'onContextMenu'>;
16
17 const mapStateToProps = () => ({ properties }: RootState): BreadcrumbsDataProps => ({
18     items: getProperty<ResourceBreadcrumb[]>(BREADCRUMBS)(properties) || []
19 });
20
21 const mapDispatchToProps = (dispatch: Dispatch): BreadcrumbsActionProps => ({
22     onClick: ({ uuid }: ResourceBreadcrumb) => {
23         dispatch<any>(navigateTo(uuid));
24     },
25     onContextMenu: (event, breadcrumb: ResourceBreadcrumb) => {
26         dispatch<any>(openSidePanelContextMenu(event, breadcrumb.uuid));
27     }
28 });
29
30 export const Breadcrumbs = connect(mapStateToProps(), mapDispatchToProps)(BreadcrumbsComponent);