Reverting broken filter from (#12352)
# Introdution Reverting introduced bug by https://github.com/twentyhq/twenty/pull/12082 We need to address the bug that was "fixed" by this in order to refresh the recordFilters state, will have a look with @lucasbordeau 🙏
This commit is contained in:
@ -3,13 +3,14 @@ import { useFilterableFieldMetadataItems } from '@/object-record/record-filter/h
|
||||
import { currentRecordFiltersComponentState } from '@/object-record/record-filter/states/currentRecordFiltersComponentState';
|
||||
import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext';
|
||||
import { prefetchViewFromViewIdFamilySelector } from '@/prefetch/states/selector/prefetchViewFromViewIdFamilySelector';
|
||||
import { useRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentStateV2';
|
||||
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 { hasInitializedCurrentRecordFiltersComponentFamilyState } from '@/views/states/hasInitializedCurrentRecordFiltersComponentFamilyState';
|
||||
import { mapViewFiltersToFilters } from '@/views/utils/mapViewFiltersToFilters';
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
export const ViewBarRecordFilterEffect = () => {
|
||||
const currentViewId = useRecoilComponentValueV2(
|
||||
@ -24,32 +25,45 @@ export const ViewBarRecordFilterEffect = () => {
|
||||
}),
|
||||
);
|
||||
|
||||
const [currentRecordFilters, setCurrentRecordFilters] =
|
||||
useRecoilComponentStateV2(currentRecordFiltersComponentState);
|
||||
const [
|
||||
hasInitializedCurrentRecordFilters,
|
||||
setHasInitializedCurrentRecordFilters,
|
||||
] = useRecoilComponentFamilyStateV2(
|
||||
hasInitializedCurrentRecordFiltersComponentFamilyState,
|
||||
{
|
||||
viewId: currentViewId ?? undefined,
|
||||
},
|
||||
);
|
||||
|
||||
const setCurrentRecordFilters = useSetRecoilComponentStateV2(
|
||||
currentRecordFiltersComponentState,
|
||||
);
|
||||
|
||||
const { filterableFieldMetadataItems } = useFilterableFieldMetadataItems(
|
||||
objectMetadataItem.id,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (isDefined(currentView)) {
|
||||
if (!hasInitializedCurrentRecordFilters && isDefined(currentView)) {
|
||||
if (currentView.objectMetadataId !== objectMetadataItem.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newRecordFilters = mapViewFiltersToFilters(
|
||||
currentView.viewFilters,
|
||||
filterableFieldMetadataItems,
|
||||
setCurrentRecordFilters(
|
||||
mapViewFiltersToFilters(
|
||||
currentView.viewFilters,
|
||||
filterableFieldMetadataItems,
|
||||
),
|
||||
);
|
||||
if (!isDeeplyEqual(currentRecordFilters, newRecordFilters)) {
|
||||
setCurrentRecordFilters(newRecordFilters);
|
||||
}
|
||||
|
||||
setHasInitializedCurrentRecordFilters(true);
|
||||
}
|
||||
}, [
|
||||
currentViewId,
|
||||
currentRecordFilters,
|
||||
setCurrentRecordFilters,
|
||||
filterableFieldMetadataItems,
|
||||
hasInitializedCurrentRecordFilters,
|
||||
setHasInitializedCurrentRecordFilters,
|
||||
currentView,
|
||||
objectMetadataItem,
|
||||
]);
|
||||
|
||||
@ -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