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 } from 'components/data-table/data-table';
13 import { SortDirection } from 'components/data-table/data-column';
14 import { GroupMembersCount, ResourceUuid } from 'views-components/data-explorer/renderers';
15 import { AddIcon } from 'components/icon/icon';
16 import { ResourceName } from 'views-components/data-explorer/renderers';
17 import { createTree } from 'models/tree';
18 import { GROUPS_PANEL_ID, openCreateGroupDialog } from 'store/groups-panel/groups-panel-actions';
19 import { noop } from 'lodash/fp';
20 import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
21 import { getResource, ResourcesState } from 'store/resources/resources';
22 import { GroupResource } from 'models/group';
23 import { RootState } from 'store/store';
24 import { openContextMenu } from 'store/context-menu/context-menu-actions';
25 import { ArvadosTheme } from 'common/custom-theme';
26 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
27 import { toggleOne, deselectAllOthers } from 'store/multiselect/multiselect-actions';
29 type CssRules = "root";
31 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
37 export enum GroupsPanelColumnNames {
43 export const groupsPanelColumns: DataColumns<string, GroupResource> = [
45 name: GroupsPanelColumnNames.GROUP,
48 sort: {direction: SortDirection.ASC, field: "name"},
49 filters: createTree(),
50 render: uuid => <ResourceName uuid={uuid} />
53 name: GroupsPanelColumnNames.UUID,
56 filters: createTree(),
57 render: uuid => <ResourceUuid uuid={uuid} />,
60 name: GroupsPanelColumnNames.MEMBERS,
63 filters: createTree(),
64 render: uuid => <GroupMembersCount uuid={uuid} />,
68 const mapStateToProps = (state: RootState) => {
70 resources: state.resources
74 const mapDispatchToProps = (dispatch: any) => {
76 onContextMenu: (ev, resource) => dispatch(openContextMenu(ev, resource)),
77 onNewGroup: () => dispatch(openCreateGroupDialog()),
78 handleRowClick: (uuid: string) => {
79 dispatch(toggleOne(uuid))
80 dispatch(deselectAllOthers(uuid))
81 dispatch(loadDetailsPanel(uuid));
86 export interface GroupsPanelProps {
87 onNewGroup: () => void;
88 handleRowClick: (uuid: string) => void;
89 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
90 resources: ResourcesState;
93 export const GroupsPanel = withStyles(styles)(connect(
94 mapStateToProps, mapDispatchToProps
96 class GroupsPanel extends React.Component<GroupsPanelProps & WithStyles<CssRules>> {
100 <div className={this.props.classes.root}><DataExplorer
102 data-cy="groups-panel-data-explorer"
103 onRowClick={this.props.handleRowClick}
104 onRowDoubleClick={noop}
105 onContextMenu={this.handleContextMenu}
106 contextMenuColumn={true}
109 <Grid container justifyContent='flex-end'>
111 data-cy="groups-panel-new-group"
114 onClick={this.props.onNewGroup}>
115 <AddIcon /> New group
122 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
123 const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
125 this.props.onContextMenu(event, {
128 description: resource.description,
129 ownerUuid: resource.ownerUuid,
131 menuKind: ContextMenuKind.GROUPS