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 { ResourcesState } from 'store/resources/resources';
13 import classNames from 'classnames';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import { extractUuidKind, ResourceKind } from 'models/resource';
16 import { ClassNameMap } from '@material-ui/core/styles/withStyles';
18 export interface Breadcrumb {
24 type CssRules = "item" | "defaultItem" | "processItem" | "collectionItem" | "parentItem" | "currentItem" | "label" | "icon" | "frozenIcon";
26 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31 backgroundColor: theme.customs.colors.grey300,
33 backgroundColor: theme.customs.colors.grey400,
37 backgroundColor: theme.customs.colors.lightGreen300,
39 backgroundColor: theme.customs.colors.lightGreen400,
43 backgroundColor: theme.customs.colors.cyan100,
45 backgroundColor: theme.customs.colors.cyan200,
69 export interface BreadcrumbsProps {
71 resources: ResourcesState;
72 onClick: (breadcrumb: Breadcrumb) => void;
73 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => void;
76 const getBreadcrumbClass = (item: Breadcrumb, classes: ClassNameMap<CssRules>): string => {
77 switch (extractUuidKind(item.uuid)) {
78 case ResourceKind.PROCESS:
79 return classes.processItem;
80 case ResourceKind.COLLECTION:
81 return classes.collectionItem;
83 return classes.defaultItem;
87 export const Breadcrumbs = withStyles(styles)(
88 ({ classes, onClick, onContextMenu, items, resources }: BreadcrumbsProps & WithStyles<CssRules>) =>
89 <Grid container data-cy='breadcrumbs' alignItems="center" wrap="nowrap">
91 items.map((item, index) => {
92 const isLastItem = index === items.length - 1;
93 const isFirstItem = index === 0;
94 const Icon = item.icon || (() => (null));
96 <React.Fragment key={index}>
97 {isFirstItem ? null : <IllegalNamingWarning name={item.label} />}
98 <Tooltip title={item.label}>
106 className={classNames(
107 isLastItem ? classes.currentItem : classes.parentItem,
109 getBreadcrumbClass(item, classes)
111 onClick={() => onClick(item)}
112 onContextMenu={event => onContextMenu(event, item)}>
113 <Icon className={classes.icon} />
117 className={classes.label}>
121 (resources[item.uuid] as any)?.frozenByUuid ? <FreezeIcon className={classes.frozenIcon} /> : null
125 {!isLastItem && <ChevronRightIcon color="inherit" className={classes.parentItem} />}