Skip to content

Commit 4880091

Browse files
committed
display users and groups as text
Signed-off-by: David BRAQUART <[email protected]>
1 parent 8e9b404 commit 4880091

File tree

7 files changed

+74
-169
lines changed

7 files changed

+74
-169
lines changed

src/pages/common/multi-chips-renderer-component.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/pages/common/multi-select-editor-component.tsx

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/pages/common/table-selection.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const TableSelection: FunctionComponent<TableSelectionProps> = (props) => {
4646
filter: true,
4747
sortable: true,
4848
minWidth: 80,
49+
tooltipField: 'id',
4950
},
5051
],
5152
[]

src/pages/groups/groups-table.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ import { useIntl } from 'react-intl';
1010
import { GroupAdd } from '@mui/icons-material';
1111
import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid';
1212
import { GroupInfos, UserAdminSrv, UserInfos } from '../../services';
13-
import { ColDef, GetRowIdParams, RowClickedEvent, SelectionChangedEvent, TextFilterParams } from 'ag-grid-community';
13+
import {
14+
ColDef,
15+
GetRowIdParams,
16+
ITooltipParams,
17+
RowClickedEvent,
18+
SelectionChangedEvent,
19+
TextFilterParams
20+
} from 'ag-grid-community';
1421
import { useSnackMessage } from '@gridsuite/commons-ui';
1522
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog';
1623
import { defaultColDef, defaultRowSelection } from '../common/table-config';
17-
import MultiChipsRendererComponent from '../common/multi-chips-renderer-component';
1824

