mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-07 09:17:31 +03:00
Fix tasks (#5199)
## Query depth deprecation I'm deprecating depth parameter in our graphql query / cache tooling. They were obsolete since we introduce the possibility to provide RecordGqlFields ## Refactor combinedFindManyRecordHook The hook can now take an array of operationSignatures ## Fix tasks issues Fix optimistic rendering issue. Note that we still haven't handle optimisticEffect on creation properly
This commit is contained in:
parent
c946572fde
commit
6a14b1c6d6
@ -3,4 +3,5 @@ export type BlocklistItem = {
|
||||
handle: string;
|
||||
workspaceMemberId: string;
|
||||
createdAt: string;
|
||||
__typename: 'BlocklistItem';
|
||||
};
|
||||
|
@ -9,4 +9,5 @@ export type CalendarChannel = {
|
||||
isContactAutoCreationEnabled?: boolean;
|
||||
isSyncEnabled?: boolean;
|
||||
visibility: CalendarChannelVisibility;
|
||||
__typename: 'CalendarChannel';
|
||||
};
|
||||
|
@ -13,4 +13,5 @@ export type ConnectedAccount = {
|
||||
authFailedAt: Date | null;
|
||||
messageChannels: MessageChannel[];
|
||||
calendarChannels: CalendarChannel[];
|
||||
__typename: 'ConnectedAccount';
|
||||
};
|
||||
|
@ -7,4 +7,5 @@ export type MessageChannel = {
|
||||
isSyncEnabled: boolean;
|
||||
visibility: InboxSettingsVisibilityValue;
|
||||
syncStatus: string;
|
||||
__typename: 'MessageChannel';
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ import { sortDesc } from '~/utils/sort';
|
||||
|
||||
type CalendarEventGeneric = Omit<
|
||||
CalendarEvent,
|
||||
'participants' | 'externalCreatedAt'
|
||||
'participants' | 'externalCreatedAt' | '__typename'
|
||||
>;
|
||||
|
||||
export const useCalendarEvents = <T extends CalendarEventGeneric>(
|
||||
|
@ -14,7 +14,6 @@ export const RightDrawerCalendarEvent = () => {
|
||||
objectNameSingular: CoreObjectNameSingular.CalendarEvent,
|
||||
objectRecordId: viewableCalendarEventId ?? '',
|
||||
onCompleted: (record) => setRecords([record]),
|
||||
depth: 2,
|
||||
});
|
||||
|
||||
if (!calendarEvent) return null;
|
||||
|
@ -17,4 +17,5 @@ export type CalendarEvent = {
|
||||
title?: string;
|
||||
visibility: 'METADATA' | 'SHARE_EVERYTHING';
|
||||
calendarEventParticipants?: CalendarEventParticipant[];
|
||||
__typename: 'CalendarEvent';
|
||||
};
|
||||
|
@ -161,6 +161,7 @@ export const ActivityBodyEditor = ({
|
||||
...oldActivity,
|
||||
id: activityId,
|
||||
body: newStringifiedBody,
|
||||
__typename: 'Activity',
|
||||
};
|
||||
});
|
||||
|
||||
@ -192,6 +193,7 @@ export const ActivityBodyEditor = ({
|
||||
...oldActivity,
|
||||
id: activityId,
|
||||
title: newTitleFromBody,
|
||||
__typename: 'Activity',
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -134,6 +134,7 @@ export const ActivityTitle = ({ activityId }: ActivityTitleProps) => {
|
||||
...currentActivity,
|
||||
id: activity.id,
|
||||
title: newTitle,
|
||||
__typename: activity.__typename,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -28,7 +28,6 @@ export const useRightDrawerEmailThread = () => {
|
||||
loading,
|
||||
fetchMoreRecords,
|
||||
} = useFindManyRecords<EmailThreadMessageType>({
|
||||
depth: 3,
|
||||
limit: 10,
|
||||
filter: {
|
||||
messageThreadId: {
|
||||
|
@ -5,4 +5,5 @@ export type EmailThreadMessage = {
|
||||
text: string;
|
||||
receivedAt: string;
|
||||
messageParticipants: EmailThreadMessageParticipant[];
|
||||
__typename: 'EmailThreadMessage';
|
||||
};
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { Attachment } from '@/activities/files/types/Attachment';
|
||||
import { getFileType } from '@/activities/files/utils/getFileType';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getActivityTargetObjectFieldIdName';
|
||||
import { Attachment } from '@/attachments/types/Attachment';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
|
@ -8,7 +8,9 @@ export type Attachment = {
|
||||
activityId: string;
|
||||
authorId: string;
|
||||
createdAt: string;
|
||||
__typename: string;
|
||||
};
|
||||
|
||||
export type AttachmentType =
|
||||
| 'Archive'
|
||||
| 'Audio'
|
||||
|
@ -1,12 +1,11 @@
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { QueryKey } from '@/object-record/query-keys/types/QueryKey';
|
||||
import { RecordGqlOperationSignature } from '@/object-record/graphql/types/RecordGqlOperationSignature';
|
||||
|
||||
export const FIND_MANY_ACTIVITIES_QUERY_KEY: QueryKey = {
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
variables: {},
|
||||
fieldsFactory: (_objectMetadataItems: ObjectMetadataItem[]) => {
|
||||
return {
|
||||
export const CREATE_ONE_ACTIVITY_OPERATION_SIGNATURE: RecordGqlOperationSignature =
|
||||
{
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
variables: {},
|
||||
fields: {
|
||||
id: true,
|
||||
__typename: true,
|
||||
createdAt: true,
|
||||
@ -31,8 +30,5 @@ export const FIND_MANY_ACTIVITIES_QUERY_KEY: QueryKey = {
|
||||
dueAt: true,
|
||||
reminderAt: true,
|
||||
type: true,
|
||||
activityTargets: true,
|
||||
};
|
||||
},
|
||||
depth: 2,
|
||||
};
|
||||
},
|
||||
};
|
@ -0,0 +1,45 @@
|
||||
import { generateActivityTargetMorphFieldKeys } from '@/activities/utils/generateActivityTargetMorphFieldKeys';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { RecordGqlOperationSignatureFactory } from '@/object-record/graphql/types/RecordGqlOperationSignatureFactory';
|
||||
|
||||
export const findActivitiesOperationSignatureFactory: RecordGqlOperationSignatureFactory =
|
||||
({ objectMetadataItems }: { objectMetadataItems: ObjectMetadataItem[] }) => ({
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
variables: {},
|
||||
fields: {
|
||||
id: true,
|
||||
__typename: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
author: {
|
||||
id: true,
|
||||
name: true,
|
||||
__typename: true,
|
||||
},
|
||||
authorId: true,
|
||||
assigneeId: true,
|
||||
assignee: {
|
||||
id: true,
|
||||
name: true,
|
||||
__typename: true,
|
||||
},
|
||||
comments: true,
|
||||
attachments: true,
|
||||
body: true,
|
||||
title: true,
|
||||
completedAt: true,
|
||||
dueAt: true,
|
||||
reminderAt: true,
|
||||
type: true,
|
||||
activityTargets: {
|
||||
id: true,
|
||||
__typename: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
activity: true,
|
||||
activityId: true,
|
||||
...generateActivityTargetMorphFieldKeys(objectMetadataItems),
|
||||
},
|
||||
},
|
||||
});
|
@ -1,13 +1,13 @@
|
||||
import { generateActivityTargetMorphFieldKeys } from '@/activities/utils/generateActivityTargetMorphFieldKeys';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { QueryKey } from '@/object-record/query-keys/types/QueryKey';
|
||||
import { RecordGqlOperationSignatureFactory } from '@/object-record/graphql/types/RecordGqlOperationSignatureFactory';
|
||||
|
||||
export const FIND_MANY_ACTIVITY_TARGETS_QUERY_KEY: QueryKey = {
|
||||
objectNameSingular: CoreObjectNameSingular.ActivityTarget,
|
||||
variables: {},
|
||||
fieldsFactory: (objectMetadataItems: ObjectMetadataItem[]) => {
|
||||
return {
|
||||
export const findActivityTargetsOperationSignatureFactory: RecordGqlOperationSignatureFactory =
|
||||
({ objectMetadataItems }: { objectMetadataItems: ObjectMetadataItem[] }) => ({
|
||||
objectNameSingular: CoreObjectNameSingular.ActivityTarget,
|
||||
variables: {},
|
||||
fields: {
|
||||
id: true,
|
||||
__typename: true,
|
||||
createdAt: true,
|
||||
@ -15,7 +15,5 @@ export const FIND_MANY_ACTIVITY_TARGETS_QUERY_KEY: QueryKey = {
|
||||
activity: true,
|
||||
activityId: true,
|
||||
...generateActivityTargetMorphFieldKeys(objectMetadataItems),
|
||||
};
|
||||
},
|
||||
depth: 1,
|
||||
};
|
||||
},
|
||||
});
|
@ -79,7 +79,7 @@ const mocks: MockedResponse[] = [
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
filter: { activityTargetId: { eq: '123' } },
|
||||
filter: { companyId: { eq: '123' } },
|
||||
limit: undefined,
|
||||
orderBy: undefined,
|
||||
},
|
||||
@ -180,7 +180,6 @@ describe('useActivities', () => {
|
||||
activitiesFilters: {},
|
||||
activitiesOrderByVariables: {},
|
||||
skip: false,
|
||||
skipActivityTargets: false,
|
||||
}),
|
||||
{ wrapper: Wrapper },
|
||||
);
|
||||
@ -188,8 +187,6 @@ describe('useActivities', () => {
|
||||
expect(result.current).toEqual({
|
||||
activities: [],
|
||||
loading: false,
|
||||
initialized: true,
|
||||
noActivities: true,
|
||||
});
|
||||
});
|
||||
|
||||
@ -202,12 +199,11 @@ describe('useActivities', () => {
|
||||
|
||||
const activities = useActivities({
|
||||
targetableObjects: [
|
||||
{ targetObjectNameSingular: 'activityTarget', id: '123' },
|
||||
{ targetObjectNameSingular: 'company', id: '123' },
|
||||
],
|
||||
activitiesFilters: {},
|
||||
activitiesOrderByVariables: {},
|
||||
skip: false,
|
||||
skipActivityTargets: false,
|
||||
});
|
||||
return { activities, setCurrentWorkspaceMember };
|
||||
},
|
||||
@ -218,18 +214,9 @@ describe('useActivities', () => {
|
||||
result.current.setCurrentWorkspaceMember(mockWorkspaceMembers[0]);
|
||||
});
|
||||
|
||||
expect(result.current.activities.loading).toBe(true);
|
||||
|
||||
// Wait for activityTargets to complete fetching
|
||||
await waitFor(() => !result.current.activities.loading);
|
||||
|
||||
expect(result.current.activities.loading).toBe(false);
|
||||
|
||||
// Wait for request to fetch activities to be made
|
||||
await waitFor(() => result.current.activities.loading);
|
||||
|
||||
// Wait for activities to complete fetching
|
||||
await waitFor(() => !result.current.activities.loading);
|
||||
await waitFor(() => {
|
||||
expect(result.current.activities.loading).toBe(false);
|
||||
});
|
||||
|
||||
const { activities } = result.current;
|
||||
|
||||
|
@ -10,8 +10,8 @@ import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadat
|
||||
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
|
||||
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
|
||||
import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope';
|
||||
import { JestObjectMetadataItemSetter } from '~/testing/jest/JestObjectMetadataItemSetter';
|
||||
import { mockWorkspaceMembers } from '~/testing/mock-data/workspace-members';
|
||||
|
||||
const mockObjectMetadataItems = getObjectMetadataItemsMock();
|
||||
|
||||
const cache = new InMemoryCache();
|
||||
@ -85,7 +85,6 @@ cache.writeFragment({
|
||||
id
|
||||
createdAt
|
||||
updatedAt
|
||||
targetObjectNameSingular
|
||||
personId
|
||||
companyId
|
||||
company {
|
||||
@ -114,9 +113,11 @@ cache.writeFragment({
|
||||
const Wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<RecoilRoot>
|
||||
<MockedProvider cache={cache}>
|
||||
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
|
||||
{children}
|
||||
</SnackBarProviderScope>
|
||||
<JestObjectMetadataItemSetter>
|
||||
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
|
||||
{children}
|
||||
</SnackBarProviderScope>
|
||||
</JestObjectMetadataItemSetter>
|
||||
</MockedProvider>
|
||||
</RecoilRoot>
|
||||
);
|
||||
|
@ -82,7 +82,10 @@ describe('useCreateActivityInDB', () => {
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.createActivityInDB(mockedActivity);
|
||||
await result.current.createActivityInDB({
|
||||
...mockedActivity,
|
||||
__typename: 'Activity',
|
||||
});
|
||||
});
|
||||
|
||||
expect(mocks[0].result).toHaveBeenCalled();
|
||||
|
@ -1,15 +1,14 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { findActivitiesOperationSignatureFactory } from '@/activities/graphql/operation-signatures/factories/findActivitiesOperationSignatureFactory';
|
||||
import { useActivityTargetsForTargetableObjects } from '@/activities/hooks/useActivityTargetsForTargetableObjects';
|
||||
import { FIND_MANY_ACTIVITIES_QUERY_KEY } from '@/activities/query-keys/FindManyActivitiesQueryKey';
|
||||
import { Activity } from '@/activities/types/Activity';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
||||
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';
|
||||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
import { ObjectRecordQueryFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { sortByAscString } from '~/utils/array/sortByAscString';
|
||||
|
||||
@ -18,26 +17,19 @@ export const useActivities = ({
|
||||
activitiesFilters,
|
||||
activitiesOrderByVariables,
|
||||
skip,
|
||||
skipActivityTargets,
|
||||
}: {
|
||||
targetableObjects: ActivityTargetableObject[];
|
||||
activitiesFilters: ObjectRecordQueryFilter;
|
||||
activitiesOrderByVariables: OrderByField;
|
||||
activitiesFilters: RecordGqlOperationFilter;
|
||||
activitiesOrderByVariables: RecordGqlOperationOrderBy;
|
||||
skip?: boolean;
|
||||
skipActivityTargets?: boolean;
|
||||
}) => {
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
const { objectMetadataItems } = useObjectMetadataItems();
|
||||
|
||||
const {
|
||||
activityTargets,
|
||||
loadingActivityTargets,
|
||||
initialized: initializedActivityTargets,
|
||||
} = useActivityTargetsForTargetableObjects({
|
||||
targetableObjects,
|
||||
skip: skipActivityTargets || skip,
|
||||
});
|
||||
const { activityTargets, loadingActivityTargets } =
|
||||
useActivityTargetsForTargetableObjects({
|
||||
targetableObjects,
|
||||
skip: skip,
|
||||
});
|
||||
|
||||
const activityIds = [
|
||||
...new Set(
|
||||
@ -51,70 +43,40 @@ export const useActivities = ({
|
||||
),
|
||||
];
|
||||
|
||||
const activityTargetsFound =
|
||||
initializedActivityTargets && isNonEmptyArray(activityTargets);
|
||||
|
||||
const filter: ObjectRecordQueryFilter = {
|
||||
id: activityTargetsFound
|
||||
? {
|
||||
in: activityIds,
|
||||
}
|
||||
: undefined,
|
||||
const filter: RecordGqlOperationFilter = {
|
||||
id:
|
||||
targetableObjects.length > 0
|
||||
? {
|
||||
in: activityIds,
|
||||
}
|
||||
: undefined,
|
||||
...activitiesFilters,
|
||||
};
|
||||
|
||||
const skipActivities =
|
||||
skip ||
|
||||
(!skipActivityTargets &&
|
||||
(!initializedActivityTargets || !activityTargetsFound));
|
||||
const FIND_ACTIVITIES_OPERATION_SIGNATURE =
|
||||
findActivitiesOperationSignatureFactory({ objectMetadataItems });
|
||||
|
||||
const { records: activities, loading: loadingActivities } =
|
||||
useFindManyRecords<Activity>({
|
||||
skip: skipActivities,
|
||||
objectNameSingular: FIND_MANY_ACTIVITIES_QUERY_KEY.objectNameSingular,
|
||||
depth: FIND_MANY_ACTIVITIES_QUERY_KEY.depth,
|
||||
queryFields:
|
||||
FIND_MANY_ACTIVITIES_QUERY_KEY.fieldsFactory?.(objectMetadataItems),
|
||||
skip: skip || loadingActivityTargets,
|
||||
objectNameSingular:
|
||||
FIND_ACTIVITIES_OPERATION_SIGNATURE.objectNameSingular,
|
||||
recordGqlFields: FIND_ACTIVITIES_OPERATION_SIGNATURE.fields,
|
||||
filter,
|
||||
orderBy: activitiesOrderByVariables,
|
||||
onCompleted: useRecoilCallback(
|
||||
({ set }) =>
|
||||
(activities) => {
|
||||
if (!initialized) {
|
||||
setInitialized(true);
|
||||
}
|
||||
|
||||
for (const activity of activities) {
|
||||
set(recordStoreFamilyState(activity.id), activity);
|
||||
}
|
||||
},
|
||||
[initialized],
|
||||
[],
|
||||
),
|
||||
});
|
||||
|
||||
const loading = loadingActivities || loadingActivityTargets;
|
||||
|
||||
const noActivities =
|
||||
(!activityTargetsFound && !skipActivityTargets && initialized) ||
|
||||
(initialized && !loading && !isNonEmptyArray(activities));
|
||||
|
||||
useEffect(() => {
|
||||
if (skipActivities || noActivities) {
|
||||
setInitialized(true);
|
||||
}
|
||||
}, [
|
||||
activities,
|
||||
initialized,
|
||||
loading,
|
||||
noActivities,
|
||||
skipActivities,
|
||||
skipActivityTargets,
|
||||
]);
|
||||
|
||||
return {
|
||||
activities,
|
||||
loading,
|
||||
initialized,
|
||||
noActivities,
|
||||
loading: loadingActivities || loadingActivityTargets,
|
||||
};
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { useState } from 'react';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { ActivityTarget } from '@/activities/types/ActivityTarget';
|
||||
@ -16,8 +15,6 @@ export const useActivityTargetsForTargetableObject = ({
|
||||
nameSingular: targetableObject.targetObjectNameSingular,
|
||||
});
|
||||
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
const targetableObjectId = targetableObject.id;
|
||||
|
||||
const skipRequest = !isNonEmptyString(targetableObjectId);
|
||||
@ -34,16 +31,10 @@ export const useActivityTargetsForTargetableObject = ({
|
||||
eq: targetableObject.id,
|
||||
},
|
||||
},
|
||||
onCompleted: () => {
|
||||
if (!initialized) {
|
||||
setInitialized(true);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
activityTargets,
|
||||
loadingActivityTargets,
|
||||
initialized,
|
||||
};
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { FIND_MANY_ACTIVITY_TARGETS_QUERY_KEY } from '@/activities/query-keys/FindManyActivityTargetsQueryKey';
|
||||
import { findActivityTargetsOperationSignatureFactory } from '@/activities/graphql/operation-signatures/factories/findActivityTargetsOperationSignatureFactory';
|
||||
import { ActivityTarget } from '@/activities/types/ActivityTarget';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { getActivityTargetsFilter } from '@/activities/utils/getActivityTargetsFilter';
|
||||
@ -11,12 +10,14 @@ import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
||||
export const useActivityTargetsForTargetableObjects = ({
|
||||
targetableObjects,
|
||||
skip,
|
||||
onCompleted,
|
||||
}: {
|
||||
targetableObjects: Pick<
|
||||
ActivityTargetableObject,
|
||||
'id' | 'targetObjectNameSingular'
|
||||
>[];
|
||||
skip?: boolean;
|
||||
onCompleted?: (activityTargets: ActivityTarget[]) => void;
|
||||
}) => {
|
||||
const activityTargetsFilter = getActivityTargetsFilter({
|
||||
targetableObjects: targetableObjects,
|
||||
@ -24,7 +25,8 @@ export const useActivityTargetsForTargetableObjects = ({
|
||||
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
const FIND_ACTIVITY_TARGETS_OPERATION_SIGNATURE =
|
||||
findActivityTargetsOperationSignatureFactory({ objectMetadataItems });
|
||||
|
||||
// TODO: We want to optimistically remove from this request
|
||||
// If we are on a show page and we remove the current show page object corresponding activity target
|
||||
@ -33,22 +35,14 @@ export const useActivityTargetsForTargetableObjects = ({
|
||||
useFindManyRecords<ActivityTarget>({
|
||||
skip,
|
||||
objectNameSingular:
|
||||
FIND_MANY_ACTIVITY_TARGETS_QUERY_KEY.objectNameSingular,
|
||||
FIND_ACTIVITY_TARGETS_OPERATION_SIGNATURE.objectNameSingular,
|
||||
filter: activityTargetsFilter,
|
||||
queryFields:
|
||||
FIND_MANY_ACTIVITY_TARGETS_QUERY_KEY.fieldsFactory?.(
|
||||
objectMetadataItems,
|
||||
),
|
||||
onCompleted: () => {
|
||||
if (!initialized) {
|
||||
setInitialized(true);
|
||||
}
|
||||
},
|
||||
recordGqlFields: FIND_ACTIVITY_TARGETS_OPERATION_SIGNATURE.fields,
|
||||
onCompleted,
|
||||
});
|
||||
|
||||
return {
|
||||
activityTargets,
|
||||
loadingActivityTargets,
|
||||
initialized,
|
||||
};
|
||||
};
|
||||
|
@ -34,7 +34,6 @@ export const useCreateActivityInCache = () => {
|
||||
const { record: currentWorkspaceMemberRecord } = useFindOneRecord({
|
||||
objectNameSingular: CoreObjectNameSingular.WorkspaceMember,
|
||||
objectRecordId: currentWorkspaceMember?.id,
|
||||
depth: 0,
|
||||
});
|
||||
|
||||
const { objectMetadataItem: objectMetadataItemActivity } =
|
||||
@ -66,6 +65,7 @@ export const useCreateActivityInCache = () => {
|
||||
|
||||
const createdActivityInCache = createOneActivityInCache({
|
||||
id: activityId,
|
||||
__typename: 'Activity',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
author: currentWorkspaceMemberRecord,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
|
||||
import { CREATE_ONE_ACTIVITY_QUERY_KEY } from '@/activities/query-keys/CreateOneActivityQueryKey';
|
||||
import { CREATE_ONE_ACTIVITY_OPERATION_SIGNATURE } from '@/activities/graphql/operation-signatures/CreateOneActivityOperationSignature';
|
||||
import { ActivityForEditor } from '@/activities/types/ActivityForEditor';
|
||||
import { ActivityTarget } from '@/activities/types/ActivityTarget';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
@ -9,9 +9,9 @@ import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
|
||||
export const useCreateActivityInDB = () => {
|
||||
const { createOneRecord: createOneActivity } = useCreateOneRecord({
|
||||
objectNameSingular: CREATE_ONE_ACTIVITY_QUERY_KEY.objectNameSingular,
|
||||
queryFields: CREATE_ONE_ACTIVITY_QUERY_KEY.fields,
|
||||
depth: CREATE_ONE_ACTIVITY_QUERY_KEY.depth,
|
||||
objectNameSingular:
|
||||
CREATE_ONE_ACTIVITY_OPERATION_SIGNATURE.objectNameSingular,
|
||||
recordGqlFields: CREATE_ONE_ACTIVITY_OPERATION_SIGNATURE.fields,
|
||||
});
|
||||
|
||||
const { createManyRecords: createManyActivityTargets } =
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
|
||||
import { FIND_MANY_ACTIVITIES_QUERY_KEY } from '@/activities/query-keys/FindManyActivitiesQueryKey';
|
||||
import { findActivitiesOperationSignatureFactory } from '@/activities/graphql/operation-signatures/factories/findActivitiesOperationSignatureFactory';
|
||||
import { Activity } from '@/activities/types/Activity';
|
||||
import { ActivityTarget } from '@/activities/types/ActivityTarget';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
@ -104,15 +104,16 @@ export const usePrepareFindManyActivitiesQuery = () => {
|
||||
return a.createdAt > b.createdAt ? -1 : 1;
|
||||
});
|
||||
|
||||
const FIND_ACTIVITIES_OPERATION_SIGNATURE =
|
||||
findActivitiesOperationSignatureFactory({ objectMetadataItems });
|
||||
|
||||
upsertFindManyActivitiesInCache({
|
||||
objectRecordsToOverwrite: filteredActivities,
|
||||
queryVariables: {
|
||||
...nextFindManyActivitiesQueryFilter,
|
||||
orderBy: { createdAt: 'DescNullsFirst' },
|
||||
},
|
||||
depth: FIND_MANY_ACTIVITIES_QUERY_KEY.depth,
|
||||
queryFields:
|
||||
FIND_MANY_ACTIVITIES_QUERY_KEY.fieldsFactory?.(objectMetadataItems),
|
||||
recordGqlFields: FIND_ACTIVITIES_OPERATION_SIGNATURE.fields,
|
||||
computeReferences: true,
|
||||
});
|
||||
};
|
||||
|
@ -27,14 +27,10 @@ export const Notes = ({
|
||||
}: {
|
||||
targetableObject: ActivityTargetableObject;
|
||||
}) => {
|
||||
const { notes, initialized } = useNotes(targetableObject);
|
||||
const { notes } = useNotes(targetableObject);
|
||||
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
if (!initialized) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
if (notes?.length === 0) {
|
||||
return (
|
||||
<AnimatedPlaceholderEmptyContainer>
|
||||
|
@ -6,7 +6,6 @@ import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableE
|
||||
jest.mock('@/activities/hooks/useActivities', () => ({
|
||||
useActivities: jest.fn(() => ({
|
||||
activities: [{ id: '1', content: 'Example Note' }],
|
||||
initialized: true,
|
||||
loading: false,
|
||||
})),
|
||||
}));
|
||||
@ -29,7 +28,7 @@ jest.mock('recoil', () => {
|
||||
});
|
||||
|
||||
describe('useNotes', () => {
|
||||
it('should return notes, initialized, and loading as expected', () => {
|
||||
it('should return notes, and loading as expected', () => {
|
||||
const mockTargetableObject: ActivityTargetableObject = {
|
||||
id: '1',
|
||||
targetObjectNameSingular: 'Example Target',
|
||||
@ -39,7 +38,6 @@ describe('useNotes', () => {
|
||||
expect(result.current.notes).toEqual([
|
||||
{ id: '1', content: 'Example Note' },
|
||||
]);
|
||||
expect(result.current.initialized).toBe(true);
|
||||
expect(result.current.loading).toBe(false);
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,7 @@ import { useActivities } from '@/activities/hooks/useActivities';
|
||||
import { currentNotesQueryVariablesState } from '@/activities/notes/states/currentNotesQueryVariablesState';
|
||||
import { FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY } from '@/activities/timeline/constants/FindManyTimelineActivitiesOrderBy';
|
||||
import { Note } from '@/activities/types/Note';
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
import { ActivityTargetableObject } from '../../types/ActivityTargetableEntity';
|
||||
@ -18,11 +18,11 @@ export const useNotes = (targetableObject: ActivityTargetableObject) => {
|
||||
type: { eq: 'Note' },
|
||||
},
|
||||
orderBy: FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY,
|
||||
}) as ObjectRecordQueryVariables,
|
||||
}) as RecordGqlOperationVariables,
|
||||
[],
|
||||
);
|
||||
|
||||
const { activities, initialized, loading } = useActivities({
|
||||
const { activities, loading } = useActivities({
|
||||
activitiesFilters: notesQueryVariables.filter ?? {},
|
||||
activitiesOrderByVariables: notesQueryVariables.orderBy ?? {},
|
||||
targetableObjects: [targetableObject],
|
||||
@ -44,7 +44,6 @@ export const useNotes = (targetableObject: ActivityTargetableObject) => {
|
||||
|
||||
return {
|
||||
notes: activities as Note[],
|
||||
initialized,
|
||||
loading,
|
||||
};
|
||||
};
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
|
||||
export const currentNotesQueryVariablesState =
|
||||
atom<ObjectRecordQueryVariables | null>({
|
||||
atom<RecordGqlOperationVariables | null>({
|
||||
default: null,
|
||||
key: 'currentNotesQueryVariablesState',
|
||||
});
|
||||
|
@ -1,34 +0,0 @@
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { QueryKey } from '@/object-record/query-keys/types/QueryKey';
|
||||
|
||||
export const CREATE_ONE_ACTIVITY_QUERY_KEY: QueryKey = {
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
variables: {},
|
||||
fields: {
|
||||
id: true,
|
||||
__typename: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
author: {
|
||||
id: true,
|
||||
name: true,
|
||||
__typename: true,
|
||||
},
|
||||
authorId: true,
|
||||
assigneeId: true,
|
||||
assignee: {
|
||||
id: true,
|
||||
name: true,
|
||||
__typename: true,
|
||||
},
|
||||
comments: true,
|
||||
attachments: true,
|
||||
body: true,
|
||||
title: true,
|
||||
completedAt: true,
|
||||
dueAt: true,
|
||||
reminderAt: true,
|
||||
type: true,
|
||||
},
|
||||
depth: 1,
|
||||
};
|
@ -19,7 +19,6 @@ import { useDeleteRecordFromCache } from '@/object-record/cache/hooks/useDeleteR
|
||||
import { useDeleteManyRecords } from '@/object-record/hooks/useDeleteManyRecords';
|
||||
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
|
||||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
||||
import { getChildRelationArray } from '@/object-record/utils/getChildRelationArray';
|
||||
import { mapToRecordId } from '@/object-record/utils/mapToObjectId';
|
||||
import { IconButton } from '@/ui/input/button/components/IconButton';
|
||||
import { isRightDrawerOpenState } from '@/ui/layout/right-drawer/states/isRightDrawerOpenState';
|
||||
@ -85,10 +84,6 @@ export const ActivityActionBar = () => {
|
||||
.getLoadable(recordStoreFamilyState(activityIdInDrawer))
|
||||
.getValue() as Activity;
|
||||
|
||||
const activityTargets = getChildRelationArray({
|
||||
childRelation: activity.activityTargets,
|
||||
});
|
||||
|
||||
setIsRightDrawerOpen(false);
|
||||
|
||||
if (!isNonEmptyString(viewableActivityId)) {
|
||||
@ -103,10 +98,10 @@ export const ActivityActionBar = () => {
|
||||
|
||||
if (isNonEmptyString(activityIdInDrawer)) {
|
||||
const activityTargetIdsToDelete: string[] =
|
||||
activityTargets.map(mapToRecordId) ?? [];
|
||||
activity.activityTargets.map(mapToRecordId) ?? [];
|
||||
|
||||
deleteActivityFromCache(activity);
|
||||
activityTargets.forEach((activityTarget: ActivityTarget) => {
|
||||
activity.activityTargets.forEach((activityTarget: ActivityTarget) => {
|
||||
deleteActivityTargetFromCache(activityTarget);
|
||||
});
|
||||
|
||||
|
@ -18,7 +18,6 @@ export const CurrentUserDueTaskCountEffect = () => {
|
||||
|
||||
const { records: tasks } = useFindManyRecords<Activity>({
|
||||
objectNameSingular: CoreObjectNameSingular.Activity,
|
||||
depth: 0,
|
||||
filter: {
|
||||
type: { eq: 'Task' },
|
||||
completedAt: { is: 'NULL' },
|
||||
|
@ -40,7 +40,6 @@ export const TaskGroups = ({
|
||||
upcomingTasks,
|
||||
unscheduledTasks,
|
||||
completedTasks,
|
||||
initialized,
|
||||
} = useTasks({
|
||||
filterDropdownId: filterDropdownId,
|
||||
targetableObjects: targetableObjects ?? [],
|
||||
@ -51,10 +50,6 @@ export const TaskGroups = ({
|
||||
const { activeTabIdState } = useTabList(TASKS_TAB_LIST_COMPONENT_ID);
|
||||
const activeTabId = useRecoilValue(activeTabIdState);
|
||||
|
||||
if (!initialized) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
if (
|
||||
(activeTabId !== 'done' &&
|
||||
todayOrPreviousTasks?.length === 0 &&
|
||||
|
@ -49,7 +49,6 @@ const useActivitiesMock = jest.fn(
|
||||
activities: isCompletedFilter
|
||||
? completedTasks
|
||||
: [...todayOrPreviousTasks, ...unscheduledTasks],
|
||||
initialized: true,
|
||||
};
|
||||
},
|
||||
);
|
||||
@ -79,7 +78,6 @@ describe('useTasks', () => {
|
||||
upcomingTasks: [],
|
||||
unscheduledTasks,
|
||||
completedTasks,
|
||||
initialized: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { DateTime } from 'luxon';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
|
||||
@ -9,8 +8,8 @@ import { currentIncompleteTaskQueryVariablesState } from '@/activities/tasks/sta
|
||||
import { FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY } from '@/activities/timeline/constants/FindManyTimelineActivitiesOrderBy';
|
||||
import { Activity } from '@/activities/types/Activity';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown';
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { parseDate } from '~/utils/date-utils';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
|
||||
@ -41,8 +40,6 @@ export const useTasks = ({
|
||||
[selectedFilter],
|
||||
);
|
||||
|
||||
const skipActivityTargets = !isNonEmptyArray(targetableObjects);
|
||||
|
||||
const completedQueryVariables = useMemo(
|
||||
() =>
|
||||
({
|
||||
@ -52,7 +49,7 @@ export const useTasks = ({
|
||||
...assigneeIdFilter,
|
||||
},
|
||||
orderBy: FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY,
|
||||
}) as ObjectRecordQueryVariables,
|
||||
}) as RecordGqlOperationVariables,
|
||||
[assigneeIdFilter],
|
||||
);
|
||||
|
||||
@ -65,7 +62,7 @@ export const useTasks = ({
|
||||
...assigneeIdFilter,
|
||||
},
|
||||
orderBy: FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY,
|
||||
}) as ObjectRecordQueryVariables,
|
||||
}) as RecordGqlOperationVariables,
|
||||
[assigneeIdFilter],
|
||||
);
|
||||
|
||||
@ -110,24 +107,16 @@ export const useTasks = ({
|
||||
setCurrentIncompleteTaskQueryVariables,
|
||||
]);
|
||||
|
||||
const {
|
||||
activities: completeTasksData,
|
||||
initialized: initializedCompleteTasks,
|
||||
} = useActivities({
|
||||
const { activities: completeTasksData } = useActivities({
|
||||
targetableObjects,
|
||||
activitiesFilters: completedQueryVariables.filter ?? {},
|
||||
activitiesOrderByVariables: completedQueryVariables.orderBy ?? {},
|
||||
skipActivityTargets,
|
||||
});
|
||||
|
||||
const {
|
||||
activities: incompleteTaskData,
|
||||
initialized: initializedIncompleteTasks,
|
||||
} = useActivities({
|
||||
const { activities: incompleteTaskData } = useActivities({
|
||||
targetableObjects,
|
||||
activitiesFilters: incompleteQueryVariables.filter ?? {},
|
||||
activitiesOrderByVariables: incompleteQueryVariables.orderBy ?? {},
|
||||
skipActivityTargets,
|
||||
});
|
||||
|
||||
const todayOrPreviousTasks = incompleteTaskData?.filter((task) => {
|
||||
@ -159,6 +148,5 @@ export const useTasks = ({
|
||||
upcomingTasks: (upcomingTasks ?? []) as Activity[],
|
||||
unscheduledTasks: (unscheduledTasks ?? []) as Activity[],
|
||||
completedTasks: (completedTasks ?? []) as Activity[],
|
||||
initialized: initializedCompleteTasks && initializedIncompleteTasks,
|
||||
};
|
||||
};
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
|
||||
export const currentCompletedTaskQueryVariablesState =
|
||||
atom<ObjectRecordQueryVariables | null>({
|
||||
atom<RecordGqlOperationVariables | null>({
|
||||
default: null,
|
||||
key: 'currentCompletedTaskQueryVariablesState',
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
|
||||
export const currentIncompleteTaskQueryVariablesState =
|
||||
atom<ObjectRecordQueryVariables | null>({
|
||||
atom<RecordGqlOperationVariables | null>({
|
||||
default: null,
|
||||
key: 'currentIncompleteTaskQueryVariablesState',
|
||||
});
|
||||
|
@ -2,7 +2,7 @@ import styled from '@emotion/styled';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { TimelineCreateButtonGroup } from '@/activities/timeline/components/TimelineCreateButtonGroup';
|
||||
import { timelineActivitiesNetworkingState } from '@/activities/timeline/states/timelineActivitiesNetworkingState';
|
||||
import { timelineActivitiesForGroupState } from '@/activities/timeline/states/timelineActivitiesForGroupState';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
|
||||
import {
|
||||
@ -32,20 +32,11 @@ export const Timeline = ({
|
||||
}: {
|
||||
targetableObject: ActivityTargetableObject;
|
||||
}) => {
|
||||
const { initialized, noActivities } = useRecoilValue(
|
||||
timelineActivitiesNetworkingState,
|
||||
const timelineActivitiesForGroup = useRecoilValue(
|
||||
timelineActivitiesForGroupState,
|
||||
);
|
||||
|
||||
const showEmptyState = noActivities;
|
||||
|
||||
const showLoadingState = !initialized;
|
||||
|
||||
if (showLoadingState) {
|
||||
// TODO: Display a beautiful loading page
|
||||
return <></>;
|
||||
}
|
||||
|
||||
if (showEmptyState) {
|
||||
if (timelineActivitiesForGroup.length === 0) {
|
||||
return (
|
||||
<AnimatedPlaceholderEmptyContainer>
|
||||
<AnimatedPlaceholder type="emptyTimeline" />
|
||||
|
@ -6,7 +6,6 @@ import { FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY } from '@/activities/timeline/co
|
||||
import { objectShowPageTargetableObjectState } from '@/activities/timeline/states/objectShowPageTargetableObjectIdState';
|
||||
import { timelineActivitiesFammilyState } from '@/activities/timeline/states/timelineActivitiesFamilyState';
|
||||
import { timelineActivitiesForGroupState } from '@/activities/timeline/states/timelineActivitiesForGroupState';
|
||||
import { timelineActivitiesNetworkingState } from '@/activities/timeline/states/timelineActivitiesNetworkingState';
|
||||
import { timelineActivityWithoutTargetsFamilyState } from '@/activities/timeline/states/timelineActivityWithoutTargetsFamilyState';
|
||||
import { Activity } from '@/activities/types/Activity';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
@ -27,16 +26,13 @@ export const TimelineQueryEffect = ({
|
||||
setTimelineTargetableObject(targetableObject);
|
||||
}, [targetableObject, setTimelineTargetableObject]);
|
||||
|
||||
const { activities, initialized, noActivities } = useActivities({
|
||||
const { activities } = useActivities({
|
||||
targetableObjects: [targetableObject],
|
||||
activitiesFilters: {},
|
||||
activitiesOrderByVariables: FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY,
|
||||
skip: !isDefined(targetableObject),
|
||||
});
|
||||
|
||||
const [timelineActivitiesNetworking, setTimelineActivitiesNetworking] =
|
||||
useRecoilState(timelineActivitiesNetworkingState);
|
||||
|
||||
const [timelineActivitiesForGroup, setTimelineActivitiesForGroup] =
|
||||
useRecoilState(timelineActivitiesForGroupState);
|
||||
|
||||
@ -49,6 +45,7 @@ export const TimelineQueryEffect = ({
|
||||
...activities.map((activity) => ({
|
||||
id: activity.id,
|
||||
createdAt: activity.createdAt,
|
||||
__typename: activity.__typename,
|
||||
})),
|
||||
].sort(sortObjectRecordByDateField('createdAt', 'DescNullsLast'));
|
||||
|
||||
@ -59,23 +56,9 @@ export const TimelineQueryEffect = ({
|
||||
if (!isDeeplyEqual(activitiesForGroup, timelineActivitiesForGroupSorted)) {
|
||||
setTimelineActivitiesForGroup(activitiesForGroup);
|
||||
}
|
||||
|
||||
if (
|
||||
!isDeeplyEqual(timelineActivitiesNetworking.initialized, initialized) ||
|
||||
!isDeeplyEqual(timelineActivitiesNetworking.noActivities, noActivities)
|
||||
) {
|
||||
setTimelineActivitiesNetworking({
|
||||
initialized,
|
||||
noActivities,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
activities,
|
||||
initialized,
|
||||
noActivities,
|
||||
setTimelineActivitiesNetworking,
|
||||
targetableObject,
|
||||
timelineActivitiesNetworking,
|
||||
timelineActivitiesForGroup,
|
||||
setTimelineActivitiesForGroup,
|
||||
]);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';
|
||||
|
||||
export const FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY: OrderByField = {
|
||||
createdAt: 'DescNullsFirst',
|
||||
};
|
||||
export const FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY: RecordGqlOperationOrderBy =
|
||||
{
|
||||
createdAt: 'DescNullsFirst',
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { isNonEmptyArray, isNonEmptyString } from '@sniptt/guards';
|
||||
import { useRecoilCallback, useRecoilState } from 'recoil';
|
||||
|
||||
@ -28,15 +28,10 @@ export const useTimelineActivities = ({
|
||||
}
|
||||
}, [targetableObject, setObjectShowPageTargetableObject]);
|
||||
|
||||
const {
|
||||
activityTargets,
|
||||
loadingActivityTargets,
|
||||
initialized: initializedActivityTargets,
|
||||
} = useActivityTargetsForTargetableObject({
|
||||
targetableObject,
|
||||
});
|
||||
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
const { activityTargets, loadingActivityTargets } =
|
||||
useActivityTargetsForTargetableObject({
|
||||
targetableObject,
|
||||
});
|
||||
|
||||
const activityIds = Array.from(
|
||||
new Set(
|
||||
@ -65,33 +60,18 @@ export const useTimelineActivities = ({
|
||||
onCompleted: useRecoilCallback(
|
||||
({ set }) =>
|
||||
(activities) => {
|
||||
if (!initialized) {
|
||||
setInitialized(true);
|
||||
}
|
||||
|
||||
for (const activity of activities) {
|
||||
set(recordStoreFamilyState(activity.id), activity);
|
||||
}
|
||||
},
|
||||
[initialized],
|
||||
[],
|
||||
),
|
||||
depth: 3,
|
||||
});
|
||||
|
||||
const noActivityTargets =
|
||||
initializedActivityTargets && !isNonEmptyArray(activityTargets);
|
||||
|
||||
useEffect(() => {
|
||||
if (noActivityTargets) {
|
||||
setInitialized(true);
|
||||
}
|
||||
}, [noActivityTargets]);
|
||||
|
||||
const loading = loadingActivities || loadingActivityTargets;
|
||||
|
||||
return {
|
||||
activities,
|
||||
loading,
|
||||
initialized,
|
||||
};
|
||||
};
|
||||
|
@ -1,12 +0,0 @@
|
||||
import { createState } from 'twenty-ui';
|
||||
|
||||
export const timelineActivitiesNetworkingState = createState<{
|
||||
initialized: boolean;
|
||||
noActivities: boolean;
|
||||
}>({
|
||||
key: 'timelineActivitiesNetworkingState',
|
||||
defaultValue: {
|
||||
initialized: false,
|
||||
noActivities: false,
|
||||
},
|
||||
});
|
@ -1,7 +1,10 @@
|
||||
import { Activity } from '@/activities/types/Activity';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export type ActivityForActivityGroup = Pick<Activity, 'id' | 'createdAt'>;
|
||||
export type ActivityForActivityGroup = Pick<
|
||||
Activity,
|
||||
'id' | 'createdAt' | '__typename'
|
||||
>;
|
||||
|
||||
export type ActivityGroup = {
|
||||
month: number;
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { sortByAscString } from '~/utils/array/sortByAscString';
|
||||
|
||||
// Todo: this should be replace by the operationSignatureFactory pattern
|
||||
export const makeTimelineActivitiesQueryVariables = ({
|
||||
activityIds,
|
||||
}: {
|
||||
activityIds: string[];
|
||||
}): ObjectRecordQueryVariables => {
|
||||
}): RecordGqlOperationVariables => {
|
||||
return {
|
||||
filter: {
|
||||
id: {
|
||||
|
@ -12,4 +12,5 @@ export type TimelineActivity = {
|
||||
linkedRecordCachedName: string;
|
||||
linkedRecordId: string;
|
||||
linkedObjectMetadataId: string;
|
||||
__typename: 'TimelineActivity';
|
||||
};
|
||||
|
@ -5,7 +5,14 @@ import { WorkspaceMember } from '~/generated-metadata/graphql';
|
||||
|
||||
export type ActivityForEditor = Pick<
|
||||
Activity,
|
||||
'id' | 'title' | 'body' | 'type' | 'completedAt' | 'dueAt' | 'updatedAt'
|
||||
| 'id'
|
||||
| 'title'
|
||||
| 'body'
|
||||
| 'type'
|
||||
| 'completedAt'
|
||||
| 'dueAt'
|
||||
| 'updatedAt'
|
||||
| '__typename'
|
||||
> & {
|
||||
comments?: Comment[];
|
||||
} & {
|
||||
|
@ -12,4 +12,5 @@ export type ActivityTarget = {
|
||||
person?: Pick<Person, 'id' | 'name' | 'avatarUrl'> | null;
|
||||
company?: Pick<Company, 'id' | 'name' | 'domainName'> | null;
|
||||
[key: string]: any;
|
||||
__typename: 'ActivityTarget';
|
||||
};
|
||||
|
@ -7,4 +7,5 @@ export type Comment = {
|
||||
updatedAt: string;
|
||||
activityId: string;
|
||||
author: Pick<WorkspaceMember, 'id' | 'name' | 'avatarUrl'>;
|
||||
__typename: 'Comment';
|
||||
};
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Reference, StoreObject } from '@apollo/client';
|
||||
import { ReadFieldFunction } from '@apollo/client/cache/core/types/common';
|
||||
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { sortAsc, sortDesc, sortNullsFirst, sortNullsLast } from '~/utils/sort';
|
||||
|
||||
@ -12,8 +12,8 @@ export const sortCachedObjectEdges = ({
|
||||
orderBy,
|
||||
readCacheField,
|
||||
}: {
|
||||
edges: CachedObjectRecordEdge[];
|
||||
orderBy: OrderByField;
|
||||
edges: RecordGqlRefEdge[];
|
||||
orderBy: RecordGqlOperationOrderBy;
|
||||
readCacheField: ReadFieldFunction;
|
||||
}) => {
|
||||
const [orderByFieldName, orderByFieldValue] = Object.entries(orderBy)[0];
|
||||
@ -23,7 +23,7 @@ export const sortCachedObjectEdges = ({
|
||||
: Object.entries(orderByFieldValue)[0];
|
||||
|
||||
const readFieldValueToSort = (
|
||||
edge: CachedObjectRecordEdge,
|
||||
edge: RecordGqlRefEdge,
|
||||
): string | number | null => {
|
||||
const recordFromCache = edge.node;
|
||||
const fieldValue =
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ApolloCache, StoreObject } from '@apollo/client';
|
||||
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { isObjectRecordConnectionWithRefs } from '@/object-record/cache/utils/isObjectRecordConnectionWithRefs';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
@ -48,7 +48,7 @@ export const triggerAttachRelationOptimisticEffect = ({
|
||||
}
|
||||
|
||||
if (fieldValueisObjectRecordConnectionWithRefs) {
|
||||
const nextEdges: CachedObjectRecordEdge[] = [
|
||||
const nextEdges: RecordGqlRefEdge[] = [
|
||||
...targetRecordFieldValue.edges,
|
||||
{
|
||||
__typename: `${sourceRecordTypeName}Edge`,
|
||||
|
@ -2,11 +2,11 @@ import { ApolloCache, StoreObject } from '@apollo/client';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import { triggerUpdateRelationsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect';
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
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';
|
||||
|
||||
/*
|
||||
TODO: for now new records are added to all cached record lists, no matter what the variables (filters, orderBy, etc.) are.
|
||||
@ -21,7 +21,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
}: {
|
||||
cache: ApolloCache<unknown>;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
recordsToCreate: CachedObjectRecord[];
|
||||
recordsToCreate: RecordGqlNode[];
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
}) => {
|
||||
recordsToCreate.forEach((record) =>
|
||||
@ -56,7 +56,7 @@ export const triggerCreateRecordsOptimisticEffect = ({
|
||||
|
||||
const rootQueryCachedObjectRecordConnection = rootQueryCachedResponse;
|
||||
|
||||
const rootQueryCachedRecordEdges = readField<CachedObjectRecordEdge[]>(
|
||||
const rootQueryCachedRecordEdges = readField<RecordGqlRefEdge[]>(
|
||||
'edges',
|
||||
rootQueryCachedObjectRecordConnection,
|
||||
);
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { ApolloCache, StoreObject } from '@apollo/client';
|
||||
|
||||
import { triggerUpdateRelationsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect';
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { CachedObjectRecordQueryVariables } from '@/apollo/types/CachedObjectRecordQueryVariables';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { isObjectRecordConnectionWithRefs } from '@/object-record/cache/utils/isObjectRecordConnectionWithRefs';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { parseApolloStoreFieldName } from '~/utils/parseApolloStoreFieldName';
|
||||
|
||||
@ -17,7 +17,7 @@ export const triggerDeleteRecordsOptimisticEffect = ({
|
||||
}: {
|
||||
cache: ApolloCache<unknown>;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
recordsToDelete: CachedObjectRecord[];
|
||||
recordsToDelete: RecordGqlNode[];
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
}) => {
|
||||
cache.modify<StoreObject>({
|
||||
@ -45,7 +45,7 @@ export const triggerDeleteRecordsOptimisticEffect = ({
|
||||
|
||||
const recordIdsToDelete = recordsToDelete.map(({ id }) => id);
|
||||
|
||||
const cachedEdges = readField<CachedObjectRecordEdge[]>(
|
||||
const cachedEdges = readField<RecordGqlRefEdge[]>(
|
||||
'edges',
|
||||
rootQueryCachedObjectRecordConnection,
|
||||
);
|
||||
|
@ -2,12 +2,12 @@ import { ApolloCache, StoreObject } from '@apollo/client';
|
||||
|
||||
import { sortCachedObjectEdges } from '@/apollo/optimistic-effect/utils/sortCachedObjectEdges';
|
||||
import { triggerUpdateRelationsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerUpdateRelationsOptimisticEffect';
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { CachedObjectRecordQueryVariables } from '@/apollo/types/CachedObjectRecordQueryVariables';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
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 { isDefined } from '~/utils/isDefined';
|
||||
import { parseApolloStoreFieldName } from '~/utils/parseApolloStoreFieldName';
|
||||
@ -23,8 +23,8 @@ export const triggerUpdateRecordOptimisticEffect = ({
|
||||
}: {
|
||||
cache: ApolloCache<unknown>;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
currentRecord: CachedObjectRecord;
|
||||
updatedRecord: CachedObjectRecord;
|
||||
currentRecord: RecordGqlNode;
|
||||
updatedRecord: RecordGqlNode;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
}) => {
|
||||
triggerUpdateRelationsOptimisticEffect({
|
||||
@ -58,8 +58,7 @@ export const triggerUpdateRecordOptimisticEffect = ({
|
||||
);
|
||||
|
||||
const rootQueryCurrentEdges =
|
||||
readField<CachedObjectRecordEdge[]>('edges', rootQueryConnection) ??
|
||||
[];
|
||||
readField<RecordGqlRefEdge[]>('edges', rootQueryConnection) ?? [];
|
||||
|
||||
let rootQueryNextEdges = [...rootQueryCurrentEdges];
|
||||
|
||||
|
@ -4,12 +4,13 @@ import { getRelationDefinition } from '@/apollo/optimistic-effect/utils/getRelat
|
||||
import { triggerAttachRelationOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerAttachRelationOptimisticEffect';
|
||||
import { triggerDeleteRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDeleteRecordsOptimisticEffect';
|
||||
import { triggerDetachRelationOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDetachRelationOptimisticEffect';
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { CORE_OBJECT_NAMES_TO_DELETE_ON_TRIGGER_RELATION_DETACH } from '@/apollo/types/coreObjectNamesToDeleteOnRelationDetach';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { isObjectRecordConnection } from '@/object-record/cache/utils/isObjectRecordConnection';
|
||||
import { ObjectRecordConnection } from '@/object-record/types/ObjectRecordConnection';
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
@ -23,8 +24,8 @@ export const triggerUpdateRelationsOptimisticEffect = ({
|
||||
}: {
|
||||
cache: ApolloCache<unknown>;
|
||||
sourceObjectMetadataItem: ObjectMetadataItem;
|
||||
currentSourceRecord: CachedObjectRecord | null;
|
||||
updatedSourceRecord: CachedObjectRecord | null;
|
||||
currentSourceRecord: ObjectRecord | null;
|
||||
updatedSourceRecord: ObjectRecord | null;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
}) => {
|
||||
return sourceObjectMetadataItem.fields.forEach(
|
||||
@ -56,13 +57,13 @@ export const triggerUpdateRelationsOptimisticEffect = ({
|
||||
relationDefinition;
|
||||
|
||||
const currentFieldValueOnSourceRecord:
|
||||
| ObjectRecordConnection
|
||||
| CachedObjectRecord
|
||||
| RecordGqlConnection
|
||||
| RecordGqlNode
|
||||
| null = currentSourceRecord?.[fieldMetadataItemOnSourceRecord.name];
|
||||
|
||||
const updatedFieldValueOnSourceRecord:
|
||||
| ObjectRecordConnection
|
||||
| CachedObjectRecord
|
||||
| RecordGqlConnection
|
||||
| RecordGqlNode
|
||||
| null = updatedSourceRecord?.[fieldMetadataItemOnSourceRecord.name];
|
||||
|
||||
if (
|
||||
@ -85,7 +86,7 @@ export const triggerUpdateRelationsOptimisticEffect = ({
|
||||
const targetRecordsToDetachFrom =
|
||||
currentFieldValueOnSourceRecordIsARecordConnection
|
||||
? currentFieldValueOnSourceRecord.edges.map(
|
||||
({ node }) => node as CachedObjectRecord,
|
||||
({ node }) => node as RecordGqlNode,
|
||||
)
|
||||
: [currentFieldValueOnSourceRecord].filter(isDefined);
|
||||
|
||||
@ -98,7 +99,7 @@ export const triggerUpdateRelationsOptimisticEffect = ({
|
||||
const targetRecordsToAttachTo =
|
||||
updatedFieldValueOnSourceRecordIsARecordConnection
|
||||
? updatedFieldValueOnSourceRecord.edges.map(
|
||||
({ node }) => node as CachedObjectRecord,
|
||||
({ node }) => node as RecordGqlNode,
|
||||
)
|
||||
: [updatedFieldValueOnSourceRecord].filter(isDefined);
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
|
||||
export type CachedObjectRecord<T extends ObjectRecord = ObjectRecord> = T & {
|
||||
__typename: string;
|
||||
};
|
@ -1,9 +0,0 @@
|
||||
import { CachedObjectRecordEdge } from '@/apollo/types/CachedObjectRecordEdge';
|
||||
import { ObjectRecordConnection } from '@/object-record/types/ObjectRecordConnection';
|
||||
|
||||
export type CachedObjectRecordConnection = Omit<
|
||||
ObjectRecordConnection,
|
||||
'edges'
|
||||
> & {
|
||||
edges: CachedObjectRecordEdge[];
|
||||
};
|
@ -1,7 +0,0 @@
|
||||
import { Reference } from '@apollo/client';
|
||||
|
||||
import { ObjectRecordEdge } from '@/object-record/types/ObjectRecordEdge';
|
||||
|
||||
export type CachedObjectRecordEdge = Omit<ObjectRecordEdge, 'node'> & {
|
||||
node: Reference;
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
|
||||
export type CachedObjectRecordQueryVariables = Omit<
|
||||
ObjectRecordQueryVariables,
|
||||
RecordGqlOperationVariables,
|
||||
'limit'
|
||||
> & { first?: ObjectRecordQueryVariables['limit'] };
|
||||
> & { first?: RecordGqlOperationVariables['limit'] };
|
||||
|
@ -1,6 +0,0 @@
|
||||
export type Attachment = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
};
|
@ -9,4 +9,5 @@ export type Favorite = {
|
||||
avatarType: AvatarType;
|
||||
link: string;
|
||||
recordId: string;
|
||||
__typename: 'Favorite';
|
||||
};
|
||||
|
@ -4,6 +4,7 @@ import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import { useFindManyObjectMetadataItems } from '@/object-metadata/hooks/useFindManyObjectMetadataItems';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
|
||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
|
||||
@ -19,10 +20,18 @@ export const ObjectMetadataItemsLoadEffect = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isDeeplyEqual(objectMetadataItems, newObjectMetadataItems)) {
|
||||
setObjectMetadataItems(newObjectMetadataItems);
|
||||
const toSetObjectMetadataItems = isUndefinedOrNull(currentUser)
|
||||
? getObjectMetadataItemsMock()
|
||||
: newObjectMetadataItems;
|
||||
if (!isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems)) {
|
||||
setObjectMetadataItems(toSetObjectMetadataItems);
|
||||
}
|
||||
}, [newObjectMetadataItems, objectMetadataItems, setObjectMetadataItems]);
|
||||
}, [
|
||||
currentUser,
|
||||
newObjectMetadataItems,
|
||||
objectMetadataItems,
|
||||
setObjectMetadataItems,
|
||||
]);
|
||||
|
||||
return <></>;
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { ObjectMetadataItemsLoadEffect } from '@/object-metadata/components/ObjectMetadataItemsLoadEffect';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { RelationPickerScope } from '@/object-record/relation-picker/scopes/RelationPickerScope';
|
||||
@ -10,10 +9,8 @@ export const ObjectMetadataItemsProvider = ({
|
||||
children,
|
||||
}: React.PropsWithChildren) => {
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
||||
|
||||
const shouldDisplayChildren =
|
||||
objectMetadataItems.length > 0 || !currentWorkspaceMember;
|
||||
const shouldDisplayChildren = objectMetadataItems.length > 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -5,7 +5,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
|
||||
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
|
||||
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
|
||||
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
|
||||
import { GraphQLView } from '@/views/types/GraphQLView';
|
||||
import { View } from '@/views/types/View';
|
||||
import { getObjectMetadataItemViews } from '@/views/utils/getObjectMetadataItemViews';
|
||||
|
||||
export const ObjectMetadataNavItems = () => {
|
||||
@ -14,9 +14,7 @@ export const ObjectMetadataNavItems = () => {
|
||||
const { getIcon } = useIcons();
|
||||
const currentPath = useLocation().pathname;
|
||||
|
||||
const { records: views } = usePrefetchedData<GraphQLView>(
|
||||
PrefetchKey.AllViews,
|
||||
);
|
||||
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { getOrderByFieldForObjectMetadataItem } from '@/object-metadata/utils/getObjectOrderByField';
|
||||
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';
|
||||
|
||||
export const useGetObjectOrderByField = ({
|
||||
objectNameSingular,
|
||||
@ -12,7 +12,9 @@ export const useGetObjectOrderByField = ({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const getObjectOrderByField = (orderBy: OrderBy): OrderByField => {
|
||||
const getObjectOrderByField = (
|
||||
orderBy: OrderBy,
|
||||
): RecordGqlOperationOrderBy => {
|
||||
return getOrderByFieldForObjectMetadataItem(objectMetadataItem, orderBy);
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@ export const useObjectMetadataItem = ({
|
||||
}: ObjectMetadataItemIdentifier) => {
|
||||
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
||||
|
||||
// Todo: deprecate this logic as mocked objectMetadataItems are laod in ObjectMetadataItemsLoadEffect anyway
|
||||
const mockObjectMetadataItems = getObjectMetadataItemsMock();
|
||||
|
||||
let objectMetadataItem = useRecoilValue(
|
||||
|
@ -37,21 +37,10 @@ describe('mapFieldMetadataToGraphQLQuery', () => {
|
||||
lastName
|
||||
}`);
|
||||
});
|
||||
it('should not return relation if depth is < 1', async () => {
|
||||
const res = mapFieldMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
depth: 0,
|
||||
field: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'company',
|
||||
)!,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual('');
|
||||
});
|
||||
|
||||
it('should return relation if it matches depth', async () => {
|
||||
it('should return non relation subFields if relation', async () => {
|
||||
const res = mapFieldMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
depth: 1,
|
||||
field: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'company',
|
||||
)!,
|
||||
@ -83,168 +72,14 @@ accountOwnerId
|
||||
employees
|
||||
id
|
||||
idealCustomerProfile
|
||||
}`);
|
||||
});
|
||||
it('should return relation with all sub relations if it matches depth', async () => {
|
||||
const res = mapFieldMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
depth: 2,
|
||||
field: personObjectMetadataItem.fields.find(
|
||||
(field) => field.name === 'company',
|
||||
)!,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`company
|
||||
{
|
||||
__typename
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
accountOwner
|
||||
{
|
||||
__typename
|
||||
colorScheme
|
||||
name
|
||||
{
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
locale
|
||||
userId
|
||||
avatarUrl
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
}
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
attachments
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
updatedAt
|
||||
createdAt
|
||||
name
|
||||
personId
|
||||
activityId
|
||||
companyId
|
||||
id
|
||||
authorId
|
||||
type
|
||||
fullPath
|
||||
}
|
||||
}
|
||||
}
|
||||
domainName
|
||||
opportunities
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
personId
|
||||
pointOfContactId
|
||||
updatedAt
|
||||
companyId
|
||||
probability
|
||||
closeDate
|
||||
amount
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
id
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
annualRecurringRevenue
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
createdAt
|
||||
address
|
||||
updatedAt
|
||||
activityTargets
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
updatedAt
|
||||
createdAt
|
||||
personId
|
||||
activityId
|
||||
companyId
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
favorites
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
id
|
||||
companyId
|
||||
createdAt
|
||||
personId
|
||||
position
|
||||
workspaceMemberId
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
people
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
id
|
||||
createdAt
|
||||
city
|
||||
email
|
||||
jobTitle
|
||||
name
|
||||
{
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
phone
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
updatedAt
|
||||
avatarUrl
|
||||
companyId
|
||||
}
|
||||
}
|
||||
}
|
||||
name
|
||||
accountOwnerId
|
||||
employees
|
||||
id
|
||||
idealCustomerProfile
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should return GraphQL fields based on queryFields', async () => {
|
||||
it('should return only return relation subFields that are in recordGqlFields', async () => {
|
||||
const res = mapFieldMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
depth: 2,
|
||||
queryFields: {
|
||||
accountOwner: true,
|
||||
relationrecordFields: {
|
||||
accountOwner: { id: true, name: true },
|
||||
people: true,
|
||||
xLink: true,
|
||||
linkedinLink: true,
|
||||
@ -274,17 +109,11 @@ xLink
|
||||
accountOwner
|
||||
{
|
||||
__typename
|
||||
colorScheme
|
||||
name
|
||||
{
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
locale
|
||||
userId
|
||||
avatarUrl
|
||||
createdAt
|
||||
updatedAt
|
||||
id
|
||||
}
|
||||
linkedinLink
|
||||
|
@ -15,209 +15,11 @@ if (!personObjectMetadataItem) {
|
||||
}
|
||||
|
||||
describe('mapObjectMetadataToGraphQLQuery', () => {
|
||||
it('should return typename if depth < 0', async () => {
|
||||
it('should query only specified recordGqlFields', async () => {
|
||||
const res = mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
depth: -1,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`{
|
||||
__typename
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should return depth 0 if depth = 0', async () => {
|
||||
const res = mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
depth: 0,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`{
|
||||
__typename
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
id
|
||||
createdAt
|
||||
city
|
||||
email
|
||||
jobTitle
|
||||
name
|
||||
{
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
phone
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
updatedAt
|
||||
avatarUrl
|
||||
companyId
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should return depth 1 if depth = 1', async () => {
|
||||
const res = mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
depth: 1,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`{
|
||||
__typename
|
||||
opportunities
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
personId
|
||||
pointOfContactId
|
||||
updatedAt
|
||||
companyId
|
||||
probability
|
||||
closeDate
|
||||
amount
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
id
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
id
|
||||
pointOfContactForOpportunities
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
personId
|
||||
pointOfContactId
|
||||
updatedAt
|
||||
companyId
|
||||
probability
|
||||
closeDate
|
||||
amount
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
id
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
createdAt
|
||||
company
|
||||
{
|
||||
__typename
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
domainName
|
||||
annualRecurringRevenue
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
createdAt
|
||||
address
|
||||
updatedAt
|
||||
name
|
||||
accountOwnerId
|
||||
employees
|
||||
id
|
||||
idealCustomerProfile
|
||||
}
|
||||
city
|
||||
email
|
||||
activityTargets
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
updatedAt
|
||||
createdAt
|
||||
personId
|
||||
activityId
|
||||
companyId
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
jobTitle
|
||||
favorites
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
id
|
||||
companyId
|
||||
createdAt
|
||||
personId
|
||||
position
|
||||
workspaceMemberId
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
attachments
|
||||
{
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
updatedAt
|
||||
createdAt
|
||||
name
|
||||
personId
|
||||
activityId
|
||||
companyId
|
||||
id
|
||||
authorId
|
||||
type
|
||||
fullPath
|
||||
}
|
||||
}
|
||||
}
|
||||
name
|
||||
{
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
phone
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
updatedAt
|
||||
avatarUrl
|
||||
companyId
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should query only specified queryFields', async () => {
|
||||
const res = mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
queryFields: {
|
||||
recordGqlFields: {
|
||||
company: true,
|
||||
xLink: true,
|
||||
id: true,
|
||||
@ -232,7 +34,6 @@ companyId
|
||||
avatarUrl: true,
|
||||
companyId: true,
|
||||
},
|
||||
depth: 1,
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`{
|
||||
__typename
|
||||
@ -291,12 +92,11 @@ companyId
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should load only specified query fields', async () => {
|
||||
it('should load only specified operation fields nested', async () => {
|
||||
const res = mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems: mockObjectMetadataItems,
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
queryFields: { company: true, id: true, name: true },
|
||||
depth: 1,
|
||||
recordGqlFields: { company: { id: true }, id: true, name: true },
|
||||
});
|
||||
expect(formatGQLString(res)).toEqual(`{
|
||||
__typename
|
||||
@ -304,30 +104,7 @@ id
|
||||
company
|
||||
{
|
||||
__typename
|
||||
xLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
linkedinLink
|
||||
{
|
||||
label
|
||||
url
|
||||
}
|
||||
domainName
|
||||
annualRecurringRevenue
|
||||
{
|
||||
amountMicros
|
||||
currencyCode
|
||||
}
|
||||
createdAt
|
||||
address
|
||||
updatedAt
|
||||
name
|
||||
accountOwnerId
|
||||
employees
|
||||
id
|
||||
idealCustomerProfile
|
||||
}
|
||||
name
|
||||
{
|
||||
|
@ -2,113 +2,50 @@ import { shouldFieldBeQueried } from '@/object-metadata/utils/shouldFieldBeQueri
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
describe('shouldFieldBeQueried', () => {
|
||||
describe('if field is not relation', () => {
|
||||
it('should be queried if depth is undefined', () => {
|
||||
describe('if recordGqlFields is absent, we query all except relations', () => {
|
||||
it('should be queried if the field is not a relation', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should be queried depth = 0', () => {
|
||||
it('should not be queried if the field is a relation', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 0,
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should be queried depth > 0', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 1,
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should NOT be queried depth < 0', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: -1,
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
|
||||
it('should not depends on queryFields', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 0,
|
||||
queryFields: {
|
||||
fieldName: true,
|
||||
},
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Boolean },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('if field is relation', () => {
|
||||
it('should be queried if queryFields and depth are undefined', () => {
|
||||
describe('if recordGqlFields is present, we respect it', () => {
|
||||
it('should be queried if true', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
recordGqlFields: { fieldName: true },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should be queried if queryFields is undefined and depth = 1', () => {
|
||||
it('should be queried if object', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 1,
|
||||
recordGqlFields: { fieldName: { subFieldName: false } },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should be queried if queryFields is undefined and depth > 1', () => {
|
||||
it('should not be queried if false', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 2,
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should NOT be queried if queryFields is undefined and depth < 1', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 0,
|
||||
recordGqlFields: { fieldName: false },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
|
||||
it('should be queried if queryFields is matching and depth > 1', () => {
|
||||
it('should not be queried if absent', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 1,
|
||||
queryFields: { fieldName: true },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should NOT be queried if queryFields is matching and depth < 1', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 0,
|
||||
queryFields: { fieldName: true },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
|
||||
it('should NOT be queried if queryFields is not matching (falsy) and depth < 1', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 1,
|
||||
queryFields: { fieldName: false },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(false);
|
||||
});
|
||||
|
||||
it('should NOT be queried if queryFields is not matching and depth < 1', () => {
|
||||
const res = shouldFieldBeQueried({
|
||||
depth: 0,
|
||||
queryFields: { anotherFieldName: true },
|
||||
recordGqlFields: { otherFieldName: false },
|
||||
field: { name: 'fieldName', type: FieldMetadataType.Relation },
|
||||
});
|
||||
expect(res).toBe(false);
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
import { OrderByField } from '@/object-metadata/types/OrderByField';
|
||||
import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/getLabelIdentifierFieldMetadataItem';
|
||||
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export const getOrderByFieldForObjectMetadataItem = (
|
||||
objectMetadataItem: ObjectMetadataItem,
|
||||
orderBy?: OrderBy | null,
|
||||
): OrderByField => {
|
||||
): RecordGqlOperationOrderBy => {
|
||||
const labelIdentifierFieldMetadata =
|
||||
getLabelIdentifierFieldMetadataItem(objectMetadataItem);
|
||||
|
||||
|
@ -10,8 +10,7 @@ import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
||||
export const mapFieldMetadataToGraphQLQuery = ({
|
||||
objectMetadataItems,
|
||||
field,
|
||||
depth = 0,
|
||||
queryFields,
|
||||
relationrecordFields,
|
||||
computeReferences = false,
|
||||
}: {
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
@ -19,8 +18,7 @@ export const mapFieldMetadataToGraphQLQuery = ({
|
||||
FieldMetadataItem,
|
||||
'name' | 'type' | 'toRelationMetadata' | 'fromRelationMetadata'
|
||||
>;
|
||||
depth?: number;
|
||||
queryFields?: Record<string, any>;
|
||||
relationrecordFields?: Record<string, any>;
|
||||
computeReferences?: boolean;
|
||||
}): any => {
|
||||
const fieldType = field.type;
|
||||
@ -47,8 +45,7 @@ export const mapFieldMetadataToGraphQLQuery = ({
|
||||
return field.name;
|
||||
} else if (
|
||||
fieldType === 'RELATION' &&
|
||||
field.toRelationMetadata?.relationType === 'ONE_TO_MANY' &&
|
||||
depth > 0
|
||||
field.toRelationMetadata?.relationType === 'ONE_TO_MANY'
|
||||
) {
|
||||
const relationMetadataItem = objectMetadataItems.find(
|
||||
(objectMetadataItem) =>
|
||||
@ -64,15 +61,13 @@ export const mapFieldMetadataToGraphQLQuery = ({
|
||||
${mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem: relationMetadataItem,
|
||||
depth: depth - 1,
|
||||
queryFields,
|
||||
recordGqlFields: relationrecordFields,
|
||||
computeReferences: computeReferences,
|
||||
isRootLevel: false,
|
||||
})}`;
|
||||
} else if (
|
||||
fieldType === 'RELATION' &&
|
||||
field.fromRelationMetadata?.relationType === 'ONE_TO_MANY' &&
|
||||
depth > 0
|
||||
field.fromRelationMetadata?.relationType === 'ONE_TO_MANY'
|
||||
) {
|
||||
const relationMetadataItem = objectMetadataItems.find(
|
||||
(objectMetadataItem) =>
|
||||
@ -90,8 +85,7 @@ ${mapObjectMetadataToGraphQLQuery({
|
||||
node ${mapObjectMetadataToGraphQLQuery({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem: relationMetadataItem,
|
||||
depth: depth - 1,
|
||||
queryFields,
|
||||
recordGqlFields: relationrecordFields,
|
||||
computeReferences,
|
||||
isRootLevel: false,
|
||||
})}
|
||||
|
@ -5,15 +5,13 @@ import { shouldFieldBeQueried } from '@/object-metadata/utils/shouldFieldBeQueri
|
||||
export const mapObjectMetadataToGraphQLQuery = ({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
depth = 1,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
computeReferences = false,
|
||||
isRootLevel = true,
|
||||
}: {
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: Pick<ObjectMetadataItem, 'nameSingular' | 'fields'>;
|
||||
depth?: number;
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: Record<string, any>;
|
||||
computeReferences?: boolean;
|
||||
isRootLevel?: boolean;
|
||||
}): any => {
|
||||
@ -23,8 +21,7 @@ export const mapObjectMetadataToGraphQLQuery = ({
|
||||
.filter((field) =>
|
||||
shouldFieldBeQueried({
|
||||
field,
|
||||
depth,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
}),
|
||||
) ?? [];
|
||||
|
||||
@ -37,18 +34,17 @@ export const mapObjectMetadataToGraphQLQuery = ({
|
||||
return `{
|
||||
__typename
|
||||
${fieldsThatShouldBeQueried
|
||||
.map((field) =>
|
||||
mapFieldMetadataToGraphQLQuery({
|
||||
.map((field) => {
|
||||
return mapFieldMetadataToGraphQLQuery({
|
||||
objectMetadataItems,
|
||||
field,
|
||||
depth,
|
||||
queryFields:
|
||||
typeof queryFields?.[field.name] === 'boolean'
|
||||
relationrecordFields:
|
||||
typeof recordGqlFields?.[field.name] === 'boolean'
|
||||
? undefined
|
||||
: queryFields?.[field.name],
|
||||
: recordGqlFields?.[field.name],
|
||||
computeReferences,
|
||||
}),
|
||||
)
|
||||
});
|
||||
})
|
||||
.join('\n')}
|
||||
}`;
|
||||
};
|
||||
|
@ -1,36 +1,32 @@
|
||||
import { isUndefined } from '@sniptt/guards';
|
||||
|
||||
import { RecordGqlOperationGqlRecordFields } from '@/object-record/graphql/types/RecordGqlOperationGqlRecordFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
|
||||
import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
||||
|
||||
export const shouldFieldBeQueried = ({
|
||||
field,
|
||||
depth,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
}: {
|
||||
field: Pick<FieldMetadataItem, 'name' | 'type'>;
|
||||
depth?: number;
|
||||
objectRecord?: ObjectRecord;
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: RecordGqlOperationGqlRecordFields;
|
||||
}): any => {
|
||||
if (!isUndefined(depth) && depth < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!isUndefined(depth) &&
|
||||
depth < 1 &&
|
||||
field.type === FieldMetadataType.Relation
|
||||
isUndefinedOrNull(recordGqlFields) &&
|
||||
field.type !== FieldMetadataType.Relation
|
||||
) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
isDefined(recordGqlFields) &&
|
||||
isDefined(recordGqlFields[field.name]) &&
|
||||
recordGqlFields[field.name] !== false
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isDefined(queryFields) && !queryFields[field.name]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
@ -1 +0,0 @@
|
||||
export const MAX_QUERY_DEPTH_FOR_CACHE_INJECTION = 1;
|
@ -7,6 +7,7 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
|
||||
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
|
||||
import { getRecordNodeFromRecord } from '@/object-record/cache/utils/getRecordNodeFromRecord';
|
||||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { prefillRecord } from '@/object-record/utils/prefillRecord';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
@ -32,13 +33,15 @@ export const useCreateOneRecordInCache = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
computeReferences: true,
|
||||
recordGqlFields: generateDepthOneRecordGqlFields({
|
||||
objectMetadataItem,
|
||||
}),
|
||||
})}
|
||||
`;
|
||||
|
||||
const prefilledRecord = prefillRecord({
|
||||
objectMetadataItem,
|
||||
input: record,
|
||||
depth: 1,
|
||||
});
|
||||
|
||||
const recordToCreateWithNestedConnections = getRecordNodeFromRecord({
|
||||
|
@ -5,33 +5,46 @@ import { useRecoilValue } from 'recoil';
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { getRecordFromCache } from '@/object-record/cache/utils/getRecordFromCache';
|
||||
import { RecordGqlFields } from '@/object-record/graphql/types/RecordGqlFields';
|
||||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
|
||||
export const useGetRecordFromCache = ({
|
||||
objectNameSingular,
|
||||
recordGqlFields,
|
||||
}: {
|
||||
objectNameSingular: string;
|
||||
recordGqlFields?: RecordGqlFields;
|
||||
}) => {
|
||||
const { objectMetadataItem } = useObjectMetadataItem({
|
||||
objectNameSingular,
|
||||
});
|
||||
|
||||
const appliedRecordGqlFields =
|
||||
recordGqlFields ?? generateDepthOneRecordGqlFields({ objectMetadataItem });
|
||||
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
return useCallback(
|
||||
<CachedObjectRecord extends ObjectRecord = ObjectRecord>(
|
||||
<T extends ObjectRecord = ObjectRecord>(
|
||||
recordId: string,
|
||||
cache = apolloClient.cache,
|
||||
) => {
|
||||
return getRecordFromCache<CachedObjectRecord>({
|
||||
return getRecordFromCache<T>({
|
||||
cache,
|
||||
recordId,
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
recordGqlFields: appliedRecordGqlFields,
|
||||
});
|
||||
},
|
||||
[objectMetadataItem, objectMetadataItems, apolloClient],
|
||||
[
|
||||
apolloClient.cache,
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
appliedRecordGqlFields,
|
||||
],
|
||||
);
|
||||
};
|
||||
|
@ -3,9 +3,9 @@ import { useApolloClient } from '@apollo/client';
|
||||
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
|
||||
import { RecordGqlOperationFindManyResult } from '@/object-record/graphql/types/RecordGqlOperationFindManyResult';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordQueryResult } from '@/object-record/types/ObjectRecordQueryResult';
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { generateFindManyRecordsQuery } from '@/object-record/utils/generateFindManyRecordsQuery';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
@ -22,32 +22,28 @@ export const useReadFindManyRecordsQueryInCache = ({
|
||||
T extends ObjectRecord = ObjectRecord,
|
||||
>({
|
||||
queryVariables,
|
||||
queryFields,
|
||||
depth,
|
||||
recordGqlFields,
|
||||
}: {
|
||||
queryVariables: ObjectRecordQueryVariables;
|
||||
queryFields?: Record<string, any>;
|
||||
depth?: number;
|
||||
queryVariables: RecordGqlOperationVariables;
|
||||
recordGqlFields?: Record<string, any>;
|
||||
}) => {
|
||||
const findManyRecordsQueryForCacheRead = generateFindManyRecordsQuery({
|
||||
objectMetadataItem,
|
||||
objectMetadataItems,
|
||||
queryFields,
|
||||
depth,
|
||||
recordGqlFields,
|
||||
});
|
||||
|
||||
const existingRecordsQueryResult = apolloClient.readQuery<
|
||||
ObjectRecordQueryResult<T>
|
||||
>({
|
||||
query: findManyRecordsQueryForCacheRead,
|
||||
variables: queryVariables,
|
||||
});
|
||||
const existingRecordsQueryResult =
|
||||
apolloClient.readQuery<RecordGqlOperationFindManyResult>({
|
||||
query: findManyRecordsQueryForCacheRead,
|
||||
variables: queryVariables,
|
||||
});
|
||||
|
||||
const existingRecordConnection =
|
||||
existingRecordsQueryResult?.[objectMetadataItem.namePlural];
|
||||
|
||||
const existingObjectRecords = isDefined(existingRecordConnection)
|
||||
? getRecordsFromRecordConnection({
|
||||
? getRecordsFromRecordConnection<T>({
|
||||
recordConnection: existingRecordConnection,
|
||||
})
|
||||
: [];
|
||||
|
@ -3,10 +3,9 @@ import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { MAX_QUERY_DEPTH_FOR_CACHE_INJECTION } from '@/object-record/cache/constants/MaxQueryDepthForCacheInjection';
|
||||
import { getRecordConnectionFromRecords } from '@/object-record/cache/utils/getRecordConnectionFromRecords';
|
||||
import { RecordGqlOperationVariables } from '@/object-record/graphql/types/RecordGqlOperationVariables';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordQueryVariables } from '@/object-record/types/ObjectRecordQueryVariables';
|
||||
import { generateFindManyRecordsQuery } from '@/object-record/utils/generateFindManyRecordsQuery';
|
||||
|
||||
export const useUpsertFindManyRecordsQueryInCache = ({
|
||||
@ -22,22 +21,19 @@ export const useUpsertFindManyRecordsQueryInCache = ({
|
||||
T extends ObjectRecord = ObjectRecord,
|
||||
>({
|
||||
queryVariables,
|
||||
depth = MAX_QUERY_DEPTH_FOR_CACHE_INJECTION,
|
||||
objectRecordsToOverwrite,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
computeReferences = false,
|
||||
}: {
|
||||
queryVariables: ObjectRecordQueryVariables;
|
||||
depth?: number;
|
||||
queryVariables: RecordGqlOperationVariables;
|
||||
objectRecordsToOverwrite: T[];
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: Record<string, any>;
|
||||
computeReferences?: boolean;
|
||||
}) => {
|
||||
const findManyRecordsQueryForCacheOverwrite = generateFindManyRecordsQuery({
|
||||
objectMetadataItem,
|
||||
objectMetadataItems,
|
||||
depth,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
computeReferences,
|
||||
});
|
||||
|
||||
@ -45,7 +41,7 @@ export const useUpsertFindManyRecordsQueryInCache = ({
|
||||
objectMetadataItems: objectMetadataItems,
|
||||
objectMetadataItem: objectMetadataItem,
|
||||
records: objectRecordsToOverwrite,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
computeReferences,
|
||||
});
|
||||
|
||||
|
6
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefConnection.ts
vendored
Normal file
6
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefConnection.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { RecordGqlRefEdge } from '@/object-record/cache/types/RecordGqlRefEdge';
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
|
||||
export type RecordGqlRefConnection = Omit<RecordGqlConnection, 'edges'> & {
|
||||
edges: RecordGqlRefEdge[];
|
||||
};
|
6
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefEdge.ts
vendored
Normal file
6
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefEdge.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { RecordGqlRefNode } from '@/object-record/cache/types/RecordGqlRefNode';
|
||||
import { RecordGqlEdge } from '@/object-record/graphql/types/RecordGqlEdge';
|
||||
|
||||
export type RecordGqlRefEdge = Omit<RecordGqlEdge, 'node'> & {
|
||||
node: RecordGqlRefNode;
|
||||
};
|
3
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefNode.ts
vendored
Normal file
3
packages/twenty-front/src/modules/object-record/cache/types/RecordGqlRefNode.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { Reference } from '@apollo/client';
|
||||
|
||||
export type RecordGqlRefNode = Reference;
|
@ -2,18 +2,18 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getConnectionTypename } from '@/object-record/cache/utils/getConnectionTypename';
|
||||
import { getEmptyPageInfo } from '@/object-record/cache/utils/getEmptyPageInfo';
|
||||
import { getRecordEdgeFromRecord } from '@/object-record/cache/utils/getRecordEdgeFromRecord';
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
import { RecordGqlOperationGqlRecordFields } from '@/object-record/graphql/types/RecordGqlOperationGqlRecordFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordConnection } from '@/object-record/types/ObjectRecordConnection';
|
||||
|
||||
export const getRecordConnectionFromRecords = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
records,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
withPageInfo = true,
|
||||
computeReferences = false,
|
||||
isRootLevel = true,
|
||||
depth = 1,
|
||||
}: {
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: Pick<
|
||||
@ -21,11 +21,10 @@ export const getRecordConnectionFromRecords = <T extends ObjectRecord>({
|
||||
'fields' | 'namePlural' | 'nameSingular'
|
||||
>;
|
||||
records: T[];
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: RecordGqlOperationGqlRecordFields;
|
||||
withPageInfo?: boolean;
|
||||
isRootLevel?: boolean;
|
||||
computeReferences?: boolean;
|
||||
depth?: number;
|
||||
}) => {
|
||||
return {
|
||||
__typename: getConnectionTypename(objectMetadataItem.nameSingular),
|
||||
@ -33,14 +32,13 @@ export const getRecordConnectionFromRecords = <T extends ObjectRecord>({
|
||||
return getRecordEdgeFromRecord({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
record,
|
||||
isRootLevel,
|
||||
computeReferences,
|
||||
depth,
|
||||
});
|
||||
}),
|
||||
...(withPageInfo && { pageInfo: getEmptyPageInfo() }),
|
||||
...(withPageInfo && { totalCount: records.length }),
|
||||
} as ObjectRecordConnection<T>;
|
||||
} as RecordGqlConnection;
|
||||
};
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getEdgeTypename } from '@/object-record/cache/utils/getEdgeTypename';
|
||||
import { getRecordNodeFromRecord } from '@/object-record/cache/utils/getRecordNodeFromRecord';
|
||||
import { RecordGqlEdge } from '@/object-record/graphql/types/RecordGqlEdge';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordEdge } from '@/object-record/types/ObjectRecordEdge';
|
||||
|
||||
export const getRecordEdgeFromRecord = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
record,
|
||||
computeReferences = false,
|
||||
isRootLevel = false,
|
||||
@ -17,10 +17,9 @@ export const getRecordEdgeFromRecord = <T extends ObjectRecord>({
|
||||
ObjectMetadataItem,
|
||||
'fields' | 'namePlural' | 'nameSingular'
|
||||
>;
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: Record<string, any>;
|
||||
computeReferences?: boolean;
|
||||
isRootLevel?: boolean;
|
||||
depth?: number;
|
||||
record: T;
|
||||
}) => {
|
||||
return {
|
||||
@ -29,13 +28,12 @@ export const getRecordEdgeFromRecord = <T extends ObjectRecord>({
|
||||
...getRecordNodeFromRecord({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
record,
|
||||
computeReferences,
|
||||
isRootLevel,
|
||||
depth: 1,
|
||||
}),
|
||||
},
|
||||
cursor: '',
|
||||
} as ObjectRecordEdge<T>;
|
||||
} as RecordGqlEdge;
|
||||
};
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { ApolloCache, gql } from '@apollo/client';
|
||||
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
|
||||
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
|
||||
import { RecordGqlFields } from '@/object-record/graphql/types/RecordGqlFields';
|
||||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
@ -13,16 +14,21 @@ export const getRecordFromCache = <T extends ObjectRecord = ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
cache,
|
||||
recordId,
|
||||
recordGqlFields,
|
||||
}: {
|
||||
cache: ApolloCache<object>;
|
||||
recordId: string;
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
recordGqlFields?: RecordGqlFields;
|
||||
}) => {
|
||||
if (isUndefinedOrNull(objectMetadataItem)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const appliedRecordGqlFields =
|
||||
recordGqlFields ?? generateDepthOneRecordGqlFields({ objectMetadataItem });
|
||||
|
||||
const capitalizedObjectName = capitalize(objectMetadataItem.nameSingular);
|
||||
|
||||
const cacheReadFragment = gql`
|
||||
@ -30,6 +36,7 @@ export const getRecordFromCache = <T extends ObjectRecord = ObjectRecord>({
|
||||
{
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
recordGqlFields: appliedRecordGqlFields,
|
||||
},
|
||||
)}
|
||||
`;
|
||||
@ -49,7 +56,7 @@ export const getRecordFromCache = <T extends ObjectRecord = ObjectRecord>({
|
||||
return null;
|
||||
}
|
||||
|
||||
return getRecordFromRecordNode({
|
||||
return getRecordFromRecordNode<T>({
|
||||
recordNode: record,
|
||||
}) as CachedObjectRecord<T>;
|
||||
});
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
@ -6,7 +7,7 @@ import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
export const getRecordFromRecordNode = <T extends ObjectRecord>({
|
||||
recordNode,
|
||||
}: {
|
||||
recordNode: T;
|
||||
recordNode: RecordGqlNode;
|
||||
}): T => {
|
||||
return {
|
||||
...Object.fromEntries(
|
||||
@ -32,5 +33,6 @@ export const getRecordFromRecordNode = <T extends ObjectRecord>({
|
||||
}),
|
||||
),
|
||||
id: recordNode.id,
|
||||
__typename: recordNode.__typename,
|
||||
} as T;
|
||||
};
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { isNull, isUndefined } from '@sniptt/guards';
|
||||
|
||||
import { CachedObjectRecord } from '@/apollo/types/CachedObjectRecord';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getNodeTypename } from '@/object-record/cache/utils/getNodeTypename';
|
||||
import { getObjectTypename } from '@/object-record/cache/utils/getObjectTypename';
|
||||
import { getRecordConnectionFromRecords } from '@/object-record/cache/utils/getRecordConnectionFromRecords';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import {
|
||||
FieldMetadataType,
|
||||
@ -16,22 +16,20 @@ import { lowerAndCapitalize } from '~/utils/string/lowerAndCapitalize';
|
||||
export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
queryFields,
|
||||
recordGqlFields,
|
||||
record,
|
||||
computeReferences = true,
|
||||
isRootLevel = true,
|
||||
depth = 1,
|
||||
}: {
|
||||
objectMetadataItems: ObjectMetadataItem[];
|
||||
objectMetadataItem: Pick<
|
||||
ObjectMetadataItem,
|
||||
'fields' | 'namePlural' | 'nameSingular'
|
||||
>;
|
||||
queryFields?: Record<string, any>;
|
||||
recordGqlFields?: Record<string, any>;
|
||||
computeReferences?: boolean;
|
||||
isRootLevel?: boolean;
|
||||
record: T | null;
|
||||
depth?: number;
|
||||
}) => {
|
||||
if (isNull(record)) {
|
||||
return null;
|
||||
@ -42,13 +40,13 @@ export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
if (!isRootLevel && computeReferences) {
|
||||
return {
|
||||
__ref: `${nodeTypeName}:${record.id}`,
|
||||
} as unknown as CachedObjectRecord<T>; // Todo Fix typing
|
||||
} as unknown as RecordGqlNode; // Fix typing: we want a Reference in computeReferences mode
|
||||
}
|
||||
|
||||
const nestedRecord = Object.fromEntries(
|
||||
Object.entries(record)
|
||||
.map(([fieldName, value]) => {
|
||||
if (isDefined(queryFields) && !queryFields[fieldName]) {
|
||||
if (isDefined(recordGqlFields) && !recordGqlFields[fieldName]) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -60,14 +58,6 @@ export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
!isUndefined(depth) &&
|
||||
depth < 1 &&
|
||||
field.type === FieldMetadataType.Relation
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
field.type === FieldMetadataType.Relation &&
|
||||
field.relationDefinition?.direction ===
|
||||
@ -87,15 +77,14 @@ export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem: oneToManyObjectMetadataItem,
|
||||
records: value as ObjectRecord[],
|
||||
queryFields:
|
||||
queryFields?.[fieldName] === true ||
|
||||
isUndefined(queryFields?.[fieldName])
|
||||
recordGqlFields:
|
||||
recordGqlFields?.[fieldName] === true ||
|
||||
isUndefined(recordGqlFields?.[fieldName])
|
||||
? undefined
|
||||
: queryFields?.[fieldName],
|
||||
: recordGqlFields?.[fieldName],
|
||||
withPageInfo: false,
|
||||
isRootLevel: false,
|
||||
computeReferences,
|
||||
depth: depth - 1,
|
||||
}),
|
||||
];
|
||||
}
|
||||
@ -159,8 +148,5 @@ export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
||||
.filter(isDefined),
|
||||
) as T; // Todo fix typing once we have investigated apollo edges / nodes removal
|
||||
|
||||
return {
|
||||
__typename: getNodeTypename(objectMetadataItem.nameSingular),
|
||||
...nestedRecord,
|
||||
};
|
||||
return { ...nestedRecord, __typename: nodeTypeName };
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordConnection } from '@/object-record/types/ObjectRecordConnection';
|
||||
|
||||
export const getRecordsFromRecordConnection = <T extends ObjectRecord>({
|
||||
recordConnection,
|
||||
}: {
|
||||
recordConnection: ObjectRecordConnection<T>;
|
||||
recordConnection: RecordGqlConnection;
|
||||
}): T[] => {
|
||||
return recordConnection.edges.map((edge) =>
|
||||
getRecordFromRecordNode<T>({ recordNode: edge.node }),
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ObjectRecordConnection } from '@/object-record/types/ObjectRecordConnection';
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const isObjectRecordConnection = (
|
||||
objectNameSingular: string,
|
||||
value: unknown,
|
||||
): value is ObjectRecordConnection => {
|
||||
): value is RecordGqlConnection => {
|
||||
const objectConnectionTypeName = `${capitalize(
|
||||
objectNameSingular,
|
||||
)}Connection`;
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { StoreValue } from '@apollo/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { CachedObjectRecordConnection } from '@/apollo/types/CachedObjectRecordConnection';
|
||||
import { RecordGqlRefConnection } from '@/object-record/cache/types/RecordGqlRefConnection';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
|
||||
export const isObjectRecordConnectionWithRefs = (
|
||||
objectNameSingular: string,
|
||||
storeValue: StoreValue,
|
||||
): storeValue is CachedObjectRecordConnection => {
|
||||
): storeValue is RecordGqlRefConnection => {
|
||||
const objectConnectionTypeName = `${capitalize(
|
||||
objectNameSingular,
|
||||
)}Connection`;
|
||||
|
@ -4,6 +4,7 @@ import gql from 'graphql-tag';
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
|
||||
import { getRecordNodeFromRecord } from '@/object-record/cache/utils/getRecordNodeFromRecord';
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
@ -44,14 +45,13 @@ export const updateRecordFromCache = <T extends ObjectRecord>({
|
||||
objectMetadataItems,
|
||||
objectMetadataItem,
|
||||
record,
|
||||
depth: 1,
|
||||
});
|
||||
|
||||
if (isUndefinedOrNull(recordWithConnection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cache.writeFragment<T & { __typename: string }>({
|
||||
cache.writeFragment<RecordGqlNode>({
|
||||
id: cachedRecordId,
|
||||
fragment: cacheWriteFragment,
|
||||
data: recordWithConnection,
|
||||
|
@ -1,11 +1,10 @@
|
||||
import { Nullable } from 'twenty-ui';
|
||||
|
||||
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
|
||||
import { ObjectRecordEdge } from '@/object-record/types/ObjectRecordEdge';
|
||||
import { RecordGqlEdge } from '@/object-record/graphql/types/RecordGqlEdge';
|
||||
|
||||
export type ObjectRecordConnection<T extends ObjectRecord = ObjectRecord> = {
|
||||
export type RecordGqlConnection = {
|
||||
__typename?: string;
|
||||
edges: ObjectRecordEdge<T>[];
|
||||
edges: RecordGqlEdge[];
|
||||
pageInfo: {
|
||||
hasNextPage?: boolean;
|
||||
hasPreviousPage?: boolean;
|
@ -0,0 +1,7 @@
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
|
||||
export type RecordGqlEdge = {
|
||||
__typename: string;
|
||||
node: RecordGqlNode;
|
||||
cursor: string;
|
||||
};
|
@ -0,0 +1 @@
|
||||
export type RecordGqlFields = Record<string, any>;
|
@ -0,0 +1,5 @@
|
||||
export type RecordGqlNode = {
|
||||
id: string;
|
||||
[key: string]: any;
|
||||
__typename: string;
|
||||
};
|
@ -93,22 +93,22 @@ export type LeafFilter =
|
||||
| undefined;
|
||||
|
||||
export type AndObjectRecordFilter = {
|
||||
and?: ObjectRecordQueryFilter[];
|
||||
and?: RecordGqlOperationFilter[];
|
||||
};
|
||||
|
||||
export type OrObjectRecordFilter = {
|
||||
or?: ObjectRecordQueryFilter[] | ObjectRecordQueryFilter;
|
||||
or?: RecordGqlOperationFilter[] | RecordGqlOperationFilter;
|
||||
};
|
||||
|
||||
export type NotObjectRecordFilter = {
|
||||
not?: ObjectRecordQueryFilter;
|
||||
not?: RecordGqlOperationFilter;
|
||||
};
|
||||
|
||||
export type LeafObjectRecordFilter = {
|
||||
[fieldName: string]: LeafFilter;
|
||||
};
|
||||
|
||||
export type ObjectRecordQueryFilter =
|
||||
export type RecordGqlOperationFilter =
|
||||
| LeafObjectRecordFilter
|
||||
| AndObjectRecordFilter
|
||||
| OrObjectRecordFilter
|
@ -0,0 +1,5 @@
|
||||
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
|
||||
|
||||
export type RecordGqlOperationFindManyResult = {
|
||||
[objectNamePlural: string]: RecordGqlConnection;
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
import { RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
|
||||
|
||||
export type RecordGqlOperationFindOneResult = {
|
||||
[objectNameSingular: string]: RecordGqlNode;
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
import { RecordGqlFields } from '@/object-record/graphql/types/RecordGqlFields';
|
||||
|
||||
export type RecordGqlOperationGqlRecordFields = RecordGqlFields;
|
@ -1,5 +1,5 @@
|
||||
import { OrderBy } from '@/object-metadata/types/OrderBy';
|
||||
|
||||
export type OrderByField = {
|
||||
export type RecordGqlOperationOrderBy = {
|
||||
[fieldName: string]: OrderBy | { [subFieldName: string]: OrderBy };
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user