Skip to content

Commit 4dd45b5

Browse files
committed
use chips in table display
Signed-off-by: David BRAQUART <[email protected]>
1 parent b9aff28 commit 4dd45b5

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { Chip, Grid } from '@mui/material';
9+
import { mergeSx } from '@gridsuite/commons-ui';
10+
11+
const CHIP_LIMIT_NUMBER: number = 5;
12+
13+
const chipStyles = {
14+
default: {
15+
marginTop: '16px',
16+
marginLeft: '8px',
17+
maxWidth: '50%',
18+
},
19+
withCounter: {
20+
'&.MuiChip-root': {
21+
fontWeight: 'bold',
22+
},
23+
},
24+
};
25+
26+
export interface MultiChipCellRendererProps {
27+
value: string[];
28+
}
29+
30+
const MultiChipCellRenderer = (props: MultiChipCellRendererProps) => {
31+
const values: string[] = props.value || [];
32+
33+
const customChip = (label: string, index: number, chipsNumber: number) => {
34+
if (index < CHIP_LIMIT_NUMBER) {
35+
return <Chip key={label} label={label} size={'small'} sx={chipStyles.default} />;
36+
} else if (index === CHIP_LIMIT_NUMBER) {
37+
return (
38+
<Chip
39+
size="small"
40+
label={`+${chipsNumber - CHIP_LIMIT_NUMBER}`}
41+
key={label}
42+
sx={mergeSx(chipStyles.default, chipStyles.withCounter)}
43+
/>
44+
);
45+
}
46+
return undefined;
47+
};
48+
49+
return (
50+
<Grid container direction="row" spacing={1} wrap="nowrap" sx={{ overflow: 'auto hidden' }}>
51+
{values.map((label: string, index: number) => {
52+
return customChip(label, index, values.length);
53+
})}
54+
</Grid>
55+
);
56+
};
57+
58+
export default MultiChipCellRenderer;

src/pages/groups/groups-table.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { useSnackMessage } from '@gridsuite/commons-ui';
2222
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog';
2323
import { defaultColDef, defaultRowSelection } from '../common/table-config';
24+
import MultiChipCellRenderer from '../common/multi-chip-cell-renderer';
2425

2526
export interface GroupsTableProps {
2627
gridRef: RefObject<GridTableRef<GroupInfos>>;
@@ -83,6 +84,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
8384
trimInput: true,
8485
} as TextFilterParams<GroupInfos>,
8586
initialSort: 'asc',
87+
tooltipField: 'name',
8688
},
8789
{
8890
field: 'users',
@@ -99,6 +101,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
99101
caseSensitive: false,
100102
trimInput: true,
101103
} as TextFilterParams<UserInfos>,
104+
cellRenderer: MultiChipCellRenderer,
102105
tooltipValueGetter: (p: ITooltipParams) => {
103106
const items = p.value as string[];
104107
if (items == null || items.length === 0) {

src/pages/users/users-table.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { useSnackMessage } from '@gridsuite/commons-ui';
2323
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog';
2424
import { defaultColDef, defaultRowSelection } from '../common/table-config';
25+
import MultiChipCellRenderer from 'pages/common/multi-chip-cell-renderer';
2526

2627
export interface UsersTableProps {
2728
gridRef: RefObject<GridTableRef<UserInfos>>;
@@ -66,7 +67,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
6667
{
6768
field: 'sub',
6869
cellDataType: 'text',
69-
flex: 2,
70+
flex: 1,
7071
lockVisible: true,
7172
filter: true,
7273
headerName: intl.formatMessage({ id: 'users.table.id' }),
@@ -78,6 +79,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
7879
trimInput: true,
7980
} as TextFilterParams<UserInfos>,
8081
initialSort: 'asc',
82+
tooltipField: 'sub',
8183
},
8284
{
8385
field: 'profileName',
@@ -94,11 +96,12 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
9496
caseSensitive: false,
9597
trimInput: true,
9698
} as TextFilterParams<UserInfos>,
99+
tooltipField: 'profileName',
97100
},
98101
{
99102
field: 'groups',
100103
cellDataType: 'text',
101-
flex: 3,
104+
flex: 4,
102105
filter: true,
103106
headerName: intl.formatMessage({
104107
id: 'users.table.groups',
@@ -110,6 +113,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
110113
caseSensitive: false,
111114
trimInput: true,
112115
} as TextFilterParams<GroupInfos>,
116+
cellRenderer: MultiChipCellRenderer,
113117
tooltipValueGetter: (p: ITooltipParams) => {
114118
const items = p.value as string[];
115119
if (items == null || items.length === 0) {

0 commit comments

Comments
 (0)