Skip to content

Commit f8e8d1b

Browse files
authored
Migrate directory content to AGgrid (#427)
Signed-off-by: Hugo Marcellin <[email protected]>
1 parent b847039 commit f8e8d1b

14 files changed

+799
-644
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@emotion/react": "^11.11.4",
99
"@emotion/styled": "^11.11.5",
10-
"@gridsuite/commons-ui": "0.59.1",
10+
"@gridsuite/commons-ui": "0.59.2",
1111
"@hookform/resolvers": "^3.3.4",
1212
"@mui/icons-material": "^5.15.14",
1313
"@mui/lab": "5.0.0-alpha.169",

src/components/app-wrapper.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ let lightTheme = createTheme({
8585
secondary: '#F4F4F4',
8686
hover: '#8E9C9B',
8787
},
88-
aggrid: 'ag-theme-alpine',
88+
aggrid: {
89+
theme: 'ag-theme-alpine',
90+
highlightColor: '#8e9c9b',
91+
},
8992
agGridBackground: {
9093
color: 'white',
9194
},
@@ -139,7 +142,10 @@ let darkTheme = createTheme({
139142
secondary: '#323232',
140143
hover: '#545C5B',
141144
},
142-
aggrid: 'ag-theme-alpine-dark',
145+
aggrid: {
146+
theme: 'ag-theme-alpine-dark',
147+
highlightColor: '#545c5b',
148+
},
143149
agGridBackground: {
144150
color: '#383838',
145151
},
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright (c) 2024, 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 { defaultColumnDefinition } from './utils/directory-content-utils';
9+
import {
10+
CustomAGGrid,
11+
ElementType,
12+
ElementAttributes,
13+
} from '@gridsuite/commons-ui';
14+
import { AgGridReact } from 'ag-grid-react';
15+
import { GetRowIdParams } from 'ag-grid-community/dist/types/core/interfaces/iCallbackParams';
16+
import { ColDef, GridReadyEvent, RowClassParams } from 'ag-grid-community';
17+
import { RefObject } from 'react';
18+
19+
interface DirectoryContentTableProps {
20+
gridRef: RefObject<AgGridReact<ElementAttributes>>;
21+
rows: ElementAttributes[];
22+
handleCellContextualMenu: () => void;
23+
handleRowSelected: () => void;
24+
handleCellClick: () => void;
25+
colDef: ColDef[];
26+
}
27+
28+
const onGridReady = ({ api }: GridReadyEvent<ElementAttributes>) => {
29+
api?.sizeColumnsToFit();
30+
};
31+
32+
const getRowId = (params: GetRowIdParams<ElementAttributes>) =>
33+
params.data?.elementUuid;
34+
35+
export const CUSTOM_ROW_CLASS = 'custom-row-class';
36+
37+
const getRowStyle = (cellData: RowClassParams<ElementAttributes>) => {
38+
const style: Record<string, string> = { fontSize: '1rem' };
39+
if (
40+
cellData.data &&
41+
![
42+
ElementType.CASE,
43+
ElementType.LOADFLOW_PARAMETERS,
44+
ElementType.SENSITIVITY_PARAMETERS,
45+
ElementType.SECURITY_ANALYSIS_PARAMETERS,
46+
ElementType.VOLTAGE_INIT_PARAMETERS,
47+
].includes(cellData.data.type)
48+
) {
49+
style.cursor = 'pointer';
50+
}
51+
return style;
52+
};
53+
54+
export const DirectoryContentTable = ({
55+
gridRef,
56+
rows,
57+
handleCellContextualMenu,
58+
handleRowSelected,
59+
handleCellClick,
60+
colDef,
61+
}: DirectoryContentTableProps) => {
62+
return (
63+
<CustomAGGrid
64+
ref={gridRef}
65+
rowData={rows}
66+
getRowId={getRowId}
67+
defaultColDef={defaultColumnDefinition}
68+
rowSelection="multiple"
69+
suppressRowClickSelection
70+
onGridReady={onGridReady}
71+
onCellContextMenu={handleCellContextualMenu}
72+
onCellClicked={handleCellClick}
73+
onRowSelected={handleRowSelected}
74+
animateRows={true}
75+
columnDefs={colDef}
76+
getRowStyle={getRowStyle}
77+
//We set a custom className for rows in order to easily determine if a context menu event is happening on a row or not
78+
rowClass={CUSTOM_ROW_CLASS}
79+
/>
80+
);
81+
};

0 commit comments

Comments
 (0)