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:
Thaïs
2024-01-23 14:13:00 -03:00
committed by GitHub
parent 9ebc0deaaf
commit 014f11fb6f
57 changed files with 852 additions and 1118 deletions

View File

@ -0,0 +1,21 @@
import { Maybe } from '~/generated/graphql';
export const sortNullsFirst = (
fieldValueA: Maybe<unknown>,
fieldValueB: Maybe<unknown>,
) => (fieldValueA === null ? -1 : fieldValueB === null ? 1 : 0);
export const sortNullsLast = (
fieldValueA: Maybe<unknown>,
fieldValueB: Maybe<unknown>,
) => sortNullsFirst(fieldValueB, fieldValueA);
export const sortAsc = (
fieldValueA: string | number,
fieldValueB: string | number,
) => (fieldValueA < fieldValueB ? -1 : 1);
export const sortDesc = (
fieldValueA: string | number,
fieldValueB: string | number,
) => sortAsc(fieldValueB, fieldValueA);