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';
8 import { DataExplorer } from "views-components/data-explorer/data-explorer";
9 import { DataColumns } from 'components/data-table/data-table';
10 import { ResourceLinkHeadUuid, ResourceLinkTailUsername, ResourceLinkHeadPermissionLevel, ResourceLinkTailPermissionLevel, ResourceLinkHead, ResourceLinkTail, ResourceLinkDelete, ResourceLinkTailAccountStatus, ResourceLinkTailIsVisible } 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_MEMBERS_PANEL_ID, GROUP_DETAILS_PERMISSIONS_PANEL_ID, openAddGroupMembersDialog, getCurrentGroupDetailsPanelUuid } 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 { Grid, Button, Tabs, Tab, Paper, WithStyles, withStyles, StyleRulesCallback } from '@material-ui/core';
18 import { AddIcon, UserPanelIcon, KeyIcon } from 'components/icon/icon';
19 import { getUserUuid } from 'common/getuser';
20 import { GroupResource, isBuiltinGroup } from 'models/group';
21 import { ArvadosTheme } from 'common/custom-theme';
23 type CssRules = "root" | "content";
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30 // reserve space for the tab bar
31 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
35 export enum GroupDetailsPanelMembersColumnNames {
37 USERNAME = "Username",
38 STATUS = "Account Status",
39 VISIBLE = "Visible to other members",
40 PERMISSION = "Permission",
44 export enum GroupDetailsPanelPermissionsColumnNames {
46 PERMISSION = "Permission",
51 const MEMBERS_DEFAULT_MESSAGE = 'Members list is empty.';
52 const PERMISSIONS_DEFAULT_MESSAGE = 'Permissions list is empty.';
54 export const groupDetailsMembersPanelColumns: DataColumns<string> = [
56 name: GroupDetailsPanelMembersColumnNames.FULL_NAME,
59 filters: createTree(),
60 render: uuid => <ResourceLinkTail uuid={uuid} />
63 name: GroupDetailsPanelMembersColumnNames.USERNAME,
66 filters: createTree(),
67 render: uuid => <ResourceLinkTailUsername uuid={uuid} />
70 name: GroupDetailsPanelMembersColumnNames.STATUS,
73 filters: createTree(),
74 render: uuid => <ResourceLinkTailAccountStatus uuid={uuid} />
77 name: GroupDetailsPanelMembersColumnNames.VISIBLE,
80 filters: createTree(),
81 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
84 name: GroupDetailsPanelMembersColumnNames.PERMISSION,
87 filters: createTree(),
88 render: uuid => <ResourceLinkTailPermissionLevel uuid={uuid} />
91 name: GroupDetailsPanelMembersColumnNames.REMOVE,
94 filters: createTree(),
95 render: uuid => <ResourceLinkDelete uuid={uuid} />
99 export const groupDetailsPermissionsPanelColumns: DataColumns<string> = [
101 name: GroupDetailsPanelPermissionsColumnNames.NAME,
104 filters: createTree(),
105 render: uuid => <ResourceLinkHead uuid={uuid} />
108 name: GroupDetailsPanelPermissionsColumnNames.PERMISSION,
111 filters: createTree(),
112 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
115 name: GroupDetailsPanelPermissionsColumnNames.UUID,
118 filters: createTree(),
119 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
122 name: GroupDetailsPanelPermissionsColumnNames.REMOVE,
125 filters: createTree(),
126 render: uuid => <ResourceLinkDelete uuid={uuid} />
130 const mapStateToProps = (state: RootState) => {
131 const groupUuid = getCurrentGroupDetailsPanelUuid(state.properties);
132 const group = getResource<GroupResource>(groupUuid || '')(state.resources);
133 const userUuid = getUserUuid(state);
136 resources: state.resources,
137 groupCanManage: userUuid && !isBuiltinGroup(group?.uuid || '')
138 ? group?.writableBy?.includes(userUuid)
143 const mapDispatchToProps = {
144 onContextMenu: openContextMenu,
145 onAddUser: openAddGroupMembersDialog,
148 export interface GroupDetailsPanelProps {
149 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
150 onAddUser: () => void;
151 resources: ResourcesState;
152 groupCanManage: boolean;
155 export const GroupDetailsPanel = withStyles(styles)(connect(
156 mapStateToProps, mapDispatchToProps
158 class GroupDetailsPanel extends React.Component<GroupDetailsPanelProps & WithStyles<CssRules>> {
163 componentDidMount() {
164 this.setState({ value: 0 });
168 const { value } = this.state;
170 <Paper className={this.props.classes.root}>
171 <Tabs value={value} onChange={this.handleChange} variant="fullWidth">
172 <Tab data-cy="group-details-members-tab" label="MEMBERS" />
173 <Tab data-cy="group-details-permissions-tab" label="PERMISSIONS" />
175 <div className={this.props.classes.content}>
178 id={GROUP_DETAILS_MEMBERS_PANEL_ID}
179 data-cy="group-members-data-explorer"
181 onRowDoubleClick={noop}
183 contextMenuColumn={false}
184 defaultViewIcon={UserPanelIcon}
185 defaultViewMessages={[MEMBERS_DEFAULT_MESSAGE]}
189 this.props.groupCanManage &&
190 <Grid container justify='flex-end'>
192 data-cy="group-member-add"
195 onClick={this.props.onAddUser}>
206 id={GROUP_DETAILS_PERMISSIONS_PANEL_ID}
207 data-cy="group-permissions-data-explorer"
209 onRowDoubleClick={noop}
211 contextMenuColumn={false}
212 defaultViewIcon={KeyIcon}
213 defaultViewMessages={[PERMISSIONS_DEFAULT_MESSAGE]}
225 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
226 this.setState({ value });