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 { DataColumns } from 'components/data-table/data-table';
12 import { RootState } from 'store/store';
13 import { SortDirection } from 'components/data-table/data-column';
14 import { openUserContextMenu } from "store/context-menu/context-menu-actions";
15 import { getResource, ResourcesState } from "store/resources/resources";
22 UserResourceAccountStatus,
23 } from "views-components/data-explorer/renderers";
24 import { navigateToUserProfile } from "store/navigation/navigation-action";
25 import { createTree } from 'models/tree';
26 import { compose, Dispatch } from 'redux';
27 import { UserResource } from 'models/user';
28 import { ShareMeIcon } from 'components/icon/icon';
29 import { USERS_PANEL_ID, openUserCreateDialog } from 'store/users/users-actions';
30 import { noop } from 'lodash';
31 import { CustomStyleRulesCallback } from 'common/custom-theme';
33 type UserPanelRules = "button" | 'root';
35 const styles: CustomStyleRulesCallback<UserPanelRules> = (theme) => ({
37 marginTop: theme.spacing(1),
38 marginRight: theme.spacing(2),
47 export enum UserPanelColumnNames {
51 STATUS = "Account Status",
53 REDIRECT_TO_USER = "Redirect to user",
57 export const userPanelColumns: DataColumns<string, UserResource> = [
59 name: UserPanelColumnNames.NAME,
62 sort: {direction: SortDirection.NONE, field: "firstName"},
63 filters: createTree(),
64 render: uuid => <UserResourceFullName uuid={uuid} link={true} />
67 name: UserPanelColumnNames.UUID,
70 sort: {direction: SortDirection.NONE, field: "uuid"},
71 filters: createTree(),
72 render: uuid => <ResourceUuid uuid={uuid} />
75 name: UserPanelColumnNames.EMAIL,
78 sort: {direction: SortDirection.NONE, field: "email"},
79 filters: createTree(),
80 render: uuid => <ResourceEmail uuid={uuid} />
83 name: UserPanelColumnNames.STATUS,
86 filters: createTree(),
87 render: uuid => <UserResourceAccountStatus uuid={uuid} />
90 name: UserPanelColumnNames.ADMIN,
93 filters: createTree(),
94 render: uuid => <ResourceIsAdmin uuid={uuid} />
97 name: UserPanelColumnNames.USERNAME,
100 sort: {direction: SortDirection.NONE, field: "username"},
101 filters: createTree(),
102 render: uuid => <ResourceUsername uuid={uuid} />
106 interface UserPanelDataProps {
107 resources: ResourcesState;
110 interface UserPanelActionProps {
111 openUserCreateDialog: () => void;
112 handleRowClick: (uuid: string) => void;
113 handleContextMenu: (event, resource: UserResource) => void;
116 const mapStateToProps = (state: RootState) => {
118 resources: state.resources
122 const mapDispatchToProps = (dispatch: Dispatch) => ({
123 openUserCreateDialog: () => dispatch<any>(openUserCreateDialog()),
124 handleRowClick: (uuid: string) => dispatch<any>(navigateToUserProfile(uuid)),
125 handleContextMenu: (event, resource: UserResource) => dispatch<any>(openUserContextMenu(event, resource)),
128 type UserPanelProps = UserPanelDataProps & UserPanelActionProps & DispatchProp & WithStyles<UserPanelRules>;
130 export const UserPanel = compose(
132 connect(mapStateToProps, mapDispatchToProps))(
133 class extends React.Component<UserPanelProps> {
135 return <Paper className={this.props.classes.root}>
141 User records are created automatically on first log in.
144 To add a new user, add them to your configured log in provider.
148 onRowDoubleClick={noop}
149 onContextMenu={this.handleContextMenu}
150 contextMenuColumn={true}
155 defaultViewIcon={ShareMeIcon}
156 defaultViewMessages={['Your user list is empty.']}
157 forceMultiSelectMode />
161 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
162 event.stopPropagation();
163 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
165 this.props.handleContextMenu(event, resource);