Refactor ObjectDataTable to work with new views system (#2274)
Complete work
This commit is contained in:
@ -1,6 +1,14 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { TableRecoilScopeContext } from '@/ui/data/data-table/states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||
import { tableFiltersScopedState } from '@/ui/data/data-table/states/tableFiltersScopedState';
|
||||
import { tableSortsScopedState } from '@/ui/data/data-table/states/tableSortsScopedState';
|
||||
import { turnFiltersIntoWhereClauseV2 } from '@/ui/data/filter/utils/turnFiltersIntoWhereClauseV2';
|
||||
import { turnSortsIntoOrderByV2 } from '@/ui/data/sort/utils/turnSortsIntoOrderByV2';
|
||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||
|
||||
import { useFindManyObjects } from '../hooks/useFindManyObjects';
|
||||
import { useMetadataObjectInContext } from '../hooks/useMetadataObjectInContext';
|
||||
import { useSetObjectDataTableData } from '../hooks/useSetDataTableData';
|
||||
import { MetadataObjectIdentifier } from '../types/MetadataObjectIdentifier';
|
||||
|
||||
@ -9,14 +17,33 @@ export type ObjectDataTableEffectProps = Pick<
|
||||
'objectNamePlural'
|
||||
>;
|
||||
|
||||
// TODO: merge in a single effect component
|
||||
// This should be migrated to DataTable at some point
|
||||
export const ObjectDataTableEffect = ({
|
||||
objectNamePlural,
|
||||
}: ObjectDataTableEffectProps) => {
|
||||
const setDataTableData = useSetObjectDataTableData();
|
||||
const { foundMetadataObject } = useMetadataObjectInContext();
|
||||
|
||||
const tableFilters = useRecoilScopedValue(
|
||||
tableFiltersScopedState,
|
||||
TableRecoilScopeContext,
|
||||
);
|
||||
|
||||
const tableSorts = useRecoilScopedValue(
|
||||
tableSortsScopedState,
|
||||
TableRecoilScopeContext,
|
||||
);
|
||||
|
||||
const { objects, loading } = useFindManyObjects({
|
||||
objectNamePlural,
|
||||
objectNamePlural: objectNamePlural,
|
||||
filter: turnFiltersIntoWhereClauseV2(
|
||||
tableFilters,
|
||||
foundMetadataObject?.fields ?? [],
|
||||
),
|
||||
orderBy: turnSortsIntoOrderByV2(
|
||||
tableSorts,
|
||||
foundMetadataObject?.fields ?? [],
|
||||
),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user