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';
38 type CssRules = 'root' | 'emptyRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content' | 'copyIcon';
40 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
48 padding: theme.spacing.unit * 4,
56 color: theme.palette.grey['600']
65 color: theme.palette.grey["600"]
69 justifyContent: 'flex-end'
72 // reserve space for the tab bar
73 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
76 marginLeft: theme.spacing.unit,
77 color: theme.palette.grey["500"],
86 export interface UserProfilePanelRootActionProps {
87 handleContextMenu: (event, resource: UserResource) => void;
90 export interface UserProfilePanelRootDataProps {
95 isInaccessible: boolean;
97 resources: ResourcesState;
102 { key: '', value: '' },
103 { key: 'Bio-informatician', value: 'Bio-informatician' },
104 { key: 'Data Scientist', value: 'Data Scientist' },
105 { key: 'Analyst', value: 'Analyst' },
106 { key: 'Researcher', value: 'Researcher' },
107 { key: 'Software Developer', value: 'Software Developer' },
108 { key: 'System Administrator', value: 'System Administrator' },
109 { key: 'Other', value: 'Other' }
112 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & DispatchProp & WithStyles<CssRules>;
114 export enum UserProfileGroupsColumnNames {
116 PERMISSION = "Permission",
117 VISIBLE = "Visible to other members",
128 export const userProfileGroupsColumns: DataColumns<string> = [
130 name: UserProfileGroupsColumnNames.NAME,
133 filters: createTree(),
134 render: uuid => <ResourceLinkHead uuid={uuid} />
137 name: UserProfileGroupsColumnNames.PERMISSION,
140 filters: createTree(),
141 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
144 name: UserProfileGroupsColumnNames.VISIBLE,
147 filters: createTree(),
148 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
151 name: UserProfileGroupsColumnNames.UUID,
154 filters: createTree(),
155 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
158 name: UserProfileGroupsColumnNames.REMOVE,
161 filters: createTree(),
162 render: uuid => <ResourceLinkDelete uuid={uuid} />
166 const ReadOnlyField = withStyles(styles)(
167 (props: ({ label: string, input: {value: string} }) & WithStyles<CssRules> ) => (
168 <Grid item xs={12} data-cy="field">
169 <Typography className={props.classes.label}>
172 <Typography className={props.classes.readOnlyValue} data-cy="value">
179 export const UserProfilePanelRoot = withStyles(styles)(
180 class extends React.Component<UserProfilePanelRootProps> {
185 componentDidMount() {
186 this.setState({ value: TABS.PROFILE});
190 if (this.props.isInaccessible) {
192 <Paper className={this.props.classes.emptyRoot}>
194 <DefaultView icon={DetailsIcon} messages={['This user does not exist or your account does not have permission to view it']} />
199 return <Paper className={this.props.classes.root}>
200 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
201 <Tab label={TABS.PROFILE} value={TABS.PROFILE} />
202 <Tab label={TABS.GROUPS} value={TABS.GROUPS} />
204 {this.state.value === TABS.PROFILE &&
206 <Grid container justify="space-between">
208 <Typography className={this.props.classes.title}>
209 {this.props.userUuid}
210 <CopyToClipboardSnackbar value={this.props.userUuid} />
214 <Grid container alignItems="center">
215 <Grid item style={{marginRight: '10px'}}><UserResourceAccountStatus uuid={this.props.userUuid} /></Grid>
217 <Tooltip title="Actions" disableFocusListener>
219 data-cy='user-profile-panel-options-btn'
221 onClick={(event) => this.handleContextMenu(event, this.props.userUuid)}>
229 <form onSubmit={this.props.handleSubmit} data-cy="profile-form">
230 <Grid container spacing={24}>
231 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="firstName">
235 component={TextField as any}
236 disabled={!this.props.isAdmin && !this.props.isSelf}
239 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="lastName">
243 component={TextField as any}
244 disabled={!this.props.isAdmin && !this.props.isSelf}
247 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="email">
251 component={ReadOnlyField as any}
255 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="username">
259 component={ReadOnlyField as any}
263 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
266 name="prefs.profile.organization"
267 component={TextField as any}
268 disabled={!this.props.isAdmin && !this.props.isSelf}
271 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
273 label="E-mail at Organization"
274 name="prefs.profile.organization_email"
275 component={TextField as any}
276 disabled={!this.props.isAdmin && !this.props.isSelf}
277 validate={PROFILE_EMAIL_VALIDATION}
280 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
281 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
283 id="prefs.profile.role"
284 name="prefs.profile.role"
285 component={NativeSelectField as any}
287 disabled={!this.props.isAdmin && !this.props.isSelf}
290 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
293 name="prefs.profile.website_url"
294 component={TextField as any}
295 disabled={!this.props.isAdmin && !this.props.isSelf}
296 validate={PROFILE_URL_VALIDATION}
300 <Grid container direction="row" justify="flex-end">
301 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
306 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
315 {this.state.value === TABS.GROUPS &&
316 <div className={this.props.classes.content}>
318 id={USER_PROFILE_PANEL_ID}
319 data-cy="user-profile-groups-data-explorer"
321 onRowDoubleClick={noop}
323 contextMenuColumn={false}
329 defaultViewIcon={GroupsIcon}
330 defaultViewMessages={['Group list is empty.']} />
336 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
337 this.setState({ value });
340 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
341 event.stopPropagation();
342 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
344 this.props.handleContextMenu(event, resource);