Implement Optimistic Effects (#1415)
* Fix person deletion not reflected on Opportunities POC * Fix companies, user deletion * Implement optimistic effects * Implement optimistic effects * Implement optimistic effects * Fix accoding to PR
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
import { ApolloCache } from '@apollo/client';
|
||||
|
||||
import {
|
||||
GetPeopleQuery,
|
||||
GetPeopleQueryVariables,
|
||||
Person,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { GET_PEOPLE } from '../queries/getPeople';
|
||||
|
||||
function optimisticEffectResolver({
|
||||
cache,
|
||||
entities,
|
||||
variables,
|
||||
}: {
|
||||
cache: ApolloCache<Person>;
|
||||
entities: Person[];
|
||||
variables: GetPeopleQueryVariables;
|
||||
}) {
|
||||
const existingData = cache.readQuery<GetPeopleQuery>({
|
||||
query: GET_PEOPLE,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
});
|
||||
|
||||
if (!existingData) {
|
||||
return;
|
||||
}
|
||||
|
||||
cache.writeQuery({
|
||||
query: GET_PEOPLE,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
data: {
|
||||
people: [...entities, ...existingData.people],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getPeopleOptimisticEffect(variables: GetPeopleQueryVariables) {
|
||||
return {
|
||||
key: 'generic-entity-table-data-person',
|
||||
variables: variables,
|
||||
typename: 'Person',
|
||||
resolver: optimisticEffectResolver,
|
||||
};
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import { peopleAvailableColumnDefinitions } from '@/people/constants/peopleAvailableColumnDefinitions';
|
||||
import { getPeopleOptimisticEffect } from '@/people/graphql/optimistic-effect-callback/getPeopleOptimisticEffect';
|
||||
import { usePersonTableContextMenuEntries } from '@/people/hooks/usePeopleTableContextMenuEntries';
|
||||
import { usePersonTableActionBarEntries } from '@/people/hooks/usePersonTableActionBarEntries';
|
||||
import { useSpreadsheetPersonImport } from '@/people/hooks/useSpreadsheetPersonImport';
|
||||
@ -52,6 +53,7 @@ export function PeopleTable() {
|
||||
<GenericEntityTableData
|
||||
getRequestResultKey="people"
|
||||
useGetRequest={useGetPeopleQuery}
|
||||
getRequestOptimisticEffect={getPeopleOptimisticEffect}
|
||||
orderBy={orderBy.length ? orderBy : [{ createdAt: SortOrder.Desc }]}
|
||||
whereFilters={whereFilters}
|
||||
filterDefinitionArray={peopleFilters}
|
||||
|
||||
Reference in New Issue
Block a user