Uniformize folder structure (#693)
* Uniformize folder structure * Fix icons * Fix icons * Fix tests * Fix tests
This commit is contained in:
35
front/src/modules/ui/table/hooks/useInitializeEntityTable.ts
Normal file
35
front/src/modules/ui/table/hooks/useInitializeEntityTable.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
|
||||
import { entityTableDimensionsState } from '../states/entityTableDimensionsState';
|
||||
import { tableRowIdsState } from '../states/tableRowIdsState';
|
||||
|
||||
import { useResetTableRowSelection } from './useResetTableRowSelection';
|
||||
|
||||
export type TableDimensions = {
|
||||
numberOfColumns: number;
|
||||
numberOfRows: number;
|
||||
};
|
||||
|
||||
export function useInitializeEntityTable({
|
||||
numberOfColumns,
|
||||
}: {
|
||||
numberOfColumns: number;
|
||||
}) {
|
||||
const resetTableRowSelection = useResetTableRowSelection();
|
||||
|
||||
const tableRowIds = useRecoilValue(tableRowIdsState);
|
||||
|
||||
useEffect(() => {
|
||||
resetTableRowSelection();
|
||||
}, [resetTableRowSelection]);
|
||||
|
||||
const [, setTableDimensions] = useRecoilState(entityTableDimensionsState);
|
||||
|
||||
useEffect(() => {
|
||||
setTableDimensions({
|
||||
numberOfColumns,
|
||||
numberOfRows: tableRowIds?.length,
|
||||
});
|
||||
}, [tableRowIds, numberOfColumns, setTableDimensions]);
|
||||
}
|
||||
Reference in New Issue
Block a user