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