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 { TreeItem } from "~/components/tree/tree";
15 import { ProjectPanel } from "~/views/project-panel/project-panel";
16 import { DetailsPanel } from '~/views-components/details-panel/details-panel';
17 import { ArvadosTheme } from '~/common/custom-theme';
18 import { CreateProjectDialog } from "~/views-components/create-project-dialog/create-project-dialog";
19 import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
20 import { ProjectResource } from '~/models/project';
21 import { ContextMenu } from "~/views-components/context-menu/context-menu";
22 import { FavoritePanel } from "../favorite-panel/favorite-panel";
23 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
24 import { Snackbar } from '~/views-components/snackbar/snackbar';
25 import { CreateCollectionDialog } from '~/views-components/create-collection-dialog/create-collection-dialog';
26 import { CollectionPanel } from '../collection-panel/collection-panel';
27 import { UpdateCollectionDialog } from '~/views-components/update-collection-dialog/update-collection-dialog.';
28 import { UpdateProjectDialog } from '~/views-components/update-project-dialog/update-project-dialog';
29 import { AuthService } from "~/services/auth-service/auth-service";
30 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
31 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
32 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
33 import { DialogCollectionCreateWithSelectedFile } from '~/views-components/create-collection-dialog-with-selected/create-collection-dialog-with-selected';
34 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
35 import { ProjectCopyDialog } from '~/views-components/project-copy-dialog/project-copy-dialog';
36 import { CollectionPartialCopyDialog } from '~/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
37 import { MoveProjectDialog } from '~/views-components/move-project-dialog/move-project-dialog';
38 import { MoveCollectionDialog } from '~/views-components/move-collection-dialog/move-collection-dialog';
39 import { SidePanel } from '~/views-components/side-panel/side-panel';
40 import { Routes } from '~/routes/routes';
41 import { Breadcrumbs } from '~/views-components/breadcrumbs/breadcrumbs';
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 {
79 projects: Array<TreeItem<ProjectResource>>;
80 currentProjectId: string;
82 currentToken?: string;
85 interface WorkbenchGeneralProps {
86 authService: AuthService;
90 interface WorkbenchActionProps {
93 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
95 interface NavMenuItem extends MainAppBarMenuItem {
99 interface WorkbenchState {
100 isCurrentTokenDialogOpen: boolean;
104 accountMenu: NavMenuItem[],
105 helpMenu: NavMenuItem[],
106 anonymousMenu: NavMenuItem[]
110 export const Workbench = withStyles(styles)(
111 connect<WorkbenchDataProps>(
112 (state: RootState) => ({
113 projects: state.projects.items,
114 currentProjectId: state.projects.currentItemId,
115 user: state.auth.user,
116 currentToken: state.auth.apiToken,
119 class extends React.Component<WorkbenchProps, WorkbenchState> {
121 isCurrentTokenDialogOpen: false,
128 label: 'Current token',
129 action: () => this.toggleCurrentTokenModal()
133 action: () => this.props.dispatch(logout())
137 action: () => this.props.dispatch(push("/my-account"))
143 action: () => this.props.dispatch(push("/help"))
149 action: () => this.props.dispatch(login())
156 const { classes, user } = this.props;
158 <div className={classes.root}>
159 <div className={classes.appBar}>
161 breadcrumbs={Breadcrumbs}
162 searchText={this.state.searchText}
163 user={this.props.user}
164 menuItems={this.state.menuItems}
165 buildInfo={this.props.buildInfo}
166 {...this.mainAppBarActions} />
168 {user && <SidePanel />}
169 <main className={classes.contentWrapper}>
170 <div className={classes.content}>
172 <Route path={Routes.PROJECTS} component={ProjectPanel} />
173 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
174 <Route path={Routes.FAVORITES} component={FavoritePanel} />
177 {user && <DetailsPanel />}
181 <CreateProjectDialog />
182 <CreateCollectionDialog />
184 <CollectionPartialCopyDialog />
185 <DialogCollectionCreateWithSelectedFile />
187 <ProjectCopyDialog />
188 <MultipleFilesRemoveDialog />
189 <UpdateCollectionDialog />
190 <UploadCollectionFilesDialog />
191 <UpdateProjectDialog />
192 <MoveCollectionDialog />
193 <MoveProjectDialog />
195 currentToken={this.props.currentToken}
196 open={this.state.isCurrentTokenDialogOpen}
197 handleClose={this.toggleCurrentTokenModal} />
202 mainAppBarActions: MainAppBarActionProps = {
203 onSearch: searchText => {
204 this.setState({ searchText });
205 this.props.dispatch(push(`/search?q=${searchText}`));
207 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
208 onDetailsPanelToggle: () => {
209 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
213 toggleCurrentTokenModal = () => {
214 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });