The global record filter refactor will derive everything at runtime from objectMetadataItemsState, thus removing the need for a filter definition concept. Here we don't yet remove available filter definition usage but we replace the available filter definitions states, we now derive the same value from objectMetadataItemsState. This will allow us to progressively remove the usage of the concept of filter definition, at the end it will then be easy to just remove from the codebase because nothing will use it anymore.
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { useEffect } from 'react';
|
|
|
|
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
|
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
|
|
import { useSetRecordIndexEntityCount } from '@/object-record/record-index/hooks/useSetRecordIndexEntityCount';
|
|
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
|
|
import { SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS } from '@/sign-in-background-mock/constants/SignInBackgroundMockColumnDefinitions';
|
|
import { SIGN_IN_BACKGROUND_MOCK_SORT_DEFINITIONS } from '@/sign-in-background-mock/constants/SignInBackgroundMockSortDefinitions';
|
|
import { SIGN_IN_BACKGROUND_MOCK_VIEW_FIELDS } from '@/sign-in-background-mock/constants/SignInBackgroundMockViewFields';
|
|
import { useInitViewBar } from '@/views/hooks/useInitViewBar';
|
|
import { mapViewFieldsToColumnDefinitions } from '@/views/utils/mapViewFieldsToColumnDefinitions';
|
|
|
|
type SignInBackgroundMockContainerEffectProps = {
|
|
objectNamePlural: string;
|
|
recordTableId: string;
|
|
viewId: string;
|
|
};
|
|
|
|
export const SignInBackgroundMockContainerEffect = ({
|
|
objectNamePlural,
|
|
recordTableId,
|
|
viewId,
|
|
}: SignInBackgroundMockContainerEffectProps) => {
|
|
const { setAvailableTableColumns, setOnEntityCountChange, setTableColumns } =
|
|
useRecordTable({
|
|
recordTableId,
|
|
});
|
|
|
|
const { objectNameSingular } = useObjectNameSingularFromPlural({
|
|
objectNamePlural,
|
|
});
|
|
|
|
const { objectMetadataItem } = useObjectMetadataItem({
|
|
objectNameSingular,
|
|
});
|
|
|
|
const {
|
|
setAvailableSortDefinitions,
|
|
setAvailableFieldDefinitions,
|
|
setViewObjectMetadataId,
|
|
} = useInitViewBar(viewId);
|
|
|
|
const { setRecordIndexEntityCount } = useSetRecordIndexEntityCount(viewId);
|
|
|
|
useEffect(() => {
|
|
setViewObjectMetadataId?.(objectMetadataItem.id);
|
|
|
|
setAvailableSortDefinitions?.(SIGN_IN_BACKGROUND_MOCK_SORT_DEFINITIONS);
|
|
setAvailableFieldDefinitions?.(SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS);
|
|
|
|
setAvailableTableColumns(SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS);
|
|
|
|
setTableColumns(
|
|
mapViewFieldsToColumnDefinitions({
|
|
viewFields: SIGN_IN_BACKGROUND_MOCK_VIEW_FIELDS,
|
|
columnDefinitions: SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS,
|
|
}),
|
|
);
|
|
}, [
|
|
setViewObjectMetadataId,
|
|
setAvailableSortDefinitions,
|
|
setAvailableFieldDefinitions,
|
|
objectMetadataItem,
|
|
setAvailableTableColumns,
|
|
setTableColumns,
|
|
]);
|
|
|
|
useEffect(() => {
|
|
setOnEntityCountChange(
|
|
() => (entityCount: number) => setRecordIndexEntityCount(entityCount),
|
|
);
|
|
}, [setRecordIndexEntityCount, setOnEntityCountChange]);
|
|
|
|
return <></>;
|
|
};
|