94ef7db1c8cd70189fd7d822f00ae81adda1a713
[arvados.git] / src / views / workbench / workbench.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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 { User } from "~/models/user";
10 import { RootState } from "~/store/store";
11 import { MainAppBar } from '~/views-components/main-app-bar/main-app-bar';
12 import { push } from 'react-router-redux';
13 import { ProjectPanel } from "~/views/project-panel/project-panel";
14 import { DetailsPanel } from '~/views-components/details-panel/details-panel';
15 import { ArvadosTheme } from '~/common/custom-theme';
16 import { detailsPanelActions } from "~/store/details-panel/details-panel-action";
17 import { ContextMenu } from "~/views-components/context-menu/context-menu";
18 import { FavoritePanel } from "../favorite-panel/favorite-panel";
19 import { CurrentTokenDialog } from '~/views-components/current-token-dialog/current-token-dialog';
20 import { Snackbar } from '~/views-components/snackbar/snackbar';
21 import { CollectionPanel } from '../collection-panel/collection-panel';
22 import { AuthService } from "~/services/auth-service/auth-service";
23 import { RenameFileDialog } from '~/views-components/rename-file-dialog/rename-file-dialog';
24 import { FileRemoveDialog } from '~/views-components/file-remove-dialog/file-remove-dialog';
25 import { MultipleFilesRemoveDialog } from '~/views-components/file-remove-dialog/multiple-files-remove-dialog';
26 import { Routes } from '~/routes/routes';
27 import { SidePanel } from '~/views-components/side-panel/side-panel';
28 import { ProcessPanel } from '~/views/process-panel/process-panel';
29 import { ProcessLogPanel } from '~/views/process-log-panel/process-log-panel';
30 import { CreateProjectDialog } from '~/views-components/dialog-forms/create-project-dialog';
31 import { CreateCollectionDialog } from '~/views-components/dialog-forms/create-collection-dialog';
32 import { CopyCollectionDialog } from '~/views-components/dialog-forms/copy-collection-dialog';
33 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
34 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
35 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
36 import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
37 import { FilesUploadCollectionDialog } from '~/views-components/dialog-forms/files-upload-collection-dialog';
38 import { PartialCopyCollectionDialog } from '~/views-components/dialog-forms/partial-copy-collection-dialog';
39
40 import { TrashPanel } from "~/views/trash-panel/trash-panel";
41 import { MainContentBar } from '../../views-components/main-content-bar/main-content-bar';
42 import { Grid } from '@material-ui/core';
43
44 type CssRules = 'root' | 'contentWrapper' | 'content' | 'appBar';
45
46 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
47     root: {
48         overflow: 'hidden',
49         width: '100vw',
50         height: '100vh'
51     },
52     contentWrapper: {
53         background: theme.palette.background.default,
54         minWidth: 0,
55     },
56     content: {
57         minWidth: 0,
58         overflow: 'auto',
59         paddingLeft: theme.spacing.unit * 3,
60         paddingRight: theme.spacing.unit * 3,
61     },
62     appBar: {
63         zIndex: 1,
64     }
65 });
66
67 interface WorkbenchDataProps {
68     user?: User;
69     currentToken?: string;
70 }
71
72 interface WorkbenchGeneralProps {
73     authService: AuthService;
74     buildInfo: string;
75 }
76
77 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & DispatchProp<any> & WithStyles<CssRules>;
78
79 interface WorkbenchState {
80     isCurrentTokenDialogOpen: boolean;
81     anchorEl: any;
82     searchText: string;
83 }
84
85 export const Workbench = withStyles(styles)(
86     connect<WorkbenchDataProps>(
87         (state: RootState) => ({
88             user: state.auth.user,
89             currentToken: state.auth.apiToken,
90         })
91     )(
92         class extends React.Component<WorkbenchProps, WorkbenchState> {
93             state = {
94                 isCurrentTokenDialogOpen: false,
95                 anchorEl: null,
96                 searchText: "",
97             };
98
99             render() {
100                 return <>
101                     <Grid
102                         container
103                         direction="column"
104                         className={this.props.classes.root}>
105                         <Grid className={this.props.classes.appBar}>
106                             <MainAppBar
107                                 searchText={this.state.searchText}
108                                 user={this.props.user}
109                                 onSearch={this.onSearch} />
110                         </Grid>
111                         {this.props.user &&
112                             <Grid
113                                 container
114                                 item
115                                 xs
116                                 alignItems="stretch"
117                                 wrap="nowrap">
118                                 <Grid item>
119                                     <SidePanel />
120                                 </Grid>
121                                 <Grid
122                                     container
123                                     item
124                                     xs
125                                     component="main"
126                                     direction="column"
127                                     className={this.props.classes.contentWrapper}>
128                                     <Grid item>
129                                         <MainContentBar />
130                                     </Grid>
131                                     <Grid xs className={this.props.classes.content}>
132                                         <Switch>
133                                             <Route path={Routes.PROJECTS} component={ProjectPanel} />
134                                             <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
135                                             <Route path={Routes.FAVORITES} component={FavoritePanel} />
136                                             <Route path={Routes.PROCESSES} component={ProcessPanel} />
137                                             <Route path={Routes.TRASH} component={TrashPanel} />
138                                             <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
139                                         </Switch>
140                                     </Grid>
141                                 </Grid>
142                                 <Grid item>
143                                     <DetailsPanel />
144                                 </Grid>
145                             </Grid>}
146                     </Grid>
147                     <ContextMenu />
148                     <Snackbar />
149                     <CreateProjectDialog />
150                     <CreateCollectionDialog />
151                     <RenameFileDialog />
152                     <PartialCopyCollectionDialog />
153                     <FileRemoveDialog />
154                     <CopyCollectionDialog />
155                     <FileRemoveDialog />
156                     <MultipleFilesRemoveDialog />
157                     <UpdateCollectionDialog />
158                     <FilesUploadCollectionDialog />
159                     <UpdateProjectDialog />
160                     <MoveCollectionDialog />
161                     <MoveProjectDialog />
162                     <CurrentTokenDialog
163                         currentToken={this.props.currentToken}
164                         open={this.state.isCurrentTokenDialogOpen}
165                         handleClose={this.toggleCurrentTokenModal} />
166                 </>;
167             }
168
169             onSearch = (searchText: string) => {
170                 this.setState({ searchText });
171                 this.props.dispatch(push(`/search?q=${searchText}`));
172             }
173
174             toggleDetailsPanel = () => {
175                 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
176             }
177
178             toggleCurrentTokenModal = () => {
179                 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });
180             }
181         }
182     )
183 );