Fixed various bugs in activity creation (#6208)
- Fixed activity creation in cache - Fixed activity creation in DB, where the relation target was disappearing after creation - Added an option to match root query filter in creation optimistic effect to avoid adding the newly created record in every mounted query in Apollo cache on the same object (which was causing notes to be duplicated on every object in the cache) - Fixed tab list scope id - Fixed various browser console warnings
This commit is contained in:
@ -7,7 +7,11 @@ import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { getEdgeTypename } from '@/object-record/cache/utils/getEdgeTypename';
|
||||
import { isObjectRecordConnectionWithRefs } from '@/object-record/cache/utils/isObjectRecordConnectionWithRefs';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { isRecordMatchingFilter } from '@/object-record/record-filter/utils/isRecordMatchingFilter';
|
||||
|
||||
import { CachedObjectRecordQueryVariables } from '@/apollo/types/CachedObjectRecordQueryVariables';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { parseApolloStoreFieldName } from '~/utils/parseApolloStoreFieldName';
|
||||
|
||||
/*
|
||||
TODO: for now new records are added to all cached record lists, no matter what the variables (filters, orderBy, etc.) are.
|
||||
@ -19,11 +23,13 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
objectMetadataItem,
|
||||
recordsToCreate,
|
||||
objectMetadataItems,
|
||||
shouldMatchRootQueryFilter,
|
||||
}: {
|
||||
cache: ApolloCache<unknown>;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
recordsToCreate: RecordGqlNode[];
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
shouldMatchRootQueryFilter?: boolean;
|
||||
}) => {
|
||||
recordsToCreate.forEach((record) =>
|
||||
triggerUpdateRelationsOptimisticEffect({
|
||||
@ -39,12 +45,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
fields: {
|
||||
[objectMetadataItem.namePlural]: (
|
||||
rootQueryCachedResponse,
|
||||
{
|
||||
DELETE: _DELETE,
|
||||
readField,
|
||||
storeFieldName: _storeFieldName,
|
||||
toReference,
|
||||
},
|
||||
{ DELETE: _DELETE, readField, storeFieldName, toReference },
|
||||
) => {
|
||||
const shouldSkip = !isObjectRecordConnectionWithRefs(
|
||||
objectMetadataItem.nameSingular,
|
||||
@ -55,6 +56,13 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
return rootQueryCachedResponse;
|
||||
}
|
||||
|
||||
const { fieldVariables: rootQueryVariables } =
|
||||
parseApolloStoreFieldName<CachedObjectRecordQueryVariables>(
|
||||
storeFieldName,
|
||||
);
|
||||
|
||||
const rootQueryFilter = rootQueryVariables?.filter;
|
||||
|
||||
const rootQueryCachedObjectRecordConnection = rootQueryCachedResponse;
|
||||
|
||||
const rootQueryCachedRecordEdges = readField<RecordGqlRefEdge[]>(
|
||||
@ -74,6 +82,22 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
const hasAddedRecords = recordsToCreate
|
||||
.map((recordToCreate) => {
|
||||
if (isNonEmptyString(recordToCreate.id)) {
|
||||
if (
|
||||
isDefined(rootQueryFilter) &&
|
||||
shouldMatchRootQueryFilter === true
|
||||
) {
|
||||
const recordToCreateMatchesThisRootQueryFilter =
|
||||
isRecordMatchingFilter({
|
||||
record: recordToCreate,
|
||||
filter: rootQueryFilter,
|
||||
objectMetadataItem,
|
||||
});
|
||||
|
||||
if (!recordToCreateMatchesThisRootQueryFilter) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const recordToCreateReference = toReference(recordToCreate);
|
||||
|
||||
if (!recordToCreateReference) {
|
||||
|
||||
Reference in New Issue
Block a user