1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Button, Grid, StyleRulesCallback, WithStyles, Typography, Tooltip } from '@material-ui/core';
7 import ChevronRightIcon from '@material-ui/icons/ChevronRight';
8 import { withStyles } from '@material-ui/core';
9 import { IllegalNamingWarning } from '../warning/warning';
10 import { IconType, FreezeIcon } from 'components/icon/icon';
11 import grey from '@material-ui/core/colors/grey';
12 import { getResource, ResourcesState } from 'store/resources/resources';
13 import classNames from 'classnames';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import { GroupClass } from "models/group";
16 import { navigateTo, navigateToGroupDetails } from 'store/navigation/navigation-action';
17 export interface Breadcrumb {
23 type CssRules = "item" | "chevron" | "label" | "buttonLabel" | "icon" | "frozenIcon";
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30 color: theme.customs.colors.grey700,
32 color: `${theme.palette.primary.main}`,
39 textTransform: "none",
46 justifyContent: 'flex-start',
60 export interface BreadcrumbsProps {
62 resources: ResourcesState;
63 onClick: (navFunc: (uuid: string) => void, breadcrumb: Breadcrumb) => void;
64 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => void;
67 export const Breadcrumbs = withStyles(styles)(
68 ({ classes, onClick, onContextMenu, items, resources }: BreadcrumbsProps & WithStyles<CssRules>) =>
69 <Grid container data-cy='breadcrumbs' alignItems="center" wrap="nowrap">
71 items.map((item, index) => {
72 const isLastItem = index === items.length - 1;
73 const isFirstItem = index === 0;
74 const Icon = item.icon || (() => (null));
75 const resource = getResource(item.uuid)(resources) as any;
76 const navFunc = resource && 'groupClass' in resource && resource.groupClass === GroupClass.ROLE ? navigateToGroupDetails : navigateTo;
79 <React.Fragment key={index}>
80 {isFirstItem ? null : <IllegalNamingWarning name={item.label} />}
81 <Tooltip title={item.label}>
89 className={classNames(
90 isLastItem ? null : 'parentItem',
94 label: classes.buttonLabel
97 onClick={() => onClick(navFunc, item)}
98 onContextMenu={event => onContextMenu(event, item)}>
99 <Icon className={classes.icon} />
103 className={classes.label}>
107 (resources[item.uuid] as any)?.frozenByUuid ? <FreezeIcon className={classes.frozenIcon} /> : null
111 {!isLastItem && <ChevronRightIcon color="inherit" className={classNames('parentItem', classes.chevron)} />}