mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-18 09:02:11 +03:00
[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 f89bc30689
.
---------
Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
parent
04297b0556
commit
ed1662223a
@ -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<{
|
||||
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<{
|
||||
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<{
|
||||
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<{
|
||||
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<{
|
||||
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<{
|
||||
activityId: Scalars['String'];
|
||||
@ -2849,6 +2849,8 @@ export const CreateActivityDocument = gql`
|
||||
activityId
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
comments {
|
||||
id
|
||||
@ -2931,6 +2933,8 @@ export const GetActivitiesByTargetsDocument = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2994,6 +2998,8 @@ export const GetActivitiesDocument = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3067,6 +3073,8 @@ export const GetActivityDocument = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3114,6 +3122,8 @@ export const AddActivityTargetsOnActivityDocument = gql`
|
||||
updatedAt
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3160,6 +3170,8 @@ export const RemoveActivityTargetsOnActivityDocument = gql`
|
||||
updatedAt
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,10 @@ import { flatMapAndSortEntityForSelectArrayOfArrayByName } from '../utils/flatMa
|
||||
type OwnProps = {
|
||||
activity?: Pick<Activity, 'id'> & {
|
||||
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
|
||||
?.filter((relation) => relation.commentableType === 'Person')
|
||||
.map((relation) => relation.commentableId)
|
||||
.map((relation) => relation.personId || relation.commentableId)
|
||||
.filter(assertNotNull) ?? [],
|
||||
[activity?.activityTargets],
|
||||
);
|
||||
@ -96,7 +99,7 @@ export function ActivityRelationPicker({ activity }: OwnProps) {
|
||||
() =>
|
||||
activity?.activityTargets
|
||||
?.filter((relation) => relation.commentableType === 'Company')
|
||||
.map((relation) => relation.commentableId)
|
||||
.map((relation) => relation.companyId || relation.commentableId)
|
||||
.filter(assertNotNull) ?? [],
|
||||
[activity?.activityTargets],
|
||||
);
|
||||
|
@ -68,7 +68,9 @@ export function TaskRow({ task }: { task: TaskForList }) {
|
||||
in: task?.activityTargets
|
||||
? task?.activityTargets
|
||||
.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
|
||||
? task?.activityTargets
|
||||
.filter((target) => target.commentableType === 'Company')
|
||||
.map((target) => target.commentableId ?? '')
|
||||
.map(
|
||||
(target) => (target.companyId || target.commentableId) ?? '',
|
||||
)
|
||||
: [],
|
||||
},
|
||||
},
|
||||
|
@ -16,7 +16,10 @@ import { ActivityRelationEditableFieldEditMode } from './ActivityRelationEditabl
|
||||
type OwnProps = {
|
||||
activity?: Pick<Activity, 'id'> & {
|
||||
activityTargets?: Array<
|
||||
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'>
|
||||
Pick<
|
||||
ActivityTarget,
|
||||
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
|
||||
>
|
||||
> | null;
|
||||
};
|
||||
};
|
||||
@ -29,7 +32,9 @@ export function ActivityRelationEditableField({ activity }: OwnProps) {
|
||||
in: activity?.activityTargets
|
||||
? activity?.activityTargets
|
||||
.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
|
||||
? activity?.activityTargets
|
||||
.filter((target) => target.commentableType === 'Company')
|
||||
.map((target) => target.commentableId ?? '')
|
||||
.map(
|
||||
(target) => (target.companyId || target.commentableId) ?? '',
|
||||
)
|
||||
: [],
|
||||
},
|
||||
},
|
||||
|
@ -13,7 +13,10 @@ import { assertNotNull } from '~/utils/assert';
|
||||
type OwnProps = {
|
||||
activity?: Pick<Activity, 'id'> & {
|
||||
activityTargets?: Array<
|
||||
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'>
|
||||
Pick<
|
||||
ActivityTarget,
|
||||
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
|
||||
>
|
||||
> | null;
|
||||
};
|
||||
};
|
||||
@ -31,7 +34,7 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
|
||||
() =>
|
||||
activity?.activityTargets
|
||||
?.filter((relation) => relation.commentableType === 'Person')
|
||||
.map((relation) => relation.commentableId)
|
||||
.map((relation) => relation.personId || relation.commentableId)
|
||||
.filter(assertNotNull) ?? [],
|
||||
[activity?.activityTargets],
|
||||
);
|
||||
@ -40,7 +43,7 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
|
||||
() =>
|
||||
activity?.activityTargets
|
||||
?.filter((relation) => relation.commentableType === 'Company')
|
||||
.map((relation) => relation.commentableId)
|
||||
.map((relation) => relation.companyId || relation.commentableId)
|
||||
.filter(assertNotNull) ?? [],
|
||||
[activity?.activityTargets],
|
||||
);
|
||||
|
@ -6,6 +6,7 @@ import { GET_PEOPLE } from '@/people/queries';
|
||||
import {
|
||||
Activity,
|
||||
ActivityTarget,
|
||||
CommentableType,
|
||||
useAddActivityTargetsOnActivityMutation,
|
||||
useRemoveActivityTargetsOnActivityMutation,
|
||||
} from '~/generated/graphql';
|
||||
@ -65,6 +66,10 @@ export function useHandleCheckableActivityTargetChange({
|
||||
createdAt: new Date().toISOString(),
|
||||
commentableType: entity.entityType,
|
||||
commentableId: entity.id,
|
||||
companyId:
|
||||
entity.entityType === CommentableType.Company ? entity.id : null,
|
||||
personId:
|
||||
entity.entityType === CommentableType.Person ? entity.id : null,
|
||||
})),
|
||||
},
|
||||
});
|
||||
|
@ -9,7 +9,11 @@ import { useRightDrawer } from '@/ui/right-drawer/hooks/useRightDrawer';
|
||||
import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotkeyScope';
|
||||
import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
|
||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
||||
import { ActivityType, useCreateActivityMutation } from '~/generated/graphql';
|
||||
import {
|
||||
ActivityType,
|
||||
CommentableType,
|
||||
useCreateActivityMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import {
|
||||
GET_ACTIVITIES,
|
||||
@ -53,6 +57,14 @@ export function useOpenCreateActivityDrawer() {
|
||||
{
|
||||
commentableId: entity.id,
|
||||
commentableType: entity.type,
|
||||
companyId:
|
||||
entity.type === CommentableType.Company
|
||||
? entity.id
|
||||
: null,
|
||||
personId:
|
||||
entity.type === CommentableType.Person
|
||||
? entity.id
|
||||
: null,
|
||||
id: v4(),
|
||||
createdAt: now,
|
||||
},
|
||||
|
@ -61,6 +61,10 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
|
||||
commentableType: entity.type,
|
||||
id: v4(),
|
||||
createdAt: new Date().toISOString(),
|
||||
companyId:
|
||||
entity.type === CommentableType.Company ? entity.id : null,
|
||||
personId:
|
||||
entity.type === CommentableType.Person ? entity.id : null,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
},
|
||||
|
@ -47,6 +47,8 @@ export const CREATE_ACTIVITY_WITH_COMMENT = gql`
|
||||
activityId
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
comments {
|
||||
id
|
||||
|
@ -48,6 +48,8 @@ export const GET_ACTIVITIES_BY_TARGETS = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,6 +88,8 @@ export const GET_ACTIVITIES = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,6 +135,8 @@ export const GET_ACTIVITY = gql`
|
||||
id
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ export const ADD_ACTIVITY_TARGETS = gql`
|
||||
updatedAt
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,6 +45,8 @@ export const REMOVE_ACTIVITY_TARGETS = gql`
|
||||
updatedAt
|
||||
commentableType
|
||||
commentableId
|
||||
companyId
|
||||
personId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user