1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
21 } from '@material-ui/core';
22 import { ArvadosTheme } from 'common/custom-theme';
23 import { Session, SessionStatus } from "models/session";
24 import Button from "@material-ui/core/Button";
25 import { compose, Dispatch } 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";
30 import { Config } from 'common/config';
31 import { ResourceCluster } from 'views-components/data-explorer/renderers';
32 import { TrashIcon } from "components/icon/icon";
34 type CssRules = 'root' | 'link' | 'buttonContainer' | 'table' | 'tableRow' |
35 'remoteSiteInfo' | 'buttonAdd' | 'buttonLoggedIn' | 'buttonLoggedOut' |
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
44 color: theme.palette.primary.main,
45 textDecoration: 'none',
52 marginTop: theme.spacing.unit
67 marginTop: theme.spacing.unit * 3
70 minHeight: theme.spacing.unit,
73 backgroundColor: '#009966',
75 backgroundColor: '#008450',
79 minHeight: theme.spacing.unit,
82 backgroundColor: '#FFC414',
84 backgroundColor: '#eaaf14',
89 export interface SiteManagerPanelRootActionProps {
90 toggleSession: (session: Session) => void;
91 removeSession: (session: Session) => void;
94 export interface SiteManagerPanelRootDataProps {
96 remoteHostsConfig: { [key: string]: Config };
97 localClusterConfig: Config;
100 type SiteManagerPanelRootProps = SiteManagerPanelRootDataProps & SiteManagerPanelRootActionProps & WithStyles<CssRules> & InjectedFormProps;
101 const SITE_MANAGER_FORM_NAME = 'siteManagerForm';
103 const submitSession = (remoteHost: string) =>
104 (dispatch: Dispatch) => {
105 dispatch<any>(addSession(remoteHost, undefined, true)).then(() => {
106 dispatch(reset(SITE_MANAGER_FORM_NAME));
107 }).catch((e: any) => {
111 dispatch(stopSubmit(SITE_MANAGER_FORM_NAME, errors));
115 export const SiteManagerPanelRoot = compose(
116 reduxForm<{ remoteHost: string }>({
117 form: SITE_MANAGER_FORM_NAME,
119 onSubmit: (data, dispatch) => {
120 dispatch(submitSession(data.remoteHost));
124 (({ classes, sessions, handleSubmit, toggleSession, removeSession, localClusterConfig, remoteHostsConfig }: SiteManagerPanelRootProps) =>
125 <Card className={classes.root}>
127 <Grid container direction="row">
129 <Typography paragraph={true} >
130 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.
135 {sessions.length > 0 && <Table className={classes.table}>
137 <TableRow className={classes.tableRow}>
138 <TableCell>Cluster ID</TableCell>
139 <TableCell>Host</TableCell>
140 <TableCell>Email</TableCell>
141 <TableCell>UUID</TableCell>
142 <TableCell>Status</TableCell>
143 <TableCell>Actions</TableCell>
147 {sessions.map((session, index) => {
148 const validating = session.status === SessionStatus.BEING_VALIDATED;
149 return <TableRow key={index} className={classes.tableRow}>
150 <TableCell>{remoteHostsConfig[session.clusterId] ?
151 <a href={remoteHostsConfig[session.clusterId].workbench2Url} style={{ textDecoration: 'none' }}> <ResourceCluster uuid={session.clusterId} /></a>
152 : session.clusterId}</TableCell>
153 <TableCell>{session.remoteHost}</TableCell>
154 <TableCell>{validating ? <CircularProgress size={20} /> : session.email}</TableCell>
155 <TableCell>{validating ? <CircularProgress size={20} /> : session.uuid}</TableCell>
156 <TableCell className={classes.statusCell}>
158 disabled={validating || session.status === SessionStatus.INVALIDATED || session.active}
159 className={session.loggedIn ? classes.buttonLoggedIn : classes.buttonLoggedOut}
160 onClick={() => toggleSession(session)}>
161 {validating ? "Validating"
162 : (session.loggedIn ?
163 (session.userIsActive ? "Logged in" : "Inactive")
168 {session.clusterId !== localClusterConfig.uuidPrefix &&
169 !localClusterConfig.clusterConfig.RemoteClusters[session.clusterId] &&
170 <IconButton onClick={() => removeSession(session)}>
179 <form onSubmit={handleSubmit}>
180 <Grid container direction="row">
182 <Typography paragraph={true} className={classes.remoteSiteInfo}>
183 To add a remote Arvados site, paste the remote site's host here (see "ARVADOS_API_HOST" on the "current token" page).
189 validate={SITE_MANAGER_REMOTE_HOST_VALIDATION}
190 component={TextField as any}
191 placeholder="zzzz.arvadosapi.com"
197 <Button type="submit" variant="contained" color="primary"
198 className={classes.buttonAdd}>