X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/a3f3b01052abf62ac96bb841747a657268498ad0..7a81b9d2c37ceb5add5df8fe9fe48b409d971e37:/src/views-components/main-app-bar/main-app-bar.tsx

diff --git a/src/views-components/main-app-bar/main-app-bar.tsx b/src/views-components/main-app-bar/main-app-bar.tsx
index d2082395..8a7e9f20 100644
--- a/src/views-components/main-app-bar/main-app-bar.tsx
+++ b/src/views-components/main-app-bar/main-app-bar.tsx
@@ -3,122 +3,77 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { AppBar, Toolbar, Typography, Grid, IconButton, Badge, Button, MenuItem } from "@material-ui/core";
-import NotificationsIcon from "@material-ui/icons/Notifications";
-import PersonIcon from "@material-ui/icons/Person";
-import HelpIcon from "@material-ui/icons/Help";
-import InfoIcon from '@material-ui/icons/Info';
-import SearchBar from "../../components/search-bar/search-bar";
-import Breadcrumbs, { Breadcrumb } from "../../components/breadcrumbs/breadcrumbs";
-import DropdownMenu from "../../components/dropdown-menu/dropdown-menu";
-import { User, getUserFullname } from "../../models/user";
+import { AppBar, Toolbar, Typography, Grid } from "@material-ui/core";
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
+import { Link } from "react-router-dom";
+import { User } from "~/models/user";
+import { SearchBar } from "~/views-components/search-bar/search-bar";
+import { Routes } from '~/routes/routes';
+import { NotificationsMenu } from "~/views-components/main-app-bar/notifications-menu";
+import { AccountMenu } from "~/views-components/main-app-bar/account-menu";
+import { HelpMenu } from '~/views-components/main-app-bar/help-menu';
+import { ReactNode } from "react";
+import { AdminMenu } from "~/views-components/main-app-bar/admin-menu";
 
-export interface MainAppBarMenuItem {
-    label: string;
-}
+type CssRules = 'toolbar' | 'link';
 
-export interface MainAppBarMenuItems {
-    accountMenu: MainAppBarMenuItem[];
-    helpMenu: MainAppBarMenuItem[];
-    anonymousMenu: MainAppBarMenuItem[];
-}
+const styles: StyleRulesCallback<CssRules> = () => ({
+    link: {
+        textDecoration: 'none',
+        color: 'inherit'
+    },
+    toolbar: {
+        height: '56px'
+    }
+});
 
 interface MainAppBarDataProps {
-    searchText: string;
-    searchDebounce?: number;
-    breadcrumbs: Breadcrumb[];
     user?: User;
-    menuItems: MainAppBarMenuItems;
-}
-
-export interface MainAppBarActionProps {
-    onSearch: (searchText: string) => void;
-    onBreadcrumbClick: (breadcrumb: Breadcrumb) => void;
-    onMenuItemClick: (menuItem: MainAppBarMenuItem) => void;
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, breadcrumb: Breadcrumb) => void;
-    onDetailsPanelToggle: () => void;
+    buildInfo?: string;
+    children?: ReactNode;
 }
 
-type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps;
+export type MainAppBarProps = MainAppBarDataProps & WithStyles<CssRules>;
 
-export const MainAppBar: React.SFC<MainAppBarProps> = (props) => {
-    return <AppBar position="static">
-        <Toolbar>
-            <Grid container justify="space-between">
-                <Grid item xs={3}>
-                    <Typography variant="headline" color="inherit" noWrap>
-                        Arvados
-                    </Typography>
-                    <Typography variant="body1" color="inherit" noWrap >
-                        Workbench 2
-                    </Typography>
-                </Grid>
-                <Grid item xs={6} container alignItems="center">
-                    {
-                        props.user && <SearchBar
-                            value={props.searchText}
-                            onSearch={props.onSearch}
-                            debounce={props.searchDebounce}
-                        />
-                    }
-                </Grid>
-                <Grid item xs={3} container alignItems="center" justify="flex-end">
-                    {
-                        props.user ? renderMenuForUser(props) : renderMenuForAnonymous(props)
-                    }
+export const MainAppBar = withStyles(styles)(
+    (props: MainAppBarProps) => {
+        return <AppBar position="absolute">
+            <Toolbar className={props.classes.toolbar}>
+                <Grid container justify="space-between">
+                    <Grid container item xs={3} direction="column" justify="center">
+                        <Typography variant="title" color="inherit" noWrap>
+                            <Link to={Routes.ROOT} className={props.classes.link}>
+                                arvados workbench
+                            </Link>
+                        </Typography>
+                        <Typography variant="caption" color="inherit">{props.buildInfo}</Typography>
+                    </Grid>
+                    <Grid
+                        item
+                        xs={6}
+                        container
+                        alignItems="center">
+                        {props.user && <SearchBar /> }
+                    </Grid>
+                    <Grid
+                        item
+                        xs={3}
+                        container
+                        alignItems="center"
+                        justify="flex-end"
+                        wrap="nowrap">
+                        {props.user
+                            ? <>
+                                <NotificationsMenu />
+                                <AccountMenu />
+                                {props.user.isAdmin && <AdminMenu />}
+                                <HelpMenu />
+                            </>
+                            : <HelpMenu />}
+                    </Grid>
                 </Grid>
-            </Grid>
-        </Toolbar>
-        <Toolbar >
-            {
-                props.user && <Breadcrumbs
-                    items={props.breadcrumbs}
-                    onClick={props.onBreadcrumbClick}
-                    onContextMenu={props.onContextMenu} />
-            }
-            <IconButton color="inherit" onClick={props.onDetailsPanelToggle}>
-                <InfoIcon />
-            </IconButton>
-        </Toolbar>
-    </AppBar>;
-};
-
-
-const renderMenuForUser = ({ user, menuItems, onMenuItemClick }: MainAppBarProps) => {
-    return (
-        <>
-            <IconButton color="inherit">
-                <Badge badgeContent={3} color="primary">
-                    <NotificationsIcon />
-                </Badge>
-            </IconButton>
-            <DropdownMenu icon={PersonIcon} id="account-menu">
-                <MenuItem>
-                    {getUserFullname(user)}
-                </MenuItem>
-                {renderMenuItems(menuItems.accountMenu, onMenuItemClick)}
-            </DropdownMenu>
-            <DropdownMenu icon={HelpIcon} id="help-menu">
-                {renderMenuItems(menuItems.helpMenu, onMenuItemClick)}
-            </DropdownMenu>
-        </>
-    );
-};
-
-const renderMenuForAnonymous = ({ onMenuItemClick, menuItems }: MainAppBarProps) => {
-    return menuItems.anonymousMenu.map((item, index) => (
-        <Button key={index} color="inherit" onClick={() => onMenuItemClick(item)}>
-            {item.label}
-        </Button>
-    ));
-};
-
-const renderMenuItems = (menuItems: MainAppBarMenuItem[], onMenuItemClick: (menuItem: MainAppBarMenuItem) => void) => {
-    return menuItems.map((item, index) => (
-        <MenuItem key={index} onClick={() => onMenuItemClick(item)}>
-            {item.label}
-        </MenuItem>
-    ));
-};
-
-export default MainAppBar;
+            </Toolbar>
+            {props.children}
+        </AppBar>;
+    }
+);
