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 { PROFILE_EMAIL_VALIDATION, PROFILE_URL_VALIDATION } from "validators/validators";
28 import { USER_PROFILE_PANEL_ID } from 'store/user-profile/user-profile-actions';
29 import { noop } from 'lodash';
30 import { DetailsIcon, GroupsIcon, MoreOptionsIcon } from 'components/icon/icon';
31 import { DataColumns } from 'components/data-table/data-table';
32 import { ResourceLinkHeadUuid, ResourceLinkHeadPermissionLevel, ResourceLinkHead, ResourceLinkDelete, ResourceLinkTailIsVisible, UserResourceAccountStatus } from 'views-components/data-explorer/renderers';
33 import { createTree } from 'models/tree';
34 import { getResource, ResourcesState } from 'store/resources/resources';
35 import { DefaultView } from 'components/default-view/default-view';
36 import { CopyToClipboardSnackbar } from 'components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar';
37 import { PermissionResource } from 'models/permission';
39 type CssRules = 'root' | 'emptyRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content' | 'copyIcon';
41 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
49 padding: theme.spacing.unit * 4,
57 color: theme.palette.grey['600']
66 color: theme.palette.grey["600"]
70 justifyContent: 'flex-end'
73 // reserve space for the tab bar
74 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
77 marginLeft: theme.spacing.unit,
78 color: theme.palette.grey["500"],
87 export interface UserProfilePanelRootActionProps {
88 handleContextMenu: (event, resource: UserResource) => void;
91 export interface UserProfilePanelRootDataProps {
96 isInaccessible: boolean;
98 resources: ResourcesState;
103 { key: '', value: '' },
104 { key: 'Bio-informatician', value: 'Bio-informatician' },
105 { key: 'Data Scientist', value: 'Data Scientist' },
106 { key: 'Analyst', value: 'Analyst' },
107 { key: 'Researcher', value: 'Researcher' },
108 { key: 'Software Developer', value: 'Software Developer' },
109 { key: 'System Administrator', value: 'System Administrator' },
110 { key: 'Other', value: 'Other' }
113 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & DispatchProp & WithStyles<CssRules>;
115 export enum UserProfileGroupsColumnNames {
117 PERMISSION = "Permission",
118 VISIBLE = "Visible to other members",
129 export const userProfileGroupsColumns: DataColumns<string, PermissionResource> = [
131 name: UserProfileGroupsColumnNames.NAME,
134 filters: createTree(),
135 render: uuid => <ResourceLinkHead uuid={uuid} />
138 name: UserProfileGroupsColumnNames.PERMISSION,
141 filters: createTree(),
142 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
145 name: UserProfileGroupsColumnNames.VISIBLE,
148 filters: createTree(),
149 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
152 name: UserProfileGroupsColumnNames.UUID,
155 filters: createTree(),
156 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
159 name: UserProfileGroupsColumnNames.REMOVE,
162 filters: createTree(),
163 render: uuid => <ResourceLinkDelete uuid={uuid} />
167 const ReadOnlyField = withStyles(styles)(
168 (props: ({ label: string, input: {value: string} }) & WithStyles<CssRules> ) => (
169 <Grid item xs={12} data-cy="field">
170 <Typography className={props.classes.label}>
173 <Typography className={props.classes.readOnlyValue} data-cy="value">
180 export const UserProfilePanelRoot = withStyles(styles)(
181 class extends React.Component<UserProfilePanelRootProps> {
186 componentDidMount() {
187 this.setState({ value: TABS.PROFILE});
191 if (this.props.isInaccessible) {
193 <Paper className={this.props.classes.emptyRoot}>
195 <DefaultView icon={DetailsIcon} messages={['This user does not exist or your account does not have permission to view it']} />
200 return <Paper className={this.props.classes.root}>
201 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
202 <Tab label={TABS.PROFILE} value={TABS.PROFILE} />
203 <Tab label={TABS.GROUPS} value={TABS.GROUPS} />
205 {this.state.value === TABS.PROFILE &&
207 <Grid container justify="space-between">
209 <Typography className={this.props.classes.title}>
210 {this.props.userUuid}
211 <CopyToClipboardSnackbar value={this.props.userUuid} />
215 <Grid container alignItems="center">
216 <Grid item style={{marginRight: '10px'}}><UserResourceAccountStatus uuid={this.props.userUuid} /></Grid>
218 <Tooltip title="Actions" disableFocusListener>
220 data-cy='user-profile-panel-options-btn'
222 onClick={(event) => this.handleContextMenu(event, this.props.userUuid)}>
230 <form onSubmit={this.props.handleSubmit} data-cy="profile-form">
231 <Grid container spacing={24}>
232 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="firstName">
236 component={TextField as any}
237 disabled={!this.props.isAdmin && !this.props.isSelf}
240 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="lastName">
244 component={TextField as any}
245 disabled={!this.props.isAdmin && !this.props.isSelf}
248 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="email">
252 component={ReadOnlyField as any}
256 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="username">
260 component={ReadOnlyField as any}
264 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
267 name="prefs.profile.organization"
268 component={TextField as any}
269 disabled={!this.props.isAdmin && !this.props.isSelf}
272 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
274 label="E-mail at Organization"
275 name="prefs.profile.organization_email"
276 component={TextField as any}
277 disabled={!this.props.isAdmin && !this.props.isSelf}
278 validate={PROFILE_EMAIL_VALIDATION}
281 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
282 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
284 id="prefs.profile.role"
285 name="prefs.profile.role"
286 component={NativeSelectField as any}
288 disabled={!this.props.isAdmin && !this.props.isSelf}
291 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
294 name="prefs.profile.website_url"
295 component={TextField as any}
296 disabled={!this.props.isAdmin && !this.props.isSelf}
297 validate={PROFILE_URL_VALIDATION}
301 <Grid container direction="row" justify="flex-end">
302 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
307 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
316 {this.state.value === TABS.GROUPS &&
317 <div className={this.props.classes.content}>
319 id={USER_PROFILE_PANEL_ID}
320 data-cy="user-profile-groups-data-explorer"
322 onRowDoubleClick={noop}
324 contextMenuColumn={false}
330 defaultViewIcon={GroupsIcon}
331 defaultViewMessages={['Group list is empty.']} />
337 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
338 this.setState({ value });
341 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
342 event.stopPropagation();
343 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
345 this.props.handleContextMenu(event, resource);