1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Paper, Typography } from '@mui/material';
7 import { WithStyles } from '@mui/styles';
8 import withStyles from '@mui/styles/withStyles';
9 import { DataExplorer } from "views-components/data-explorer/data-explorer";
10 import { connect, DispatchProp } from 'react-redux';
11 import { RootState } from 'store/store';
12 import { DataColumns, SortDirection } from 'components/data-table/data-column';
13 import { openUserContextMenu } from "store/context-menu/context-menu-actions";
14 import { getResource, ResourcesState } from "store/resources/resources";
21 UserResourceAccountStatus,
22 } from "views-components/data-explorer/renderers";
23 import { navigateToUserProfile } from "store/navigation/navigation-action";
24 import { createTree } from 'models/tree';
25 import { compose, Dispatch } from 'redux';
26 import { UserResource } from 'models/user';
27 import { ShareMeIcon } from 'components/icon/icon';
28 import { USERS_PANEL_ID, openUserCreateDialog } from 'store/users/users-actions';
29 import { noop } from 'lodash';
30 import { CustomStyleRulesCallback } from 'common/custom-theme';
32 type UserPanelRules = "button" | 'root';
34 const styles: CustomStyleRulesCallback<UserPanelRules> = (theme) => ({
36 marginTop: theme.spacing(1),
37 marginRight: theme.spacing(2),
46 export enum UserPanelColumnNames {
50 STATUS = "Account Status",
52 REDIRECT_TO_USER = "Redirect to user",
56 export const userPanelColumns: DataColumns<string, UserResource> = [
58 name: UserPanelColumnNames.NAME,
61 sort: {direction: SortDirection.NONE, field: "firstName"},
62 filters: createTree(),
63 render: uuid => <UserResourceFullName uuid={uuid} link={true} />
66 name: UserPanelColumnNames.UUID,
69 sort: {direction: SortDirection.NONE, field: "uuid"},
70 filters: createTree(),
71 render: uuid => <ResourceUuid uuid={uuid} />
74 name: UserPanelColumnNames.EMAIL,
77 sort: {direction: SortDirection.NONE, field: "email"},
78 filters: createTree(),
79 render: uuid => <ResourceEmail uuid={uuid} />
82 name: UserPanelColumnNames.STATUS,
85 filters: createTree(),
86 render: uuid => <UserResourceAccountStatus uuid={uuid} />
89 name: UserPanelColumnNames.ADMIN,
92 filters: createTree(),
93 render: uuid => <ResourceIsAdmin uuid={uuid} />
96 name: UserPanelColumnNames.USERNAME,
99 sort: {direction: SortDirection.NONE, field: "username"},
100 filters: createTree(),
101 render: uuid => <ResourceUsername uuid={uuid} />
105 interface UserPanelDataProps {
106 resources: ResourcesState;
109 interface UserPanelActionProps {
110 openUserCreateDialog: () => void;
111 handleRowClick: (uuid: string) => void;
112 handleContextMenu: (event, resource: UserResource) => void;
115 const mapStateToProps = (state: RootState) => {
117 resources: state.resources
121 const mapDispatchToProps = (dispatch: Dispatch) => ({
122 openUserCreateDialog: () => dispatch<any>(openUserCreateDialog()),
123 handleRowClick: (uuid: string) => dispatch<any>(navigateToUserProfile(uuid)),
124 handleContextMenu: (event, resource: UserResource) => dispatch<any>(openUserContextMenu(event, resource)),
127 type UserPanelProps = UserPanelDataProps & UserPanelActionProps & DispatchProp & WithStyles<UserPanelRules>;
129 export const UserPanel = compose(
131 connect(mapStateToProps, mapDispatchToProps))(
132 class extends React.Component<UserPanelProps> {
134 return <Paper className={this.props.classes.root}>
140 User records are created automatically on first log in.
143 To add a new user, add them to your configured log in provider.
147 onRowDoubleClick={noop}
148 onContextMenu={this.handleContextMenu}
149 contextMenuColumn={true}
154 defaultViewIcon={ShareMeIcon}
155 defaultViewMessages={['Your user list is empty.']}
156 forceMultiSelectMode />
160 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
161 event.stopPropagation();
162 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
164 this.props.handleContextMenu(event, resource);