14096-move-to-process
[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 { 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 { Routes } from '~/routes/routes';
28 import { SidePanel } from '~/views-components/side-panel/side-panel';
29 import { ProcessPanel } from '~/views/process-panel/process-panel';
30 import { ProcessLogPanel } from '~/views/process-log-panel/process-log-panel';
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 { 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
44 const APP_BAR_HEIGHT = 100;
45
46 type CssRules = 'root' | 'appBar' | 'content' | 'contentWrapper';
47
48 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
49     root: {
50         flexGrow: 1,
51         zIndex: 1,
52         overflow: 'hidden',
53         position: 'relative',
54         display: 'flex',
55         width: '100vw',
56         height: '100vh'
57     },
58     appBar: {
59         zIndex: theme.zIndex.drawer + 1,
60         position: "absolute",
61         width: "100%"
62     },
63     contentWrapper: {
64         backgroundColor: theme.palette.background.default,
65         display: "flex",
66         flexGrow: 1,
67         minWidth: 0,
68         paddingTop: APP_BAR_HEIGHT
69     },
70     content: {
71         padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
72         overflowY: "auto",
73         flexGrow: 1,
74         position: 'relative'
75     },
76 });
77
78 interface WorkbenchDataProps {
79     user?: User;
80     currentToken?: string;
81 }
82
83 interface WorkbenchGeneralProps {
84     authService: AuthService;
85     buildInfo: string;
86 }
87
88 interface WorkbenchActionProps {
89 }
90
91 type WorkbenchProps = WorkbenchDataProps & WorkbenchGeneralProps & WorkbenchActionProps & DispatchProp<any> & WithStyles<CssRules>;
92
93 interface NavMenuItem extends MainAppBarMenuItem {
94     action: () => void;
95 }
96
97 interface WorkbenchState {
98     isCurrentTokenDialogOpen: boolean;
99     anchorEl: any;
100     searchText: string;
101     menuItems: {
102         accountMenu: NavMenuItem[],
103         helpMenu: NavMenuItem[],
104         anonymousMenu: NavMenuItem[]
105     };
106 }
107
108 export const Workbench = withStyles(styles)(
109     connect<WorkbenchDataProps>(
110         (state: RootState) => ({
111             user: state.auth.user,
112             currentToken: state.auth.apiToken,
113         })
114     )(
115         class extends React.Component<WorkbenchProps, WorkbenchState> {
116             state = {
117                 isCurrentTokenDialogOpen: false,
118                 anchorEl: null,
119                 searchText: "",
120                 breadcrumbs: [],
121                 menuItems: {
122                     accountMenu: [
123                         {
124                             label: 'Current token',
125                             action: () => this.toggleCurrentTokenModal()
126                         },
127                         {
128                             label: "Logout",
129                             action: () => this.props.dispatch(logout())
130                         },
131                         {
132                             label: "My account",
133                             action: () => this.props.dispatch(push("/my-account"))
134                         }
135                     ],
136                     helpMenu: [
137                         {
138                             label: "Help",
139                             action: () => this.props.dispatch(push("/help"))
140                         }
141                     ],
142                     anonymousMenu: [
143                         {
144                             label: "Sign in",
145                             action: () => this.props.dispatch(login())
146                         }
147                     ]
148                 }
149             };
150
151             render() {
152                 const { classes, user } = this.props;
153                 return (
154                     <div className={classes.root}>
155                         <div className={classes.appBar}>
156                             <MainAppBar
157                                 breadcrumbs={Breadcrumbs}
158                                 searchText={this.state.searchText}
159                                 user={this.props.user}
160                                 menuItems={this.state.menuItems}
161                                 buildInfo={this.props.buildInfo}
162                                 {...this.mainAppBarActions} />
163                         </div>
164                         {user && <SidePanel />}
165                         <main className={classes.contentWrapper}>
166                             <div className={classes.content}>
167                                 <Switch>
168                                     <Route path={Routes.PROJECTS} component={ProjectPanel} />
169                                     <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
170                                     <Route path={Routes.FAVORITES} component={FavoritePanel} />
171                                     <Route path={Routes.PROCESSES} component={ProcessPanel} />
172                                     <Route path={Routes.TRASH} component={TrashPanel} />
173                                     <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
174                                 </Switch>
175                             </div>
176                             {user && <DetailsPanel />}
177                         </main>
178                         <ContextMenu />
179                         <Snackbar />
180                         <CreateProjectDialog />
181                         <CreateCollectionDialog />
182                         <RenameFileDialog />
183                         <PartialCopyCollectionDialog />
184                         <FileRemoveDialog />
185                         <CopyCollectionDialog />
186                         <FileRemoveDialog />
187                         <MultipleFilesRemoveDialog />
188                         <UpdateCollectionDialog />
189                         <FilesUploadCollectionDialog />
190                         <UpdateProjectDialog />
191                         <MoveCollectionDialog />
192                         <MoveProcessDialog />
193                         <MoveProjectDialog />
194                         <CurrentTokenDialog
195                             currentToken={this.props.currentToken}
196                             open={this.state.isCurrentTokenDialogOpen}
197                             handleClose={this.toggleCurrentTokenModal} />
198                     </div>
199                 );
200             }
201
202             mainAppBarActions: MainAppBarActionProps = {
203                 onSearch: searchText => {
204                     this.setState({ searchText });
205                     this.props.dispatch(push(`/search?q=${searchText}`));
206                 },
207                 onMenuItemClick: (menuItem: NavMenuItem) => menuItem.action(),
208                 onDetailsPanelToggle: () => {
209                     this.props.dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL());
210                 },
211             };
212
213             toggleCurrentTokenModal = () => {
214                 this.setState({ isCurrentTokenDialogOpen: !this.state.isCurrentTokenDialogOpen });
215             }
216         }
217     )
218 );