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 { ProcessLogPanel } from '~/views/process-log-panel/process-log-panel';
31 import { Breadcrumbs } from '~/views-components/breadcrumbs/breadcrumbs';
32 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
33 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
34 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
35 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
36 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
37 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
38 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 import { TrashPanel } from "~/views/trash-panel/trash-panel";
43 import { MainContentBar } from '../../views-components/main-content-bar/main-content-bar';
45 const APP_BAR_HEIGHT = 100;
47 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
49 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
60 zIndex: theme.zIndex.drawer + 1,
65 backgroundColor: theme.palette.background.default,
69 paddingTop: APP_BAR_HEIGHT
72 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
79 interface WorkbenchDataProps {
81 currentToken?: string;
84 interface WorkbenchGeneralProps {
85 authService: AuthService;
89 interface WorkbenchActionProps {
92 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
94 interface NavMenuItem extends MainAppBarMenuItem {
98 interface WorkbenchState {
99 isCurrentTokenDialogOpen: boolean;
103 accountMenu: NavMenuItem[],
104 helpMenu: NavMenuItem[],
105 anonymousMenu: NavMenuItem[]
109 export const Workbench = withStyles(styles)(
110 connect<WorkbenchDataProps>(
111 (state: RootState) => ({
112 user: state.auth.user,
113 currentToken: state.auth.apiToken,
116 class extends React.Component<WorkbenchProps, WorkbenchState> {
118 isCurrentTokenDialogOpen: false,
125 label: 'Current token',
126 action: () => this.toggleCurrentTokenModal()
130 action: () => this.props.dispatch(logout())
134 action: () => this.props.dispatch(push("/my-account"))
140 action: () => this.props.dispatch(push("/help"))
146 action: () => this.props.dispatch(login())
153 const { classes, user } = this.props;
155 <div className={classes.root}>
156 <div className={classes.appBar}>
158 breadcrumbs={Breadcrumbs}
159 searchText={this.state.searchText}
160 user={this.props.user}
161 menuItems={this.state.menuItems}
162 buildInfo={this.props.buildInfo}
163 {...this.mainAppBarActions} />
165 {user && <SidePanel />}
166 <main className={classes.contentWrapper}>
167 {this.props.user && <MainContentBar />}
168 <div className={classes.content}>
170 <Route path={Routes.PROJECTS} component={ProjectPanel} />
171 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
172 <Route path={Routes.FAVORITES} component={FavoritePanel} />
173 <Route path={Routes.PROCESSES} component={ProcessPanel} />
174 <Route path={Routes.TRASH} component={TrashPanel} />
175 <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
178 {user && <DetailsPanel />}
182 <CreateProjectDialog />
183 <CreateCollectionDialog />
185 <PartialCopyCollectionDialog />
187 <CopyCollectionDialog />
189 <MultipleFilesRemoveDialog />
190 <UpdateCollectionDialog />
191 <FilesUploadCollectionDialog />
192 <UpdateProjectDialog />
193 <MoveCollectionDialog />
194 <MoveProjectDialog />
196 currentToken={this.props.currentToken}
197 open={this.state.isCurrentTokenDialogOpen}
198 handleClose={this.toggleCurrentTokenModal} />
203 mainAppBarActions: MainAppBarActionProps = {
204 onSearch: searchText => {
205 this.setState({ searchText });
206 this.props.dispatch(push(`/search?q=${searchText}`));
208 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
209 onDetailsPanelToggle: () => {
210 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
214 toggleDetailsPanel = () => {
215 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
218 toggleCurrentTokenModal = () => {
219 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });