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 { User } from "~/models/user";
25 import { compose } from "redux";
26 import { Field, FormErrors, InjectedFormProps, reduxForm, reset, stopSubmit } from "redux-form";
27 import { TextField } from "~/components/text-field/text-field";
28 import { addSession } from "~/store/auth/auth-action-session";
29 import { SITE_MANAGER_REMOTE_HOST_VALIDATION } from "~/validators/validators";
31 type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' |
32 'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' |
35 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
41 color: theme.palette.primary.main,
42 textDecoration: 'none',
49 marginTop: theme.spacing.unit
64 marginTop: theme.spacing.unit * 3
67 minHeight: theme.spacing.unit,
70 backgroundColor: '#009966',
72 backgroundColor: '#008450',
76 minHeight: theme.spacing.unit,
79 backgroundColor: '#FFC414',
81 backgroundColor: '#eaaf14',
86 export interface SiteManagerPanelRootActionProps {
87 toggleSession: (session: Session) => void;
90 export interface SiteManagerPanelRootDataProps {
95 type SiteManagerPanelRootProps = SiteManagerPanelRootDataProps & SiteManagerPanelRootActionProps & WithStyles<CssRules> & InjectedFormProps;
96 const SITE_MANAGER_FORM_NAME = 'siteManagerForm';
98 export const SiteManagerPanelRoot = compose(
99 reduxForm<{remoteHost: string}>({
100 form: SITE_MANAGER_FORM_NAME,
102 onSubmit: (data, dispatch) => {
103 dispatch<any>(addSession(data.remoteHost)).then(() => {
104 dispatch(reset(SITE_MANAGER_FORM_NAME));
105 }).catch((e: any) => {
109 dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
114 (({ classes, sessions, handleSubmit, toggleSession }: SiteManagerPanelRootProps) =>
115 <Card className={classes.root}>
117 <Grid container direction="row">
119 <Typography variant='body1' paragraph={true} >
120 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.
125 {sessions.length > 0 && <Table className={classes.table}>
127 <TableRow className={classes.tableRow}>
128 <TableCell>Cluster ID</TableCell>
129 <TableCell>Username</TableCell>
130 <TableCell>Email</TableCell>
131 <TableCell>Status</TableCell>
135 {sessions.map((session, index) => {
136 const validating = session.status === SessionStatus.BEING_VALIDATED;
137 return <TableRow key={index} className={classes.tableRow}>
138 <TableCell>{session.clusterId}</TableCell>
139 <TableCell>{validating ? <CircularProgress size={20}/> : session.username}</TableCell>
140 <TableCell>{validating ? <CircularProgress size={20}/> : session.email}</TableCell>
141 <TableCell className={classes.statusCell}>
143 disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
144 className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
145 onClick={() => toggleSession(session)}>
146 {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")}
154 <form onSubmit={handleSubmit}>
155 <Grid container direction="row">
157 <Typography variant='body1' paragraph={true} className={classes.remoteSiteInfo}>
158 To add a remote Arvados site, paste the remote site's host here (see "ARVADOS_API_HOST" on the "current token" page).
164 validate={SITE_MANAGER_REMOTE_HOST_VALIDATION}
165 component={TextField}
166 placeholder="zzzz.arvadosapi.com"
172 <Button type="submit" variant="contained" color="primary"
173 className={classes.buttonAdd}>