Fix bug where aggregate resets record filters (#10136)
This PR fixes a bug where setting an aggregate in the footer of a record table makes the currentRecordFilters state being overwritten by the view, which we don't want.
This commit is contained in:
@ -3,9 +3,11 @@ import { useFilterableFieldMetadataItemsInRecordIndexContext } from '@/object-re
|
||||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState';
|
||||
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
|
||||
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
|
||||
import { useRecoilComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyStateV2';
|
||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';
|
||||
import { currentViewIdComponentState } from '@/views/states/currentViewIdComponentState';
|
||||
import { hasInitializedCurrentRecordFiltersComponentFamilyState } from '@/views/states/hasInitializedCurrentRecordFiltersComponentFamilyState';
|
||||
import { View } from '@/views/types/View';
|
||||
import { mapViewFiltersToFilters } from '@/views/utils/mapViewFiltersToFilters';
|
||||
import { useEffect } from 'react';
|
||||
@ -18,15 +20,29 @@ export const ViewBarRecordFilterEffect = () => {
|
||||
|
||||
const currentViewId = useRecoilComponentValueV2(currentViewIdComponentState);
|
||||
|
||||
const [
|
||||
hasInitializedCurrentRecordFilters,
|
||||
setHasInitializedCurrentRecordFilters,
|
||||
] = useRecoilComponentFamilyStateV2(
|
||||
hasInitializedCurrentRecordFiltersComponentFamilyState,
|
||||
{
|
||||
viewId: currentViewId,
|
||||
},
|
||||
);
|
||||
|
||||
const setCurrentRecordFilters = useSetRecoilComponentStateV2(
|
||||
currentRecordFiltersComponentState,
|
||||
);
|
||||
|
||||
const currentRecordFilters = useRecoilComponentValueV2(
|
||||
currentRecordFiltersComponentState,
|
||||
);
|
||||
|
||||
const { filterableFieldMetadataItems } =
|
||||
useFilterableFieldMetadataItemsInRecordIndexContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (isDataPrefetched) {
|
||||
if (isDataPrefetched && !hasInitializedCurrentRecordFilters) {
|
||||
const currentView = views.find((view) => view.id === currentViewId);
|
||||
|
||||
const filterDefinitions = filterableFieldMetadataItems.map(
|
||||
@ -40,6 +56,7 @@ export const ViewBarRecordFilterEffect = () => {
|
||||
setCurrentRecordFilters(
|
||||
mapViewFiltersToFilters(currentView.viewFilters, filterDefinitions),
|
||||
);
|
||||
setHasInitializedCurrentRecordFilters(true);
|
||||
}
|
||||
}
|
||||
}, [
|
||||
@ -48,6 +65,9 @@ export const ViewBarRecordFilterEffect = () => {
|
||||
currentViewId,
|
||||
setCurrentRecordFilters,
|
||||
filterableFieldMetadataItems,
|
||||
currentRecordFilters,
|
||||
hasInitializedCurrentRecordFilters,
|
||||
setHasInitializedCurrentRecordFilters,
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
import { RecordFiltersComponentInstanceContext } from '@/object-record/record-filter/states/context/RecordFiltersComponentInstanceContext';
|
||||
import { createComponentFamilyStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentFamilyStateV2';
|
||||
|
||||
export const hasInitializedCurrentRecordFiltersComponentFamilyState =
|
||||
createComponentFamilyStateV2<boolean, { viewId?: string }>({
|
||||
key: 'hasInitializedCurrentRecordFiltersComponentFamilyState',
|
||||
defaultValue: false,
|
||||
componentInstanceContext: RecordFiltersComponentInstanceContext,
|
||||
});
|
||||
Reference in New Issue
Block a user