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";
44 const APP_BAR_HEIGHT = 100;
46 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
48 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
59 zIndex: theme.zIndex.drawer + 1,
64 backgroundColor: theme.palette.background.default,
68 paddingTop: APP_BAR_HEIGHT
71 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
78 interface WorkbenchDataProps {
80 currentToken?: string;
83 interface WorkbenchGeneralProps {
84 authService: AuthService;
88 interface WorkbenchActionProps {
91 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
93 interface NavMenuItem extends MainAppBarMenuItem {
97 interface WorkbenchState {
98 isCurrentTokenDialogOpen: boolean;
102 accountMenu: NavMenuItem[],
103 helpMenu: NavMenuItem[],
104 anonymousMenu: NavMenuItem[]
108 export const Workbench = withStyles(styles)(
109 connect<WorkbenchDataProps>(
110 (state: RootState) => ({
111 user: state.auth.user,
112 currentToken: state.auth.apiToken,
115 class extends React.Component<WorkbenchProps, WorkbenchState> {
117 isCurrentTokenDialogOpen: false,
124 label: 'Current token',
125 action: () => this.toggleCurrentTokenModal()
129 action: () => this.props.dispatch(logout())
133 action: () => this.props.dispatch(push("/my-account"))
139 action: () => this.props.dispatch(push("/help"))
145 action: () => this.props.dispatch(login())
152 const { classes, user } = this.props;
154 <div className={classes.root}>
155 <div className={classes.appBar}>
157 breadcrumbs={Breadcrumbs}
158 searchText={this.state.searchText}
159 user={this.props.user}
160 menuItems={this.state.menuItems}
161 buildInfo={this.props.buildInfo}
162 {...this.mainAppBarActions} />
164 {user && <SidePanel />}
165 <main className={classes.contentWrapper}>
166 <div className={classes.content}>
168 <Route path={Routes.PROJECTS} component={ProjectPanel} />
169 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
170 <Route path={Routes.FAVORITES} component={FavoritePanel} />
171 <Route path={Routes.PROCESSES} component={ProcessPanel} />
172 <Route path={Routes.TRASH} component={TrashPanel} />
173 <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
176 {user && <DetailsPanel />}
180 <CreateProjectDialog />
181 <CreateCollectionDialog />
183 <PartialCopyCollectionDialog />
185 <CopyCollectionDialog />
187 <MultipleFilesRemoveDialog />
188 <UpdateCollectionDialog />
189 <FilesUploadCollectionDialog />
190 <UpdateProjectDialog />
191 <MoveCollectionDialog />
192 <MoveProjectDialog />
194 currentToken={this.props.currentToken}
195 open={this.state.isCurrentTokenDialogOpen}
196 handleClose={this.toggleCurrentTokenModal} />
201 mainAppBarActions: MainAppBarActionProps = {
202 onSearch: searchText => {
203 this.setState({ searchText });
204 this.props.dispatch(push(`/search?q=${searchText}`));
206 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
207 onDetailsPanelToggle: () => {
208 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
212 toggleCurrentTokenModal = () => {
213 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });