Activity injection into Apollo cache (#3665)
- 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
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { ActivityType } from '@/activities/types/Activity';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
|
||||
import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { ActivityTargetableObject } from '../types/ActivityTargetableEntity';
|
||||
|
||||
@ -27,21 +29,35 @@ export const useOpenCreateActivityDrawerForSelectedRowIds = (
|
||||
getSelectedRowIdsSelector(),
|
||||
);
|
||||
|
||||
let activityTargetableEntityArray: ActivityTargetableObject[] =
|
||||
selectedRowIds.map((id: string) => ({
|
||||
type: 'Custom',
|
||||
targetObjectNameSingular: objectNameSingular,
|
||||
id,
|
||||
}));
|
||||
let activityTargetableObjectArray: ActivityTargetableObject[] =
|
||||
selectedRowIds
|
||||
.map((recordId: string) => {
|
||||
const targetObjectRecord = getSnapshotValue(
|
||||
snapshot,
|
||||
recordStoreFamilyState(recordId),
|
||||
);
|
||||
|
||||
if (!targetObjectRecord) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'Custom',
|
||||
targetObjectNameSingular: objectNameSingular,
|
||||
id: recordId,
|
||||
targetObjectRecord,
|
||||
};
|
||||
})
|
||||
.filter(isDefined);
|
||||
|
||||
if (relatedEntities) {
|
||||
activityTargetableEntityArray =
|
||||
activityTargetableEntityArray.concat(relatedEntities);
|
||||
activityTargetableObjectArray =
|
||||
activityTargetableObjectArray.concat(relatedEntities);
|
||||
}
|
||||
|
||||
openCreateActivityDrawer({
|
||||
type,
|
||||
targetableObjects: activityTargetableEntityArray,
|
||||
targetableObjects: activityTargetableObjectArray,
|
||||
});
|
||||
},
|
||||
[openCreateActivityDrawer, getSelectedRowIdsSelector],
|
||||
|
||||
Reference in New Issue
Block a user