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";
29 import { Config } from '~/common/config';
30 import { ResourceCluster } from '~/views-components/data-explorer/renderers';
32 type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' |
33 'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' |
36 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 color: theme.palette.primary.main,
43 textDecoration: 'none',
50 marginTop: theme.spacing.unit
65 marginTop: theme.spacing.unit * 3
68 minHeight: theme.spacing.unit,
71 backgroundColor: '#009966',
73 backgroundColor: '#008450',
77 minHeight: theme.spacing.unit,
80 backgroundColor: '#FFC414',
82 backgroundColor: '#eaaf14',
87 export interface SiteManagerPanelRootActionProps {
88 toggleSession: (session: Session) => void;
91 export interface SiteManagerPanelRootDataProps {
93 remoteHostsConfig: { [key: string]: Config };
96 type SiteManagerPanelRootProps = SiteManagerPanelRootDataProps & SiteManagerPanelRootActionProps & WithStyles<CssRules> & InjectedFormProps;
97 const SITE_MANAGER_FORM_NAME = 'siteManagerForm';
99 const submitSession = (remoteHost: string) =>
100 (dispatch: Dispatch) => {
101 dispatch<any>(addSession(remoteHost)).then(() => {
102 dispatch(reset(SITE_MANAGER_FORM_NAME));
103 }).catch((e: any) => {
107 dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
111 export const SiteManagerPanelRoot = compose(
112 reduxForm<{ remoteHost: string }>({
113 form: SITE_MANAGER_FORM_NAME,
115 onSubmit: (data, dispatch) => {
116 dispatch(submitSession(data.remoteHost));
120 (({ classes, sessions, handleSubmit, toggleSession, remoteHostsConfig }: SiteManagerPanelRootProps) =>
121 <Card className={classes.root}>
123 <Grid container direction="row">
125 <Typography paragraph={true} >
126 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.
131 {sessions.length > 0 && <Table className={classes.table}>
133 <TableRow className={classes.tableRow}>
134 <TableCell>Cluster ID</TableCell>
135 <TableCell>Host</TableCell>
136 <TableCell>Username</TableCell>
137 <TableCell>Email</TableCell>
138 <TableCell>Status</TableCell>
142 {sessions.map((session, index) => {
143 const validating = session.status === SessionStatus.BEING_VALIDATED;
144 return <TableRow key={index} className={classes.tableRow}>
145 <TableCell>{remoteHostsConfig[session.clusterId] ?
146 <a href={remoteHostsConfig[session.clusterId].workbench2Url} style={{ textDecoration: 'none' }}> <ResourceCluster uuid={session.clusterId} /></a>
147 : session.clusterId}</TableCell>
148 <TableCell>{session.remoteHost}</TableCell>
149 <TableCell>{validating ? <CircularProgress size={20} /> : session.username}</TableCell>
150 <TableCell>{validating ? <CircularProgress size={20} /> : session.email}</TableCell>
151 <TableCell className={classes.statusCell}>
153 disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
154 className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
155 onClick={() => toggleSession(session)}>
156 {validating ? "Validating" : (session.loggedIn ? "Logged in" : "Logged out")}
164 <form onSubmit={handleSubmit}>
165 <Grid container direction="row">
167 <Typography paragraph={true} className={classes.remoteSiteInfo}>
168 To add a remote Arvados site, paste the remote site's host here (see "ARVADOS_API_HOST" on the "current token" page).
174 validate={SITE_MANAGER_REMOTE_HOST_VALIDATION}
175 component={TextField}
176 placeholder="zzzz.arvadosapi.com"
182 <Button type="submit" variant="contained" color="primary"
183 className={classes.buttonAdd}>