[Refactor] Activity morph: first phase (#1075)

* Add company and person on update and create

* Enable reading with error management on commentable ID

* [CHECKPOINT] backward-compatible

* Migrate data for activity targets

* Revert "Migrate data for activity targets"

This reverts commit f89bc30689655c83cd5370331fec41b59d03fdb9.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Emilien Chauvet
2023-08-05 00:33:50 +02:00
committed by GitHub
parent 04297b0556
commit ed1662223a
11 changed files with 80 additions and 18 deletions

View File

@ -2328,7 +2328,7 @@ export type CreateActivityMutationVariables = Exact<{
}>; }>;
export type CreateActivityMutation = { __typename?: 'Mutation', createOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, authorId: string, type: ActivityType, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, activityId: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null, comments?: Array<{ __typename?: 'Comment', id: string, createdAt: string, updatedAt: string, body: string, author: { __typename?: 'User', id: string } }> | null } }; export type CreateActivityMutation = { __typename?: 'Mutation', createOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, authorId: string, type: ActivityType, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, activityId: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null, comments?: Array<{ __typename?: 'Comment', id: string, createdAt: string, updatedAt: string, body: string, author: { __typename?: 'User', id: string } }> | null } };
export type GetActivitiesByTargetsQueryVariables = Exact<{ export type GetActivitiesByTargetsQueryVariables = Exact<{
activityTargetIds: Array<Scalars['String']> | Scalars['String']; activityTargetIds: Array<Scalars['String']> | Scalars['String'];
@ -2336,7 +2336,7 @@ export type GetActivitiesByTargetsQueryVariables = Exact<{
}>; }>;
export type GetActivitiesByTargetsQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, title?: string | null, body?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: string, updatedAt: string, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null }> }; export type GetActivitiesByTargetsQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, title?: string | null, body?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: string, updatedAt: string, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null }> };
export type GetActivitiesQueryVariables = Exact<{ export type GetActivitiesQueryVariables = Exact<{
where: ActivityWhereInput; where: ActivityWhereInput;
@ -2344,14 +2344,14 @@ export type GetActivitiesQueryVariables = Exact<{
}>; }>;
export type GetActivitiesQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, title?: string | null, body?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null }> }; export type GetActivitiesQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, title?: string | null, body?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null }> };
export type GetActivityQueryVariables = Exact<{ export type GetActivityQueryVariables = Exact<{
activityId: Scalars['String']; activityId: Scalars['String'];
}>; }>;
export type GetActivityQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, body?: string | null, title?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: string, updatedAt: string, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null }> }; export type GetActivityQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, body?: string | null, title?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: string, updatedAt: string, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null }> };
export type AddActivityTargetsOnActivityMutationVariables = Exact<{ export type AddActivityTargetsOnActivityMutationVariables = Exact<{
activityId: Scalars['String']; activityId: Scalars['String'];
@ -2359,7 +2359,7 @@ export type AddActivityTargetsOnActivityMutationVariables = Exact<{
}>; }>;
export type AddActivityTargetsOnActivityMutation = { __typename?: 'Mutation', updateOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null } }; export type AddActivityTargetsOnActivityMutation = { __typename?: 'Mutation', updateOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null } };
export type RemoveActivityTargetsOnActivityMutationVariables = Exact<{ export type RemoveActivityTargetsOnActivityMutationVariables = Exact<{
activityId: Scalars['String']; activityId: Scalars['String'];
@ -2367,7 +2367,7 @@ export type RemoveActivityTargetsOnActivityMutationVariables = Exact<{
}>; }>;
export type RemoveActivityTargetsOnActivityMutation = { __typename?: 'Mutation', updateOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, commentableType?: CommentableType | null, commentableId?: string | null }> | null } }; export type RemoveActivityTargetsOnActivityMutation = { __typename?: 'Mutation', updateOneActivity: { __typename?: 'Activity', id: string, createdAt: string, updatedAt: string, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, createdAt: string, updatedAt: string, commentableType?: CommentableType | null, commentableId?: string | null, companyId?: string | null, personId?: string | null }> | null } };
export type DeleteActivityMutationVariables = Exact<{ export type DeleteActivityMutationVariables = Exact<{
activityId: Scalars['String']; activityId: Scalars['String'];
@ -2849,6 +2849,8 @@ export const CreateActivityDocument = gql`
activityId activityId
commentableType commentableType
commentableId commentableId
companyId
personId
} }
comments { comments {
id id
@ -2931,6 +2933,8 @@ export const GetActivitiesByTargetsDocument = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -2994,6 +2998,8 @@ export const GetActivitiesDocument = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -3067,6 +3073,8 @@ export const GetActivityDocument = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -3114,6 +3122,8 @@ export const AddActivityTargetsOnActivityDocument = gql`
updatedAt updatedAt
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -3160,6 +3170,8 @@ export const RemoveActivityTargetsOnActivityDocument = gql`
updatedAt updatedAt
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }

View File

@ -27,7 +27,10 @@ import { flatMapAndSortEntityForSelectArrayOfArrayByName } from '../utils/flatMa
type OwnProps = { type OwnProps = {
activity?: Pick<Activity, 'id'> & { activity?: Pick<Activity, 'id'> & {
activityTargets: Array< activityTargets: Array<
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'> Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'companyId' | 'personId'
>
>; >;
}; };
}; };
@ -87,7 +90,7 @@ export function ActivityRelationPicker({ activity }: OwnProps) {
() => () =>
activity?.activityTargets activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Person') ?.filter((relation) => relation.commentableType === 'Person')
.map((relation) => relation.commentableId) .map((relation) => relation.personId || relation.commentableId)
.filter(assertNotNull) ?? [], .filter(assertNotNull) ?? [],
[activity?.activityTargets], [activity?.activityTargets],
); );
@ -96,7 +99,7 @@ export function ActivityRelationPicker({ activity }: OwnProps) {
() => () =>
activity?.activityTargets activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Company') ?.filter((relation) => relation.commentableType === 'Company')
.map((relation) => relation.commentableId) .map((relation) => relation.companyId || relation.commentableId)
.filter(assertNotNull) ?? [], .filter(assertNotNull) ?? [],
[activity?.activityTargets], [activity?.activityTargets],
); );

View File

@ -68,7 +68,9 @@ export function TaskRow({ task }: { task: TaskForList }) {
in: task?.activityTargets in: task?.activityTargets
? task?.activityTargets ? task?.activityTargets
.filter((target) => target.commentableType === 'Person') .filter((target) => target.commentableType === 'Person')
.map((target) => target.commentableId ?? '') .map(
(target) => (target.personId || target.commentableId) ?? '',
)
: [], : [],
}, },
}, },
@ -82,7 +84,9 @@ export function TaskRow({ task }: { task: TaskForList }) {
in: task?.activityTargets in: task?.activityTargets
? task?.activityTargets ? task?.activityTargets
.filter((target) => target.commentableType === 'Company') .filter((target) => target.commentableType === 'Company')
.map((target) => target.commentableId ?? '') .map(
(target) => (target.companyId || target.commentableId) ?? '',
)
: [], : [],
}, },
}, },

View File

@ -16,7 +16,10 @@ import { ActivityRelationEditableFieldEditMode } from './ActivityRelationEditabl
type OwnProps = { type OwnProps = {
activity?: Pick<Activity, 'id'> & { activity?: Pick<Activity, 'id'> & {
activityTargets?: Array< activityTargets?: Array<
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'> Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
>
> | null; > | null;
}; };
}; };
@ -29,7 +32,9 @@ export function ActivityRelationEditableField({ activity }: OwnProps) {
in: activity?.activityTargets in: activity?.activityTargets
? activity?.activityTargets ? activity?.activityTargets
.filter((target) => target.commentableType === 'Person') .filter((target) => target.commentableType === 'Person')
.map((target) => target.commentableId ?? '') .map(
(target) => (target.personId || target.commentableId) ?? '',
)
: [], : [],
}, },
}, },
@ -43,7 +48,9 @@ export function ActivityRelationEditableField({ activity }: OwnProps) {
in: activity?.activityTargets in: activity?.activityTargets
? activity?.activityTargets ? activity?.activityTargets
.filter((target) => target.commentableType === 'Company') .filter((target) => target.commentableType === 'Company')
.map((target) => target.commentableId ?? '') .map(
(target) => (target.companyId || target.commentableId) ?? '',
)
: [], : [],
}, },
}, },

View File

@ -13,7 +13,10 @@ import { assertNotNull } from '~/utils/assert';
type OwnProps = { type OwnProps = {
activity?: Pick<Activity, 'id'> & { activity?: Pick<Activity, 'id'> & {
activityTargets?: Array< activityTargets?: Array<
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'> Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
>
> | null; > | null;
}; };
}; };
@ -31,7 +34,7 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
() => () =>
activity?.activityTargets activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Person') ?.filter((relation) => relation.commentableType === 'Person')
.map((relation) => relation.commentableId) .map((relation) => relation.personId || relation.commentableId)
.filter(assertNotNull) ?? [], .filter(assertNotNull) ?? [],
[activity?.activityTargets], [activity?.activityTargets],
); );
@ -40,7 +43,7 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
() => () =>
activity?.activityTargets activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Company') ?.filter((relation) => relation.commentableType === 'Company')
.map((relation) => relation.commentableId) .map((relation) => relation.companyId || relation.commentableId)
.filter(assertNotNull) ?? [], .filter(assertNotNull) ?? [],
[activity?.activityTargets], [activity?.activityTargets],
); );

View File

@ -6,6 +6,7 @@ import { GET_PEOPLE } from '@/people/queries';
import { import {
Activity, Activity,
ActivityTarget, ActivityTarget,
CommentableType,
useAddActivityTargetsOnActivityMutation, useAddActivityTargetsOnActivityMutation,
useRemoveActivityTargetsOnActivityMutation, useRemoveActivityTargetsOnActivityMutation,
} from '~/generated/graphql'; } from '~/generated/graphql';
@ -65,6 +66,10 @@ export function useHandleCheckableActivityTargetChange({
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
commentableType: entity.entityType, commentableType: entity.entityType,
commentableId: entity.id, commentableId: entity.id,
companyId:
entity.entityType === CommentableType.Company ? entity.id : null,
personId:
entity.entityType === CommentableType.Person ? entity.id : null,
})), })),
}, },
}); });

View File

@ -9,7 +9,11 @@ import { useRightDrawer } from '@/ui/right-drawer/hooks/useRightDrawer';
import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotkeyScope'; import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotkeyScope';
import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages'; import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { ActivityType, useCreateActivityMutation } from '~/generated/graphql'; import {
ActivityType,
CommentableType,
useCreateActivityMutation,
} from '~/generated/graphql';
import { import {
GET_ACTIVITIES, GET_ACTIVITIES,
@ -53,6 +57,14 @@ export function useOpenCreateActivityDrawer() {
{ {
commentableId: entity.id, commentableId: entity.id,
commentableType: entity.type, commentableType: entity.type,
companyId:
entity.type === CommentableType.Company
? entity.id
: null,
personId:
entity.type === CommentableType.Person
? entity.id
: null,
id: v4(), id: v4(),
createdAt: now, createdAt: now,
}, },

View File

@ -61,6 +61,10 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
commentableType: entity.type, commentableType: entity.type,
id: v4(), id: v4(),
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
companyId:
entity.type === CommentableType.Company ? entity.id : null,
personId:
entity.type === CommentableType.Person ? entity.id : null,
})), })),
skipDuplicates: true, skipDuplicates: true,
}, },

View File

@ -47,6 +47,8 @@ export const CREATE_ACTIVITY_WITH_COMMENT = gql`
activityId activityId
commentableType commentableType
commentableId commentableId
companyId
personId
} }
comments { comments {
id id

View File

@ -48,6 +48,8 @@ export const GET_ACTIVITIES_BY_TARGETS = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -86,6 +88,8 @@ export const GET_ACTIVITIES = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -131,6 +135,8 @@ export const GET_ACTIVITY = gql`
id id
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }

View File

@ -18,6 +18,8 @@ export const ADD_ACTIVITY_TARGETS = gql`
updatedAt updatedAt
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }
@ -43,6 +45,8 @@ export const REMOVE_ACTIVITY_TARGETS = gql`
updatedAt updatedAt
commentableType commentableType
commentableId commentableId
companyId
personId
} }
} }
} }