1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
20 } from '@material-ui/core';
21 import { ArvadosTheme } from '~/common/custom-theme';
22 import { Session, SessionStatus } from "~/models/session";
23 import Button from "@material-ui/core/Button";
24 import { compose, Dispatch } from "redux";
25 import { Field, FormErrors, InjectedFormProps, reduxForm, reset, stopSubmit } from "redux-form";
26 import { TextField } from "~/components/text-field/text-field";
27 import { addSession } from "~/store/auth/auth-action-session";
28 import { SITE_MANAGER_REMOTE_HOST_VALIDATION } from "~/validators/validators";
30 type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' |
31 'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' |
34 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 color: theme.palette.primary.main,
41 textDecoration: 'none',
48 marginTop: theme.spacing.unit
63 marginTop: theme.spacing.unit * 3
66 minHeight: theme.spacing.unit,
69 backgroundColor: '#009966',
71 backgroundColor: '#008450',
75 minHeight: theme.spacing.unit,
78 backgroundColor: '#FFC414',
80 backgroundColor: '#eaaf14',
85 export interface SiteManagerPanelRootActionProps {
86 toggleSession: (session: Session) => void;
89 export interface SiteManagerPanelRootDataProps {
93 type SiteManagerPanelRootProps = SiteManagerPanelRootDataProps & SiteManagerPanelRootActionProps & WithStyles<CssRules> & InjectedFormProps;
94 const SITE_MANAGER_FORM_NAME = 'siteManagerForm';
96 const submitSession = (remoteHost: string) =>
97 (dispatch: Dispatch) => {
98 dispatch<any>(addSession(remoteHost)).then(() => {
99 dispatch(reset(SITE_MANAGER_FORM_NAME));
100 }).catch((e: any) => {
104 dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
108 export const SiteManagerPanelRoot = compose(
109 reduxForm<{remoteHost: string}>({
110 form: SITE_MANAGER_FORM_NAME,
112 onSubmit: (data, dispatch) => {
113 dispatch(submitSession(data.remoteHost));
117 (({ classes, sessions, handleSubmit, toggleSession }: SiteManagerPanelRootProps) =>
118 <Card className={classes.root}>
120 <Grid container direction="row">
122 <Typography variant='body1' paragraph={true} >
123 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.
128 {sessions.length > 0 && <Table className={classes.table}>
130 <TableRow className={classes.tableRow}>
131 <TableCell>Cluster ID</TableCell>
132 <TableCell>Username</TableCell>
133 <TableCell>Email</TableCell>
134 <TableCell>Status</TableCell>
138 {sessions.map((session, index) => {
139 const validating = session.status === SessionStatus.BEING_VALIDATED;
140 return <TableRow key={index} className={classes.tableRow}>
141 <TableCell>{session.clusterId}</TableCell>
142 <TableCell>{validating ? <CircularProgress size={20}/> : session.username}</TableCell>
143 <TableCell>{validating ? <CircularProgress size={20}/> : session.email}</TableCell>
144 <TableCell className={classes.statusCell}>
146 disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
147 className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
148 onClick={() => toggleSession(session)}>
149 {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")}
157 <form onSubmit={handleSubmit}>
158 <Grid container direction="row">
160 <Typography variant='body1' paragraph={true} className={classes.remoteSiteInfo}>
161 To add a remote Arvados site, paste the remote site's host here (see "ARVADOS_API_HOST" on the "current token" page).
167 validate={SITE_MANAGER_REMOTE_HOST_VALIDATION}
168 component={TextField}
169 placeholder="zzzz.arvadosapi.com"
175 <Button type="submit" variant="contained" color="primary"
176 className={classes.buttonAdd}>