1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import { connect, DispatchProp } from "react-redux";
8 import { Route, Switch } from "react-router";
9 import { login, logout } from "~/store/auth/auth-action";
10 import { User } from "~/models/user";
11 import { RootState } from "~/store/store";
12 import { MainAppBar, MainAppBarActionProps, MainAppBarMenuItem } from '~/views-components/main-app-bar/main-app-bar';
13 import { push } from 'react-router-redux';
14 import { ProjectPanel } from "~/views/project-panel/project-panel";
15 import { DetailsPanel } from '~/views-components/details-panel/details-panel';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
18 import { ContextMenu } from "~/views-components/context-menu/context-menu";
19 import { FavoritePanel } from "../favorite-panel/favorite-panel";
20 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
21 import { Snackbar } from '~/views-components/snackbar/snackbar';
22 import { CollectionPanel } from '../collection-panel/collection-panel';
23 import { AuthService } from "~/services/auth-service/auth-service";
24 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
25 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
26 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
27 import { Routes } from '~/routes/routes';
28 import { SidePanel } from '~/views-components/side-panel/side-panel';
29 import { ProcessPanel } from '~/views/process-panel/process-panel';
30 import { Breadcrumbs } from '~/views-components/breadcrumbs/breadcrumbs';
31 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
32 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
33 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
34 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
35 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
36 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
37 import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
39 import { FilesUploadCollectionDialog } from '~/views-components/dialog-forms/files-upload-collection-dialog';
40 import { PartialCopyCollectionDialog } from '~/views-components/dialog-forms/partial-copy-collection-dialog';
42 const APP_BAR_HEIGHT = 100;
44 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
46 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
57 zIndex: theme.zIndex.drawer + 1,
62 backgroundColor: theme.palette.background.default,
66 paddingTop: APP_BAR_HEIGHT
69 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
76 interface WorkbenchDataProps {
78 currentToken?: string;
81 interface WorkbenchGeneralProps {
82 authService: AuthService;
86 interface WorkbenchActionProps {
89 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
91 interface NavMenuItem extends MainAppBarMenuItem {
95 interface WorkbenchState {
96 isCurrentTokenDialogOpen: boolean;
100 accountMenu: NavMenuItem[],
101 helpMenu: NavMenuItem[],
102 anonymousMenu: NavMenuItem[]
106 export const Workbench = withStyles(styles)(
107 connect<WorkbenchDataProps>(
108 (state: RootState) => ({
109 user: state.auth.user,
110 currentToken: state.auth.apiToken,
113 class extends React.Component<WorkbenchProps, WorkbenchState> {
115 isCurrentTokenDialogOpen: false,
122 label: 'Current token',
123 action: () => this.toggleCurrentTokenModal()
127 action: () => this.props.dispatch(logout())
131 action: () => this.props.dispatch(push("/my-account"))
137 action: () => this.props.dispatch(push("/help"))
143 action: () => this.props.dispatch(login())
150 const { classes, user } = this.props;
152 <div className={classes.root}>
153 <div className={classes.appBar}>
155 breadcrumbs={Breadcrumbs}
156 searchText={this.state.searchText}
157 user={this.props.user}
158 menuItems={this.state.menuItems}
159 buildInfo={this.props.buildInfo}
160 {...this.mainAppBarActions} />
162 {user && <SidePanel />}
163 <main className={classes.contentWrapper}>
164 <div className={classes.content}>
166 <Route path={Routes.PROJECTS} component={ProjectPanel} />
167 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
168 <Route path={Routes.FAVORITES} component={FavoritePanel} />
169 <Route path={Routes.PROCESSES} component={ProcessPanel} />
172 {user && <DetailsPanel />}
176 <CreateProjectDialog />
177 <CreateCollectionDialog />
179 <PartialCopyCollectionDialog />
181 <CopyCollectionDialog />
183 <MultipleFilesRemoveDialog />
184 <UpdateCollectionDialog />
185 <FilesUploadCollectionDialog />
186 <UpdateProjectDialog />
187 <MoveCollectionDialog />
188 <MoveProjectDialog />
190 currentToken={this.props.currentToken}
191 open={this.state.isCurrentTokenDialogOpen}
192 handleClose={this.toggleCurrentTokenModal} />
197 mainAppBarActions: MainAppBarActionProps = {
198 onSearch: searchText => {
199 this.setState({ searchText });
200 this.props.dispatch(push(`/search?q=${searchText}`));
202 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
203 onDetailsPanelToggle: () => {
204 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
208 toggleCurrentTokenModal = () => {
209 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });