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, Tabs, Tab, Paper, Button, Grid } 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';
31 import { noop } from 'lodash';
33 type UserPanelRules = "button";
35 const styles = withStyles<UserPanelRules>(theme => ({
37 marginTop: theme.spacing.unit,
38 marginRight: theme.spacing.unit * 2,
44 export enum UserPanelColumnNames {
45 FIRST_NAME = "First Name",
46 LAST_NAME = "Last Name",
51 REDIRECT_TO_USER = "Redirect to user",
55 export const userPanelColumns: DataColumns<string> = [
57 name: UserPanelColumnNames.FIRST_NAME,
60 sortDirection: SortDirection.NONE,
61 filters: createTree(),
62 render: uuid => <ResourceFirstName uuid={uuid} />
65 name: UserPanelColumnNames.LAST_NAME,
68 sortDirection: SortDirection.NONE,
69 filters: createTree(),
70 render: uuid => <ResourceLastName uuid={uuid} />
73 name: UserPanelColumnNames.UUID,
76 sortDirection: SortDirection.NONE,
77 filters: createTree(),
78 render: uuid => <ResourceUuid uuid={uuid} />
81 name: UserPanelColumnNames.EMAIL,
84 sortDirection: SortDirection.NONE,
85 filters: createTree(),
86 render: uuid => <ResourceEmail uuid={uuid} />
89 name: UserPanelColumnNames.ACTIVE,
92 sortDirection: SortDirection.NONE,
93 filters: createTree(),
94 render: uuid => <ResourceIsActive uuid={uuid} />
97 name: UserPanelColumnNames.ADMIN,
100 sortDirection: SortDirection.NONE,
101 filters: createTree(),
102 render: uuid => <ResourceIsAdmin uuid={uuid} />
105 name: UserPanelColumnNames.USERNAME,
108 sortDirection: SortDirection.NONE,
109 filters: createTree(),
110 render: uuid => <ResourceUsername uuid={uuid} />
114 interface UserPanelDataProps {
115 resources: ResourcesState;
118 interface UserPanelActionProps {
119 openUserCreateDialog: () => void;
120 handleRowDoubleClick: (uuid: string) => void;
121 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
124 const mapStateToProps = (state: RootState) => {
126 resources: state.resources
130 const mapDispatchToProps = (dispatch: Dispatch) => ({
131 openUserCreateDialog: () => dispatch<any>(openUserCreateDialog()),
132 handleRowDoubleClick: (uuid: string) => dispatch<any>(navigateTo(uuid)),
133 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => dispatch<any>(openContextMenu(event, item))
136 type UserPanelProps = UserPanelDataProps & UserPanelActionProps & DispatchProp & WithStyles<UserPanelRules>;
138 export const UserPanel = compose(
140 connect(mapStateToProps, mapDispatchToProps))(
141 class extends React.Component<UserPanelProps> {
146 componentDidMount() {
147 this.setState({ value: 0 });
151 const { value } = this.state;
153 <Tabs value={value} onChange={this.handleChange} fullWidth>
154 <Tab label="USERS" />
155 <Tab label="ACTIVITY" disabled />
162 onRowDoubleClick={noop}
163 onContextMenu={this.handleContextMenu}
164 contextMenuColumn={true}
167 <Grid container justify='flex-end'>
168 <Button variant="contained" color="primary" onClick={this.props.openUserCreateDialog}>
176 dataTableDefaultView={
177 <DataTableDefaultView
179 messages={['Your user list is empty.']} />
185 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
186 this.setState({ value });
189 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
190 const resource = getResource<UserResource>(resourceUuid)(this.props.resources);
192 this.props.onContextMenu(event, {
195 ownerUuid: resource.ownerUuid,
197 menuKind: ContextMenuKind.USER