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 { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
28 import { CollectionPartialCopyDialog } from '~/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
29 import { SidePanel } from '~/views-components/side-panel/side-panel';
30 import { Routes } from '~/routes/routes';
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';
41 const APP_BAR_HEIGHT = 100;
43 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
45 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
56 zIndex: theme.zIndex.drawer + 1,
61 backgroundColor: theme.palette.background.default,
65 paddingTop: APP_BAR_HEIGHT
68 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
75 interface WorkbenchDataProps {
77 currentToken?: string;
80 interface WorkbenchGeneralProps {
81 authService: AuthService;
85 interface WorkbenchActionProps {
88 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
90 interface NavMenuItem extends MainAppBarMenuItem {
94 interface WorkbenchState {
95 isCurrentTokenDialogOpen: boolean;
99 accountMenu: NavMenuItem[],
100 helpMenu: NavMenuItem[],
101 anonymousMenu: NavMenuItem[]
105 export const Workbench = withStyles(styles)(
106 connect<WorkbenchDataProps>(
107 (state: RootState) => ({
108 user: state.auth.user,
109 currentToken: state.auth.apiToken,
112 class extends React.Component<WorkbenchProps, WorkbenchState> {
114 isCurrentTokenDialogOpen: false,
121 label: 'Current token',
122 action: () => this.toggleCurrentTokenModal()
126 action: () => this.props.dispatch(logout())
130 action: () => this.props.dispatch(push("/my-account"))
136 action: () => this.props.dispatch(push("/help"))
142 action: () => this.props.dispatch(login())
149 const { classes, user } = this.props;
151 <div className={classes.root}>
152 <div className={classes.appBar}>
154 breadcrumbs={Breadcrumbs}
155 searchText={this.state.searchText}
156 user={this.props.user}
157 menuItems={this.state.menuItems}
158 buildInfo={this.props.buildInfo}
159 {...this.mainAppBarActions} />
161 {user && <SidePanel />}
162 <main className={classes.contentWrapper}>
163 <div className={classes.content}>
165 <Route path={Routes.PROJECTS} component={ProjectPanel} />
166 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
167 <Route path={Routes.FAVORITES} component={FavoritePanel} />
170 {user && <DetailsPanel />}
174 <CreateProjectDialog />
175 <CreateCollectionDialog />
177 <CollectionPartialCopyDialog />
179 <CopyCollectionDialog />
180 <MultipleFilesRemoveDialog />
181 <UpdateCollectionDialog />
182 <UploadCollectionFilesDialog />
183 <UpdateProjectDialog />
184 <MoveCollectionDialog />
185 <MoveProjectDialog />
187 currentToken={this.props.currentToken}
188 open={this.state.isCurrentTokenDialogOpen}
189 handleClose={this.toggleCurrentTokenModal} />
194 mainAppBarActions: MainAppBarActionProps = {
195 onSearch: searchText => {
196 this.setState({ searchText });
197 this.props.dispatch(push(`/search?q=${searchText}`));
199 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
200 onDetailsPanelToggle: () => {
201 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
205 toggleCurrentTokenModal = () => {
206 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });