X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2a4f0a7d69cb0cb94b43a05ddff91e4cd06c6c39..29c0944feb7932889a5b6fcaf208eef9f5864a29:/src/views/site-manager-panel/site-manager-panel-root.tsx?ds=sidebyside

diff --git a/src/views/site-manager-panel/site-manager-panel-root.tsx b/src/views/site-manager-panel/site-manager-panel-root.tsx
index a64fdb25..36349774 100644
--- a/src/views/site-manager-panel/site-manager-panel-root.tsx
+++ b/src/views/site-manager-panel/site-manager-panel-root.tsx
@@ -5,7 +5,8 @@
 import * as React from 'react';
 import {
     Card,
-    CardContent, CircularProgress,
+    CardContent,
+    CircularProgress,
     Grid,
     StyleRulesCallback,
     Table,
@@ -20,23 +21,20 @@ import {
 import { ArvadosTheme } from '~/common/custom-theme';
 import { Session, SessionStatus } from "~/models/session";
 import Button from "@material-ui/core/Button";
-import { User } from "~/models/user";
-import { compose } from "redux";
+import { compose, Dispatch } from "redux";
 import { Field, FormErrors, InjectedFormProps, reduxForm, reset, stopSubmit } from "redux-form";
 import { TextField } from "~/components/text-field/text-field";
 import { addSession } from "~/store/auth/auth-action-session";
 import { SITE_MANAGER_REMOTE_HOST_VALIDATION } from "~/validators/validators";
-import {
-    RENAME_FILE_DIALOG,
-    RenameFileDialogData
-} from "~/store/collection-panel/collection-panel-files/collection-panel-files-actions";
 
-type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' | 'status' | 'remoteSiteInfo' | 'buttonAdd';
+type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' |
+    'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' |
+    'statusCell';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
-       width: '100%',
-       overflow: 'auto'
+        width: '100%',
+        overflow: 'auto'
     },
     link: {
         color: theme.palette.primary.main,
@@ -54,12 +52,8 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
             whiteSpace: 'nowrap'
         }
     },
-    status: {
-        width: 100,
-        padding: 5,
-        fontWeight: 'bold',
-        textAlign: 'center',
-        borderRadius: 4
+    statusCell: {
+        minWidth: 160
     },
     remoteSiteInfo: {
         marginTop: 20
@@ -67,45 +61,67 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     buttonAdd: {
         marginLeft: 10,
         marginTop: theme.spacing.unit * 3
+    },
+    buttonLoggedIn: {
+        minHeight: theme.spacing.unit,
+        padding: 5,
+        color: '#fff',
+        backgroundColor: '#009966',
+        '&:hover': {
+            backgroundColor: '#008450',
+        }
+    },
+    buttonLoggedOut: {
+        minHeight: theme.spacing.unit,
+        padding: 5,
+        color: '#000',
+        backgroundColor: '#FFC414',
+        '&:hover': {
+            backgroundColor: '#eaaf14',
+        }
     }
 });
 
 export interface SiteManagerPanelRootActionProps {
+    toggleSession: (session: Session) => void;
 }
 
 export interface SiteManagerPanelRootDataProps {
     sessions: Session[];
-    user: User;
 }
 
 type SiteManagerPanelRootProps = SiteManagerPanelRootDataProps & SiteManagerPanelRootActionProps & WithStyles<CssRules> & InjectedFormProps;
 const SITE_MANAGER_FORM_NAME = 'siteManagerForm';
 
+const submitSession = (remoteHost: string) =>
+    (dispatch: Dispatch) => {
+        dispatch<any>(addSession(remoteHost)).then(() => {
+            dispatch(reset(SITE_MANAGER_FORM_NAME));
+        }).catch((e: any) => {
+            const errors = {
+                remoteHost: e
+            } as FormErrors;
+            dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
+        });
+    };
+
 export const SiteManagerPanelRoot = compose(
-    reduxForm<{remoteHost: string}>({
+    reduxForm<{ remoteHost: string }>({
         form: SITE_MANAGER_FORM_NAME,
-        onSubmit: async (data, dispatch) => {
-            try {
-                await dispatch(addSession(data.remoteHost));
-                dispatch(reset(SITE_MANAGER_FORM_NAME));
-            } catch (e) {
-                const errors = {
-                    remoteHost: e
-                } as FormErrors;
-                dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
-            }
-
+        touchOnBlur: false,
+        onSubmit: (data, dispatch) => {
+            dispatch(submitSession(data.remoteHost));
         }
     }),
     withStyles(styles))
-    (({ classes, sessions, handleSubmit }: SiteManagerPanelRootProps) =>
+    (({ classes, sessions, handleSubmit, toggleSession }: SiteManagerPanelRootProps) =>
         <Card className={classes.root}>
             <CardContent>
                 <Grid container direction="row">
                     <Grid item xs={12}>
-                        <Typography variant='body1' paragraph={true} >
+                        <Typography paragraph={true} >
                             You can log in to multiple Arvados sites here, then use the multi-site search page to search collections and projects on all sites at once.
-                        </Typography>
+                    </Typography>
                     </Grid>
                 </Grid>
                 <Grid item xs={12}>
@@ -113,6 +129,7 @@ export const SiteManagerPanelRoot = compose(
                         <TableHead>
                             <TableRow className={classes.tableRow}>
                                 <TableCell>Cluster ID</TableCell>
+                                <TableCell>Host</TableCell>
                                 <TableCell>Username</TableCell>
                                 <TableCell>Email</TableCell>
                                 <TableCell>Status</TableCell>
@@ -123,15 +140,16 @@ export const SiteManagerPanelRoot = compose(
                                 const validating = session.status === SessionStatus.BEING_VALIDATED;
                                 return <TableRow key={index} className={classes.tableRow}>
                                     <TableCell>{session.clusterId}</TableCell>
-                                    <TableCell>{validating ? <CircularProgress size={20}/> : session.username}</TableCell>
-                                    <TableCell>{validating ? <CircularProgress size={20}/> : session.email}</TableCell>
-                                    <TableCell>
-                                        <div className={classes.status} style={{
-                                            color: session.loggedIn ? '#fff' : '#000',
-                                            backgroundColor: session.loggedIn ? '#009966' : '#FFC414'
-                                        }}>
-                                            {session.loggedIn ? "Logged in" : "Logged out"}
-                                        </div>
+                                    <TableCell>{session.remoteHost}</TableCell>
+                                    <TableCell>{validating ? <CircularProgress size={20} /> : session.username}</TableCell>
+                                    <TableCell>{validating ? <CircularProgress size={20} /> : session.email}</TableCell>
+                                    <TableCell className={classes.statusCell}>
+                                        <Button fullWidth
+                                            disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
+                                            className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
+                                            onClick={() => toggleSession(session)}>
+                                            {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")}
+                                        </Button>
                                     </TableCell>
                                 </TableRow>;
                             })}
@@ -141,9 +159,9 @@ export const SiteManagerPanelRoot = compose(
                 <form onSubmit={handleSubmit}>
                     <Grid container direction="row">
                         <Grid item xs={12}>
-                            <Typography variant='body1' paragraph={true} className={classes.remoteSiteInfo}>
+                            <Typography paragraph={true} className={classes.remoteSiteInfo}>
                                 To add a remote Arvados site, paste the remote site's host here (see "ARVADOS_API_HOST" on the "current token" page).
-                            </Typography>
+                        </Typography>
                         </Grid>
                         <Grid item xs={8}>
                             <Field
@@ -153,7 +171,7 @@ export const SiteManagerPanelRoot = compose(
                                 placeholder="zzzz.arvadosapi.com"
                                 margin="normal"
                                 label="New cluster"
-                                autoFocus/>
+                                autoFocus />
                         </Grid>
                         <Grid item xs={3}>
                             <Button type="submit" variant="contained" color="primary"
