|
@@ -35,10 +35,15 @@ const SkeletonCellRenderer = (props: { value?: ReactNode }) => {
|
|
|
return <div className={styles.defaultCellContainer}>{props.value}</div>;
|
|
return <div className={styles.defaultCellContainer}>{props.value}</div>;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const DEFAULT_COL_DEF = {
|
|
|
|
|
+ cellRenderer: SkeletonCellRenderer,
|
|
|
|
|
+ flex: 1,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export const TableGrid = <TData extends Record<string, unknown>>({
|
|
export const TableGrid = <TData extends Record<string, unknown>>({
|
|
|
rowData,
|
|
rowData,
|
|
|
- colDefs,
|
|
|
|
|
- isLoading,
|
|
|
|
|
|
|
+ columnDefs,
|
|
|
|
|
+ loading,
|
|
|
cardProps,
|
|
cardProps,
|
|
|
pagination,
|
|
pagination,
|
|
|
...props
|
|
...props
|
|
@@ -48,25 +53,18 @@ export const TableGrid = <TData extends Record<string, unknown>>({
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
const [totalPages, setTotalPages] = useState(1);
|
|
const [totalPages, setTotalPages] = useState(1);
|
|
|
|
|
|
|
|
- const defaultColDef = useMemo(() => {
|
|
|
|
|
- return {
|
|
|
|
|
- cellRenderer: SkeletonCellRenderer,
|
|
|
|
|
- flex: 1,
|
|
|
|
|
- };
|
|
|
|
|
- }, []);
|
|
|
|
|
-
|
|
|
|
|
const mappedColDefs = useMemo(() => {
|
|
const mappedColDefs = useMemo(() => {
|
|
|
- return colDefs.map((colDef) => {
|
|
|
|
|
|
|
+ return columnDefs.map((colDef) => {
|
|
|
return {
|
|
return {
|
|
|
...colDef,
|
|
...colDef,
|
|
|
// the types in ag-grid are `any` for the cellRenderers which is throwing an error here
|
|
// the types in ag-grid are `any` for the cellRenderers which is throwing an error here
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
- cellRenderer: isLoading
|
|
|
|
|
|
|
+ cellRenderer: loading
|
|
|
? (colDef.loadingCellRenderer ?? SkeletonCellRenderer)
|
|
? (colDef.loadingCellRenderer ?? SkeletonCellRenderer)
|
|
|
: colDef.cellRenderer,
|
|
: colDef.cellRenderer,
|
|
|
};
|
|
};
|
|
|
});
|
|
});
|
|
|
- }, [colDefs, isLoading]);
|
|
|
|
|
|
|
+ }, [columnDefs, loading]);
|
|
|
|
|
|
|
|
const onPaginationChanged = useCallback(() => {
|
|
const onPaginationChanged = useCallback(() => {
|
|
|
const api = gridRef.current?.api;
|
|
const api = gridRef.current?.api;
|
|
@@ -84,8 +82,8 @@ export const TableGrid = <TData extends Record<string, unknown>>({
|
|
|
<AgGridReact<TData>
|
|
<AgGridReact<TData>
|
|
|
className={styles.tableGrid}
|
|
className={styles.tableGrid}
|
|
|
// @ts-expect-error empty row data, which is throwing an error here btu required to display 1 row in the loading state
|
|
// @ts-expect-error empty row data, which is throwing an error here btu required to display 1 row in the loading state
|
|
|
- rowData={isLoading ? [[]] : rowData}
|
|
|
|
|
- defaultColDef={defaultColDef}
|
|
|
|
|
|
|
+ rowData={loading ? [[]] : rowData}
|
|
|
|
|
+ defaultColDef={DEFAULT_COL_DEF}
|
|
|
columnDefs={mappedColDefs}
|
|
columnDefs={mappedColDefs}
|
|
|
theme={themeQuartz}
|
|
theme={themeQuartz}
|
|
|
domLayout="autoHeight"
|
|
domLayout="autoHeight"
|