- Created addRecordInCache to inject a record in Apollo cache and inject single read query on this record - Created createOneRecordInCache and createManyRecordsInCache that uses this addRecordInCache - Created useOpenCreateActivityDrawerV2 hook to create an activity in cache and inject it into all other relevant requests in the app before opening activity drawer - Refactored DEFAULT_SEARCH_REQUEST_LIMIT constant and hardcoded arbitrary request limits - Added Apollo dev logs to see errors in the console when manipulating cache
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { v4 } from 'uuid';
|
|
|
|
import { ActivityTarget } from '@/activities/types/ActivityTarget';
|
|
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
|
import { flattenTargetableObjectsAndTheirRelatedTargetableObjects } from '@/activities/utils/flattenTargetableObjectsAndTheirRelatedTargetableObjects';
|
|
import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getTargetObjectFilterFieldName';
|
|
|
|
export const getActivityTargetsToCreateFromTargetableObjects = ({
|
|
targetableObjects,
|
|
activityId,
|
|
}: {
|
|
targetableObjects: ActivityTargetableObject[];
|
|
activityId: string;
|
|
}): Partial<ActivityTarget>[] => {
|
|
const activityTargetableObjects = targetableObjects
|
|
? flattenTargetableObjectsAndTheirRelatedTargetableObjects(
|
|
targetableObjects,
|
|
)
|
|
: [];
|
|
|
|
const activityTargetsToCreate = activityTargetableObjects.map(
|
|
(targetableObject) => {
|
|
const targetableObjectFieldIdName = getActivityTargetObjectFieldIdName({
|
|
nameSingular: targetableObject.targetObjectNameSingular,
|
|
});
|
|
|
|
return {
|
|
[targetableObject.targetObjectNameSingular]:
|
|
targetableObject.targetObjectRecord,
|
|
[targetableObjectFieldIdName]: targetableObject.id,
|
|
activityId,
|
|
id: v4(),
|
|
};
|
|
},
|
|
);
|
|
|
|
return activityTargetsToCreate;
|
|
};
|