}
class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
- renderArrow (items: boolean, arrowClass: string, open: boolean){
- return <i className={`${arrowClass} ${open ? "fas fa-caret-down" : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} />;
+ renderArrow(status: TreeItemStatus, arrowClass: string, open: boolean, id: string) {
+ return <i
+ onClick={() => this.props.toggleItem(id, status)}
+ className={`
+ ${arrowClass}
+ ${status === TreeItemStatus.Pending ? this.props.classes.arrowVisibility : ''}
- ${open ? `fas fa-caret-down ${this.props.classes.arrowTransition}` : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} />
++ ${open ? `fas fa-caret-down ${this.props.classes.arrowTransition}` : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} />;
}
render(): ReactElement<any> {
const level = this.props.level ? this.props.level : 0;
- const {classes, render, toggleItem, items} = this.props;
- const {list, arrow, activeArrow} = classes;
+ const { classes, render, toggleItem, items } = this.props;
+ const { list, inactiveArrow, activeArrow, loader } = classes;
return <List component="div" className={list}>
{items && items.map((it: TreeItem<T>, idx: number) =>
- <div key={`item/${level}/${idx}`}>
- <ListItem button onClick={() => toggleItem(it.id)} className={list} style={{paddingLeft: (level + 1) * 20}}>
- {this.renderArrow(true, it.active ? activeArrow : arrow, it.open)}
- {render(it, level)}
- </ListItem>
- {it.items && it.items.length > 0 &&
- <Collapse in={it.open} timeout="auto" unmountOnExit>
- <StyledTree
- items={it.items}
- render={render}
- toggleItem={toggleItem}
- level={level + 1}/>
- </Collapse>}
- </div>)}
+ <div key={`item/${level}/${idx}`}>
+ <ListItem button className={list} style={{ paddingLeft: (level + 1) * 20 }}>
+ {it.status === TreeItemStatus.Pending ? <CircularProgress size={10} className={loader} /> : null}
+ {it.toggled && it.items && it.items.length === 0 ? null : this.renderArrow(it.status, it.active ? activeArrow : inactiveArrow, it.open, it.id)}
+ {render(it, level)}
+ </ListItem>
+ {it.items && it.items.length > 0 &&
+ <Collapse in={it.open} timeout="auto" unmountOnExit>
+ <StyledTree
+ items={it.items}
+ render={render}
+ toggleItem={toggleItem}
+ level={level + 1} />
+ </Collapse>}
+ </div>)}
- </List>
+ </List>;
}
}
import { User } from "../../models/user";
import Grid from "@material-ui/core/Grid/Grid";
import { RootState } from "../../store/store";
- import projectActions from "../../store/project/project-action"
-
+ import MainAppBar, { MainAppBarActionProps, MainAppBarMenuItems, MainAppBarMenuItem } from '../../components/main-app-bar/main-app-bar';
+ import { Breadcrumb } from '../../components/breadcrumbs/breadcrumbs';
+ import { push } from 'react-router-redux';
+ import projectActions from "../../store/project/project-action";
import ProjectTree from '../../components/project-tree/project-tree';
-import { TreeItem } from "../../components/tree/tree";
+import { TreeItem, TreeItemStatus } from "../../components/tree/tree";
import { Project } from "../../models/project";
import { projectService } from '../../services/services';
}
class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
- constructor(props: WorkbenchProps) {
- super(props);
- this.state = {
- anchorEl: null
+ state = {
+ anchorEl: null,
+ searchText: "",
+ breadcrumbs: [
+ {
+ label: "Projects",
+ path: "/projects"
+ }, {
+ label: "Project 1",
+ path: "/projects/project-1"
+ }
+ ],
+ menuItems: {
+ accountMenu: [
+ {
+ label: "Logout",
+ action: () => this.props.dispatch(authActions.LOGOUT())
+ },
+ {
+ label: "My account",
+ action: () => this.props.dispatch(push("/my-account"))
+ }
+ ],
+ helpMenu: [
+ {
+ label: "Help",
+ action: () => this.props.dispatch(push("/help"))
+ }
+ ],
+ anonymousMenu: [
+ {
+ label: "Sign in",
+ action: () => this.props.dispatch(authActions.LOGIN())
+ }
+ ]
}
- }
-
- login = () => {
- this.props.dispatch(authActions.LOGIN());
- };
-
- logout = () => {
- this.handleClose();
- this.props.dispatch(authActions.LOGOUT());
};
- handleOpenMenu = (event: React.MouseEvent<any>) => {
- this.setState({
- anchorEl: event.currentTarget
- });
- };
- handleClose = () => {
- this.setState({
- anchorEl: null
- });
+ mainAppBarActions: MainAppBarActionProps = {
+ onBreadcrumbClick: (breadcrumb: NavBreadcrumb) => this.props.dispatch(push(breadcrumb.path)),
+ onSearch: searchText => {
+ this.setState({ searchText });
+ this.props.dispatch(push(`/search?q=${searchText}`));
+ },
+ onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action()
};
- toggleProjectTreeItem = (itemId: string) => {
- this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
+ toggleProjectTreeItem = (itemId: string, status: TreeItemStatus) => {
+ if (status === TreeItemStatus.Loaded) {
- this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId))
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
- });
+ } else {
+ this.props.dispatch<any>(projectService.getProjectList(itemId)).then(() => {
+ this.props.dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM(itemId));
- })
++ });
+ }
- };
+ }
render() {
const { classes, user } = this.props;
return (
<div className={classes.root}>
- <AppBar position="absolute" className={classes.appBar}>
- <Toolbar>
- <Typography variant="title" color="inherit" noWrap style={{ flexGrow: 1 }}>
- <span>Arvados</span><br /><span style={{ fontSize: 12 }}>Workbench 2</span>
- </Typography>
- {user ?
- <Grid container style={{ width: 'auto' }}>
- <Grid container style={{ width: 'auto' }} alignItems='center'>
- <Typography variant="title" color="inherit" noWrap>
- {user.firstName} {user.lastName}
- </Typography>
- </Grid>
- <Grid item>
- <IconButton
- aria-owns={this.state.anchorEl ? 'menu-appbar' : undefined}
- aria-haspopup="true"
- onClick={this.handleOpenMenu}
- color="inherit">
- <AccountCircle />
- </IconButton>
- </Grid>
- <Menu
- id="menu-appbar"
- anchorEl={this.state.anchorEl}
- anchorOrigin={{
- vertical: 'top',
- horizontal: 'right',
- }}
- transformOrigin={{
- vertical: 'top',
- horizontal: 'right',
- }}
- open={!!this.state.anchorEl}
- onClose={this.handleClose}>
- <MenuItem onClick={this.logout}>Logout</MenuItem>
- <MenuItem onClick={this.handleClose}>My account</MenuItem>
- </Menu>
- </Grid>
- :
- <Button color="inherit" onClick={this.login}>Login</Button>
- }
- </Toolbar>
- </AppBar>
+ <div className={classes.appBar}>
+ <MainAppBar
+ breadcrumbs={this.state.breadcrumbs}
+ searchText={this.state.searchText}
+ user={this.props.user}
+ menuItems={this.state.menuItems}
+ {...this.mainAppBarActions}
+ />
+ </div>
{user &&
- <Drawer
- variant="permanent"
- classes={{
- paper: classes.drawerPaper,
- }}>
- <div className={classes.toolbar}/>
- <ProjectTree
- projects={this.props.projects}
- toggleProjectTreeItem={this.toggleProjectTreeItem}/>
- </Drawer>}
+ <Drawer
+ variant="permanent"
+ classes={{
+ paper: classes.drawerPaper,
+ }}>
+ <div className={classes.toolbar} />
+ <ProjectTree
+ projects={this.props.projects}
+ toggleProjectTreeItem={this.toggleProjectTreeItem} />
+ </Drawer>}
<main className={classes.content}>
- <div className={classes.toolbar} />
<div className={classes.toolbar} />
<Switch>
<Route path="/project/:name" component={ProjectList} />