Add progress indicator for services
[arvados-workbench2.git] / src / views-components / main-app-bar / main-app-bar.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { AppBar, Toolbar, Typography, Grid } from "@material-ui/core";
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { Link } from "react-router-dom";
9 import { User } from "~/models/user";
10 import { SearchBar } from "~/components/search-bar/search-bar";
11 import { Routes } from '~/routes/routes';
12 import { NotificationsMenu } from "~/views-components/main-app-bar/notifications-menu";
13 import { AccountMenu } from "~/views-components/main-app-bar/account-menu";
14 import { AnonymousMenu } from "~/views-components/main-app-bar/anonymous-menu";
15 import { HelpMenu } from './help-menu';
16 import { ReactNode } from "react";
17
18 type CssRules = 'toolbar' | 'link';
19
20 const styles: StyleRulesCallback<CssRules> = () => ({
21     link: {
22         textDecoration: 'none',
23         color: 'inherit'
24     },
25     toolbar: {
26         height: '56px'
27     }
28 });
29
30 interface MainAppBarDataProps {
31     searchText: string;
32     searchDebounce?: number;
33     user?: User;
34     buildInfo?: string;
35     children?: ReactNode;
36 }
37
38 export interface MainAppBarActionProps {
39     onSearch: (searchText: string) => void;
40 }
41
42 export type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps & WithStyles<CssRules>;
43
44 export const MainAppBar = withStyles(styles)(
45     (props: MainAppBarProps) => {
46         return <AppBar position="absolute">
47             <Toolbar className={props.classes.toolbar}>
48                 <Grid container justify="space-between">
49                     <Grid container item xs={3} direction="column" justify="center">
50                         <Typography variant="title" color="inherit" noWrap>
51                             <Link to={Routes.ROOT} className={props.classes.link}>
52                                 arvados workbench
53                             </Link>
54                         </Typography>
55                         <Typography variant="caption" color="inherit">{props.buildInfo}</Typography>
56                     </Grid>
57                     <Grid
58                         item
59                         xs={6}
60                         container
61                         alignItems="center">
62                         {props.user && <SearchBar
63                             value={props.searchText}
64                             onSearch={props.onSearch}
65                             debounce={props.searchDebounce}
66                         />}
67                     </Grid>
68                     <Grid
69                         item
70                         xs={3}
71                         container
72                         alignItems="center"
73                         justify="flex-end"
74                         wrap="nowrap">
75                         {props.user
76                             ? <>
77                                 <NotificationsMenu />
78                                 <AccountMenu />
79                                 <HelpMenu />
80                             </>
81                             : <AnonymousMenu />}
82                     </Grid>
83                 </Grid>
84             </Toolbar>
85             {props.children}
86         </AppBar>;
87     }
88 );