1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Field, InjectedFormProps } from "redux-form";
7 import { DispatchProp } from 'react-redux';
8 import { UserResource } from 'models/user';
9 import { TextField } from "components/text-field/text-field";
10 import { DataExplorer } from "views-components/data-explorer/data-explorer";
11 import { NativeSelectField } from "components/select-field/select-field";
25 } from '@material-ui/core';
26 import { ArvadosTheme } from 'common/custom-theme';
27 import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
28 import { PROFILE_EMAIL_VALIDATION } from "validators/validators";
29 import { USER_PROFILE_PANEL_ID } from 'store/user-profile/user-profile-actions';
30 import { noop } from 'lodash';
31 import { CopyIcon, DetailsIcon, GroupsIcon, MoreOptionsIcon } from 'components/icon/icon';
32 import { DataColumns } from 'components/data-table/data-table';
33 import { ResourceLinkHeadUuid, ResourceLinkHeadPermissionLevel, ResourceLinkHead, ResourceLinkDelete, ResourceLinkTailIsVisible } from 'views-components/data-explorer/renderers';
34 import { createTree } from 'models/tree';
35 import { getResource, ResourcesState } from 'store/resources/resources';
36 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
37 import CopyToClipboard from 'react-copy-to-clipboard';
38 import { DefaultView } from 'components/default-view/default-view';
40 type CssRules = 'root' | 'emptyRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content' | 'copyIcon';
42 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
50 padding: theme.spacing.unit * 4,
58 color: theme.palette.grey['600']
67 color: theme.palette.grey["600"]
71 justifyContent: 'flex-end'
74 // reserve space for the tab bar
75 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
78 marginLeft: theme.spacing.unit,
79 color: theme.palette.grey["500"],
88 export interface UserProfilePanelRootActionProps {
89 handleContextMenu: (event, resource: UserResource) => void;
92 export interface UserProfilePanelRootDataProps {
97 isInaccessible: boolean;
99 resources: ResourcesState;
100 localCluster: string;
104 { key: '', value: '' },
105 { key: 'Bio-informatician', value: 'Bio-informatician' },
106 { key: 'Data Scientist', value: 'Data Scientist' },
107 { key: 'Analyst', value: 'Analyst' },
108 { key: 'Researcher', value: 'Researcher' },
109 { key: 'Software Developer', value: 'Software Developer' },
110 { key: 'System Administrator', value: 'System Administrator' },
111 { key: 'Other', value: 'Other' }
114 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & DispatchProp & WithStyles<CssRules>;
116 export enum UserProfileGroupsColumnNames {
118 PERMISSION = "Permission",
119 VISIBLE = "Visible to other members",
130 export const userProfileGroupsColumns: DataColumns<string> = [
132 name: UserProfileGroupsColumnNames.NAME,
135 filters: createTree(),
136 render: uuid => <ResourceLinkHead uuid={uuid} />
139 name: UserProfileGroupsColumnNames.PERMISSION,
142 filters: createTree(),
143 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
146 name: UserProfileGroupsColumnNames.VISIBLE,
149 filters: createTree(),
150 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
153 name: UserProfileGroupsColumnNames.UUID,
156 filters: createTree(),
157 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
160 name: UserProfileGroupsColumnNames.REMOVE,
163 filters: createTree(),
164 render: uuid => <ResourceLinkDelete uuid={uuid} />
168 const ReadOnlyField = withStyles(styles)(
169 (props: ({ label: string, input: {value: string} }) & WithStyles<CssRules> ) => (
170 <Grid item xs={12} data-cy="field">
171 <Typography className={props.classes.label}>
174 <Typography className={props.classes.readOnlyValue} data-cy="value">
181 export const UserProfilePanelRoot = withStyles(styles)(
182 class extends React.Component<UserProfilePanelRootProps> {
187 componentDidMount() {
188 this.setState({ value: TABS.PROFILE});
191 onCopy = (message: string) => {
192 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
195 kind: SnackbarKind.SUCCESS
200 if (this.props.isInaccessible) {
202 <Paper className={this.props.classes.emptyRoot}>
204 <DefaultView icon={DetailsIcon} messages={['This user does not exist or your account does not have permission to view it']} />
209 return <Paper className={this.props.classes.root}>
210 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
211 <Tab label={TABS.PROFILE} value={TABS.PROFILE} />
212 <Tab label={TABS.GROUPS} value={TABS.GROUPS} />
214 {this.state.value === TABS.PROFILE &&
216 <Grid container justify="space-between">
218 <Typography className={this.props.classes.title}>
219 {this.props.userUuid}
220 <Tooltip title="Copy to clipboard">
221 <span className={this.props.classes.copyIcon}>
222 <CopyToClipboard text={this.props.userUuid || ""} onCopy={() => this.onCopy!("Copied")}>
229 <Grid item xs={1} style={{ textAlign: "right" }}>
230 <Tooltip title="Actions" disableFocusListener>
232 data-cy='collection-panel-options-btn'
234 onClick={(event) => this.handleContextMenu(event, this.props.userUuid)}>
240 <form onSubmit={this.props.handleSubmit} data-cy="profile-form">
241 <Grid container spacing={24}>
242 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="firstName">
246 component={ReadOnlyField as any}
250 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="lastName">
254 component={ReadOnlyField as any}
258 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="email">
262 component={ReadOnlyField as any}
266 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="username">
270 component={ReadOnlyField as any}
274 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
277 name="prefs.profile.organization"
278 component={TextField as any}
279 disabled={!this.props.isAdmin && !this.props.isSelf}
282 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
284 label="E-mail at Organization"
285 name="prefs.profile.organization_email"
286 component={TextField as any}
287 disabled={!this.props.isAdmin && !this.props.isSelf}
288 validate={PROFILE_EMAIL_VALIDATION}
291 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
292 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
294 id="prefs.profile.role"
295 name="prefs.profile.role"
296 component={NativeSelectField as any}
298 disabled={!this.props.isAdmin && !this.props.isSelf}
301 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
304 name="prefs.profile.website_url"
305 component={TextField as any}
306 disabled={!this.props.isAdmin && !this.props.isSelf}
311 <Grid container direction="row" justify="flex-end">
312 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
317 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
326 {this.state.value === TABS.GROUPS &&
327 <div className={this.props.classes.content}>
329 id={USER_PROFILE_PANEL_ID}
330 data-cy="user-profile-groups-data-explorer"
332 onRowDoubleClick={noop}
334 contextMenuColumn={false}
340 dataTableDefaultView={
341 <DataTableDefaultView
343 messages={['Group list is empty.']} />
350 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
351 this.setState({ value });
354 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
355 event.stopPropagation();
356 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
358 this.props.handleContextMenu(event, resource);