15530: Set homeCluster to LoginCluster
[arvados-workbench2.git] / src / views / login-panel / login-panel.tsx
index 48c6e163ff3f110dcdb093e316eb38642446e1cc..70a673bb8e25c351e01963a3f860b19a55aa8213 100644 (file)
@@ -4,13 +4,11 @@
 
 import * as React from 'react';
 import { connect, DispatchProp } from 'react-redux';
-import { Grid, Typography, Button } from '@material-ui/core';
+import { Grid, Typography, Button, Select } from '@material-ui/core';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
-import { login } from '~/store/auth/auth-action';
+import { login, authActions } from '~/store/auth/auth-action';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { RootState } from '~/store/store';
-import { getProperty } from '~/store/properties/properties';
-import { propertiesActions } from '~/store/properties/properties-actions';
 import * as classNames from 'classnames';
 
 type CssRules = 'root' | 'container' | 'title' | 'content' | 'content__bolder' | 'button';
@@ -52,26 +50,22 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 });
 
 type LoginPanelProps = DispatchProp<any> & WithStyles<CssRules> & {
-    remoteHosts: any,
+    remoteHosts: { [key: string]: string },
     homeCluster: string,
-    uuidPrefix: string
+    uuidPrefix: string,
+    loginCluster: string
 };
 
-export const REMOTE_HOSTS_NAME = 'remoteHosts';
-export const HOME_CLUSTER_NAME = 'homeCluster';
-export const setRemoteHosts = (remoteHosts: any) =>
-    propertiesActions.SET_PROPERTY({ key: REMOTE_HOSTS_NAME, value: remoteHosts });
-
-export const setHomeCluster = (homeCluster: string) =>
-    propertiesActions.SET_PROPERTY({ key: HOME_CLUSTER_NAME, value: homeCluster });
-
 export const LoginPanel = withStyles(styles)(
     connect((state: RootState) => ({
-        remoteHosts: state.properties.remoteHosts,
-        homeCluster: state.properties.homeCluster,
-        uuidPrefix: state.properties.uuidPrefix
-    }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix }: LoginPanelProps) =>
-        <Grid container direction="column" item xs alignItems="center" justify="center" className={classes.root}>
+        remoteHosts: state.auth.remoteHosts,
+        homeCluster: state.auth.homeCluster,
+        uuidPrefix: state.auth.localCluster,
+        loginCluster: state.auth.loginCluster
+    }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix, loginCluster }: LoginPanelProps) =>
+        <Grid container justify="center" alignItems="center"
+            className={classes.root}
+            style={{ marginTop: 56, overflowY: "auto", height: "100%" }}>
             <Grid item className={classes.container}>
                 <Typography variant='h6' align="center" className={classes.title}>
                     Welcome to the Arvados Workbench
@@ -90,21 +84,23 @@ export const LoginPanel = withStyles(styles)(
                     Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google.
                </Typography>
 
-                <Typography className={classes.content}>
-                    <form>
-                        <label>
-                            Choose your home cluster:
-                           <select value={homeCluster} onChange={(event) => dispatch(setHomeCluster(event.target.value))}>
-                                {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
-                            </select>
-                        </label>
-                    </form>
-                </Typography>
+                {Object.keys(remoteHosts).length > 1 && loginCluster === "" &&
+                    <Typography component="div" align="right">
+                        <label>Please select the cluster that hosts your user account:</label>
+                        <Select native value={homeCluster} style={{ margin: "1em" }}
+                            onChange={(event) => dispatch(authActions.SET_HOME_CLUSTER(event.target.value))}>
+                            {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
+                        </Select>
+                    </Typography>}
+
                 <Typography component="div" align="right">
-                    <Button variant="contained" color="primary" className={classes.button} onClick={() => dispatch(login(uuidPrefix, remoteHosts[homeCluster]))}>
-                        Log in
-                   </Button>
+                    <Button variant="contained" color="primary" style={{ margin: "1em" }} className={classes.button}
+                        onClick={() => dispatch(login(uuidPrefix, homeCluster, remoteHosts))}>
+                        Log in to {uuidPrefix}
+                        {uuidPrefix !== homeCluster &&
+                            <span>&nbsp;with user from {homeCluster}</span>}
+                    </Button>
                 </Typography>
             </Grid>
-        </Grid>
+        </Grid >
     ));