1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { AppBar, Toolbar, Typography, Grid, IconButton, Badge, Paper, Input, StyleRulesCallback, withStyles, WithStyles, Button, MenuItem } from "@material-ui/core";
7 import NotificationsIcon from "@material-ui/icons/Notifications";
8 import PersonIcon from "@material-ui/icons/Person";
9 import HelpIcon from "@material-ui/icons/Help";
10 import SearchBar from "./search-bar/search-bar";
11 import Breadcrumbs, { Breadcrumb } from "../breadcrumbs/breadcrumbs"
12 import DropdownMenu from "./dropdown-menu/dropdown-menu"
13 import { User } from "../../models/user";
15 export interface MainAppBarMenuItem {
19 export interface MainAppBarMenuItems {
20 accountMenu: MainAppBarMenuItem[];
21 helpMenu: MainAppBarMenuItem[];
22 anonymousMenu: MainAppBarMenuItem[];
25 interface MainAppBarDataProps {
27 searchDebounce?: number;
28 breadcrumbs: Breadcrumb[];
30 menuItems: MainAppBarMenuItems;
33 export interface MainAppBarActionProps {
34 onSearch: (searchText: string) => void,
35 onBreadcrumbClick: (breadcrumb: Breadcrumb) => void,
36 onMenuItemClick: (menuItem: MainAppBarMenuItem) => void
39 type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps & WithStyles<CssRules>;
41 export class MainAppBar extends React.Component<MainAppBarProps> {
44 const { classes, searchText, breadcrumbs, searchDebounce } = this.props
45 return <AppBar className={classes.appBar} position="static">
49 justify="space-between"
52 <Typography variant="title" color="inherit" noWrap style={{ flexGrow: 1 }}>
53 <span>Arvados</span><br /><span style={{ fontSize: 12 }}>Workbench 2</span>
56 <Grid item xs={6} container alignItems="center">
58 this.props.user && <SearchBar
60 onSearch={this.props.onSearch}
61 debounce={searchDebounce}
65 <Grid item xs={3} container alignItems="center" justify="flex-end">
67 this.props.user ? this.renderMenuForUser() : this.renderMenuForAnonymous()
73 this.props.user && <Toolbar>
74 <Breadcrumbs items={breadcrumbs} onClick={this.props.onBreadcrumbClick} />
80 renderMenuForUser = () => {
81 const { user } = this.props
84 <IconButton color="inherit">
85 <Badge badgeContent={3} color="primary">
89 <DropdownMenu icon={PersonIcon} id="account-menu">
90 <MenuItem>{this.getUserFullname()}</MenuItem>
91 {this.renderMenuItems(this.props.menuItems.accountMenu)}
93 <DropdownMenu icon={HelpIcon} id="help-menu">
94 {this.renderMenuItems(this.props.menuItems.helpMenu)}
100 renderMenuForAnonymous = () => {
101 return this.props.menuItems.anonymousMenu.map((item, index) => (
102 <Button color="inherit" onClick={() => this.props.onMenuItemClick(item)}>{item.label}</Button>
106 renderMenuItems = (menuItems: MainAppBarMenuItem[]) => {
107 return menuItems.map((item, index) => (
108 <MenuItem key={index} onClick={() => this.props.onMenuItemClick(item)}>{item.label}</MenuItem>
112 getUserFullname = () => {
113 const { user } = this.props;
114 return user ? `${user.firstName} ${user.lastName}` : "";
119 type CssRules = "appBar"
121 const styles: StyleRulesCallback<CssRules> = theme => ({
123 backgroundColor: "#692498"
127 export default withStyles(styles)(MainAppBar)