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, Button, MenuItem } from "@material-ui/core";
7 import { User, getUserFullname } from "~/models/user";
8 import { SearchBar } from "~/components/search-bar/search-bar";
9 import { Breadcrumbs, Breadcrumb } from "~/components/breadcrumbs/breadcrumbs";
10 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
11 import { DetailsIcon, NotificationIcon, UserPanelIcon, HelpIcon } from "~/components/icon/icon";
13 export interface MainAppBarMenuItem {
17 export interface MainAppBarMenuItems {
18 accountMenu: MainAppBarMenuItem[];
19 helpMenu: MainAppBarMenuItem[];
20 anonymousMenu: MainAppBarMenuItem[];
23 interface MainAppBarDataProps {
25 searchDebounce?: number;
26 breadcrumbs: React.ComponentType<any>;
28 menuItems: MainAppBarMenuItems;
32 export interface MainAppBarActionProps {
33 onSearch: (searchText: string) => void;
34 onBreadcrumbClick: (breadcrumb: Breadcrumb) => void;
35 onMenuItemClick: (menuItem: MainAppBarMenuItem) => void;
36 onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => void;
37 onDetailsPanelToggle: () => void;
40 type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps;
42 export const MainAppBar: React.SFC<MainAppBarProps> = (props) => {
43 return <AppBar position="static">
45 <Grid container justify="space-between">
47 <Typography variant="headline" color="inherit" noWrap>
50 <Typography variant="body1" color="inherit" noWrap >
54 <Grid item xs={6} container alignItems="center">
56 props.user && <SearchBar
57 value={props.searchText}
58 onSearch={props.onSearch}
59 debounce={props.searchDebounce}
63 <Grid item xs={3} container alignItems="center" justify="flex-end">
65 props.user ? renderMenuForUser(props) : renderMenuForAnonymous(props)
71 {props.user && <props.breadcrumbs />}
72 {props.user && <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
80 const renderMenuForUser = ({ user, menuItems, onMenuItemClick }: MainAppBarProps) => {
83 <IconButton color="inherit">
84 <Badge badgeContent={3} color="primary">
88 <DropdownMenu icon={<UserPanelIcon />} id="account-menu">
90 {getUserFullname(user)}
92 {renderMenuItems(menuItems.accountMenu, onMenuItemClick)}
94 <DropdownMenu icon={<HelpIcon />} id="help-menu">
95 {renderMenuItems(menuItems.helpMenu, onMenuItemClick)}
101 const renderMenuForAnonymous = ({ onMenuItemClick, menuItems }: MainAppBarProps) => {
102 return menuItems.anonymousMenu.map((item, index) => (
103 <Button key={index} color="inherit" onClick={() => onMenuItemClick(item)}>
109 const renderMenuItems = (menuItems: MainAppBarMenuItem[], onMenuItemClick: (menuItem: MainAppBarMenuItem) => void) => {
110 return menuItems.map((item, index) => (
111 <MenuItem key={index} onClick={() => onMenuItemClick(item)}>