[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

@ -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],
);

View File

@ -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) ?? '',
)
: [],
},
},

View File

@ -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) ?? '',
)
: [],
},
},

View File

@ -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],
);

View File

@ -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,
})),
},
});

View File

@ -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,
},

View File

@ -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,
},

View File

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

View File

@ -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
}
}
}

View File

@ -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
}
}
}