15397: Fix usage of deprecated assertRegexpMatches.
[arvados.git] / services / workbench2 / 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 { Breadcrumb, Breadcrumbs as BreadcrumbsComponent, BreadcrumbsProps } from 'components/breadcrumbs/breadcrumbs';
7 import { RootState } from 'store/store';
8 import { Dispatch } from 'redux';
9 import { getProperty } from '../../store/properties/properties';
10 import { BREADCRUMBS } from '../../store/breadcrumbs/breadcrumbs-actions';
11 import { openSidePanelContextMenu } from 'store/context-menu/context-menu-actions';
12
13 type BreadcrumbsDataProps = Pick<BreadcrumbsProps, 'items' | 'resources'>;
14 type BreadcrumbsActionProps = Pick<BreadcrumbsProps, 'onClick' | 'onContextMenu'>;
15
16 const mapStateToProps = () => ({ properties, resources }: RootState): BreadcrumbsDataProps => ({
17     items: (getProperty<Breadcrumb[]>(BREADCRUMBS)(properties) || []),
18     resources,
19 });
20
21 const mapDispatchToProps = (dispatch: Dispatch): BreadcrumbsActionProps => ({
22     onClick: (navFunc, { uuid }: Breadcrumb) => {
23         dispatch<any>(navFunc(uuid));
24     },
25     onContextMenu: (event, breadcrumb: Breadcrumb) => {
26         dispatch<any>(openSidePanelContextMenu(event, breadcrumb.uuid));
27     }
28 });
29
30 export const Breadcrumbs = connect(mapStateToProps(), mapDispatchToProps)(BreadcrumbsComponent);