1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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 { RemoveWorkflowDialog } from "views-components/workflow-remove-dialog/workflow-remove-dialog";
43 import { MainContentBar } from "views-components/main-content-bar/main-content-bar";
44 import { Grid } from "@material-ui/core";
45 import { TrashPanel } from "views/trash-panel/trash-panel";
46 import { SharedWithMePanel } from "views/shared-with-me-panel/shared-with-me-panel";
47 import { RunProcessPanel } from "views/run-process-panel/run-process-panel";
48 import SplitterLayout from "react-splitter-layout";
49 import { WorkflowPanel } from "views/workflow-panel/workflow-panel";
50 import { RegisteredWorkflowPanel } from "views/workflow-panel/registered-workflow-panel";
51 import { SearchResultsPanel } from "views/search-results-panel/search-results-panel";
52 import { SshKeyPanel } from "views/ssh-key-panel/ssh-key-panel";
53 import { SshKeyAdminPanel } from "views/ssh-key-panel/ssh-key-admin-panel";
54 import { SiteManagerPanel } from "views/site-manager-panel/site-manager-panel";
55 import { UserProfilePanel } from "views/user-profile-panel/user-profile-panel";
56 import { SharingDialog } from "views-components/sharing-dialog/sharing-dialog";
57 import { NotFoundDialog } from "views-components/not-found-dialog/not-found-dialog";
58 import { AdvancedTabDialog } from "views-components/advanced-tab-dialog/advanced-tab-dialog";
59 import { ProcessInputDialog } from "views-components/process-input-dialog/process-input-dialog";
60 import { VirtualMachineUserPanel } from "views/virtual-machine-panel/virtual-machine-user-panel";
61 import { VirtualMachineAdminPanel } from "views/virtual-machine-panel/virtual-machine-admin-panel";
62 import { RepositoriesPanel } from "views/repositories-panel/repositories-panel";
63 import { KeepServicePanel } from "views/keep-service-panel/keep-service-panel";
64 import { ApiClientAuthorizationPanel } from "views/api-client-authorization-panel/api-client-authorization-panel";
65 import { LinkPanel } from "views/link-panel/link-panel";
66 import { RepositoriesSampleGitDialog } from "views-components/repositories-sample-git-dialog/repositories-sample-git-dialog";
67 import { RepositoryAttributesDialog } from "views-components/repository-attributes-dialog/repository-attributes-dialog";
68 import { CreateRepositoryDialog } from "views-components/dialog-forms/create-repository-dialog";
69 import { RemoveRepositoryDialog } from "views-components/repository-remove-dialog/repository-remove-dialog";
70 import { CreateSshKeyDialog } from "views-components/dialog-forms/create-ssh-key-dialog";
71 import { PublicKeyDialog } from "views-components/ssh-keys-dialog/public-key-dialog";
72 import { RemoveApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/remove-dialog";
73 import { RemoveKeepServiceDialog } from "views-components/keep-services-dialog/remove-dialog";
74 import { RemoveLinkDialog } from "views-components/links-dialog/remove-dialog";
75 import { RemoveSshKeyDialog } from "views-components/ssh-keys-dialog/remove-dialog";
76 import { VirtualMachineAttributesDialog } from "views-components/virtual-machines-dialog/attributes-dialog";
77 import { RemoveVirtualMachineDialog } from "views-components/virtual-machines-dialog/remove-dialog";
78 import { RemoveVirtualMachineLoginDialog } from "views-components/virtual-machines-dialog/remove-login-dialog";
79 import { VirtualMachineAddLoginDialog } from "views-components/virtual-machines-dialog/add-login-dialog";
80 import { AttributesApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/attributes-dialog";
81 import { AttributesKeepServiceDialog } from "views-components/keep-services-dialog/attributes-dialog";
82 import { AttributesLinkDialog } from "views-components/links-dialog/attributes-dialog";
83 import { AttributesSshKeyDialog } from "views-components/ssh-keys-dialog/attributes-dialog";
84 import { UserPanel } from "views/user-panel/user-panel";
85 import { UserAttributesDialog } from "views-components/user-dialog/attributes-dialog";
86 import { CreateUserDialog } from "views-components/dialog-forms/create-user-dialog";
87 import { HelpApiClientAuthorizationDialog } from "views-components/api-client-authorizations-dialog/help-dialog";
88 import { DeactivateDialog } from "views-components/user-dialog/deactivate-dialog";
89 import { ActivateDialog } from "views-components/user-dialog/activate-dialog";
90 import { SetupDialog } from "views-components/user-dialog/setup-dialog";
91 import { GroupsPanel } from "views/groups-panel/groups-panel";
92 import { RemoveGroupDialog } from "views-components/groups-dialog/remove-dialog";
93 import { GroupAttributesDialog } from "views-components/groups-dialog/attributes-dialog";
94 import { GroupDetailsPanel } from "views/group-details-panel/group-details-panel";
95 import { RemoveGroupMemberDialog } from "views-components/groups-dialog/member-remove-dialog";
96 import { GroupMemberAttributesDialog } from "views-components/groups-dialog/member-attributes-dialog";
97 import { PublicFavoritePanel } from "views/public-favorites-panel/public-favorites-panel";
98 import { LinkAccountPanel } from "views/link-account-panel/link-account-panel";
99 import { FedLogin } from "./fed-login";
100 import { CollectionsContentAddressPanel } from "views/collection-content-address-panel/collection-content-address-panel";
101 import { AllProcessesPanel } from "../all-processes-panel/all-processes-panel";
102 import { NotFoundPanel } from "../not-found-panel/not-found-panel";
103 import { AutoLogout } from "views-components/auto-logout/auto-logout";
104 import { RestoreCollectionVersionDialog } from "views-components/collections-dialog/restore-version-dialog";
105 import { WebDavS3InfoDialog } from "views-components/webdav-s3-dialog/webdav-s3-dialog";
106 import { pluginConfig } from "plugins";
107 import { ElementListReducer } from "common/plugintypes";
108 import { COLLAPSE_ICON_SIZE } from "views-components/side-panel-toggle/side-panel-toggle";
109 import { Banner } from "views-components/baner/banner";
110 import { InstanceTypesPanel } from "views/instance-types-panel/instance-types-panel";
112 type CssRules = "root" | "container" | "splitter" | "asidePanel" | "contentWrapper" | "content";
114 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
116 paddingTop: theme.spacing.unit * 7,
117 background: theme.palette.background.default,
120 position: "relative",
123 "& > .layout-splitter": {
126 "& > .layout-splitter-disabled": {
127 pointerEvents: "none",
132 paddingTop: theme.spacing.unit,
136 paddingTop: theme.spacing.unit,
141 paddingLeft: theme.spacing.unit * 3,
142 paddingRight: theme.spacing.unit * 3,
143 // Reserve vertical space for app bar + MainContentBar
144 minHeight: `calc(100vh - ${theme.spacing.unit * 16}px)`,
149 interface WorkbenchDataProps {
150 isUserActive: boolean;
151 isNotLinking: boolean;
152 sessionIdleTimeout: number;
153 sidePanelIsCollapsed: boolean;
154 isTransitioning: boolean;
155 currentSideWidth: number;
158 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
160 const defaultSplitterSize = 90;
162 const getSplitterInitialSize = () => {
163 const splitterSize = localStorage.getItem("splitterSize");
164 return splitterSize ? Number(splitterSize) : defaultSplitterSize;
167 const saveSplitterSize = (size: number) => localStorage.setItem("splitterSize", size.toString());
172 path={Routes.PROJECTS}
173 component={ProjectPanel}
176 path={Routes.COLLECTIONS}
177 component={CollectionPanel}
180 path={Routes.FAVORITES}
181 component={FavoritePanel}
184 path={Routes.ALL_PROCESSES}
185 component={AllProcessesPanel}
188 path={Routes.PROCESSES}
189 component={ProcessPanel}
193 component={TrashPanel}
196 path={Routes.SHARED_WITH_ME}
197 component={SharedWithMePanel}
200 path={Routes.RUN_PROCESS}
201 component={RunProcessPanel}
204 path={Routes.REGISTEREDWORKFLOW}
205 component={RegisteredWorkflowPanel}
208 path={Routes.WORKFLOWS}
209 component={WorkflowPanel}
212 path={Routes.SEARCH_RESULTS}
213 component={SearchResultsPanel}
216 path={Routes.VIRTUAL_MACHINES_USER}
217 component={VirtualMachineUserPanel}
220 path={Routes.VIRTUAL_MACHINES_ADMIN}
221 component={VirtualMachineAdminPanel}
224 path={Routes.REPOSITORIES}
225 component={RepositoriesPanel}
228 path={Routes.SSH_KEYS_USER}
229 component={SshKeyPanel}
232 path={Routes.SSH_KEYS_ADMIN}
233 component={SshKeyAdminPanel}
236 path={Routes.INSTANCE_TYPES}
237 component={InstanceTypesPanel}
240 path={Routes.SITE_MANAGER}
241 component={SiteManagerPanel}
244 path={Routes.KEEP_SERVICES}
245 component={KeepServicePanel}
249 component={UserPanel}
252 path={Routes.API_CLIENT_AUTHORIZATIONS}
253 component={ApiClientAuthorizationPanel}
256 path={Routes.MY_ACCOUNT}
257 component={UserProfilePanel}
260 path={Routes.USER_PROFILE}
261 component={UserProfilePanel}
265 component={GroupsPanel}
268 path={Routes.GROUP_DETAILS}
269 component={GroupDetailsPanel}
273 component={LinkPanel}
276 path={Routes.PUBLIC_FAVORITES}
277 component={PublicFavoritePanel}
280 path={Routes.LINK_ACCOUNT}
281 component={LinkAccountPanel}
284 path={Routes.COLLECTIONS_CONTENT_ADDRESS}
285 component={CollectionsContentAddressPanel}
290 const reduceRoutesFn: (a: React.ReactElement[], b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
292 routes = React.createElement(
295 pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children))
298 export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => {
299 const { classes, sidePanelIsCollapsed, isNotLinking, isTransitioning, isUserActive, sessionIdleTimeout, currentSideWidth } = props
301 const applyCollapsedState = (savedWidthInPx) => {
302 const rightPanel: Element = document.getElementsByClassName("layout-pane")[1];
303 const totalWidth: number = document.getElementsByClassName("splitter-layout")[0]?.clientWidth;
304 const savedWidthInPercent = (savedWidthInPx / totalWidth) * 100
305 const rightPanelExpandedWidth = (totalWidth - COLLAPSE_ICON_SIZE) / (totalWidth / 100);
307 if(isTransitioning && !!rightPanel) {
308 rightPanel.setAttribute('style', `width: ${sidePanelIsCollapsed ? `calc(${savedWidthInPercent}% - 1rem)` : `${getSplitterInitialSize()}%`};`)
312 rightPanel.setAttribute("style", `width: ${sidePanelIsCollapsed ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`};`);
314 const splitter = document.getElementsByClassName("layout-splitter")[0];
315 sidePanelIsCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled");
318 const [savedWidth, setSavedWidth] = useState<number>(0)
321 if (isTransitioning) setSavedWidth(currentSideWidth)
322 }, [isTransitioning, currentSideWidth])
325 if (isTransitioning) applyCollapsedState(savedWidth);
326 // eslint-disable-next-line react-hooks/exhaustive-deps
327 }, [isTransitioning, savedWidth])
329 applyCollapsedState(savedWidth);
336 className={classes.root}
338 {sessionIdleTimeout > 0 && <AutoLogout />}
343 className={classes.container}
346 customClassName={classes.splitter}
350 secondaryInitialSize={getSplitterInitialSize()}
351 secondaryMinSize={40}
352 onSecondaryPaneSizeChange={saveSplitterSize}
354 {isUserActive && isNotLinking && (
361 className={classes.asidePanel}
372 className={classes.contentWrapper}
378 {isNotLinking && <MainContentBar />}
383 className={classes.content}
386 {routes.props.children}
388 path={Routes.NO_MATCH}
389 component={NotFoundPanel}
399 <AdvancedTabDialog />
400 <AttributesApiClientAuthorizationDialog />
401 <AttributesKeepServiceDialog />
402 <AttributesLinkDialog />
403 <AttributesSshKeyDialog />
404 <ChangeWorkflowDialog />
406 <CopyCollectionDialog />
407 <CopyMultiCollectionDialog />
408 <CopyProcessDialog />
409 <CreateCollectionDialog />
410 <CreateProjectDialog />
411 <CreateRepositoryDialog />
412 <CreateSshKeyDialog />
416 <FilesUploadCollectionDialog />
417 <GroupAttributesDialog />
418 <GroupMemberAttributesDialog />
419 <HelpApiClientAuthorizationDialog />
420 <MoveCollectionDialog />
421 <MoveProcessDialog />
422 <MoveProjectDialog />
423 <MultipleFilesRemoveDialog />
425 <PartialCopyToNewCollectionDialog />
426 <PartialCopyToExistingCollectionDialog />
427 <PartialCopyToSeparateCollectionsDialog />
428 <PartialMoveToNewCollectionDialog />
429 <PartialMoveToExistingCollectionDialog />
430 <PartialMoveToSeparateCollectionsDialog />
431 <ProcessInputDialog />
432 <RestoreCollectionVersionDialog />
433 <RemoveApiClientAuthorizationDialog />
434 <RemoveGroupDialog />
435 <RemoveGroupMemberDialog />
436 <RemoveKeepServiceDialog />
438 <RemoveProcessDialog />
439 <RemoveWorkflowDialog />
440 <RemoveRepositoryDialog />
441 <RemoveSshKeyDialog />
442 <RemoveVirtualMachineDialog />
443 <RemoveVirtualMachineLoginDialog />
444 <VirtualMachineAddLoginDialog />
446 <RepositoryAttributesDialog />
447 <RepositoriesSampleGitDialog />
448 <RichTextEditorDialog />
452 <UpdateCollectionDialog />
453 <UpdateProcessDialog />
454 <UpdateProjectDialog />
455 <UserAttributesDialog />
459 <VirtualMachineAttributesDialog />
461 <WebDavS3InfoDialog />
463 {React.createElement(React.Fragment, null, pluginConfig.dialogs)}