1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
15 } from '@material-ui/core';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { UserResource } from "~/models/user";
18 import { LinkAccountType } from "~/models/link-account";
19 import { formatDate } from "~/common/formatters";
20 import { LinkAccountPanelStatus, LinkAccountPanelError } from "~/store/link-account-panel/link-account-panel-reducer";
22 type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31 export interface LinkAccountPanelRootDataProps {
32 targetUser?: UserResource;
33 userToLink?: UserResource;
34 remoteHosts: { [key: string]: string };
35 hasRemoteHosts: boolean;
36 status : LinkAccountPanelStatus;
37 error: LinkAccountPanelError;
38 selectedCluster?: string;
41 export interface LinkAccountPanelRootActionProps {
42 startLinking: (type: LinkAccountType) => void;
43 cancelLinking: () => void;
44 linkAccount: () => void;
45 setSelectedCluster: (cluster: string) => void;
48 function displayUser(user: UserResource, showCreatedAt: boolean = false, showCluster: boolean = false) {
50 disp.push(<span><b>{user.email}</b> ({user.username}, {user.uuid})</span>);
52 const homeCluster = user.uuid.substr(0,5);
53 disp.push(<span> hosted on cluster <b>{homeCluster}</b> and </span>);
56 disp.push(<span> created on <b>{formatDate(user.createdAt, true)}</b></span>);
61 type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles<CssRules>;
63 export const LinkAccountPanelRoot = withStyles(styles) (
64 ({classes, targetUser, userToLink, status, error, startLinking, cancelLinking, linkAccount,
65 remoteHosts, hasRemoteHosts, selectedCluster, setSelectedCluster}: LinkAccountPanelRootProps) => {
66 return <Card className={classes.root}>
68 { status === LinkAccountPanelStatus.INITIAL && targetUser &&
69 <Grid container spacing={24}>
70 <Grid container item direction="column" spacing={24}>
72 You are currently logged in as {displayUser(targetUser, true, hasRemoteHosts)}
75 You can link Arvados accounts. After linking, either login will take you to the same account.
77 {hasRemoteHosts && selectedCluster && <Grid item>
78 Please select the cluster that hosts the account you want to link with:
79 <Select id="remoteHostsDropdown" native defaultValue={selectedCluster} style={{ marginLeft: "1em" }}
80 onChange={(event) => setSelectedCluster(event.target.value)}>
81 {Object.keys(remoteHosts).map((k) => <option key={k} value={k}>{k}</option>)}
85 <Grid container item direction="row" spacing={24}>
87 <Button disabled={!targetUser.isActive} color="primary" variant="contained" onClick={() => startLinking(LinkAccountType.ADD_OTHER_LOGIN)}>
88 Add another login {hasRemoteHosts ? <label> from {selectedCluster} </label> : null} to this account
92 <Button color="primary" variant="contained" onClick={() => startLinking(LinkAccountType.ACCESS_OTHER_ACCOUNT)}>
93 Use this login to access another account {hasRemoteHosts ? <label> on {selectedCluster} </label> : null}
98 { (status === LinkAccountPanelStatus.LINKING || status === LinkAccountPanelStatus.ERROR) && userToLink && targetUser &&
99 <Grid container spacing={24}>
100 { status === LinkAccountPanelStatus.LINKING && <Grid container item direction="column" spacing={24}>
102 Clicking 'Link accounts' will link {displayUser(userToLink, true, hasRemoteHosts)} to {displayUser(targetUser, true, hasRemoteHosts)}.
105 After linking, logging in as {displayUser(userToLink)} will log you into the same account as {displayUser(targetUser)}.
108 Any object owned by {displayUser(userToLink)} will be transfered to {displayUser(targetUser)}.
111 { error === LinkAccountPanelError.NON_ADMIN && <Grid item>
112 Cannot link admin account {displayUser(userToLink)} to non-admin account {displayUser(targetUser)}.
114 { error === LinkAccountPanelError.SAME_USER && <Grid item>
115 Cannot link {displayUser(targetUser)} to the same account.
117 { error === LinkAccountPanelError.INACTIVE && <Grid item>
118 Cannot link account {displayUser(userToLink)} to inactive account {displayUser(targetUser)}.
120 <Grid container item direction="row" spacing={24}>
122 <Button variant="contained" onClick={() => cancelLinking()}>
127 <Button disabled={status === LinkAccountPanelStatus.ERROR} color="primary" variant="contained" onClick={() => linkAccount()}>