1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { WithStyles, withStyles, Paper, Typography } from '@material-ui/core';
7 import { DataExplorer } from "views-components/data-explorer/data-explorer";
8 import { connect, DispatchProp } from 'react-redux';
9 import { DataColumns } from 'components/data-table/data-table';
10 import { RootState } from 'store/store';
11 import { SortDirection } from 'components/data-table/data-column';
12 import { openUserContextMenu } from "store/context-menu/context-menu-actions";
13 import { getResource, ResourcesState } from "store/resources/resources";
20 UserResourceAccountStatus,
21 } from "views-components/data-explorer/renderers";
22 import { navigateToUserProfile } from "store/navigation/navigation-action";
23 import { createTree } from 'models/tree';
24 import { compose, Dispatch } from 'redux';
25 import { UserResource } from 'models/user';
26 import { ShareMeIcon } from 'components/icon/icon';
27 import { USERS_PANEL_ID, openUserCreateDialog } from 'store/users/users-actions';
28 import { noop } from 'lodash';
30 type UserPanelRules = "button" | 'root';
32 const styles = withStyles<UserPanelRules>(theme => ({
34 marginTop: theme.spacing.unit,
35 marginRight: theme.spacing.unit * 2,
44 export enum UserPanelColumnNames {
48 STATUS = "Account Status",
50 REDIRECT_TO_USER = "Redirect to user",
54 export const userPanelColumns: DataColumns<string> = [
56 name: UserPanelColumnNames.NAME,
59 sortDirection: SortDirection.NONE,
60 filters: createTree(),
61 render: uuid => <UserResourceFullName uuid={uuid} link={true} />
64 name: UserPanelColumnNames.UUID,
67 sortDirection: SortDirection.NONE,
68 filters: createTree(),
69 render: uuid => <ResourceUuid uuid={uuid} />
72 name: UserPanelColumnNames.EMAIL,
75 sortDirection: SortDirection.NONE,
76 filters: createTree(),
77 render: uuid => <ResourceEmail uuid={uuid} />
80 name: UserPanelColumnNames.STATUS,
83 filters: createTree(),
84 render: uuid => <UserResourceAccountStatus uuid={uuid} />
87 name: UserPanelColumnNames.ADMIN,
90 filters: createTree(),
91 render: uuid => <ResourceIsAdmin uuid={uuid} />
94 name: UserPanelColumnNames.USERNAME,
97 sortDirection: SortDirection.NONE,
98 filters: createTree(),
99 render: uuid => <ResourceUsername uuid={uuid} />
103 interface UserPanelDataProps {
104 resources: ResourcesState;
107 interface UserPanelActionProps {
108 openUserCreateDialog: () => void;
109 handleRowClick: (uuid: string) => void;
110 handleContextMenu: (event, resource: UserResource) => void;
113 const mapStateToProps = (state: RootState) => {
115 resources: state.resources
119 const mapDispatchToProps = (dispatch: Dispatch) => ({
120 openUserCreateDialog: () => dispatch<any>(openUserCreateDialog()),
121 handleRowClick: (uuid: string) => dispatch<any>(navigateToUserProfile(uuid)),
122 handleContextMenu: (event, resource: UserResource) => dispatch<any>(openUserContextMenu(event, resource)),
125 type UserPanelProps = UserPanelDataProps & UserPanelActionProps & DispatchProp & WithStyles<UserPanelRules>;
127 export const UserPanel = compose(
129 connect(mapStateToProps, mapDispatchToProps))(
130 class extends React.Component<UserPanelProps> {
132 return <Paper className={this.props.classes.root}>
138 User records are created automatically on first log in.
141 To add a new user, add them to your configured log in provider.
145 onRowDoubleClick={noop}
146 onContextMenu={this.handleContextMenu}
147 contextMenuColumn={true}
152 defaultViewIcon={ShareMeIcon}
153 defaultViewMessages={['Your user list is empty.']} />
157 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
158 event.stopPropagation();
159 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
161 this.props.handleContextMenu(event, resource);