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 { detailsPanelActions } from "~/store/details-panel/details-panel-action";
19 import { ProjectResource } from '~/models/project';
20 import { ContextMenu } from "~/views-components/context-menu/context-menu";
21 import { FavoritePanel } from "../favorite-panel/favorite-panel";
22 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
23 import { Snackbar } from '~/views-components/snackbar/snackbar';
24 import { CollectionPanel } from '../collection-panel/collection-panel';
25 import { AuthService } from "~/services/auth-service/auth-service";
26 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
27 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
28 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
29 import { UploadCollectionFilesDialog } from '~/views-components/upload-collection-files-dialog/upload-collection-files-dialog';
30 import { CollectionPartialCopyDialog } from '~/views-components/collection-partial-copy-dialog/collection-partial-copy-dialog';
31 import { SidePanel } from '~/views-components/side-panel/side-panel';
32 import { Routes } from '~/routes/routes';
33 import { Breadcrumbs } from '~/views-components/breadcrumbs/breadcrumbs';
34 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
35 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
36 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
37 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
38 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
39 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
40 import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
43 const APP_BAR_HEIGHT = 100;
45 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
47 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
58 zIndex: theme.zIndex.drawer + 1,
63 backgroundColor: theme.palette.background.default,
67 paddingTop: APP_BAR_HEIGHT
70 padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
77 interface WorkbenchDataProps {
78 projects: Array<TreeItem<ProjectResource>>;
79 currentProjectId: string;
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 projects: state.projects.items,
113 currentProjectId: state.projects.currentItemId,
114 user: state.auth.user,
115 currentToken: state.auth.apiToken,
118 class extends React.Component<WorkbenchProps, WorkbenchState> {
120 isCurrentTokenDialogOpen: false,
127 label: 'Current token',
128 action: () => this.toggleCurrentTokenModal()
132 action: () => this.props.dispatch(logout())
136 action: () => this.props.dispatch(push("/my-account"))
142 action: () => this.props.dispatch(push("/help"))
148 action: () => this.props.dispatch(login())
155 const { classes, user } = this.props;
157 <div className={classes.root}>
158 <div className={classes.appBar}>
160 breadcrumbs={Breadcrumbs}
161 searchText={this.state.searchText}
162 user={this.props.user}
163 menuItems={this.state.menuItems}
164 buildInfo={this.props.buildInfo}
165 {...this.mainAppBarActions} />
167 {user && <SidePanel />}
168 <main className={classes.contentWrapper}>
169 <div className={classes.content}>
171 <Route path={Routes.PROJECTS} component={ProjectPanel} />
172 <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
173 <Route path={Routes.FAVORITES} component={FavoritePanel} />
176 {user && <DetailsPanel />}
180 <CreateProjectDialog />
181 <CreateCollectionDialog />
183 <CollectionPartialCopyDialog />
185 <CopyCollectionDialog />
186 <MultipleFilesRemoveDialog />
187 <UpdateCollectionDialog />
188 <UploadCollectionFilesDialog />
189 <UpdateProjectDialog />
190 <MoveCollectionDialog />
191 <MoveProjectDialog />
193 currentToken={this.props.currentToken}
194 open={this.state.isCurrentTokenDialogOpen}
195 handleClose={this.toggleCurrentTokenModal} />
200 mainAppBarActions: MainAppBarActionProps = {
201 onSearch: searchText => {
202 this.setState({ searchText });
203 this.props.dispatch(push(`/search?q=${searchText}`));
205 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
206 onDetailsPanelToggle: () => {
207 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
211 toggleCurrentTokenModal = () => {
212 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });