Fix useFindManyRecords withSoftDeleterFilter (#11056)
Fixes #11038 # Fix useFindManyRecords withSoftDeleterFilter The error came from a faulty implementation of the `withSoftDeleted` parameter inside `useFindManyRecords` and from the fact that `withSoftDeleted: true` was added to access deleted records actions. However, this parameter was always set in `useFindManyRecordsSelectedInContextStore` instead of considering whether the filter was active or not. ``` const withSoftDeleterFilter = { or: [{ deletedAt: { is: 'NULL' } }, { deletedAt: { is: 'NOT_NULL' } }], }; ``` The final filter was incorrectly doing an `or` operation between the base filter and `withSoftDeleterFilter` when it should have been an `and`: ``` filter: { ...filter, ...(withSoftDeleted ? withSoftDeleterFilter : {}), } ``` The correct implementation should be: ``` filter: filter || withSoftDeleted ? { and: [ ...(filter ? [filter] : []), ...(withSoftDeleted ? [withSoftDeleterFilter] : []), ], } : undefined, ``` # Fix useFindManyRecordsSelectedInContextStore - Check if the soft deleted filter is active before using the `withSoftDeleterFilter` parameter
This commit is contained in:
@ -72,14 +72,14 @@ export const useFindManyRecords = <T extends ObjectRecord = ObjectRecord>({
|
||||
useQuery<RecordGqlOperationFindManyResult>(findManyRecordsQuery, {
|
||||
skip: skip || !objectMetadataItem,
|
||||
variables: {
|
||||
...(filter || withSoftDeleted
|
||||
filter: withSoftDeleted
|
||||
? {
|
||||
filter: {
|
||||
...filter,
|
||||
...(withSoftDeleted ? withSoftDeleterFilter : {}),
|
||||
},
|
||||
and: [
|
||||
...(filter ? [filter] : []),
|
||||
...(withSoftDeleted ? [withSoftDeleterFilter] : []),
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
: filter,
|
||||
orderBy,
|
||||
lastCursor: cursorFilter?.cursor ?? undefined,
|
||||
limit,
|
||||
|
||||
Reference in New Issue
Block a user