17782: Removes the last linter warnings.
[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 React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import { Route, Switch } from "react-router";
8 import { ProjectPanel } from "views/project-panel/project-panel";
9 import { DetailsPanel } from 'views-components/details-panel/details-panel';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import { ContextMenu } from "views-components/context-menu/context-menu";
12 import { FavoritePanel } from "../favorite-panel/favorite-panel";
13 import { TokenDialog } from 'views-components/token-dialog/token-dialog';
14 import { RichTextEditorDialog } from 'views-components/rich-text-editor-dialog/rich-text-editor-dialog';
15 import { Snackbar } from 'views-components/snackbar/snackbar';
16 import { CollectionPanel } from '../collection-panel/collection-panel';
17 import { RenameFileDialog } from 'views-components/rename-file-dialog/rename-file-dialog';
18 import { FileRemoveDialog } from 'views-components/file-remove-dialog/file-remove-dialog';
19 import { MultipleFilesRemoveDialog } from 'views-components/file-remove-dialog/multiple-files-remove-dialog';
20 import { Routes } from 'routes/routes';
21 import { SidePanel } from 'views-components/side-panel/side-panel';
22 import { ProcessPanel } from 'views/process-panel/process-panel';
23 import { ProcessLogPanel } from 'views/process-log-panel/process-log-panel';
24 import { ChangeWorkflowDialog } from 'views-components/run-process-dialog/change-workflow-dialog';
25 import { CreateProjectDialog } from 'views-components/dialog-forms/create-project-dialog';
26 import { CreateCollectionDialog } from 'views-components/dialog-forms/create-collection-dialog';
27 import { CopyCollectionDialog } from 'views-components/dialog-forms/copy-collection-dialog';
28 import { CopyProcessDialog } from 'views-components/dialog-forms/copy-process-dialog';
29 import { UpdateCollectionDialog } from 'views-components/dialog-forms/update-collection-dialog';
30 import { UpdateProcessDialog } from 'views-components/dialog-forms/update-process-dialog';
31 import { UpdateProjectDialog } from 'views-components/dialog-forms/update-project-dialog';
32 import { MoveProcessDialog } from 'views-components/dialog-forms/move-process-dialog';
33 import { MoveProjectDialog } from 'views-components/dialog-forms/move-project-dialog';
34 import { MoveCollectionDialog } from 'views-components/dialog-forms/move-collection-dialog';
35 import { FilesUploadCollectionDialog } from 'views-components/dialog-forms/files-upload-collection-dialog';
36 import { PartialCopyCollectionDialog } from 'views-components/dialog-forms/partial-copy-collection-dialog';
37 import { ProcessCommandDialog } from 'views-components/process-command-dialog/process-command-dialog';
38 import { RemoveProcessDialog } from 'views-components/process-remove-dialog/process-remove-dialog';
39 import { MainContentBar } from 'views-components/main-content-bar/main-content-bar';
40 import { Grid } from '@material-ui/core';
41 import { TrashPanel } from "views/trash-panel/trash-panel";
42 import { SharedWithMePanel } from 'views/shared-with-me-panel/shared-with-me-panel';
43 import { RunProcessPanel } from 'views/run-process-panel/run-process-panel';
44 import SplitterLayout from 'react-splitter-layout';
45 import { WorkflowPanel } from 'views/workflow-panel/workflow-panel';
46 import { SearchResultsPanel } from 'views/search-results-panel/search-results-panel';
47 import { SshKeyPanel } from 'views/ssh-key-panel/ssh-key-panel';
48 import { SiteManagerPanel } from "views/site-manager-panel/site-manager-panel";
49 import { MyAccountPanel } from 'views/my-account-panel/my-account-panel';
50 import { SharingDialog } from 'views-components/sharing-dialog/sharing-dialog';
51 import { NotFoundDialog } from 'views-components/not-found-dialog/not-found-dialog';
52 import { AdvancedTabDialog } from 'views-components/advanced-tab-dialog/advanced-tab-dialog';
53 import { ProcessInputDialog } from 'views-components/process-input-dialog/process-input-dialog';
54 import { VirtualMachineUserPanel } from 'views/virtual-machine-panel/virtual-machine-user-panel';
55 import { VirtualMachineAdminPanel } from 'views/virtual-machine-panel/virtual-machine-admin-panel';
56 import { ProjectPropertiesDialog } from 'views-components/project-properties-dialog/project-properties-dialog';
57 import { RepositoriesPanel } from 'views/repositories-panel/repositories-panel';
58 import { KeepServicePanel } from 'views/keep-service-panel/keep-service-panel';
59 import { ComputeNodePanel } from 'views/compute-node-panel/compute-node-panel';
60 import { ApiClientAuthorizationPanel } from 'views/api-client-authorization-panel/api-client-authorization-panel';
61 import { LinkPanel } from 'views/link-panel/link-panel';
62 import { RepositoriesSampleGitDialog } from 'views-components/repositories-sample-git-dialog/repositories-sample-git-dialog';
63 import { RepositoryAttributesDialog } from 'views-components/repository-attributes-dialog/repository-attributes-dialog';
64 import { CreateRepositoryDialog } from 'views-components/dialog-forms/create-repository-dialog';
65 import { RemoveRepositoryDialog } from 'views-components/repository-remove-dialog/repository-remove-dialog';
66 import { CreateSshKeyDialog } from 'views-components/dialog-forms/create-ssh-key-dialog';
67 import { PublicKeyDialog } from 'views-components/ssh-keys-dialog/public-key-dialog';
68 import { RemoveApiClientAuthorizationDialog } from 'views-components/api-client-authorizations-dialog/remove-dialog';
69 import { RemoveComputeNodeDialog } from 'views-components/compute-nodes-dialog/remove-dialog';
70 import { RemoveKeepServiceDialog } from 'views-components/keep-services-dialog/remove-dialog';
71 import { RemoveLinkDialog } from 'views-components/links-dialog/remove-dialog';
72 import { RemoveSshKeyDialog } from 'views-components/ssh-keys-dialog/remove-dialog';
73 import { RemoveVirtualMachineDialog } from 'views-components/virtual-machines-dialog/remove-dialog';
74 import { AttributesApiClientAuthorizationDialog } from 'views-components/api-client-authorizations-dialog/attributes-dialog';
75 import { AttributesComputeNodeDialog } from 'views-components/compute-nodes-dialog/attributes-dialog';
76 import { AttributesKeepServiceDialog } from 'views-components/keep-services-dialog/attributes-dialog';
77 import { AttributesLinkDialog } from 'views-components/links-dialog/attributes-dialog';
78 import { AttributesSshKeyDialog } from 'views-components/ssh-keys-dialog/attributes-dialog';
79 import { VirtualMachineAttributesDialog } from 'views-components/virtual-machines-dialog/attributes-dialog';
80 import { UserPanel } from 'views/user-panel/user-panel';
81 import { UserAttributesDialog } from 'views-components/user-dialog/attributes-dialog';
82 import { CreateUserDialog } from 'views-components/dialog-forms/create-user-dialog';
83 import { HelpApiClientAuthorizationDialog } from 'views-components/api-client-authorizations-dialog/help-dialog';
84 import { UserManageDialog } from 'views-components/user-dialog/manage-dialog';
85 import { SetupShellAccountDialog } from 'views-components/dialog-forms/setup-shell-account-dialog';
86 import { GroupsPanel } from 'views/groups-panel/groups-panel';
87 import { CreateGroupDialog } from 'views-components/dialog-forms/create-group-dialog';
88 import { RemoveGroupDialog } from 'views-components/groups-dialog/remove-dialog';
89 import { GroupAttributesDialog } from 'views-components/groups-dialog/attributes-dialog';
90 import { GroupDetailsPanel } from 'views/group-details-panel/group-details-panel';
91 import { RemoveGroupMemberDialog } from 'views-components/groups-dialog/member-remove-dialog';
92 import { GroupMemberAttributesDialog } from 'views-components/groups-dialog/member-attributes-dialog';
93 import { AddGroupMembersDialog } from 'views-components/dialog-forms/add-group-member-dialog';
94 import { PartialCopyToCollectionDialog } from 'views-components/dialog-forms/partial-copy-to-collection-dialog';
95 import { PublicFavoritePanel } from 'views/public-favorites-panel/public-favorites-panel';
96 import { LinkAccountPanel } from 'views/link-account-panel/link-account-panel';
97 import { FedLogin } from './fed-login';
98 import { CollectionsContentAddressPanel } from 'views/collection-content-address-panel/collection-content-address-panel';
99 import { AllProcessesPanel } from '../all-processes-panel/all-processes-panel';
100 import { NotFoundPanel } from '../not-found-panel/not-found-panel';
101 import { AutoLogout } from 'views-components/auto-logout/auto-logout';
102 import { RestoreCollectionVersionDialog } from 'views-components/collections-dialog/restore-version-dialog';
103 import { WebDavS3InfoDialog } from 'views-components/webdav-s3-dialog/webdav-s3-dialog';
104 import { pluginConfig } from 'plugins';
105 import { ElementListReducer } from 'common/plugintypes';
106
107 type CssRules = 'root' | 'container' | 'splitter' | 'asidePanel' | 'contentWrapper' | 'content';
108
109 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
110     root: {
111         paddingTop: theme.spacing.unit * 7,
112         background: theme.palette.background.default
113     },
114     container: {
115         position: 'relative'
116     },
117     splitter: {
118         '& > .layout-splitter': {
119             width: '2px'
120         }
121     },
122     asidePanel: {
123         paddingTop: theme.spacing.unit,
124         height: '100%'
125     },
126     contentWrapper: {
127         paddingTop: theme.spacing.unit,
128         minWidth: 0
129     },
130     content: {
131         minWidth: 0,
132         paddingLeft: theme.spacing.unit * 3,
133         paddingRight: theme.spacing.unit * 3,
134     }
135 });
136
137 interface WorkbenchDataProps {
138     isUserActive: boolean;
139     isNotLinking: boolean;
140     sessionIdleTimeout: number;
141 }
142
143 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
144
145 const defaultSplitterSize = 90;
146
147 const getSplitterInitialSize = () => {
148     const splitterSize = localStorage.getItem('splitterSize');
149     return splitterSize ? Number(splitterSize) : defaultSplitterSize;
150 };
151
152 const saveSplitterSize = (size: number) => localStorage.setItem('splitterSize', size.toString());
153
154 let routes = <>
155     <Route path={Routes.PROJECTS} component={ProjectPanel} />
156     <Route path={Routes.COLLECTIONS} component={CollectionPanel} />
157     <Route path={Routes.FAVORITES} component={FavoritePanel} />
158     <Route path={Routes.ALL_PROCESSES} component={AllProcessesPanel} />
159     <Route path={Routes.PROCESSES} component={ProcessPanel} />
160     <Route path={Routes.TRASH} component={TrashPanel} />
161     <Route path={Routes.PROCESS_LOGS} component={ProcessLogPanel} />
162     <Route path={Routes.SHARED_WITH_ME} component={SharedWithMePanel} />
163     <Route path={Routes.RUN_PROCESS} component={RunProcessPanel} />
164     <Route path={Routes.WORKFLOWS} component={WorkflowPanel} />
165     <Route path={Routes.SEARCH_RESULTS} component={SearchResultsPanel} />
166     <Route path={Routes.VIRTUAL_MACHINES_USER} component={VirtualMachineUserPanel} />
167     <Route path={Routes.VIRTUAL_MACHINES_ADMIN} component={VirtualMachineAdminPanel} />
168     <Route path={Routes.REPOSITORIES} component={RepositoriesPanel} />
169     <Route path={Routes.SSH_KEYS_USER} component={SshKeyPanel} />
170     <Route path={Routes.SSH_KEYS_ADMIN} component={SshKeyPanel} />
171     <Route path={Routes.SITE_MANAGER} component={SiteManagerPanel} />
172     <Route path={Routes.KEEP_SERVICES} component={KeepServicePanel} />
173     <Route path={Routes.USERS} component={UserPanel} />
174     <Route path={Routes.COMPUTE_NODES} component={ComputeNodePanel} />
175     <Route path={Routes.API_CLIENT_AUTHORIZATIONS} component={ApiClientAuthorizationPanel} />
176     <Route path={Routes.MY_ACCOUNT} component={MyAccountPanel} />
177     <Route path={Routes.GROUPS} component={GroupsPanel} />
178     <Route path={Routes.GROUP_DETAILS} component={GroupDetailsPanel} />
179     <Route path={Routes.LINKS} component={LinkPanel} />
180     <Route path={Routes.PUBLIC_FAVORITES} component={PublicFavoritePanel} />
181     <Route path={Routes.LINK_ACCOUNT} component={LinkAccountPanel} />
182     <Route path={Routes.COLLECTIONS_CONTENT_ADDRESS} component={CollectionsContentAddressPanel} />
183 </>;
184
185 const reduceRoutesFn: (a: React.ReactElement[],
186     b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
187
188 routes = React.createElement(React.Fragment, null, pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children)));
189
190 export const WorkbenchPanel =
191     withStyles(styles)((props: WorkbenchPanelProps) =>
192         <Grid container item xs className={props.classes.root}>
193             {props.sessionIdleTimeout > 0 && <AutoLogout />}
194             <Grid container item xs className={props.classes.container}>
195                 <SplitterLayout customClassName={props.classes.splitter} percentage={true}
196                     primaryIndex={0} primaryMinSize={10}
197                     secondaryInitialSize={getSplitterInitialSize()} secondaryMinSize={40}
198                     onSecondaryPaneSizeChange={saveSplitterSize}>
199                     {props.isUserActive && props.isNotLinking && <Grid container item xs component='aside' direction='column' className={props.classes.asidePanel}>
200                         <SidePanel />
201                     </Grid>}
202                     <Grid container item xs component="main" direction="column" className={props.classes.contentWrapper}>
203                         <Grid item xs>
204                             {props.isNotLinking && <MainContentBar />}
205                         </Grid>
206                         <Grid item xs className={props.classes.content}>
207                             <Switch>
208                                 {routes.props.children}
209                                 <Route path={Routes.NO_MATCH} component={NotFoundPanel} />
210                             </Switch>
211                         </Grid>
212                     </Grid>
213                 </SplitterLayout>
214             </Grid>
215             <Grid item>
216                 <DetailsPanel />
217             </Grid>
218             <AddGroupMembersDialog />
219             <AdvancedTabDialog />
220             <AttributesApiClientAuthorizationDialog />
221             <AttributesComputeNodeDialog />
222             <AttributesKeepServiceDialog />
223             <AttributesLinkDialog />
224             <AttributesSshKeyDialog />
225             <ChangeWorkflowDialog />
226             <ContextMenu />
227             <CopyCollectionDialog />
228             <CopyProcessDialog />
229             <CreateCollectionDialog />
230             <CreateGroupDialog />
231             <CreateProjectDialog />
232             <CreateRepositoryDialog />
233             <CreateSshKeyDialog />
234             <CreateUserDialog />
235             <TokenDialog />
236             <FileRemoveDialog />
237             <FilesUploadCollectionDialog />
238             <GroupAttributesDialog />
239             <GroupMemberAttributesDialog />
240             <HelpApiClientAuthorizationDialog />
241             <MoveCollectionDialog />
242             <MoveProcessDialog />
243             <MoveProjectDialog />
244             <MultipleFilesRemoveDialog />
245             <PublicKeyDialog />
246             <PartialCopyCollectionDialog />
247             <PartialCopyToCollectionDialog />
248             <ProcessCommandDialog />
249             <ProcessInputDialog />
250             <ProjectPropertiesDialog />
251             <RestoreCollectionVersionDialog />
252             <RemoveApiClientAuthorizationDialog />
253             <RemoveComputeNodeDialog />
254             <RemoveGroupDialog />
255             <RemoveGroupMemberDialog />
256             <RemoveKeepServiceDialog />
257             <RemoveLinkDialog />
258             <RemoveProcessDialog />
259             <RemoveRepositoryDialog />
260             <RemoveSshKeyDialog />
261             <RemoveVirtualMachineDialog />
262             <RenameFileDialog />
263             <RepositoryAttributesDialog />
264             <RepositoriesSampleGitDialog />
265             <RichTextEditorDialog />
266             <SetupShellAccountDialog />
267             <SharingDialog />
268             <NotFoundDialog />
269             <Snackbar />
270             <UpdateCollectionDialog />
271             <UpdateProcessDialog />
272             <UpdateProjectDialog />
273             <UserAttributesDialog />
274             <UserManageDialog />
275             <VirtualMachineAttributesDialog />
276             <FedLogin />
277             <WebDavS3InfoDialog />
278             {React.createElement(React.Fragment, null, pluginConfig.dialogs)}
279         </Grid>
280     );