1925
export interface GroupsTableProps {
2026
gridRef: RefObject<GridTableRef<GroupInfos>>;
@@ -65,7 +71,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
6571
{
6672
field: 'name',
6773
cellDataType: 'text',
68-
flex: 3,
74+
flex: 2,
6975
lockVisible: true,
7076
filter: true,
7177
headerName: intl.formatMessage({ id: 'groups.table.id' }),
@@ -81,7 +87,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
8187
{
8288
field: 'users',
8389
cellDataType: 'text',
84-
flex: 1,
90+
flex: 3,
8591
filter: true,
8692
headerName: intl.formatMessage({
8793
id: 'groups.table.users',
@@ -93,7 +99,19 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
9399
caseSensitive: false,
94100
trimInput: true,
95101
} as TextFilterParams<UserInfos>,
96-
cellRenderer: MultiChipsRendererComponent,
102+
tooltipValueGetter: (p: ITooltipParams) => {
103+
const items = p.value as string[];
104+
if (items == null || items.length === 0) {
105+
return '';
106+
}
107+
let userWord = intl.formatMessage({
108+
id: 'form.delete.dialog.user',
109+
});
110+
if (items.length > 1) {
111+
userWord = userWord.concat('s');
112+
}
113+
return `${items.length} ${userWord}`;
114+
},
97115
},
98116
],
99117
[intl]
@@ -106,6 +124,7 @@ const GroupsTable: FunctionComponent<GroupsTableProps> = (props) => {
106124
dataLoader={UserAdminSrv.fetchGroups}
107125
columnDefs={columns}
108126
defaultColDef={defaultColDef}
127+
tooltipShowDelay={1000}
109128
gridId="table-groups"
110129
getRowId={getRowId}
111130
rowSelection={defaultRowSelection}

src/pages/profiles/profiles-page.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ const ProfilesPage: FunctionComponent = () => {
4343
return (
4444
<Grid item container direction="column" spacing={2} component="section">
4545
<Grid item container xs sx={{ width: 1 }}>
46-
<ProfileModificationDialog
47-
profileId={editingProfileId}
48-
open={openProfileModificationDialog}
49-
onClose={handleCloseProfileModificationDialog}
50-
onUpdate={handleUpdateProfileModificationDialog}
51-
/>
5246
<ProfilesTable
5347
gridRef={gridRef}
5448
onRowClicked={onRowClicked}
5549
setOpenAddProfileDialog={setOpenAddProfileDialog}
5650
/>
5751
<AddProfileDialog gridRef={gridRef} open={openAddProfileDialog} setOpen={setOpenAddProfileDialog} />
52+
<ProfileModificationDialog
53+
profileId={editingProfileId}
54+
open={openProfileModificationDialog}
55+
onClose={handleCloseProfileModificationDialog}
56+
onUpdate={handleUpdateProfileModificationDialog}
57+
/>
5858
</Grid>
5959
</Grid>
6060
);

src/pages/profiles/profiles-table.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
7575
caseSensitive: false,
7676
trimInput: true,
7777
} as TextFilterParams<UserProfile>,
78-
editable: false,
7978
},
8079
{
8180
field: 'allLinksValid',
@@ -85,13 +84,13 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
8584
alignItems: 'center',
8685
}),
8786
cellRenderer: (params: any) => {
88-
return params.value == null ? (
89-
<RadioButtonUnchecked fontSize="small" />
90-
) : params.value ? (
91-
<CheckCircle fontSize="small" color="success" />
92-
) : (
93-
<Cancel fontSize="small" color="error" />
94-
);
87+
if (params.value == null) {
88+
return <RadioButtonUnchecked fontSize="small" />;
89+
} else if (params.value) {
90+
return <CheckCircle fontSize="small" color="success" />;
91+
} else {
92+
return <Cancel fontSize="small" color="error" />;
93+
}
9594
},
9695
flex: 1,
9796
headerName: intl.formatMessage({

src/pages/users/users-table.tsx

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { FunctionComponent, RefObject, useCallback, useEffect, useMemo, useState } from 'react';
8+
import { FunctionComponent, RefObject, useCallback, useMemo, useState } from 'react';
99
import { useIntl } from 'react-intl';
1010
import { PersonAdd } from '@mui/icons-material';
1111
import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid';
12-
import { GroupInfos, UpdateUserInfos, UserAdminSrv, UserInfos } from '../../services';
12+
import { GroupInfos, UserAdminSrv, UserInfos } from '../../services';
1313
import {
1414
ColDef,
1515
GetRowIdParams,
16-
ICellEditorParams,
1716
ICheckboxCellRendererParams,
17+
ITooltipParams,
1818
RowClickedEvent,
1919
SelectionChangedEvent,
2020
TextFilterParams,
2121
} from 'ag-grid-community';
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 MultiChipsRendererComponent from '../common/multi-chips-renderer-component';
26-
import MultiSelectEditorComponent from '../common/multi-select-editor-component';
2725

2826
export interface UsersTableProps {
2927
gridRef: RefObject<GridTableRef<UserInfos>>;
@@ -37,23 +35,6 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
3735

3836
const [rowsSelection, setRowsSelection] = useState<UserInfos[]>([]);
3937
const [showDeletionDialog, setShowDeletionDialog] = useState(false);
40-
const [groupsOptions, setGroupsOptions] = useState<string[]>([]);
41-
42-
useEffect(() => {
43-
// fetch available groups
44-
UserAdminSrv.fetchGroups()
45-
.then((allGroups: GroupInfos[]) => {
46-
let groups: string[] = [];
47-
allGroups?.forEach((g) => groups.push(g.name));
48-
setGroupsOptions(groups);
49-
})
50-
.catch((error) =>
51-
snackError({
52-
messageTxt: error.message,
53-
headerId: 'users.table.error.groups',
54-
})
55-
);
56-
}, [intl, snackError]);
5738

5839
function getRowId(params: GetRowIdParams<UserInfos>): string {
5940
return params.data.sub ?? '';
@@ -80,32 +61,12 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
8061

8162
const deleteUsersDisabled = useMemo(() => rowsSelection.length <= 0, [rowsSelection.length]);
8263

83-
const updateUserCallback = useCallback(
84-
(sub: string, profileName: string | undefined, isAdmin: boolean | undefined, groups: string[]) => {
85-
const newData: UpdateUserInfos = {
86-
sub: sub,
87-
profileName: profileName,
88-
isAdmin: isAdmin,
89-
groups: groups,
90-
};
91-
UserAdminSrv.udpateUser(newData)
92-
.catch((error) =>
93-
snackError({
94-
messageTxt: error.message,
95-
headerId: 'users.table.error.update',
96-
})
97-
)
98-
.then(() => props.gridRef?.current?.context?.refresh?.());
99-
},
100-
[props.gridRef, snackError]
101-
);
102-
10364
const columns = useMemo(
10465
(): ColDef<UserInfos>[] => [
10566
{
10667
field: 'sub',
10768
cellDataType: 'text',
108-
flex: 3,
69+
flex: 2,
10970
lockVisible: true,
11071
filter: true,
11172
headerName: intl.formatMessage({ id: 'users.table.id' }),
@@ -121,7 +82,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
12182
{
12283
field: 'profileName',
12384
cellDataType: 'text',
124-
flex: 1,
85+
flex: 2,
12586
filter: true,
12687
headerName: intl.formatMessage({
12788
id: 'users.table.profileName',
@@ -134,26 +95,10 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
13495
trimInput: true,
13596
} as TextFilterParams<UserInfos>,
13697
},
137-
{
138-
field: 'isAdmin',
139-
cellDataType: 'boolean',
140-
//detected as cellRenderer: 'agCheckboxCellRenderer',
141-
cellRendererParams: {
142-
disabled: true,
143-
} as ICheckboxCellRendererParams<UserInfos, {}>,
144-
flex: 1,
145-
headerName: intl.formatMessage({
146-
id: 'users.table.isAdmin',
147-
}),
148-
headerTooltip: intl.formatMessage({
149-
id: 'users.table.isAdmin.description',
150-
}),
151-
filter: true,
152-
},
15398
{
15499
field: 'groups',
155100
cellDataType: 'text',
156-
flex: 1,
101+
flex: 3,
157102
filter: true,
158103
headerName: intl.formatMessage({
159104
id: 'users.table.groups',
@@ -165,20 +110,38 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
165110
caseSensitive: false,
166111
trimInput: true,
167112
} as TextFilterParams<GroupInfos>,
168-
editable: true,
169-
cellRenderer: MultiChipsRendererComponent,
170-
cellEditor: MultiSelectEditorComponent,
171-
cellEditorParams: (params: ICellEditorParams<UserInfos>) => ({
172-
options: groupsOptions,
173-
setValue: (values: string[]) => {
174-
if (params.data?.sub) {
175-
updateUserCallback(params.data.sub, params.data.profileName, params.data.isAdmin, values);
176-
}
177-
},
113+
tooltipValueGetter: (p: ITooltipParams) => {
114+
const items = p.value as string[];
115+
if (items == null || items.length === 0) {
116+
return '';
117+
}
118+
let groupWord = intl.formatMessage({
119+
id: 'form.delete.dialog.group',
120+
});
121+
if (items.length > 1) {
122+
groupWord = groupWord.concat('s');
123+
}
124+
return `${items.length} ${groupWord}`;
125+
},
126+
},
127+
{
128+
field: 'isAdmin',
129+
cellDataType: 'boolean',
130+
//detected as cellRenderer: 'agCheckboxCellRenderer',
131+
cellRendererParams: {
132+
disabled: true,
133+
} as ICheckboxCellRendererParams<UserInfos, {}>,
134+
flex: 1,
135+
headerName: intl.formatMessage({
136+
id: 'users.table.isAdmin',
178137
}),
138+
headerTooltip: intl.formatMessage({
139+
id: 'users.table.isAdmin.description',
140+
}),
141+
filter: true,
179142
},
180143
],
181-
[groupsOptions, intl, updateUserCallback]
144+
[intl]
182145
);
183146

184147
return (
@@ -193,6 +156,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
193156
rowSelection={defaultRowSelection}
194157
onRowClicked={props.onRowClicked}
195158
onSelectionChanged={onSelectionChanged}
159+
tooltipShowDelay={1000}
196160
>
197161
<GridButton
198162
labelId="users.table.toolbar.add.label"

0 commit comments

Comments
 (0)