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';
7 import { Grid, Button, Typography } from "@material-ui/core";
8 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
9 import { DataColumns } from '~/components/data-table/data-table';
10 import { SortDirection } from '~/components/data-table/data-column';
11 import { ResourceOwner } from '~/views-components/data-explorer/renderers';
12 import { AddIcon } from '~/components/icon/icon';
13 import { ResourceName } from '~/views-components/data-explorer/renderers';
14 import { createTree } from '~/models/tree';
15 import { GROUPS_PANEL_ID, openCreateGroupDialog } from '~/store/groups-panel/groups-panel-actions';
16 import { noop } from 'lodash/fp';
17 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
18 import { getResource, ResourcesState, filterResources } from '~/store/resources/resources';
19 import { GroupResource } from '~/models/group';
20 import { RootState } from '~/store/store';
21 import { openContextMenu } from '~/store/context-menu/context-menu-actions';
22 import { ResourceKind } from '~/models/resource';
23 import { LinkClass, LinkResource } from '~/models/link';
24 import { navigateToGroupDetails } from '~/store/navigation/navigation-action';
26 export enum GroupsPanelColumnNames {
32 export const groupsPanelColumns: DataColumns<string> = [
34 name: GroupsPanelColumnNames.GROUP,
37 sortDirection: SortDirection.ASC,
38 filters: createTree(),
39 render: uuid => <ResourceName uuid={uuid} />
42 name: GroupsPanelColumnNames.OWNER,
45 filters: createTree(),
46 render: uuid => <ResourceOwner uuid={uuid} />,
49 name: GroupsPanelColumnNames.MEMBERS,
52 filters: createTree(),
53 render: uuid => <GroupMembersCount uuid={uuid} />,
57 const mapStateToProps = (state: RootState) => {
59 resources: state.resources
63 const mapDispatchToProps = {
64 onContextMenu: openContextMenu,
65 onRowDoubleClick: (uuid: string) =>
66 navigateToGroupDetails(uuid),
67 onNewGroup: openCreateGroupDialog,
70 export interface GroupsPanelProps {
71 onNewGroup: () => void;
72 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
73 onRowDoubleClick: (item: string) => void;
74 resources: ResourcesState;
77 export const GroupsPanel = connect(
78 mapStateToProps, mapDispatchToProps
80 class GroupsPanel extends React.Component<GroupsPanelProps> {
87 onRowDoubleClick={this.props.onRowDoubleClick}
88 onContextMenu={this.handleContextMenu}
89 contextMenuColumn={true}
92 <Grid container justify='flex-end'>
96 onClick={this.props.onNewGroup}>
104 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
105 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
107 this.props.onContextMenu(event, {
110 ownerUuid: resource.ownerUuid,
112 menuKind: ContextMenuKind.GROUPS
119 const GroupMembersCount = connect(
120 (state: RootState, props: { uuid: string }) => {
122 const permissions = filterResources((resource: LinkResource) =>
123 resource.kind === ResourceKind.LINK &&
124 resource.linkClass === LinkClass.PERMISSION &&
125 resource.tailUuid === props.uuid
129 children: permissions.length,