1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { WithStyles, withStyles, Typography, Tabs, Tab, Paper, Button } 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 { openContextMenu } from "~/store/context-menu/context-menu-actions";
13 import { getResource, ResourcesState } from "~/store/resources/resources";
22 } from "~/views-components/data-explorer/renderers";
23 import { navigateTo } from "~/store/navigation/navigation-action";
24 import { ContextMenuKind } from "~/views-components/context-menu/context-menu";
25 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
26 import { createTree } from '~/models/tree';
27 import { compose, Dispatch } from 'redux';
28 import { UserResource } from '~/models/user';
29 import { ShareMeIcon, AddIcon } from '~/components/icon/icon';
30 import { USERS_PANEL_ID, openUserCreateDialog } from '~/store/users/users-actions';
32 type UserPanelRules = "button";
34 const styles = withStyles<UserPanelRules>(theme => ({
36 marginTop: theme.spacing.unit,
37 marginRight: theme.spacing.unit * 2,
43 export enum UserPanelColumnNames {
44 FIRST_NAME = "First Name",
45 LAST_NAME = "Last Name",
50 REDIRECT_TO_USER = "Redirect to user",
54 export const userPanelColumns: DataColumns<string> = [
56 name: UserPanelColumnNames.FIRST_NAME,
59 sortDirection: SortDirection.NONE,
60 filters: createTree(),
61 render: uuid => <ResourceFirstName uuid={uuid} />
64 name: UserPanelColumnNames.LAST_NAME,
67 sortDirection: SortDirection.NONE,
68 filters: createTree(),
69 render: uuid => <ResourceLastName uuid={uuid} />
72 name: UserPanelColumnNames.UUID,
75 sortDirection: SortDirection.NONE,
76 filters: createTree(),
77 render: uuid => <ResourceUuid uuid={uuid} />
80 name: UserPanelColumnNames.EMAIL,
83 sortDirection: SortDirection.NONE,
84 filters: createTree(),
85 render: uuid => <ResourceEmail uuid={uuid} />
88 name: UserPanelColumnNames.ACTIVE,
91 sortDirection: SortDirection.NONE,
92 filters: createTree(),
93 render: uuid => <ResourceIsActive uuid={uuid} />
96 name: UserPanelColumnNames.ADMIN,
99 sortDirection: SortDirection.NONE,
100 filters: createTree(),
101 render: uuid => <ResourceIsAdmin uuid={uuid} />
104 name: UserPanelColumnNames.REDIRECT_TO_USER,
107 sortDirection: SortDirection.NONE,
108 filters: createTree(),
109 render: () => <Typography noWrap>(none)</Typography>
112 name: UserPanelColumnNames.USERNAME,
115 sortDirection: SortDirection.NONE,
116 filters: createTree(),
117 render: uuid => <ResourceUsername uuid={uuid} />
121 interface UserPanelDataProps {
122 resources: ResourcesState;
125 interface UserPanelActionProps {
126 openUserCreateDialog: () => void;
127 handleRowDoubleClick: (uuid: string) => void;
128 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
131 const mapStateToProps = (state: RootState) => {
133 resources: state.resources
137 const mapDispatchToProps = (dispatch: Dispatch) => ({
138 openUserCreateDialog: () => dispatch<any>(openUserCreateDialog()),
139 handleRowDoubleClick: (uuid: string) => dispatch<any>(navigateTo(uuid)),
140 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => dispatch<any>(openContextMenu(event, item))
143 type UserPanelProps = UserPanelDataProps & UserPanelActionProps & DispatchProp & WithStyles<UserPanelRules>;
145 export const UserPanel = compose(
147 connect(mapStateToProps, mapDispatchToProps))(
148 class extends React.Component<UserPanelProps> {
153 componentDidMount() {
154 this.setState({ value: 0 });
158 const { value } = this.state;
160 <Tabs value={value} onChange={this.handleChange} fullWidth>
161 <Tab label="USERS" />
162 <Tab label="ACTIVITY" disabled />
166 <div className={this.props.classes.button}>
167 <Button variant="contained" color="primary" onClick={this.props.openUserCreateDialog}>
173 onRowClick={this.handleRowClick}
174 onRowDoubleClick={this.handleRowDoubleClick}
175 onContextMenu={this.handleContextMenu}
176 contextMenuColumn={true}
178 dataTableDefaultView={
179 <DataTableDefaultView
181 messages={['Your user list is empty.']} />
187 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
188 this.setState({ value });
191 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
192 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
194 this.props.onContextMenu(event, {
197 ownerUuid: resource.ownerUuid,
199 menuKind: ContextMenuKind.USER
204 handleRowDoubleClick = (uuid: string) => {
205 this.props.handleRowDoubleClick(uuid);
208 handleRowClick = () => {