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 { 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";
111 type CssRules = "root" | "container" | "splitter" | "asidePanel" | "contentWrapper" | "content";
113 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
115 paddingTop: theme.spacing.unit * 7,
116 background: theme.palette.background.default,
119 position: "relative",
122 "& > .layout-splitter": {
125 "& > .layout-splitter-disabled": {
126 pointerEvents: "none",
131 paddingTop: theme.spacing.unit,
135 paddingTop: theme.spacing.unit,
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)`,
148 interface WorkbenchDataProps {
149 isUserActive: boolean;
150 isNotLinking: boolean;
151 sessionIdleTimeout: number;
152 sidePanelIsCollapsed: boolean;
153 isTransitioning: boolean;
154 currentSideWidth: number;
157 type WorkbenchPanelProps = WithStyles<CssRules> & WorkbenchDataProps;
159 const defaultSplitterSize = 90;
161 const getSplitterInitialSize = () => {
162 const splitterSize = localStorage.getItem("splitterSize");
163 return splitterSize ? Number(splitterSize) : defaultSplitterSize;
166 const saveSplitterSize = (size: number) => localStorage.setItem("splitterSize", size.toString());
171 path={Routes.PROJECTS}
172 component={ProjectPanel}
175 path={Routes.COLLECTIONS}
176 component={CollectionPanel}
179 path={Routes.FAVORITES}
180 component={FavoritePanel}
183 path={Routes.ALL_PROCESSES}
184 component={AllProcessesPanel}
187 path={Routes.PROCESSES}
188 component={ProcessPanel}
192 component={TrashPanel}
195 path={Routes.SHARED_WITH_ME}
196 component={SharedWithMePanel}
199 path={Routes.RUN_PROCESS}
200 component={RunProcessPanel}
203 path={Routes.REGISTEREDWORKFLOW}
204 component={RegisteredWorkflowPanel}
207 path={Routes.WORKFLOWS}
208 component={WorkflowPanel}
211 path={Routes.SEARCH_RESULTS}
212 component={SearchResultsPanel}
215 path={Routes.VIRTUAL_MACHINES_USER}
216 component={VirtualMachineUserPanel}
219 path={Routes.VIRTUAL_MACHINES_ADMIN}
220 component={VirtualMachineAdminPanel}
223 path={Routes.REPOSITORIES}
224 component={RepositoriesPanel}
227 path={Routes.SSH_KEYS_USER}
228 component={SshKeyPanel}
231 path={Routes.SSH_KEYS_ADMIN}
232 component={SshKeyAdminPanel}
235 path={Routes.INSTANCE_TYPES}
236 component={InstanceTypesPanel}
239 path={Routes.SITE_MANAGER}
240 component={SiteManagerPanel}
243 path={Routes.KEEP_SERVICES}
244 component={KeepServicePanel}
248 component={UserPanel}
251 path={Routes.API_CLIENT_AUTHORIZATIONS}
252 component={ApiClientAuthorizationPanel}
255 path={Routes.MY_ACCOUNT}
256 component={UserProfilePanel}
259 path={Routes.USER_PROFILE}
260 component={UserProfilePanel}
264 component={GroupsPanel}
267 path={Routes.GROUP_DETAILS}
268 component={GroupDetailsPanel}
272 component={LinkPanel}
275 path={Routes.PUBLIC_FAVORITES}
276 component={PublicFavoritePanel}
279 path={Routes.LINK_ACCOUNT}
280 component={LinkAccountPanel}
283 path={Routes.COLLECTIONS_CONTENT_ADDRESS}
284 component={CollectionsContentAddressPanel}
289 const reduceRoutesFn: (a: React.ReactElement[], b: ElementListReducer) => React.ReactElement[] = (a, b) => b(a);
291 routes = React.createElement(
294 pluginConfig.centerPanelList.reduce(reduceRoutesFn, React.Children.toArray(routes.props.children))
297 export const WorkbenchPanel = withStyles(styles)((props: WorkbenchPanelProps) => {
298 const { classes, sidePanelIsCollapsed, isNotLinking, isTransitioning, isUserActive, sessionIdleTimeout, currentSideWidth } = props
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);
306 if(isTransitioning && !!rightPanel) {
307 rightPanel.setAttribute('style', `width: ${sidePanelIsCollapsed ? `calc(${savedWidthInPercent}% - 1rem)` : `${getSplitterInitialSize()}%`};`)
311 rightPanel.setAttribute("style", `width: ${sidePanelIsCollapsed ? `calc(${rightPanelExpandedWidth}% - 1rem)` : `${getSplitterInitialSize()}%`};`);
313 const splitter = document.getElementsByClassName("layout-splitter")[0];
314 sidePanelIsCollapsed ? splitter?.classList.add("layout-splitter-disabled") : splitter?.classList.remove("layout-splitter-disabled");
317 const [savedWidth, setSavedWidth] = useState<number>(0)
320 if (isTransitioning) setSavedWidth(currentSideWidth)
321 }, [isTransitioning, currentSideWidth])
324 if (isTransitioning) applyCollapsedState(savedWidth);
325 // eslint-disable-next-line react-hooks/exhaustive-deps
326 }, [isTransitioning, savedWidth])
328 applyCollapsedState(savedWidth);
335 className={classes.root}
337 {sessionIdleTimeout > 0 && <AutoLogout />}
342 className={classes.container}
345 customClassName={classes.splitter}
349 secondaryInitialSize={getSplitterInitialSize()}
350 secondaryMinSize={40}
351 onSecondaryPaneSizeChange={saveSplitterSize}
353 {isUserActive && isNotLinking && (
360 className={classes.asidePanel}
371 className={classes.contentWrapper}
377 {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 <RemoveRepositoryDialog />
439 <RemoveSshKeyDialog />
440 <RemoveVirtualMachineDialog />
441 <RemoveVirtualMachineLoginDialog />
442 <VirtualMachineAddLoginDialog />
444 <RepositoryAttributesDialog />
445 <RepositoriesSampleGitDialog />
446 <RichTextEditorDialog />
450 <UpdateCollectionDialog />
451 <UpdateProcessDialog />
452 <UpdateProjectDialog />
453 <UserAttributesDialog />
457 <VirtualMachineAttributesDialog />
459 <WebDavS3InfoDialog />
461 {React.createElement(React.Fragment, null, pluginConfig.dialogs)}