perf: apply record optimistic effects with cache.modify on mutation (#3540)
* perf: apply record optimistic effects with cache.modify on mutation Closes #3509 * refactor: return early when created records do not match filter * fix: fix id generation on record creation * fix: comment filtering behavior on record creation * Fixed typing error * refactor: review - use ?? * refactor: review - add variables in readFieldValueToSort * docs: review - add comments for variables.first in triggerUpdateRecordOptimisticEffect * refactor: review - add intermediary variable for 'not' filter in useMultiObjectSearchMatchesSearchFilterAndToSelectQuery * refactor: review - add filter utils * fix: fix tests --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -42,19 +42,6 @@ const response = {
|
||||
};
|
||||
|
||||
const mocks = [
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
variables: {
|
||||
filterNameSingular: { and: [{}, { id: { in: ['1'] } }] },
|
||||
orderByNameSingular: { createdAt: 'DescNullsLast' },
|
||||
limitNameSingular: 60,
|
||||
},
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: response,
|
||||
})),
|
||||
},
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
@ -72,8 +59,20 @@ const mocks = [
|
||||
request: {
|
||||
query,
|
||||
variables: {
|
||||
orderByNameSingular: { createdAt: 'DescNullsLast' },
|
||||
limitNameSingular: 60,
|
||||
filterNameSingular: { and: [{}, { not: { id: { in: ['1'] } } }] },
|
||||
},
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: response,
|
||||
})),
|
||||
},
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
variables: {
|
||||
limitNameSingular: 60,
|
||||
filterNameSingular: { not: { id: { in: ['1'] } } },
|
||||
orderByNameSingular: { createdAt: 'DescNullsLast' },
|
||||
},
|
||||
},
|
||||
|
||||
@ -53,23 +53,9 @@ export const useMultiObjectSearchMatchesSearchFilterAndSelectedItemsQuery = ({
|
||||
|
||||
if (!isNonEmptyArray(selectedIds)) return null;
|
||||
|
||||
const searchFilter =
|
||||
searchFilterPerMetadataItemNameSingular[nameSingular] ?? {};
|
||||
|
||||
return [
|
||||
`filter${capitalize(nameSingular)}`,
|
||||
{
|
||||
and: [
|
||||
{
|
||||
...searchFilter,
|
||||
},
|
||||
{
|
||||
id: {
|
||||
in: selectedIds,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
searchFilterPerMetadataItemNameSingular[nameSingular],
|
||||
];
|
||||
})
|
||||
.filter(isDefined),
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { useQuery } from '@apollo/client';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { EMPTY_QUERY } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
@ -14,7 +13,7 @@ import {
|
||||
import { SelectedObjectRecordId } from '@/object-record/relation-picker/hooks/useMultiObjectSearch';
|
||||
import { useOrderByFieldPerMetadataItem } from '@/object-record/relation-picker/hooks/useOrderByFieldPerMetadataItem';
|
||||
import { useSearchFilterPerMetadataItem } from '@/object-record/relation-picker/hooks/useSearchFilterPerMetadataItem';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
import { andFilterVariables } from '@/object-record/utils/andFilterVariables';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
@ -58,35 +57,19 @@ export const useMultiObjectSearchMatchesSearchFilterAndToSelectQuery = ({
|
||||
)
|
||||
.map(({ id }) => id);
|
||||
|
||||
const searchFilter =
|
||||
searchFilterPerMetadataItemNameSingular[nameSingular] ?? {};
|
||||
|
||||
const excludedIdsUnion = [...selectedIds, ...excludedIds];
|
||||
const excludedIdsFilter = excludedIdsUnion.length
|
||||
? { not: { id: { in: excludedIdsUnion } } }
|
||||
: undefined;
|
||||
|
||||
const noFilter =
|
||||
!isNonEmptyArray(excludedIdsUnion) &&
|
||||
isDeeplyEqual(searchFilter, {});
|
||||
const searchFilters = [
|
||||
searchFilterPerMetadataItemNameSingular[nameSingular],
|
||||
excludedIdsFilter,
|
||||
];
|
||||
|
||||
return [
|
||||
`filter${capitalize(nameSingular)}`,
|
||||
!noFilter
|
||||
? {
|
||||
and: [
|
||||
{
|
||||
...searchFilter,
|
||||
},
|
||||
isNonEmptyArray(excludedIdsUnion)
|
||||
? {
|
||||
not: {
|
||||
id: {
|
||||
in: [...selectedIds, ...excludedIds],
|
||||
},
|
||||
},
|
||||
}
|
||||
: {},
|
||||
],
|
||||
}
|
||||
: {},
|
||||
andFilterVariables(searchFilters),
|
||||
];
|
||||
})
|
||||
.filter(isDefined),
|
||||
|
||||
Reference in New Issue
Block a user