Merge branch '14185-initial-load-page-flickering'
[arvados-workbench2.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 { CopyProcessDialog } from '~/views-components/dialog-forms/copy-process-dialog';
34 import { UpdateCollectionDialog } from '~/views-components/dialog-forms/update-collection-dialog';
35 import { UpdateProcessDialog } from '~/views-components/dialog-forms/update-process-dialog';
36 import { UpdateProjectDialog } from '~/views-components/dialog-forms/update-project-dialog';
37 import { MoveProcessDialog } from '~/views-components/dialog-forms/move-process-dialog';
38 import { MoveProjectDialog } from '~/views-components/dialog-forms/move-project-dialog';
39 import { MoveCollectionDialog } from '~/views-components/dialog-forms/move-collection-dialog';
40 import { FilesUploadCollectionDialog } from '~/views-components/dialog-forms/files-upload-collection-dialog';
41 import { PartialCopyCollectionDialog } from '~/views-components/dialog-forms/partial-copy-collection-dialog';
42 import { TrashPanel } from "~/views/trash-panel/trash-panel";
43 import { MainContentBar } from '~/views-components/main-content-bar/main-content-bar';
44 import { Grid, LinearProgress } from '@material-ui/core';
45 import { SharedWithMePanel } from '../shared-with-me-panel/shared-with-me-panel';
46 import SplitterLayout from 'react-splitter-layout';
47 import { ProcessCommandDialog } from '~/views-components/process-command-dialog/process-command-dialog';
48 import { isSystemWorking } from "~/store/progress-indicator/progress-indicator-reducer";
49 import { WorkbenchLoadingScreen } from './workbench-loading-screen';
50 import { isWorkbenchLoading } from '../../store/workbench/workbench-actions';
51
52 type CssRules = 'root' | 'container' | 'splitter' | 'asidePanel' | 'contentWrapper' | 'content' | 'appBar';
53
54 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
55     root: {
56         overflow: 'hidden',
57         width: '100vw',
58         height: '100vh',
59         paddingTop: theme.spacing.unit * 8
60     },
61     container: {
62         position: 'relative'
63     },
64     splitter: {
65         '& > .layout-splitter': {
66             width: '2px'
67         }
68     },
69     asidePanel: {
70         height: '100%',
71         background: theme.palette.background.default
72     },
73     contentWrapper: {
74         background: theme.palette.background.default,
75         minWidth: 0,
76     },
77     content: {
78         minWidth: 0,
79         paddingLeft: theme.spacing.unit * 3,
80         paddingRight: theme.spacing.unit * 3,
81     },
82     appBar: {
83         zIndex: 1,
84     }
85 });
86
87 interface WorkbenchDataProps {
88     user?: User;
89     currentToken?: string;
90     working: boolean;
91     loading: boolean;
92 }
93
94 interface WorkbenchGeneralProps {
95     authService: AuthService;
96     buildInfo: string;
97 }
98
99 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & DispatchProp<any> & WithStyles<CssRules>;
100
101 interface WorkbenchState {
102     searchText: string;
103 }
104
105 export const Workbench = withStyles(styles)(
106     connect<WorkbenchDataProps>(
107         (state: RootState) => ({
108             user: state.auth.user,
109             currentToken: state.auth.apiToken,
110             working: isSystemWorking(state.progressIndicator),
111             loading: isWorkbenchLoading(state),
112         })
113     )(
114         class extends React.Component<WorkbenchProps, WorkbenchState> {
115             state = {
116                 searchText: "",
117             };
118             render() {
119                 const { classes, loading } = this.props;
120                 return loading
121                     ? <WorkbenchLoadingScreen />
122                     : <>
123                         <MainAppBar
124                             searchText={this.state.searchText}
125                             user={this.props.user}
126                             onSearch={this.onSearch}
127                             buildInfo={this.props.buildInfo}>
128                             {this.props.working ? <LinearProgress color="secondary" /> : null}
129                         </MainAppBar>
130                         <Grid container direction="column" className={classes.root}>
131                             {this.props.user &&
132                                 <Grid container item xs alignItems="stretch" wrap="nowrap">
133                                     <Grid container item className={classes.container}>
134                                         <SplitterLayout customClassName={classes.splitter} percentage={true}
135                                             primaryIndex={0} primaryMinSize={20} secondaryInitialSize={80} secondaryMinSize={40}>
136                                             <Grid container item xs component='aside' direction='column' className={classes.asidePanel}>
137                                                 <SidePanel />
138                                             </Grid>
139                                             <Grid container item xs component="main" direction="column" className={classes.contentWrapper}>
140                                                 <Grid item>
141                                                     <MainContentBar />
142                                                 </Grid>
143                                                 <Grid item xs className={classes.content}>
144                                                     <Switch>
145                                                         <Route path={Routes.PROJECTS} component={ProjectPanel} />
146                                                         <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
147                                                         <Route path={Routes.FAVORITES} component={FavoritePanel} />
148                                                         <Route path={Routes.PROCESSES} component={ProcessPanel} />
149                                                         <Route path={Routes.TRASH} component={TrashPanel} />
150                                                         <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
151                                                         <Route path={Routes.SHARED_WITH_ME} component={SharedWithMePanel} />
152                                                     </Switch>
153                                                 </Grid>
154                                             </Grid>
155                                         </SplitterLayout>
156                                     </Grid>
157                                     <Grid item>
158                                         <DetailsPanel />
159                                     </Grid>
160                                 </Grid>
161                             }
162                         </Grid>
163                         <ContextMenu />
164                         <CopyCollectionDialog />
165                         <CopyProcessDialog />
166                         <CreateCollectionDialog />
167                         <CreateProjectDialog />
168                         <CurrentTokenDialog />
169                         <FileRemoveDialog />
170                         <FileRemoveDialog />
171                         <FilesUploadCollectionDialog />
172                         <MoveCollectionDialog />
173                         <MoveProcessDialog />
174                         <MoveProjectDialog />
175                         <MultipleFilesRemoveDialog />
176                         <PartialCopyCollectionDialog />
177                         <ProcessCommandDialog />
178                         <RenameFileDialog />
179                         <Snackbar />
180                         <UpdateCollectionDialog />
181                         <UpdateProcessDialog />
182                         <UpdateProjectDialog />
183                     </>;
184             }
185
186             onSearch = (searchText: string) => {
187                 this.setState({ searchText });
188                 this.props.dispatch(push(`/search?q=${searchText}`));
189             }
190
191             toggleDetailsPanel = () => {
192                 this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
193             }
194
195         }
196     )
197 );