1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { CustomStyleRulesCallback } from 'common/custom-theme';
8 import { Grid, Button } from "@mui/material";
9 import { WithStyles } from '@mui/styles';
10 import withStyles from '@mui/styles/withStyles';
11 import { DataExplorer } from "views-components/data-explorer/data-explorer";
12 import { DataColumns, SortDirection } from 'components/data-table/data-column';
13 import { GroupMembersCount, ResourceUuid } from 'views-components/data-explorer/renderers';
14 import { AddIcon } from 'components/icon/icon';
15 import { ResourceName } from 'views-components/data-explorer/renderers';
16 import { createTree } from 'models/tree';
17 import { GROUPS_PANEL_ID, openCreateGroupDialog } from 'store/groups-panel/groups-panel-actions';
18 import { noop } from 'lodash/fp';
19 import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
20 import { getResource, ResourcesState } from 'store/resources/resources';
21 import { GroupResource } from 'models/group';
22 import { RootState } from 'store/store';
23 import { openContextMenu } from 'store/context-menu/context-menu-actions';
24 import { ArvadosTheme } from 'common/custom-theme';
25 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
26 import { toggleOne, deselectAllOthers } from 'store/multiselect/multiselect-actions';
28 type CssRules = "root";
30 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
36 export enum GroupsPanelColumnNames {
42 export const groupsPanelColumns: DataColumns<string, GroupResource> = [
44 name: GroupsPanelColumnNames.GROUP,
47 sort: {direction: SortDirection.ASC, field: "name"},
48 filters: createTree(),
49 render: uuid => <ResourceName uuid={uuid} />
52 name: GroupsPanelColumnNames.UUID,
55 filters: createTree(),
56 render: uuid => <ResourceUuid uuid={uuid} />,
59 name: GroupsPanelColumnNames.MEMBERS,
62 filters: createTree(),
63 render: uuid => <GroupMembersCount uuid={uuid} />,
67 const mapStateToProps = (state: RootState) => {
69 resources: state.resources
73 const mapDispatchToProps = (dispatch: any) => {
75 onContextMenu: (ev, resource) => dispatch(openContextMenu(ev, resource)),
76 onNewGroup: () => dispatch(openCreateGroupDialog()),
77 handleRowClick: (uuid: string) => {
78 dispatch(toggleOne(uuid))
79 dispatch(deselectAllOthers(uuid))
80 dispatch(loadDetailsPanel(uuid));
85 export interface GroupsPanelProps {
86 onNewGroup: () => void;
87 handleRowClick: (uuid: string) => void;
88 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
89 resources: ResourcesState;
92 export const GroupsPanel = withStyles(styles)(connect(
93 mapStateToProps, mapDispatchToProps
95 class GroupsPanel extends React.Component<GroupsPanelProps & WithStyles<CssRules>> {
99 <div className={this.props.classes.root}><DataExplorer
101 data-cy="groups-panel-data-explorer"
102 onRowClick={this.props.handleRowClick}
103 onRowDoubleClick={noop}
104 onContextMenu={this.handleContextMenu}
105 contextMenuColumn={true}
108 <Grid container justifyContent='flex-end'>
110 data-cy="groups-panel-new-group"
113 onClick={this.props.onNewGroup}>
114 <AddIcon /> New group
121 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
122 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
124 this.props.onContextMenu(event, {
127 description: resource.description,
128 ownerUuid: resource.ownerUuid,
130 menuKind: ContextMenuKind.GROUPS