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, 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';
39 type CssRules = 'root' | 'adminRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content' | 'copyIcon';
41 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
47 // ...theme.mixins.gutters()
55 color: theme.palette.grey['600']
64 color: theme.palette.grey["600"]
68 justifyContent: 'flex-end'
71 // reserve space for the tab bar
72 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
75 marginLeft: theme.spacing.unit,
76 color: theme.palette.grey["500"],
85 export interface UserProfilePanelRootActionProps {
86 handleContextMenu: (event, resource: UserResource) => void;
89 export interface UserProfilePanelRootDataProps {
95 resources: ResourcesState
100 { key: '', value: '' },
101 { key: 'Bio-informatician', value: 'Bio-informatician' },
102 { key: 'Data Scientist', value: 'Data Scientist' },
103 { key: 'Analyst', value: 'Analyst' },
104 { key: 'Researcher', value: 'Researcher' },
105 { key: 'Software Developer', value: 'Software Developer' },
106 { key: 'System Administrator', value: 'System Administrator' },
107 { key: 'Other', value: 'Other' }
110 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & DispatchProp & WithStyles<CssRules>;
112 export enum UserProfileGroupsColumnNames {
114 PERMISSION = "Permission",
115 VISIBLE = "Visible to other members",
126 export const userProfileGroupsColumns: DataColumns<string> = [
128 name: UserProfileGroupsColumnNames.NAME,
131 filters: createTree(),
132 render: uuid => <ResourceLinkHead uuid={uuid} />
135 name: UserProfileGroupsColumnNames.PERMISSION,
138 filters: createTree(),
139 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
142 name: UserProfileGroupsColumnNames.VISIBLE,
145 filters: createTree(),
146 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
149 name: UserProfileGroupsColumnNames.UUID,
152 filters: createTree(),
153 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
156 name: UserProfileGroupsColumnNames.REMOVE,
159 filters: createTree(),
160 render: uuid => <ResourceLinkDelete uuid={uuid} />
164 const ReadOnlyField = withStyles(styles)(
165 (props: ({ label: string, input: {value: string} }) & WithStyles<CssRules> ) => (
166 <Grid item xs={12} data-cy="field">
167 <Typography className={props.classes.label}>
170 <Typography className={props.classes.readOnlyValue} data-cy="value">
177 export const UserProfilePanelRoot = withStyles(styles)(
178 class extends React.Component<UserProfilePanelRootProps> {
183 componentDidMount() {
184 this.setState({ value: TABS.PROFILE});
187 onCopy = (message: string) => {
188 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
191 kind: SnackbarKind.SUCCESS
196 return <Paper className={this.props.classes.root}>
197 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
198 <Tab label={TABS.PROFILE} value={TABS.PROFILE} />
199 <Tab label={TABS.GROUPS} value={TABS.GROUPS} />
201 {this.state.value === TABS.PROFILE &&
203 <Grid container justify="space-between">
205 <Typography className={this.props.classes.title}>
206 {this.props.userUuid}
207 <Tooltip title="Copy to clipboard">
208 <span className={this.props.classes.copyIcon}>
209 <CopyToClipboard text={this.props.userUuid || ""} onCopy={() => this.onCopy!("Copied")}>
216 <Grid item xs={1} style={{ textAlign: "right" }}>
217 <Tooltip title="Actions" disableFocusListener>
219 data-cy='collection-panel-options-btn'
221 onClick={(event) => this.handleContextMenu(event, this.props.userUuid)}>
227 <form onSubmit={this.props.handleSubmit} data-cy="profile-form">
228 <Grid container spacing={24}>
229 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="firstName">
233 component={ReadOnlyField as any}
237 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="lastName">
241 component={ReadOnlyField as any}
245 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="email">
249 component={ReadOnlyField as any}
253 <Grid item className={this.props.classes.gridItem} sm={6} xs={12} data-cy="username">
257 component={ReadOnlyField as any}
261 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
264 name="prefs.profile.organization"
265 component={TextField as any}
266 disabled={!this.props.isAdmin && !this.props.isSelf}
269 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
271 label="E-mail at Organization"
272 name="prefs.profile.organization_email"
273 component={TextField as any}
274 disabled={!this.props.isAdmin && !this.props.isSelf}
275 validate={PROFILE_EMAIL_VALIDATION}
278 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
279 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
281 id="prefs.profile.role"
282 name="prefs.profile.role"
283 component={NativeSelectField as any}
285 disabled={!this.props.isAdmin && !this.props.isSelf}
288 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
291 name="prefs.profile.website_url"
292 component={TextField as any}
293 disabled={!this.props.isAdmin && !this.props.isSelf}
297 <Grid container direction="row" justify="flex-end">
298 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
303 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
312 {this.state.value === TABS.GROUPS &&
313 <div className={this.props.classes.content}>
315 id={USER_PROFILE_PANEL_ID}
316 data-cy="user-profile-groups-data-explorer"
318 onRowDoubleClick={noop}
320 contextMenuColumn={false}
326 dataTableDefaultView={
327 <DataTableDefaultView
329 messages={['Group list is empty.']} />
335 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
336 this.setState({ value });
339 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
340 event.stopPropagation();
341 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
343 this.props.handleContextMenu(event, resource);