Fix optimistic effect for implicit and filters (#9935)
The optimistic effect for record creations and updates wasn't working properly for `and filters` without explicit `and`. The problem was located inside `isRecordMatchingFilter` which didn't consider implicit `and filters` as `and filters`. This caused queries to be updated by the optimistic effect even if they didn't match the root query filter. I also removed `fetchPolicy: 'cache-and-network'` from a query. This was a temporary fix for this issue. Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -53,7 +53,6 @@ export const useFindManyRecordsSelectedInContextStore = ({
|
||||
contextStoreTargetedRecordsRule.mode === 'selection' &&
|
||||
contextStoreTargetedRecordsRule.selectedRecordIds.length === 0,
|
||||
limit,
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -50,6 +50,9 @@ const isAndFilter = (
|
||||
filter: RecordGqlOperationFilter,
|
||||
): filter is AndObjectRecordFilter => 'and' in filter && !!filter.and;
|
||||
|
||||
const isImplicitAndFilter = (filter: RecordGqlOperationFilter) =>
|
||||
Object.keys(filter).length > 1;
|
||||
|
||||
const isOrFilter = (
|
||||
filter: RecordGqlOperationFilter,
|
||||
): filter is OrObjectRecordFilter => 'or' in filter && !!filter.or;
|
||||
@ -71,6 +74,16 @@ export const isRecordMatchingFilter = ({
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isImplicitAndFilter(filter)) {
|
||||
return Object.entries(filter).every(([filterKey, value]) =>
|
||||
isRecordMatchingFilter({
|
||||
record,
|
||||
filter: { [filterKey]: value },
|
||||
objectMetadataItem,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (isAndFilter(filter)) {
|
||||
const filterValue = filter.and;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user