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 { 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";
114 type CssRules = "root" | "container" | "splitter" | "asidePanel" | "contentWrapper" | "content";
116 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
118 paddingTop: theme.spacing(7),
119 background: theme.palette.background.default,
122 position: "relative",
125 "& > .layout-splitter": {
128 "& > .layout-splitter-disabled": {
129 pointerEvents: "none",
134 paddingTop: theme.spacing(1),
138 paddingTop: theme.spacing(1),
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)})`,
151 interface WorkbenchDataProps {
152 isUserActive: boolean;
153 isNotLinking: boolean;
154 sessionIdleTimeout: number;
155 sidePanelIsCollapsed: boolean;
156 isTransitioning: boolean;
157 currentSideWidth: number;
160 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
162 const defaultSplitterSize = 90;
164 const getSplitterInitialSize = () => {
165 const splitterSize = localStorage.getItem("splitterSize");
166 return splitterSize ? Number(splitterSize) : defaultSplitterSize;
169 const saveSplitterSize = (size: number) => localStorage.setItem("splitterSize", size.toString());
174 path={Routes.PROJECTS}
175 component={ProjectPanel}
178 path={Routes.COLLECTIONS}
179 component={CollectionPanel}
182 path={Routes.FAVORITES}
183 component={FavoritePanel}
186 path={Routes.ALL_PROCESSES}
187 component={AllProcessesPanel}
190 path={Routes.PROCESSES}
191 component={ProcessPanel}
195 component={TrashPanel}
198 path={Routes.SHARED_WITH_ME}
199 component={SharedWithMePanel}
202 path={Routes.RUN_PROCESS}
203 component={RunProcessPanel}
206 path={Routes.REGISTEREDWORKFLOW}
207 component={RegisteredWorkflowPanel}
210 path={Routes.WORKFLOWS}
211 component={WorkflowPanel}
214 path={Routes.SEARCH_RESULTS}
215 component={SearchResultsPanel}
218 path={Routes.VIRTUAL_MACHINES_USER}
219 component={VirtualMachineUserPanel}
222 path={Routes.VIRTUAL_MACHINES_ADMIN}
223 component={VirtualMachineAdminPanel}
226 path={Routes.REPOSITORIES}
227 component={RepositoriesPanel}
230 path={Routes.SSH_KEYS_USER}
231 component={SshKeyPanel}
234 path={Routes.SSH_KEYS_ADMIN}
235 component={SshKeyAdminPanel}
238 path={Routes.INSTANCE_TYPES}
239 component={InstanceTypesPanel}
242 path={Routes.SITE_MANAGER}
243 component={SiteManagerPanel}
246 path={Routes.KEEP_SERVICES}
247 component={KeepServicePanel}
251 component={UserPanel}
254 path={Routes.API_CLIENT_AUTHORIZATIONS}
255 component={ApiClientAuthorizationPanel}
258 path={Routes.MY_ACCOUNT}
259 component={UserProfilePanel}
262 path={Routes.USER_PROFILE}
263 component={UserProfilePanel}
267 component={GroupsPanel}
270 path={Routes.GROUP_DETAILS}
271 component={GroupDetailsPanel}
275 component={LinkPanel}
278 path={Routes.PUBLIC_FAVORITES}
279 component={PublicFavoritePanel}
282 path={Routes.LINK_ACCOUNT}
283 component={LinkAccountPanel}
286 path={Routes.COLLECTIONS_CONTENT_ADDRESS}
287 component={CollectionsContentAddressPanel}
292 const reduceRoutesFn: (a: React.ReactElement[], b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
294 routes = React.createElement(
297 pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children))
300 export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => {
301 const { classes, sidePanelIsCollapsed, isNotLinking, isTransitioning, isUserActive, sessionIdleTimeout, currentSideWidth } = props
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);
309 if(isTransitioning && !!rightPanel) {
310 rightPanel.setAttribute('style', `width: ${sidePanelIsCollapsed ? `calc(${savedWidthInPercent}% - 1rem)` : `${getSplitterInitialSize()}%`};`)
314 rightPanel.setAttribute("style", `width: ${sidePanelIsCollapsed ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`};`);
316 const splitter = document.getElementsByClassName("layout-splitter")[0];
317 sidePanelIsCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled");
320 const [savedWidth, setSavedWidth] = useState<number>(0)
323 if (isTransitioning) setSavedWidth(currentSideWidth)
324 }, [isTransitioning, currentSideWidth])
327 if (isTransitioning) applyCollapsedState(savedWidth);
328 // eslint-disable-next-line react-hooks/exhaustive-deps
329 }, [isTransitioning, savedWidth])
331 applyCollapsedState(savedWidth);
338 className={classes.root}
340 {sessionIdleTimeout > 0 && <AutoLogout />}
345 className={classes.container}
348 customClassName={classes.splitter}
352 secondaryInitialSize={getSplitterInitialSize()}
353 secondaryMinSize={40}
354 onSecondaryPaneSizeChange={saveSplitterSize}
356 {isUserActive && isNotLinking && (
362 className={classes.asidePanel}
373 className={classes.contentWrapper}
378 {isNotLinking && <MainContentBar />}
382 className={classes.content}
385 {routes.props.children}
387 path={Routes.NO_MATCH}
388 component={NotFoundPanel}
398 <AdvancedTabDialog />
399 <AttributesApiClientAuthorizationDialog />
400 <AttributesKeepServiceDialog />
401 <AttributesLinkDialog />
402 <AttributesSshKeyDialog />
403 <ChangeWorkflowDialog />
405 <CopyCollectionDialog />
406 <CopyMultiCollectionDialog />
407 <CopyProcessDialog />
408 <CreateCollectionDialog />
409 <CreateProjectDialog />
410 <CreateRepositoryDialog />
411 <CreateSshKeyDialog />
415 <FilesUploadCollectionDialog />
416 <GroupAttributesDialog />
417 <GroupMemberAttributesDialog />
418 <HelpApiClientAuthorizationDialog />
419 <MoveCollectionDialog />
420 <MoveProcessDialog />
421 <MoveProjectDialog />
422 <MultipleFilesRemoveDialog />
424 <PartialCopyToNewCollectionDialog />
425 <PartialCopyToExistingCollectionDialog />
426 <PartialCopyToSeparateCollectionsDialog />
427 <PartialMoveToNewCollectionDialog />
428 <PartialMoveToExistingCollectionDialog />
429 <PartialMoveToSeparateCollectionsDialog />
430 <ProcessInputDialog />
431 <RestoreCollectionVersionDialog />
432 <RemoveApiClientAuthorizationDialog />
433 <RemoveGroupDialog />
434 <RemoveGroupMemberDialog />
435 <RemoveKeepServiceDialog />
437 <RemoveProcessDialog />
438 <RemoveWorkflowDialog />
439 <RemoveRepositoryDialog />
440 <RemoveSshKeyDialog />
441 <RemoveVirtualMachineDialog />
442 <RemoveVirtualMachineLoginDialog />
443 <VirtualMachineAddLoginDialog />
445 <RepositoryAttributesDialog />
446 <RepositoriesSampleGitDialog />
447 <RichTextEditorDialog />
451 <UpdateCollectionDialog />
452 <UpdateProcessDialog />
453 <UpdateProjectDialog />
454 <UserAttributesDialog />
458 <VirtualMachineAttributesDialog />
460 <WebDavS3InfoDialog />
462 {React.createElement(React.Fragment, null, pluginConfig.dialogs)}