21224: set toolbar to only display if the global selected uuid is populated Arvados...
[arvados.git] / services / workbench2 / src / views / main-panel / main-panel-root.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React, { useEffect } from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles, Grid, LinearProgress } from '@material-ui/core';
7 import { User } from "models/user";
8 import { ArvadosTheme } from 'common/custom-theme';
9 import { WorkbenchPanel } from 'views/workbench/workbench';
10 import { LoginPanel } from 'views/login-panel/login-panel';
11 import { InactivePanel } from 'views/inactive-panel/inactive-panel';
12 import { WorkbenchLoadingScreen } from 'views/workbench/workbench-loading-screen';
13 import { MainAppBar } from 'views-components/main-app-bar/main-app-bar';
14 import { Routes } from 'routes/routes';
15
16 type CssRules = 'root';
17
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19     root: {
20         overflow: 'hidden',
21         width: '100vw',
22         height: '100vh'
23     }
24 });
25
26 export interface MainPanelRootDataProps {
27     user?: User;
28     working: boolean;
29     loading: boolean;
30     buildInfo: string;
31     uuidPrefix: string;
32     isNotLinking: boolean;
33     isLinkingPath: boolean;
34     siteBanner: string;
35     sessionIdleTimeout: number;
36     sidePanelIsCollapsed: boolean;
37     isTransitioning: boolean;
38     currentSideWidth: number;
39     currentRoute: string;
40 }
41
42 interface MainPanelRootDispatchProps {
43     toggleSidePanel: () => void,
44     setCurrentRouteUuid: (uuid: string) => void;
45 }
46
47 type MainPanelRootProps = MainPanelRootDataProps & MainPanelRootDispatchProps & WithStyles<CssRules>;
48
49 export const MainPanelRoot = withStyles(styles)(
50     ({ classes, loading, working, user, buildInfo, uuidPrefix,
51         isNotLinking, isLinkingPath, siteBanner, sessionIdleTimeout, 
52         sidePanelIsCollapsed, isTransitioning, currentSideWidth, currentRoute, setCurrentRouteUuid}: MainPanelRootProps) =>{
53
54             useEffect(() => {
55                 const splitRoute = currentRoute.split('/');
56                 const uuid = splitRoute[splitRoute.length - 1];
57                 if(Object.values(Routes).includes(`/${uuid}`) === false) {
58                     setCurrentRouteUuid(uuid);
59                 }
60                 // eslint-disable-next-line react-hooks/exhaustive-deps
61             }, [currentRoute]);
62
63         return loading
64             ? <WorkbenchLoadingScreen />
65             : <>
66             {isNotLinking && <MainAppBar
67                 user={user}
68                 buildInfo={buildInfo}
69                 uuidPrefix={uuidPrefix}
70                 siteBanner={siteBanner}
71                 sidePanelIsCollapsed={sidePanelIsCollapsed}
72                 >
73                 {working
74                     ? <LinearProgress color="secondary" data-cy="linear-progress" />
75                     : null}
76             </MainAppBar>}
77             <Grid container direction="column" className={classes.root}>
78                 {user
79                     ? (user.isActive || (!user.isActive && isLinkingPath)
80                     ? <WorkbenchPanel 
81                         isNotLinking={isNotLinking}
82                         isUserActive={user.isActive}
83                         sessionIdleTimeout={sessionIdleTimeout}
84                         sidePanelIsCollapsed={sidePanelIsCollapsed}
85                         isTransitioning={isTransitioning}
86                         currentSideWidth={currentSideWidth}/>
87                     : <InactivePanel />)
88                     : <LoginPanel />}
89             </Grid>
90         </>
91     }
92 );