refactor: Update TableComponent to use optional chaining for hiding overlay

This commit is contained in:
cristhianzl 2024-06-13 17:44:28 -03:00
commit 8980b66bec

View file

@ -35,7 +35,7 @@ const TableComponent = forwardRef<
alertDescription = DEFAULT_TABLE_ALERT_MSG,
...props
},
ref
ref,
) => {
let colDef = props.columnDefs.map((col, index) => {
let newCol = {
@ -105,13 +105,13 @@ const TableComponent = forwardRef<
}
}, 50);
setTimeout(() => {
realRef.current.api.hideOverlay();
realRef?.current?.api?.hideOverlay();
}, 1000);
if (props.onGridReady) props.onGridReady(params);
};
const onColumnMoved = (params) => {
const updatedColumnDefs = makeLastColumnNonResizable(
params.columnApi.getAllGridColumns().map((col) => col.getColDef())
params.columnApi.getAllGridColumns().map((col) => col.getColDef()),
);
params.api.setGridOption("columnDefs", updatedColumnDefs);
if (props.onColumnMoved) props.onColumnMoved(params);
@ -135,7 +135,7 @@ const TableComponent = forwardRef<
className={cn(
dark ? "ag-theme-quartz-dark" : "ag-theme-quartz",
"ag-theme-shadcn flex h-full flex-col",
"relative"
"relative",
)} // applying the grid theme
>
<AgGridReact
@ -152,7 +152,7 @@ const TableComponent = forwardRef<
if (e.sources.some((source) => source.includes("column"))) {
localStorage.setItem(
storeReference,
JSON.stringify(realRef.current?.api?.getColumnState())
JSON.stringify(realRef.current?.api?.getColumnState()),
);
setColumnStateChange(true);
}
@ -175,7 +175,7 @@ const TableComponent = forwardRef<
)}
</div>
);
}
},
);
export default TableComponent;