19231: Add smaller page sizes (10 and 20 items) to load faster
[arvados-workbench2.git] / src / components / breadcrumbs / breadcrumbs.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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 } from 'components/icon/icon';
11 import grey from '@material-ui/core/colors/grey';
12
13 export interface Breadcrumb {
14     label: string;
15     icon?: IconType;
16 }
17
18 type CssRules = "item" | "currentItem" | "label" | "icon";
19
20 const styles: StyleRulesCallback<CssRules> = theme => ({
21     item: {
22         opacity: 0.6
23     },
24     currentItem: {
25         opacity: 1
26     },
27     label: {
28         textTransform: "none"
29     },
30     icon: {
31         fontSize: 20,
32         color: grey["600"]
33     },
34 });
35
36 export interface BreadcrumbsProps {
37     items: Breadcrumb[];
38     onClick: (breadcrumb: Breadcrumb) => void;
39     onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => void;
40 }
41
42 export const Breadcrumbs = withStyles(styles)(
43     ({ classes, onClick, onContextMenu, items }: BreadcrumbsProps & WithStyles<CssRules>) =>
44     <Grid container data-cy='breadcrumbs' alignItems="center" wrap="nowrap">
45     {
46         items.map((item, index) => {
47             const isLastItem = index === items.length - 1;
48             const isFirstItem = index === 0;
49             const Icon = item.icon || (() => (null));
50             return (
51                 <React.Fragment key={index}>
52                     {isFirstItem ? null : <IllegalNamingWarning name={item.label} />}
53                     <Tooltip title={item.label}>
54                         <Button
55                             data-cy={
56                                 isFirstItem
57                                 ? 'breadcrumb-first'
58                                 : isLastItem
59                                     ? 'breadcrumb-last'
60                                     : false}
61                             color="inherit"
62                             className={isLastItem ? classes.currentItem : classes.item}
63                             onClick={() => onClick(item)}
64                             onContextMenu={event => onContextMenu(event, item)}>
65                             <Icon className={classes.icon} />
66                             <Typography
67                                 noWrap
68                                 color="inherit"
69                                 className={classes.label}>
70                                 {item.label}
71                             </Typography>
72                         </Button>
73                     </Tooltip>
74                     {!isLastItem && <ChevronRightIcon color="inherit" className={classes.item} />}
75                 </React.Fragment>
76             );
77         })
78     }
79     </Grid>
80 );