21386: allprocesses loading view good Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados.git] / services / workbench2 / 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, { useEffect, useState } 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 { ChangeWorkflowDialog } from "views-components/run-process-dialog/change-workflow-dialog";
24 import { CreateProjectDialog } from "views-components/dialog-forms/create-project-dialog";
25 import { CreateCollectionDialog } from "views-components/dialog-forms/create-collection-dialog";
26 import { CopyCollectionDialog, CopyMultiCollectionDialog } from "views-components/dialog-forms/copy-collection-dialog";
27 import { CopyProcessDialog } from "views-components/dialog-forms/copy-process-dialog";
28 import { UpdateCollectionDialog } from "views-components/dialog-forms/update-collection-dialog";
29 import { UpdateProcessDialog } from "views-components/dialog-forms/update-process-dialog";
30 import { UpdateProjectDialog } from "views-components/dialog-forms/update-project-dialog";
31 import { MoveProcessDialog } from "views-components/dialog-forms/move-process-dialog";
32 import { MoveProjectDialog } from "views-components/dialog-forms/move-project-dialog";
33 import { MoveCollectionDialog } from "views-components/dialog-forms/move-collection-dialog";
34 import { FilesUploadCollectionDialog } from "views-components/dialog-forms/files-upload-collection-dialog";
35 import { PartialCopyToNewCollectionDialog } from "views-components/dialog-forms/partial-copy-to-new-collection-dialog";
36 import { PartialCopyToExistingCollectionDialog } from "views-components/dialog-forms/partial-copy-to-existing-collection-dialog";
37 import { PartialCopyToSeparateCollectionsDialog } from "views-components/dialog-forms/partial-copy-to-separate-collections-dialog";
38 import { PartialMoveToNewCollectionDialog } from "views-components/dialog-forms/partial-move-to-new-collection-dialog";
39 import { PartialMoveToExistingCollectionDialog } from "views-components/dialog-forms/partial-move-to-existing-collection-dialog";
40 import { PartialMoveToSeparateCollectionsDialog } from "views-components/dialog-forms/partial-move-to-separate-collections-dialog";
41 import { RemoveProcessDialog } from "views-components/process-remove-dialog/process-remove-dialog";
42 import { MainContentBar } from "views-components/main-content-bar/main-content-bar";
43 import { Grid } from "@material-ui/core";
44 import { TrashPanel } from "views/trash-panel/trash-panel";
45 import { SharedWithMePanel } from "views/shared-with-me-panel/shared-with-me-panel";
46 import { RunProcessPanel } from "views/run-process-panel/run-process-panel";
47 import SplitterLayout from "react-splitter-layout";
48 import { WorkflowPanel } from "views/workflow-panel/workflow-panel";
49 import { RegisteredWorkflowPanel } from "views/workflow-panel/registered-workflow-panel";
50 import { SearchResultsPanel } from "views/search-results-panel/search-results-panel";
51 import { SshKeyPanel } from "views/ssh-key-panel/ssh-key-panel";
52 import { SshKeyAdminPanel } from "views/ssh-key-panel/ssh-key-admin-panel";
53 import { SiteManagerPanel } from "views/site-manager-panel/site-manager-panel";
54 import { UserProfilePanel } from "views/user-profile-panel/user-profile-panel";
55 import { SharingDialog } from "views-components/sharing-dialog/sharing-dialog";
56 import { NotFoundDialog } from "views-components/not-found-dialog/not-found-dialog";
57 import { AdvancedTabDialog } from "views-components/advanced-tab-dialog/advanced-tab-dialog";
58 import { ProcessInputDialog } from "views-components/process-input-dialog/process-input-dialog";
59 import { VirtualMachineUserPanel } from "views/virtual-machine-panel/virtual-machine-user-panel";
60 import { VirtualMachineAdminPanel } from "views/virtual-machine-panel/virtual-machine-admin-panel";
61 import { RepositoriesPanel } from "views/repositories-panel/repositories-panel";
62 import { KeepServicePanel } from "views/keep-service-panel/keep-service-panel";
63 import { ApiClientAuthorizationPanel } from "views/api-client-authorization-panel/api-client-authorization-panel";
64 import { LinkPanel } from "views/link-panel/link-panel";
65 import { RepositoriesSampleGitDialog } from "views-components/repositories-sample-git-dialog/repositories-sample-git-dialog";
66 import { RepositoryAttributesDialog } from "views-components/repository-attributes-dialog/repository-attributes-dialog";
67 import { CreateRepositoryDialog } from "views-components/dialog-forms/create-repository-dialog";
68 import { RemoveRepositoryDialog } from "views-components/repository-remove-dialog/repository-remove-dialog";
69 import { CreateSshKeyDialog } from "views-components/dialog-forms/create-ssh-key-dialog";
70 import { PublicKeyDialog } from "views-components/ssh-keys-dialog/public-key-dialog";
71 import { RemoveApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/remove-dialog";
72 import { RemoveKeepServiceDialog } from "views-components/keep-services-dialog/remove-dialog";
73 import { RemoveLinkDialog } from "views-components/links-dialog/remove-dialog";
74 import { RemoveSshKeyDialog } from "views-components/ssh-keys-dialog/remove-dialog";
75 import { VirtualMachineAttributesDialog } from "views-components/virtual-machines-dialog/attributes-dialog";
76 import { RemoveVirtualMachineDialog } from "views-components/virtual-machines-dialog/remove-dialog";
77 import { RemoveVirtualMachineLoginDialog } from "views-components/virtual-machines-dialog/remove-login-dialog";
78 import { VirtualMachineAddLoginDialog } from "views-components/virtual-machines-dialog/add-login-dialog";
79 import { AttributesApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/attributes-dialog";
80 import { AttributesKeepServiceDialog } from "views-components/keep-services-dialog/attributes-dialog";
81 import { AttributesLinkDialog } from "views-components/links-dialog/attributes-dialog";
82 import { AttributesSshKeyDialog } from "views-components/ssh-keys-dialog/attributes-dialog";
83 import { UserPanel } from "views/user-panel/user-panel";
84 import { UserAttributesDialog } from "views-components/user-dialog/attributes-dialog";
85 import { CreateUserDialog } from "views-components/dialog-forms/create-user-dialog";
86 import { HelpApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/help-dialog";
87 import { DeactivateDialog } from "views-components/user-dialog/deactivate-dialog";
88 import { ActivateDialog } from "views-components/user-dialog/activate-dialog";
89 import { SetupDialog } from "views-components/user-dialog/setup-dialog";
90 import { GroupsPanel } from "views/groups-panel/groups-panel";
91 import { RemoveGroupDialog } from "views-components/groups-dialog/remove-dialog";
92 import { GroupAttributesDialog } from "views-components/groups-dialog/attributes-dialog";
93 import { GroupDetailsPanel } from "views/group-details-panel/group-details-panel";
94 import { RemoveGroupMemberDialog } from "views-components/groups-dialog/member-remove-dialog";
95 import { GroupMemberAttributesDialog } from "views-components/groups-dialog/member-attributes-dialog";
96 import { PublicFavoritePanel } from "views/public-favorites-panel/public-favorites-panel";
97 import { LinkAccountPanel } from "views/link-account-panel/link-account-panel";
98 import { FedLogin } from "./fed-login";
99 import { CollectionsContentAddressPanel } from "views/collection-content-address-panel/collection-content-address-panel";
100 import { AllProcessesPanel } from "../all-processes-panel/all-processes-panel";
101 import { NotFoundPanel } from "../not-found-panel/not-found-panel";
102 import { AutoLogout } from "views-components/auto-logout/auto-logout";
103 import { RestoreCollectionVersionDialog } from "views-components/collections-dialog/restore-version-dialog";
104 import { WebDavS3InfoDialog } from "views-components/webdav-s3-dialog/webdav-s3-dialog";
105 import { pluginConfig } from "plugins";
106 import { ElementListReducer } from "common/plugintypes";
107 import { COLLAPSE_ICON_SIZE } from "views-components/side-panel-toggle/side-panel-toggle";
108 import { Banner } from "views-components/baner/banner";
109 import { InstanceTypesPanel } from "views/instance-types-panel/instance-types-panel";
110
111 type CssRules = "root" | "container" | "splitter" | "asidePanel" | "contentWrapper" | "content";
112
113 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
114     root: {
115         paddingTop: theme.spacing.unit * 7,
116         background: theme.palette.background.default,
117     },
118     container: {
119         position: "relative",
120     },
121     splitter: {
122         "& > .layout-splitter": {
123             width: "3px",
124         },
125         "& > .layout-splitter-disabled": {
126             pointerEvents: "none",
127             cursor: "pointer",
128         },
129     },
130     asidePanel: {
131         paddingTop: theme.spacing.unit,
132         height: "100%",
133     },
134     contentWrapper: {
135         paddingTop: theme.spacing.unit,
136         minWidth: 0,
137     },
138     content: {
139         minWidth: 0,
140         paddingLeft: theme.spacing.unit * 3,
141         paddingRight: theme.spacing.unit * 3,
142         // Reserve vertical space for app bar + MainContentBar
143         minHeight: `calc(100vh - ${theme.spacing.unit * 16}px)`,
144         display: "flex",
145     },
146 });
147
148 interface WorkbenchDataProps {
149     isUserActive: boolean;
150     isNotLinking: boolean;
151     sessionIdleTimeout: number;
152     sidePanelIsCollapsed: boolean;
153     isTransitioning: boolean;
154     currentSideWidth: number;
155 }
156
157 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
158
159 const defaultSplitterSize = 90;
160
161 const getSplitterInitialSize = () => {
162     const splitterSize = localStorage.getItem("splitterSize");
163     return splitterSize ? Number(splitterSize) : defaultSplitterSize;
164 };
165
166 const saveSplitterSize = (size: number) => localStorage.setItem("splitterSize", size.toString());
167
168 let routes = (
169     <>
170         <Route
171             path={Routes.PROJECTS}
172             component={ProjectPanel}
173         />
174         <Route
175             path={Routes.COLLECTIONS}
176             component={CollectionPanel}
177         />
178         <Route
179             path={Routes.FAVORITES}
180             component={FavoritePanel}
181         />
182         <Route
183             path={Routes.ALL_PROCESSES}
184             component={AllProcessesPanel}
185         />
186         <Route
187             path={Routes.PROCESSES}
188             component={ProcessPanel}
189         />
190         <Route
191             path={Routes.TRASH}
192             component={TrashPanel}
193         />
194         <Route
195             path={Routes.SHARED_WITH_ME}
196             component={SharedWithMePanel}
197         />
198         <Route
199             path={Routes.RUN_PROCESS}
200             component={RunProcessPanel}
201         />
202         <Route
203             path={Routes.REGISTEREDWORKFLOW}
204             component={RegisteredWorkflowPanel}
205         />
206         <Route
207             path={Routes.WORKFLOWS}
208             component={WorkflowPanel}
209         />
210         <Route
211             path={Routes.SEARCH_RESULTS}
212             component={SearchResultsPanel}
213         />
214         <Route
215             path={Routes.VIRTUAL_MACHINES_USER}
216             component={VirtualMachineUserPanel}
217         />
218         <Route
219             path={Routes.VIRTUAL_MACHINES_ADMIN}
220             component={VirtualMachineAdminPanel}
221         />
222         <Route
223             path={Routes.REPOSITORIES}
224             component={RepositoriesPanel}
225         />
226         <Route
227             path={Routes.SSH_KEYS_USER}
228             component={SshKeyPanel}
229         />
230         <Route
231             path={Routes.SSH_KEYS_ADMIN}
232             component={SshKeyAdminPanel}
233         />
234         <Route
235             path={Routes.INSTANCE_TYPES}
236             component={InstanceTypesPanel}
237         />
238         <Route
239             path={Routes.SITE_MANAGER}
240             component={SiteManagerPanel}
241         />
242         <Route
243             path={Routes.KEEP_SERVICES}
244             component={KeepServicePanel}
245         />
246         <Route
247             path={Routes.USERS}
248             component={UserPanel}
249         />
250         <Route
251             path={Routes.API_CLIENT_AUTHORIZATIONS}
252             component={ApiClientAuthorizationPanel}
253         />
254         <Route
255             path={Routes.MY_ACCOUNT}
256             component={UserProfilePanel}
257         />
258         <Route
259             path={Routes.USER_PROFILE}
260             component={UserProfilePanel}
261         />
262         <Route
263             path={Routes.GROUPS}
264             component={GroupsPanel}
265         />
266         <Route
267             path={Routes.GROUP_DETAILS}
268             component={GroupDetailsPanel}
269         />
270         <Route
271             path={Routes.LINKS}
272             component={LinkPanel}
273         />
274         <Route
275             path={Routes.PUBLIC_FAVORITES}
276             component={PublicFavoritePanel}
277         />
278         <Route
279             path={Routes.LINK_ACCOUNT}
280             component={LinkAccountPanel}
281         />
282         <Route
283             path={Routes.COLLECTIONS_CONTENT_ADDRESS}
284             component={CollectionsContentAddressPanel}
285         />
286     </>
287 );
288
289 const reduceRoutesFn: (a: React.ReactElement[], b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
290
291 routes = React.createElement(
292     React.Fragment,
293     null,
294     pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children))
295 );
296
297 export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => {
298 const { classes, sidePanelIsCollapsed, isNotLinking, isTransitioning, isUserActive, sessionIdleTimeout, currentSideWidth } = props
299
300     const applyCollapsedState = (savedWidthInPx) => {
301         const rightPanel: Element = document.getElementsByClassName("layout-pane")[1];
302         const totalWidth: number = document.getElementsByClassName("splitter-layout")[0]?.clientWidth;
303         const savedWidthInPercent = (savedWidthInPx / totalWidth) * 100
304         const rightPanelExpandedWidth = (totalWidth - COLLAPSE_ICON_SIZE) / (totalWidth / 100);
305
306         if(isTransitioning && !!rightPanel) {
307             rightPanel.setAttribute('style', `width: ${sidePanelIsCollapsed ? `calc(${savedWidthInPercent}% - 1rem)` : `${getSplitterInitialSize()}%`};`)
308         }
309
310         if (rightPanel) {
311             rightPanel.setAttribute("style", `width: ${sidePanelIsCollapsed ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`};`);
312         }
313         const splitter = document.getElementsByClassName("layout-splitter")[0];
314         sidePanelIsCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled");
315     };
316
317     const [savedWidth, setSavedWidth] = useState<number>(0)
318
319     useEffect(()=>{
320         if (isTransitioning) setSavedWidth(currentSideWidth)
321     }, [isTransitioning, currentSideWidth])
322
323     useEffect(()=>{
324         if (isTransitioning) applyCollapsedState(savedWidth);
325         // eslint-disable-next-line react-hooks/exhaustive-deps
326     }, [isTransitioning, savedWidth])
327
328     applyCollapsedState(savedWidth);
329
330     return (
331         <Grid
332             container
333             item
334             xs
335             className={classes.root}
336         >
337             {sessionIdleTimeout > 0 && <AutoLogout />}
338             <Grid
339                 container
340                 item
341                 xs
342                 className={classes.container}
343             >
344                 <SplitterLayout
345                     customClassName={classes.splitter}
346                     percentage={true}
347                     primaryIndex={0}
348                     primaryMinSize={10}
349                     secondaryInitialSize={getSplitterInitialSize()}
350                     secondaryMinSize={40}
351                     onSecondaryPaneSizeChange={saveSplitterSize}
352                 >
353                     {isUserActive && isNotLinking && (
354                         <Grid
355                             container
356                             item
357                             xs
358                             component="aside"
359                             direction="column"
360                             className={classes.asidePanel}
361                         >
362                             <SidePanel />
363                         </Grid>
364                     )}
365                     <Grid
366                         container
367                         item
368                         xs
369                         component="main"
370                         direction="column"
371                         className={classes.contentWrapper}
372                     >
373                         <Grid
374                             item
375                             xs
376                         >
377                             {isNotLinking && <MainContentBar />}
378                         </Grid>
379                         <Grid
380                             item
381                             xs
382                             className={classes.content}
383                         >
384                             <Switch>
385                                 {routes.props.children}
386                                 <Route
387                                     path={Routes.NO_MATCH}
388                                     component={NotFoundPanel}
389                                 />
390                             </Switch>
391                         </Grid>
392                     </Grid>
393                 </SplitterLayout>
394             </Grid>
395             <Grid item>
396                 <DetailsPanel />
397             </Grid>
398             <AdvancedTabDialog />
399             <AttributesApiClientAuthorizationDialog />
400             <AttributesKeepServiceDialog />
401             <AttributesLinkDialog />
402             <AttributesSshKeyDialog />
403             <ChangeWorkflowDialog />
404             <ContextMenu />
405             <CopyCollectionDialog />
406             <CopyMultiCollectionDialog />
407             <CopyProcessDialog />
408             <CreateCollectionDialog />
409             <CreateProjectDialog />
410             <CreateRepositoryDialog />
411             <CreateSshKeyDialog />
412             <CreateUserDialog />
413             <TokenDialog />
414             <FileRemoveDialog />
415             <FilesUploadCollectionDialog />
416             <GroupAttributesDialog />
417             <GroupMemberAttributesDialog />
418             <HelpApiClientAuthorizationDialog />
419             <MoveCollectionDialog />
420             <MoveProcessDialog />
421             <MoveProjectDialog />
422             <MultipleFilesRemoveDialog />
423             <PublicKeyDialog />
424             <PartialCopyToNewCollectionDialog />
425             <PartialCopyToExistingCollectionDialog />
426             <PartialCopyToSeparateCollectionsDialog />
427             <PartialMoveToNewCollectionDialog />
428             <PartialMoveToExistingCollectionDialog />
429             <PartialMoveToSeparateCollectionsDialog />
430             <ProcessInputDialog />
431             <RestoreCollectionVersionDialog />
432             <RemoveApiClientAuthorizationDialog />
433             <RemoveGroupDialog />
434             <RemoveGroupMemberDialog />
435             <RemoveKeepServiceDialog />
436             <RemoveLinkDialog />
437             <RemoveProcessDialog />
438             <RemoveRepositoryDialog />
439             <RemoveSshKeyDialog />
440             <RemoveVirtualMachineDialog />
441             <RemoveVirtualMachineLoginDialog />
442             <VirtualMachineAddLoginDialog />
443             <RenameFileDialog />
444             <RepositoryAttributesDialog />
445             <RepositoriesSampleGitDialog />
446             <RichTextEditorDialog />
447             <SharingDialog />
448             <NotFoundDialog />
449             <Snackbar />
450             <UpdateCollectionDialog />
451             <UpdateProcessDialog />
452             <UpdateProjectDialog />
453             <UserAttributesDialog />
454             <DeactivateDialog />
455             <ActivateDialog />
456             <SetupDialog />
457             <VirtualMachineAttributesDialog />
458             <FedLogin />
459             <WebDavS3InfoDialog />
460             <Banner />
461             {React.createElement(React.Fragment, null, pluginConfig.dialogs)}
462         </Grid>
463     );
464 });