// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; import { Field, InjectedFormProps } from "redux-form"; import { DispatchProp } from 'react-redux'; import { UserResource } from 'models/user'; import { TextField } from "components/text-field/text-field"; import { DataExplorer } from "views-components/data-explorer/data-explorer"; import { NativeSelectField } from "components/select-field/select-field"; import { StyleRulesCallback, WithStyles, withStyles, CardContent, Button, Typography, Grid, InputLabel, Tabs, Tab, Paper, Tooltip, IconButton, } from '@material-ui/core'; import { ArvadosTheme } from 'common/custom-theme'; import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view'; import { PROFILE_EMAIL_VALIDATION, PROFILE_URL_VALIDATION } from "validators/validators"; import { USER_PROFILE_PANEL_ID } from 'store/user-profile/user-profile-actions'; import { noop } from 'lodash'; import { DetailsIcon, GroupsIcon, MoreOptionsIcon } from 'components/icon/icon'; import { DataColumns } from 'components/data-table/data-table'; import { ResourceLinkHeadUuid, ResourceLinkHeadPermissionLevel, ResourceLinkHead, ResourceLinkDelete, ResourceLinkTailIsVisible, UserResourceAccountStatus } from 'views-components/data-explorer/renderers'; import { createTree } from 'models/tree'; import { getResource, ResourcesState } from 'store/resources/resources'; import { DefaultView } from 'components/default-view/default-view'; import { CopyToClipboardSnackbar } from 'components/copy-to-clipboard-snackbar/copy-to-clipboard-snackbar'; type CssRules = 'root' | 'emptyRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content' | 'copyIcon'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { width: '100%', overflow: 'auto' }, emptyRoot: { width: '100%', overflow: 'auto', padding: theme.spacing.unit * 4, }, gridItem: { height: 45, marginBottom: 20 }, label: { fontSize: '0.675rem', color: theme.palette.grey['600'] }, readOnlyValue: { fontSize: '0.875rem', }, title: { fontSize: '1.1rem', }, description: { color: theme.palette.grey["600"] }, actions: { display: 'flex', justifyContent: 'flex-end' }, content: { // reserve space for the tab bar height: `calc(100% - ${theme.spacing.unit * 7}px)`, }, copyIcon: { marginLeft: theme.spacing.unit, color: theme.palette.grey["500"], cursor: 'pointer', display: 'inline', '& svg': { fontSize: '1rem' } } }); export interface UserProfilePanelRootActionProps { handleContextMenu: (event, resource: UserResource) => void; } export interface UserProfilePanelRootDataProps { isAdmin: boolean; isSelf: boolean; isPristine: boolean; isValid: boolean; isInaccessible: boolean; userUuid: string; resources: ResourcesState; localCluster: string; } const RoleTypes = [ { key: '', value: '' }, { key: 'Bio-informatician', value: 'Bio-informatician' }, { key: 'Data Scientist', value: 'Data Scientist' }, { key: 'Analyst', value: 'Analyst' }, { key: 'Researcher', value: 'Researcher' }, { key: 'Software Developer', value: 'Software Developer' }, { key: 'System Administrator', value: 'System Administrator' }, { key: 'Other', value: 'Other' } ]; type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & DispatchProp & WithStyles; export enum UserProfileGroupsColumnNames { NAME = "Name", PERMISSION = "Permission", VISIBLE = "Visible to other members", UUID = "UUID", REMOVE = "Remove", } enum TABS { PROFILE = "PROFILE", GROUPS = "GROUPS", } export const userProfileGroupsColumns: DataColumns = [ { name: UserProfileGroupsColumnNames.NAME, selected: true, configurable: true, filters: createTree(), render: uuid => }, { name: UserProfileGroupsColumnNames.PERMISSION, selected: true, configurable: true, filters: createTree(), render: uuid => }, { name: UserProfileGroupsColumnNames.VISIBLE, selected: true, configurable: true, filters: createTree(), render: uuid => }, { name: UserProfileGroupsColumnNames.UUID, selected: true, configurable: true, filters: createTree(), render: uuid => }, { name: UserProfileGroupsColumnNames.REMOVE, selected: true, configurable: true, filters: createTree(), render: uuid => }, ]; const ReadOnlyField = withStyles(styles)( (props: ({ label: string, input: {value: string} }) & WithStyles ) => ( {props.label} {props.input.value} ) ); export const UserProfilePanelRoot = withStyles(styles)( class extends React.Component { state = { value: TABS.PROFILE, }; componentDidMount() { this.setState({ value: TABS.PROFILE}); } render() { if (this.props.isInaccessible) { return ( ); } else { return {this.state.value === TABS.PROFILE && {this.props.userUuid} this.handleContextMenu(event, this.props.userUuid)}>
Role
} {this.state.value === TABS.GROUPS &&
} />
}
; } } handleChange = (event: React.MouseEvent, value: number) => { this.setState({ value }); } handleContextMenu = (event: React.MouseEvent, resourceUuid: string) => { event.stopPropagation(); const resource = getResource(resourceUuid)(this.props.resources); if (resource) { this.props.handleContextMenu(event, resource); } } } );