Skip to content

Commit e656e9a

Browse files
Merge remote-tracking branch 'origin/main' into update/eslint
2 parents 8fb526a + 4961f6b commit e656e9a

File tree

7 files changed

+39
-170
lines changed

7 files changed

+39
-170
lines changed

package-lock.json

+11-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@emotion/react": "^11.14.0",
1818
"@emotion/styled": "^11.14.0",
19-
"@gridsuite/commons-ui": "0.94.0",
19+
"@gridsuite/commons-ui": "0.95.0",
2020
"@hookform/resolvers": "^4.0.0",
2121
"@mui/icons-material": "^5.16.14",
2222
"@mui/lab": "5.0.0-alpha.175",

src/components/App/app-wrapper.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ const lightTheme: ThemeOptions = {
6666
link: {
6767
color: 'blue',
6868
},
69-
agGridTheme: 'ag-theme-alpine',
69+
aggrid: {
70+
theme: 'ag-theme-alpine',
71+
},
7072
};
7173

7274
const darkTheme: ThemeOptions = {
@@ -92,7 +94,9 @@ const darkTheme: ThemeOptions = {
9294
link: {
9395
color: 'green',
9496
},
95-
agGridTheme: 'ag-theme-alpine-dark',
97+
aggrid: {
98+
theme: 'ag-theme-alpine-dark',
99+
},
96100
};
97101

98102
const getMuiTheme = (theme: GsTheme, locale: GsLangUser): Theme => {

src/components/Grid/AgGrid.tsx

+14-28
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import 'ag-grid-community/styles/ag-grid.css';
9-
import 'ag-grid-community/styles/ag-theme-alpine.css';
10-
118
import {
129
ForwardedRef,
1310
forwardRef,
@@ -19,18 +16,10 @@ import {
1916
useImperativeHandle,
2017
useRef,
2118
} from 'react';
22-
import { Box, useTheme } from '@mui/material';
2319
import { AgGridReact } from 'ag-grid-react';
24-
import { useIntl } from 'react-intl';
25-
import { LANG_FRENCH } from '@gridsuite/commons-ui';
26-
import { AG_GRID_LOCALE_FR } from '../../translations/ag-grid/locales';
27-
import { GridOptions } from 'ag-grid-community';
20+
import { CustomAGGrid, type CustomAGGridProps } from '@gridsuite/commons-ui';
2821
import { useDebugRender } from '../../utils/hooks';
2922

30-
const messages: Record<string, Record<string, string>> = {
31-
[LANG_FRENCH]: AG_GRID_LOCALE_FR,
32-
};
33-
3423
type AccessibleAgGridReact<TData> = Omit<
3524
AgGridReact<TData>,
3625
'apiListeners' | 'setGridApi' //private in class
@@ -47,12 +36,13 @@ export type AgGridRef<TData, TContext extends {}> = {
4736
type ForwardRef<Props, Ref> = typeof forwardRef<Props, Ref>;
4837
type ForwardRefComponent<Props, Ref> = ReturnType<ForwardRef<Props, Ref>>;
4938

50-
interface AgGridWithRef extends FunctionComponent<GridOptions<unknown>> {
39+
interface AgGridWithRef extends FunctionComponent<CustomAGGridProps<unknown>> {
5140
<TData, TContext extends {}>(
52-
props: PropsWithoutRef<GridOptions<TData>> & RefAttributes<AgGridRef<TData, TContext>>
53-
): ReturnType<ForwardRefComponent<GridOptions<TData>, AgGridRef<TData, TContext>>>;
41+
props: PropsWithoutRef<CustomAGGridProps<TData>> & RefAttributes<AgGridRef<TData, TContext>>
42+
): ReturnType<ForwardRefComponent<CustomAGGridProps<TData>, AgGridRef<TData, TContext>>>;
5443
}
5544

45+
// TODO move&merge to commons-ui
5646
const style = {
5747
// default overridable style
5848
width: '100%',
@@ -62,13 +52,12 @@ const style = {
6252
},
6353
};
6454

55+
// TODO move type generic restoration to commons-ui
56+
// TODO move useDebug feature from env to commons-ui
6557
export const AgGrid: AgGridWithRef = forwardRef(function AgGrid<TData, TContext extends {} = {}>(
66-
props: GridOptions<TData>,
58+
props: CustomAGGridProps<TData>,
6759
gridRef?: ForwardedRef<AgGridRef<TData, TContext>>
6860
): ReactNode {
69-
const intl = useIntl();
70-
const theme = useTheme();
71-
7261
const id = useId();
7362
useDebugRender(`ag-grid(${id}) ${props.gridId}`);
7463

@@ -84,15 +73,12 @@ export const AgGrid: AgGridWithRef = forwardRef(function AgGrid<TData, TContext
8473
);
8574

8675
return (
87-
// wrapping container with theme & size
88-
<Box component="div" className={theme.agGridTheme} sx={style}>
89-
<AgGridReact<TData>
90-
ref={agGridRef}
91-
localeText={messages[intl.locale] ?? messages[intl.defaultLocale] ?? undefined}
92-
{...props} //destruct props to optimize react props change detection
93-
debug={import.meta.env.VITE_DEBUG_AGGRID === 'true' || props.debug}
94-
/>
95-
</Box>
76+
<CustomAGGrid //TODO <TData>
77+
ref={agGridRef}
78+
{...props} //destruct props to optimize react props change detection
79+
debug={import.meta.env.VITE_DEBUG_AGGRID === 'true' || props.debug}
80+
sx={style}
81+
/>
9682
);
9783
});
9884
export default AgGrid;

src/components/Grid/GridTable.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type GridTableExposed = {
3131

3232
export type GridTableRef<TData, TContext extends {} = {}> = AgGridRef<TData, TContext & GridTableExposed>;
3333

34-
export interface GridTableProps<TData> extends Omit<GridOptions<TData>, 'rowData'>, PropsWithChildren<{}> {
34+
export interface GridTableProps<TData>
35+
extends Omit<GridOptions<TData>, 'rowData' | 'alwaysShowVerticalScroll' | 'onGridReady'>,
36+
PropsWithChildren<{}> {
3537
//accessRef: RefObject<GridTableRef<TData, TContext>>;
3638
dataLoader: () => Promise<TData[]>;
3739
}
@@ -40,8 +42,7 @@ export interface GridTableProps<TData> extends Omit<GridOptions<TData>, 'rowData
4042
* Restore lost generics from `forwardRef()`<br/>
4143
* https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
4244
*/
43-
type ForwardRef<Props, Ref> = typeof forwardRef<Props, Ref>;
44-
type ForwardRefComponent<Props, Ref> = ReturnType<ForwardRef<Props, Ref>>;
45+
type ForwardRefComponent<Props, Ref> = ReturnType<typeof forwardRef<Props, Ref>>;
4546

4647
interface GridTableWithRef extends FunctionComponent<PropsWithChildren<GridTableProps<unknown>>> {
4748
<TData, TContext extends {}>(

src/module-mui.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ declare module '@mui/material/styles/createTheme' {
1818
circle_hover: CSSObject;
1919
link: CSSObject;
2020
mapboxStyle: string;
21-
agGridTheme: 'ag-theme-alpine' | 'ag-theme-alpine-dark';
21+
aggrid: {
22+
theme: 'ag-theme-alpine' | 'ag-theme-alpine-dark';
23+
};
2224
agGridThemeOverride?: CSSObject;
2325
};
2426

src/translations/ag-grid/locales.ts

-131
This file was deleted.

0 commit comments

Comments
 (0)