Skip to content

Commit 1836614

Browse files
committed
use separate componant for validity (sonar issue)
Signed-off-by: David BRAQUART <[email protected]>
1 parent 7156e68 commit 1836614

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/pages/profiles/profiles-table.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { FunctionComponent, RefObject, useCallback, useMemo, useState } from 'react';
99
import { useIntl } from 'react-intl';
10-
import { Cancel, CheckCircle, ManageAccounts, RadioButtonUnchecked } from '@mui/icons-material';
10+
import { ManageAccounts } from '@mui/icons-material';
1111
import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid';
1212
import { UserAdminSrv, UserProfile } from '../../services';
1313
import {
@@ -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 ValidityCellRenderer from './validity-cell-renderer';
2425

2526
export interface ProfilesTableProps {
2627
gridRef: RefObject<GridTableRef<UserProfile>>;
@@ -82,6 +83,7 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
8283
caseSensitive: false,
8384
trimInput: true,
8485
} as TextFilterParams<UserProfile>,
86+
tooltipField: 'name',
8587
},
8688
{
8789
field: 'allLinksValid',
@@ -90,15 +92,7 @@ const ProfilesTable: FunctionComponent<ProfilesTableProps> = (props) => {
9092
display: 'flex',
9193
alignItems: 'center',
9294
}),
93-
cellRenderer: (params: any) => {
94-
if (params.value == null) {
95-
return <RadioButtonUnchecked fontSize="small" />;
96-
} else if (params.value) {
97-
return <CheckCircle fontSize="small" color="success" />;
98-
} else {
99-
return <Cancel fontSize="small" color="error" />;
100-
}
101-
},
95+
cellRenderer: ValidityCellRenderer,
10296
tooltipValueGetter: (p: ITooltipParams) => {
10397
if (p.value == null) {
10498
return intl.formatMessage({
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 { Grid } from '@mui/material';
9+
import { Cancel, CheckCircle, RadioButtonUnchecked } from '@mui/icons-material';
10+
import { ICellRendererParams } from 'ag-grid-community';
11+
12+
export const ValidityCellRenderer = (props: ICellRendererParams) => {
13+
const renderIcon = (valid: boolean | undefined | null) => {
14+
if (valid == null) {
15+
return <RadioButtonUnchecked fontSize="small" />;
16+
} else if (valid) {
17+
return <CheckCircle fontSize="small" color="success" />;
18+
} else {
19+
return <Cancel fontSize="small" color="error" />;
20+
}
21+
};
22+
23+
return <Grid container>{renderIcon(props.value)}</Grid>;
24+
};
25+
26+
export default ValidityCellRenderer;

0 commit comments

Comments
 (0)