1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect } from 'react-redux';
8 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
9 import { DataColumns } from '~/components/data-table/data-table';
10 import { ResourceUuid, ResourceFirstName, ResourceLastName, ResourceEmail, ResourceUsername } from '~/views-components/data-explorer/renderers';
11 import { createTree } from '~/models/tree';
12 import { noop } from 'lodash/fp';
13 import { RootState } from '~/store/store';
14 import { GROUP_DETAILS_PANEL_ID, openAddGroupMembersDialog } from '~/store/group-details-panel/group-details-panel-actions';
15 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
16 import { ResourcesState, getResource } from '~/store/resources/resources';
17 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
18 import { PermissionResource } from '~/models/permission';
19 import { Grid, Button } from '@material-ui/core';
20 import { AddIcon } from '~/components/icon/icon';
22 export enum GroupDetailsPanelColumnNames {
23 FIRST_NAME = "First name",
24 LAST_NAME = "Last name",
27 USERNAME = "Username",
30 export const groupDetailsPanelColumns: DataColumns<string> = [
32 name: GroupDetailsPanelColumnNames.FIRST_NAME,
35 filters: createTree(),
36 render: uuid => <ResourceFirstName uuid={uuid} />
39 name: GroupDetailsPanelColumnNames.LAST_NAME,
42 filters: createTree(),
43 render: uuid => <ResourceLastName uuid={uuid} />
46 name: GroupDetailsPanelColumnNames.UUID,
49 filters: createTree(),
50 render: uuid => <ResourceUuid uuid={uuid} />
53 name: GroupDetailsPanelColumnNames.EMAIL,
56 filters: createTree(),
57 render: uuid => <ResourceEmail uuid={uuid} />
60 name: GroupDetailsPanelColumnNames.USERNAME,
63 filters: createTree(),
64 render: uuid => <ResourceUsername uuid={uuid} />
68 const mapStateToProps = (state: RootState) => {
70 resources: state.resources
74 const mapDispatchToProps = {
75 onContextMenu: openContextMenu,
76 onAddUser: openAddGroupMembersDialog,
79 export interface GroupDetailsPanelProps {
80 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
81 onAddUser: () => void;
82 resources: ResourcesState;
85 export const GroupDetailsPanel = connect(
86 mapStateToProps, mapDispatchToProps
88 class GroupDetailsPanel extends React.Component<GroupDetailsPanelProps> {
93 id={GROUP_DETAILS_PANEL_ID}
95 onRowDoubleClick={noop}
96 onContextMenu={this.handleContextMenu}
97 contextMenuColumn={true}
101 <Grid container justify='flex-end'>
105 onClick={this.props.onAddUser}>
113 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
114 const resource = getResource<PermissionResource>(resourceUuid)(this.props.resources);
116 this.props.onContextMenu(event, {
119 ownerUuid: resource.ownerUuid,
121 menuKind: ContextMenuKind.GROUP_MEMBER