20251: Fix flaky collection file browser by using race-free state update callback
[arvados-workbench2.git] / src / views / inactive-panel / inactive-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { Dispatch } from 'redux';
7 import { connect } from 'react-redux';
8 import { Grid, Typography, Button } from '@material-ui/core';
9 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import { navigateToLinkAccount } from 'store/navigation/navigation-action';
12 import { RootState } from 'store/store';
13
14 export type CssRules = 'root' | 'ontop' | 'title';
15
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
17     root: {
18         position: 'relative',
19         backgroundColor: theme.palette.grey["200"],
20         background: 'url("arvados-logo-big.png") no-repeat center center',
21         backgroundBlendMode: 'soft-light',
22     },
23     ontop: {
24         zIndex: 10
25     },
26     title: {
27         marginBottom: theme.spacing.unit * 6,
28         color: theme.palette.grey["800"]
29     }
30 });
31
32 export interface InactivePanelActionProps {
33     startLinking: () => void;
34 }
35
36 const mapDispatchToProps = (dispatch: Dispatch): InactivePanelActionProps => ({
37     startLinking: () => {
38         dispatch<any>(navigateToLinkAccount);
39     }
40 });
41
42 const mapStateToProps = (state: RootState): InactivePanelStateProps => ({
43     inactivePageText: state.auth.config.clusterConfig.Workbench.InactivePageHTML,
44     isLoginClusterFederation: state.auth.config.clusterConfig.Login.LoginCluster !== '',
45 });
46
47 export interface InactivePanelStateProps {
48     inactivePageText: string;
49     isLoginClusterFederation: boolean;
50 }
51
52 type InactivePanelProps = WithStyles<CssRules> & InactivePanelActionProps & InactivePanelStateProps;
53
54 export const InactivePanelRoot = ({ classes, startLinking, inactivePageText, isLoginClusterFederation }: InactivePanelProps) =>
55     <Grid container justify="center" alignItems="center" direction="column" spacing={24}
56         className={classes.root}
57         style={{ marginTop: 56, height: "100%" }}>
58         <Grid item>
59             <Typography>
60                 <span dangerouslySetInnerHTML={{ __html: inactivePageText }} style={{ margin: "1em" }} />
61             </Typography>
62         </Grid>
63         { !isLoginClusterFederation
64         ? <><Grid item>
65             <Typography align="center">
66             If you would like to use this login to access another account click "Link Account".
67             </Typography>
68         </Grid>
69         <Grid item>
70             <Button className={classes.ontop} color="primary" variant="contained" onClick={() => startLinking()}>
71                 Link Account
72             </Button>
73         </Grid></>
74         : <><Grid item>
75             <Typography align="center">
76                 If you would like to use this login to access another account, please contact your administrator.
77             </Typography>
78         </Grid></> }
79     </Grid >;
80
81 export const InactivePanel = connect(mapStateToProps, mapDispatchToProps)(
82     withStyles(styles)(InactivePanelRoot));