Remove activityType and Id (#1179)

* Remove activityType and Id

* Fix tests

* Fix tests
This commit is contained in:
Charles Bochet 2023-08-12 02:31:54 +02:00 committed by GitHub
parent a30222fe76
commit 35ea6b5a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 360 additions and 822 deletions

View File

@ -117,8 +117,6 @@ export type ActivityTarget = {
__typename?: 'ActivityTarget';
activity: Activity;
activityId: Scalars['String'];
commentableId?: Maybe<Scalars['String']>;
commentableType?: Maybe<CommentableType>;
company?: Maybe<Company>;
companyId?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
@ -129,8 +127,6 @@ export type ActivityTarget = {
};
export type ActivityTargetCreateManyActivityInput = {
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
companyId?: InputMaybe<Scalars['String']>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -145,8 +141,6 @@ export type ActivityTargetCreateManyActivityInputEnvelope = {
export type ActivityTargetCreateManyCompanyInput = {
activityId: Scalars['String'];
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
personId?: InputMaybe<Scalars['String']>;
@ -160,8 +154,6 @@ export type ActivityTargetCreateManyCompanyInputEnvelope = {
export type ActivityTargetCreateManyPersonInput = {
activityId: Scalars['String'];
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
companyId?: InputMaybe<Scalars['String']>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -175,8 +167,6 @@ export type ActivityTargetCreateManyPersonInputEnvelope = {
export type ActivityTargetCreateManyWorkspaceInput = {
activityId: Scalars['String'];
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
companyId?: InputMaybe<Scalars['String']>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -231,8 +221,6 @@ export type ActivityTargetCreateOrConnectWithoutWorkspaceInput = {
};
export type ActivityTargetCreateWithoutActivityInput = {
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
company?: InputMaybe<CompanyCreateNestedOneWithoutActivityTargetInput>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -242,8 +230,6 @@ export type ActivityTargetCreateWithoutActivityInput = {
export type ActivityTargetCreateWithoutCompanyInput = {
activity: ActivityCreateNestedOneWithoutActivityTargetsInput;
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
person?: InputMaybe<PersonCreateNestedOneWithoutActivityTargetInput>;
@ -252,8 +238,6 @@ export type ActivityTargetCreateWithoutCompanyInput = {
export type ActivityTargetCreateWithoutPersonInput = {
activity: ActivityCreateNestedOneWithoutActivityTargetsInput;
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
company?: InputMaybe<CompanyCreateNestedOneWithoutActivityTargetInput>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -262,8 +246,6 @@ export type ActivityTargetCreateWithoutPersonInput = {
export type ActivityTargetCreateWithoutWorkspaceInput = {
activity: ActivityCreateNestedOneWithoutActivityTargetsInput;
commentableId?: InputMaybe<Scalars['String']>;
commentableType?: InputMaybe<CommentableType>;
company?: InputMaybe<CompanyCreateNestedOneWithoutActivityTargetInput>;
createdAt?: InputMaybe<Scalars['DateTime']>;
id?: InputMaybe<Scalars['String']>;
@ -286,8 +268,6 @@ export type ActivityTargetScalarWhereInput = {
NOT?: InputMaybe<Array<ActivityTargetScalarWhereInput>>;
OR?: InputMaybe<Array<ActivityTargetScalarWhereInput>>;
activityId?: InputMaybe<StringFilter>;
commentableId?: InputMaybe<StringNullableFilter>;
commentableType?: InputMaybe<EnumCommentableTypeNullableFilter>;
companyId?: InputMaybe<StringNullableFilter>;
createdAt?: InputMaybe<DateTimeFilter>;
id?: InputMaybe<StringFilter>;
@ -345,8 +325,6 @@ export type ActivityTargetWhereInput = {
OR?: InputMaybe<Array<ActivityTargetWhereInput>>;
activity?: InputMaybe<ActivityRelationFilter>;
activityId?: InputMaybe<StringFilter>;
commentableId?: InputMaybe<StringNullableFilter>;
commentableType?: InputMaybe<EnumCommentableTypeNullableFilter>;
company?: InputMaybe<CompanyRelationFilter>;
companyId?: InputMaybe<StringNullableFilter>;
createdAt?: InputMaybe<DateTimeFilter>;
@ -632,11 +610,6 @@ export type CommentWhereUniqueInput = {
id?: InputMaybe<Scalars['String']>;
};
export enum CommentableType {
Company = 'Company',
Person = 'Person'
}
export type Company = {
__typename?: 'Company';
ActivityTarget?: Maybe<Array<ActivityTarget>>;
@ -837,13 +810,6 @@ export type EnumColorSchemeFilter = {
notIn?: InputMaybe<Array<ColorScheme>>;
};
export type EnumCommentableTypeNullableFilter = {
equals?: InputMaybe<CommentableType>;
in?: InputMaybe<Array<CommentableType>>;
not?: InputMaybe<NestedEnumCommentableTypeNullableFilter>;
notIn?: InputMaybe<Array<CommentableType>>;
};
export type EnumPipelineProgressableTypeFilter = {
equals?: InputMaybe<PipelineProgressableType>;
in?: InputMaybe<Array<PipelineProgressableType>>;
@ -1286,13 +1252,6 @@ export type NestedEnumColorSchemeFilter = {
notIn?: InputMaybe<Array<ColorScheme>>;
};
export type NestedEnumCommentableTypeNullableFilter = {
equals?: InputMaybe<CommentableType>;
in?: InputMaybe<Array<CommentableType>>;
not?: InputMaybe<NestedEnumCommentableTypeNullableFilter>;
notIn?: InputMaybe<Array<CommentableType>>;
};
export type NestedEnumPipelineProgressableTypeFilter = {
equals?: InputMaybe<PipelineProgressableType>;
in?: InputMaybe<Array<PipelineProgressableType>>;
@ -2694,7 +2653,9 @@ 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, 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 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, 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 ActivityQueryFragmentFragment = { __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, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | null }> | null };
export type GetActivitiesByTargetsQueryVariables = Exact<{
activityTargetIds: Array<Scalars['String']> | Scalars['String'];
@ -2702,7 +2663,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, companyId?: string | null, personId?: 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, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | null }> | null }> };
export type GetActivitiesQueryVariables = Exact<{
where: ActivityWhereInput;
@ -2710,14 +2671,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, companyId?: string | null, personId?: 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, 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, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | 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, companyId?: string | null, personId?: string | null }> | null }> };
export type GetActivityQuery = { __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, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | null }> | null }> };
export type AddActivityTargetsOnActivityMutationVariables = Exact<{
activityId: Scalars['String'];
@ -2725,7 +2686,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, companyId?: string | null, personId?: 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, companyId?: string | null, personId?: string | null }> | null } };
export type RemoveActivityTargetsOnActivityMutationVariables = Exact<{
activityId: Scalars['String'];
@ -2733,7 +2694,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, companyId?: string | null, personId?: 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, companyId?: string | null, personId?: string | null }> | null } };
export type DeleteActivityMutationVariables = Exact<{
activityId: Scalars['String'];
@ -3223,6 +3184,58 @@ export type DeleteCurrentWorkspaceMutationVariables = Exact<{ [key: string]: nev
export type DeleteCurrentWorkspaceMutation = { __typename?: 'Mutation', deleteCurrentWorkspace: { __typename?: 'Workspace', id: string } };
export const ActivityQueryFragmentFragmentDoc = gql`
fragment ActivityQueryFragment on Activity {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
}
}
activityTargets {
id
companyId
personId
company {
id
name
domainName
}
person {
id
displayName
avatarUrl
}
}
}
`;
export const ActivityUpdatePartsFragmentDoc = gql`
fragment ActivityUpdateParts on Activity {
id
@ -3319,8 +3332,6 @@ export const CreateActivityDocument = gql`
createdAt
updatedAt
activityId
commentableType
commentableId
companyId
personId
}
@ -3366,51 +3377,12 @@ export const GetActivitiesByTargetsDocument = gql`
query GetActivitiesByTargets($activityTargetIds: [String!]!, $orderBy: [ActivityOrderByWithRelationInput!]) {
findManyActivities(
orderBy: $orderBy
where: {activityTargets: {some: {commentableId: {in: $activityTargetIds}}}}
where: {activityTargets: {some: {OR: [{personId: {in: $activityTargetIds}}, {companyId: {in: $activityTargetIds}}]}}}
) {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
}
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
...ActivityQueryFragment
}
}
`;
${ActivityQueryFragmentFragmentDoc}`;
/**
* __useGetActivitiesByTargetsQuery__
@ -3443,39 +3415,10 @@ export type GetActivitiesByTargetsQueryResult = Apollo.QueryResult<GetActivities
export const GetActivitiesDocument = gql`
query GetActivities($where: ActivityWhereInput!, $orderBy: [ActivityOrderByWithRelationInput!]) {
findManyActivities(orderBy: $orderBy, where: $where) {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
...ActivityQueryFragment
}
}
`;
${ActivityQueryFragmentFragmentDoc}`;
/**
* __useGetActivitiesQuery__
@ -3508,49 +3451,10 @@ export type GetActivitiesQueryResult = Apollo.QueryResult<GetActivitiesQuery, Ge
export const GetActivityDocument = gql`
query GetActivity($activityId: String!) {
findManyActivities(where: {id: {equals: $activityId}}) {
id
createdAt
body
title
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
}
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
...ActivityQueryFragment
}
}
`;
${ActivityQueryFragmentFragmentDoc}`;
/**
* __useGetActivityQuery__
@ -3592,8 +3496,6 @@ export const AddActivityTargetsOnActivityDocument = gql`
id
createdAt
updatedAt
commentableType
commentableId
companyId
personId
}
@ -3640,8 +3542,6 @@ export const RemoveActivityTargetsOnActivityDocument = gql`
id
createdAt
updatedAt
commentableType
commentableId
companyId
personId
}

View File

@ -72,9 +72,7 @@ type OwnProps = {
'id' | 'firstName' | 'lastName' | 'displayName'
> | null;
} & {
activityTargets?: Array<
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'>
> | null;
activityTargets?: Array<Pick<ActivityTarget, 'id'>> | null;
};
showComment?: boolean;
autoFillTitle?: boolean;

View File

@ -1,251 +0,0 @@
import { useCallback, useMemo, useState } from 'react';
import styled from '@emotion/styled';
import {
autoUpdate,
flip,
offset,
size,
useFloating,
} from '@floating-ui/react';
import { CompanyChip } from '@/companies/components/CompanyChip';
import { useFilteredSearchCompanyQuery } from '@/companies/queries';
import { PersonChip } from '@/people/components/PersonChip';
import { useFilteredSearchPeopleQuery } from '@/people/queries';
import { MultipleEntitySelect } from '@/ui/input/relation-picker/components/MultipleEntitySelect';
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import { Activity, ActivityTarget, CommentableType } from '~/generated/graphql';
import { assertNotNull } from '~/utils/assert';
import { useHandleCheckableActivityTargetChange } from '../hooks/useHandleCheckableActivityTargetChange';
import { flatMapAndSortEntityForSelectArrayOfArrayByName } from '../utils/flatMapAndSortEntityForSelectArrayByName';
type OwnProps = {
activity?: Pick<Activity, 'id'> & {
activityTargets: Array<
Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'companyId' | 'personId'
>
>;
};
};
const StyledContainer = styled.div`
align-items: flex-start;
display: flex;
flex-direction: row;
gap: ${({ theme }) => theme.spacing(2)};
justify-content: flex-start;
width: 100%;
`;
const StyledRelationContainer = styled.div`
--horizontal-padding: ${({ theme }) => theme.spacing(1)};
--vertical-padding: ${({ theme }) => theme.spacing(1.5)};
border: 1px solid transparent;
cursor: pointer;
display: flex;
flex-wrap: wrap;
gap: ${({ theme }) => theme.spacing(2)};
&:hover {
background-color: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.light};
}
min-height: calc(32px - 2 * var(--vertical-padding));
overflow: hidden;
padding: var(--vertical-padding) var(--horizontal-padding);
width: calc(100% - 2 * var(--horizontal-padding));
`;
const StyledMenuWrapper = styled.div`
z-index: ${({ theme }) => theme.lastLayerZIndex};
`;
export function ActivityRelationPicker({ activity }: OwnProps) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [searchFilter, setSearchFilter] = useState('');
const [selectedEntityIds, setSelectedEntityIds] = useState<
Record<string, boolean>
>({});
const {
setHotkeyScopeAndMemorizePreviousScope,
goBackToPreviousHotkeyScope,
} = usePreviousHotkeyScope();
const initialPeopleIds = useMemo(
() =>
activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Person')
.map((relation) => relation.personId || relation.commentableId)
.filter(assertNotNull) ?? [],
[activity?.activityTargets],
);
const initialCompanyIds = useMemo(
() =>
activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Company')
.map((relation) => relation.companyId || relation.commentableId)
.filter(assertNotNull) ?? [],
[activity?.activityTargets],
);
const initialSelectedEntityIds = useMemo(
() =>
[...initialPeopleIds, ...initialCompanyIds].reduce<
Record<string, boolean>
>((result, entityId) => ({ ...result, [entityId]: true }), {}),
[initialPeopleIds, initialCompanyIds],
);
const personsForMultiSelect = useFilteredSearchPeopleQuery({
searchFilter,
selectedIds: initialPeopleIds,
});
const companiesForMultiSelect = useFilteredSearchCompanyQuery({
searchFilter,
selectedIds: initialCompanyIds,
});
const selectedEntities = flatMapAndSortEntityForSelectArrayOfArrayByName([
personsForMultiSelect.selectedEntities,
companiesForMultiSelect.selectedEntities,
]);
const filteredSelectedEntities =
flatMapAndSortEntityForSelectArrayOfArrayByName([
personsForMultiSelect.filteredSelectedEntities,
companiesForMultiSelect.filteredSelectedEntities,
]);
const entitiesToSelect = flatMapAndSortEntityForSelectArrayOfArrayByName([
personsForMultiSelect.entitiesToSelect,
companiesForMultiSelect.entitiesToSelect,
]);
const handleCheckItemsChange = useHandleCheckableActivityTargetChange({
activity,
});
const exitEditMode = useCallback(() => {
goBackToPreviousHotkeyScope();
setIsMenuOpen(false);
setSearchFilter('');
if (Object.values(selectedEntityIds).some((value) => !!value)) {
handleCheckItemsChange(selectedEntityIds, entitiesToSelect);
}
}, [
entitiesToSelect,
selectedEntityIds,
goBackToPreviousHotkeyScope,
handleCheckItemsChange,
]);
const handleRelationContainerClick = useCallback(() => {
if (isMenuOpen) {
exitEditMode();
} else {
setIsMenuOpen(true);
setSelectedEntityIds(initialSelectedEntityIds);
setHotkeyScopeAndMemorizePreviousScope(
RelationPickerHotkeyScope.RelationPicker,
);
}
}, [
initialSelectedEntityIds,
exitEditMode,
isMenuOpen,
setHotkeyScopeAndMemorizePreviousScope,
]);
useScopedHotkeys(
['esc', 'enter'],
() => {
exitEditMode();
},
RelationPickerHotkeyScope.RelationPicker,
[exitEditMode],
);
const { refs, floatingStyles } = useFloating({
strategy: 'absolute',
middleware: [
offset(({ rects }) => {
return -rects.reference.height;
}),
flip(),
size(),
],
whileElementsMounted: autoUpdate,
open: isMenuOpen,
placement: 'bottom-start',
});
useListenClickOutside({
refs: [refs.floating, refs.domReference],
callback: () => {
exitEditMode();
},
});
return (
<StyledContainer>
<StyledRelationContainer
ref={refs.setReference}
onClick={handleRelationContainerClick}
>
{selectedEntities?.map((entity) =>
entity.entityType === CommentableType.Company ? (
<CompanyChip
key={entity.id}
id={entity.id}
name={entity.name}
pictureUrl={entity.avatarUrl}
/>
) : (
<PersonChip
key={entity.id}
name={entity.name}
id={entity.id}
pictureUrl={entity.avatarUrl ?? ''}
/>
),
)}
</StyledRelationContainer>
{isMenuOpen && (
<RecoilScope>
<StyledMenuWrapper ref={refs.setFloating} style={floatingStyles}>
<MultipleEntitySelect
entities={{
entitiesToSelect,
filteredSelectedEntities,
selectedEntities,
loading: false, // TODO implement skeleton loading
}}
onChange={setSelectedEntityIds}
onSearchFilterChange={setSearchFilter}
searchFilter={searchFilter}
value={selectedEntityIds}
/>
</StyledMenuWrapper>
</RecoilScope>
)}
</StyledContainer>
);
}

View File

@ -2,7 +2,7 @@ import styled from '@emotion/styled';
import { CompanyChip } from '@/companies/components/CompanyChip';
import { PersonChip } from '@/people/components/PersonChip';
import { GetCompaniesQuery, GetPeopleQuery } from '~/generated/graphql';
import { ActivityTarget, Company, Person } from '~/generated/graphql';
import { getLogoUrlFromDomainName } from '~/utils';
const StyledContainer = styled.div`
@ -12,32 +12,44 @@ const StyledContainer = styled.div`
`;
export function ActivityTargetChips({
targetCompanies,
targetPeople,
targets,
}: {
targetCompanies?: GetCompaniesQuery;
targetPeople?: GetPeopleQuery;
targets?: Array<
Pick<ActivityTarget, 'id'> & {
person?: Pick<Person, 'id' | 'displayName' | 'avatarUrl'> | null;
company?: Pick<Company, 'id' | 'domainName' | 'name'> | null;
}
> | null;
}) {
if (!targets) {
return null;
}
return (
<StyledContainer>
{targetCompanies?.companies &&
targetCompanies.companies.map((company) => (
<CompanyChip
key={company.id}
id={company.id}
name={company.name}
pictureUrl={getLogoUrlFromDomainName(company.domainName)}
/>
))}
{targetPeople?.people &&
targetPeople.people.map((person) => (
<PersonChip
key={person.id}
id={person.id}
name={person.displayName}
pictureUrl={person.avatarUrl ?? ''}
/>
))}
{targets.map(({ company, person }) => {
if (company) {
return (
<CompanyChip
key={company.id}
id={company.id}
name={company.name}
pictureUrl={getLogoUrlFromDomainName(company.domainName)}
/>
);
}
if (person) {
return (
<PersonChip
key={person.id}
id={person.id}
name={person.displayName}
pictureUrl={person.avatarUrl ?? undefined}
/>
);
}
return <></>;
})}
</StyledContainer>
);
}

View File

@ -9,7 +9,6 @@ import {
CheckboxShape,
} from '@/ui/input/checkbox/components/Checkbox';
import { OverflowingTextWithTooltip } from '@/ui/tooltip/OverflowingTextWithTooltip';
import { useGetCompaniesQuery, useGetPeopleQuery } from '~/generated/graphql';
import { beautifyExactDate } from '~/utils/date-utils';
import { useCompleteTask } from '../hooks/useCompleteTask';
@ -62,37 +61,7 @@ const StyledFieldsContainer = styled.div`
export function TaskRow({ task }: { task: TaskForList }) {
const theme = useTheme();
const openActivityRightDrawer = useOpenActivityRightDrawer();
const { data: targetPeople } = useGetPeopleQuery({
variables: {
where: {
id: {
in: task?.activityTargets
? task?.activityTargets
.filter((target) => target.commentableType === 'Person')
.map(
(target) => (target.personId || target.commentableId) ?? '',
)
: [],
},
},
},
});
const { data: targetCompanies } = useGetCompaniesQuery({
variables: {
where: {
id: {
in: task?.activityTargets
? task?.activityTargets
.filter((target) => target.commentableType === 'Company')
.map(
(target) => (target.companyId || target.commentableId) ?? '',
)
: [],
},
},
},
});
const body = JSON.parse(task.body ?? '{}')[0]?.content[0]?.text;
const { completeTask } = useCompleteTask(task);
@ -123,10 +92,7 @@ export function TaskRow({ task }: { task: TaskForList }) {
)}
</StyledTaskBody>
<StyledFieldsContainer>
<ActivityTargetChips
targetCompanies={targetCompanies}
targetPeople={targetPeople}
/>
<ActivityTargetChips targets={task.activityTargets} />
<StyledDueDate>
<IconCalendar size={theme.icon.size.md} />
{task.dueAt && beautifyExactDate(task.dueAt)}

View File

@ -1,37 +0,0 @@
import { MemoryRouter } from 'react-router-dom';
import styled from '@emotion/styled';
import type { Meta, StoryObj } from '@storybook/react';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { mockedActivities } from '~/testing/mock-data/activities';
import { ActivityRelationPicker } from '../ActivityRelationPicker';
const StyledContainer = styled.div`
width: 400px;
`;
const meta: Meta<typeof ActivityRelationPicker> = {
title: 'Modules/Comments/ActivityRelationPicker',
component: ActivityRelationPicker,
decorators: [
(Story) => (
<MemoryRouter>
<StyledContainer>
<Story />
</StyledContainer>
</MemoryRouter>
),
ComponentDecorator,
],
args: { activity: mockedActivities[0] },
parameters: {
msw: graphqlMocks,
},
};
export default meta;
type Story = StoryObj<typeof ActivityRelationPicker>;
export const Default: Story = {};

View File

@ -4,59 +4,22 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconArrowUpRight } from '@/ui/icon';
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
import {
Activity,
ActivityTarget,
useGetCompaniesQuery,
useGetPeopleQuery,
} from '~/generated/graphql';
import { Activity, ActivityTarget, Company, Person } from '~/generated/graphql';
import { ActivityRelationEditableFieldEditMode } from './ActivityRelationEditableFieldEditMode';
type OwnProps = {
activity?: Pick<Activity, 'id'> & {
activityTargets?: Array<
Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
>
Pick<ActivityTarget, 'id' | 'personId' | 'companyId'> & {
person?: Pick<Person, 'id' | 'displayName'>;
company?: Pick<Company, 'id' | 'domainName' | 'name'>;
}
> | null;
};
};
export function ActivityRelationEditableField({ activity }: OwnProps) {
const { data: targetPeople } = useGetPeopleQuery({
variables: {
where: {
id: {
in: activity?.activityTargets
? activity?.activityTargets
.filter((target) => target.commentableType === 'Person')
.map(
(target) => (target.personId || target.commentableId) ?? '',
)
: [],
},
},
},
});
const { data: targetCompanies } = useGetCompaniesQuery({
variables: {
where: {
id: {
in: activity?.activityTargets
? activity?.activityTargets
.filter((target) => target.commentableType === 'Company')
.map(
(target) => (target.companyId || target.commentableId) ?? '',
)
: [],
},
},
},
});
return (
<RecoilScope SpecificContext={FieldContext}>
<RecoilScope>
@ -71,10 +34,7 @@ export function ActivityRelationEditableField({ activity }: OwnProps) {
}
label="Relations"
displayModeContent={
<ActivityTargetChips
targetCompanies={targetCompanies}
targetPeople={targetPeople}
/>
<ActivityTargetChips targets={activity?.activityTargets} />
}
/>
</RecoilScope>

View File

@ -13,10 +13,7 @@ import { assertNotNull } from '~/utils/assert';
type OwnProps = {
activity?: Pick<Activity, 'id'> & {
activityTargets?: Array<
Pick<
ActivityTarget,
'id' | 'commentableId' | 'commentableType' | 'personId' | 'companyId'
>
Pick<ActivityTarget, 'id' | 'personId' | 'companyId'>
> | null;
};
};
@ -33,8 +30,8 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
const initialPeopleIds = useMemo(
() =>
activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Person')
.map((relation) => relation.personId || relation.commentableId)
?.filter((relation) => relation.personId !== null)
.map((relation) => relation.personId)
.filter(assertNotNull) ?? [],
[activity?.activityTargets],
);
@ -42,8 +39,8 @@ export function ActivityRelationEditableFieldEditMode({ activity }: OwnProps) {
const initialCompanyIds = useMemo(
() =>
activity?.activityTargets
?.filter((relation) => relation.commentableType === 'Company')
.map((relation) => relation.companyId || relation.commentableId)
?.filter((relation) => relation.companyId !== null)
.map((relation) => relation.companyId)
.filter(assertNotNull) ?? [],
[activity?.activityTargets],
);

View File

@ -6,20 +6,20 @@ import { GET_PEOPLE } from '@/people/queries';
import {
Activity,
ActivityTarget,
CommentableType,
useAddActivityTargetsOnActivityMutation,
useRemoveActivityTargetsOnActivityMutation,
} from '~/generated/graphql';
import { GET_ACTIVITY } from '../queries';
import { CommentableEntityForSelect } from '../types/CommentableEntityForSelect';
import { ActivityTargetableEntityType } from '../types/ActivityTargetableEntity';
import { ActivityTargetableEntityForSelect } from '../types/ActivityTargetableEntityForSelect';
export function useHandleCheckableActivityTargetChange({
activity,
}: {
activity?: Pick<Activity, 'id'> & {
activityTargets?: Array<
Pick<ActivityTarget, 'id' | 'commentableId' | 'commentableType'>
Pick<ActivityTarget, 'id' | 'personId' | 'companyId'>
> | null;
};
}) {
@ -43,14 +43,16 @@ export function useHandleCheckableActivityTargetChange({
return async function handleCheckItemsChange(
entityValues: Record<string, boolean>,
entities: CommentableEntityForSelect[],
entities: ActivityTargetableEntityForSelect[],
) {
if (!activity) {
return;
}
const currentEntityIds = activity.activityTargets
? activity.activityTargets.map(({ commentableId }) => commentableId)
? activity.activityTargets.map(
({ personId, companyId }) => personId ?? companyId,
)
: [];
const entitiesToAdd = entities.filter(
@ -64,12 +66,14 @@ export function useHandleCheckableActivityTargetChange({
activityTargetInputs: entitiesToAdd.map((entity) => ({
id: v4(),
createdAt: new Date().toISOString(),
commentableType: entity.entityType,
commentableId: entity.id,
companyId:
entity.entityType === CommentableType.Company ? entity.id : null,
entity.entityType === ActivityTargetableEntityType.Company
? entity.id
: null,
personId:
entity.entityType === CommentableType.Person ? entity.id : null,
entity.entityType === ActivityTargetableEntityType.Person
? entity.id
: null,
})),
},
});
@ -77,8 +81,9 @@ export function useHandleCheckableActivityTargetChange({
const activityTargetIdsToDelete = activity.activityTargets
? activity.activityTargets
.filter(
({ commentableId }) =>
commentableId && !entityValues[commentableId],
({ personId, companyId }) =>
(personId ?? companyId) &&
!entityValues[personId ?? companyId ?? ''],
)
.map(({ id }) => id)
: [];

View File

@ -9,20 +9,19 @@ 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,
CommentableType,
useCreateActivityMutation,
} from '~/generated/graphql';
import { ActivityType, useCreateActivityMutation } from '~/generated/graphql';
import {
GET_ACTIVITIES,
GET_ACTIVITIES_BY_TARGETS,
GET_ACTIVITY,
} from '../queries';
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
import { activityTargetableEntityArrayState } from '../states/activityTargetableEntityArrayState';
import { viewableActivityIdState } from '../states/viewableActivityIdState';
import { CommentableEntity } from '../types/CommentableEntity';
import {
ActivityTargetableEntity,
ActivityTargetableEntityType,
} from '../types/ActivityTargetableEntity';
export function useOpenCreateActivityDrawer() {
const { openRightDrawer } = useRightDrawer();
@ -30,14 +29,14 @@ export function useOpenCreateActivityDrawer() {
const currentUser = useRecoilValue(currentUserState);
const setHotkeyScope = useSetHotkeyScope();
const [, setCommentableEntityArray] = useRecoilState(
commentableEntityArrayState,
const [, setActivityTargetableEntityArray] = useRecoilState(
activityTargetableEntityArrayState,
);
const [, setViewableActivityId] = useRecoilState(viewableActivityIdState);
return function openCreateActivityDrawer(
type: ActivityType,
entities?: CommentableEntity[],
entities?: ActivityTargetableEntity[],
) {
const now = new Date().toISOString();
@ -54,14 +53,14 @@ export function useOpenCreateActivityDrawer() {
createMany: {
data: entities
? entities.map((entity) => ({
commentableId: entity.id,
commentableType: entity.type,
companyId:
entity.type === CommentableType.Company
entity.type === ActivityTargetableEntityType.Company
? entity.id
: null,
personId:
entity.type === CommentableType.Person ? entity.id : null,
entity.type === ActivityTargetableEntityType.Person
? entity.id
: null,
id: v4(),
createdAt: now,
}))
@ -81,7 +80,7 @@ export function useOpenCreateActivityDrawer() {
onCompleted(data) {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
setViewableActivityId(data.createOneActivity.id);
setCommentableEntityArray(entities ?? []);
setActivityTargetableEntityArray(entities ?? []);
openRightDrawer(RightDrawerPages.CreateActivity);
},
});

View File

@ -1,9 +1,12 @@
import { useRecoilValue } from 'recoil';
import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
import { ActivityType, CommentableType } from '~/generated/graphql';
import { ActivityType } from '~/generated/graphql';
import { CommentableEntity } from '../types/CommentableEntity';
import {
ActivityTargetableEntity,
ActivityTargetableEntityType,
} from '../types/ActivityTargetableEntity';
import { useOpenCreateActivityDrawer } from './useOpenCreateActivityDrawer';
@ -14,14 +17,13 @@ export function useOpenCreateActivityDrawerForSelectedRowIds() {
return function openCreateCommentDrawerForSelectedRowIds(
type: ActivityType,
entityType: CommentableType,
entityType: ActivityTargetableEntityType,
) {
const commentableEntityArray: CommentableEntity[] = selectedEntityIds.map(
(id) => ({
const activityTargetableEntityArray: ActivityTargetableEntity[] =
selectedEntityIds.map((id) => ({
type: entityType,
id,
}),
);
openCreateActivityDrawer(type, commentableEntityArray);
}));
openCreateActivityDrawer(type, activityTargetableEntityArray);
};
}

View File

@ -5,22 +5,22 @@ import { RightDrawerHotkeyScope } from '@/ui/right-drawer/types/RightDrawerHotke
import { RightDrawerPages } from '@/ui/right-drawer/types/RightDrawerPages';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { commentableEntityArrayState } from '../states/commentableEntityArrayState';
import { CommentableEntity } from '../types/CommentableEntity';
import { activityTargetableEntityArrayState } from '../states/activityTargetableEntityArrayState';
import { ActivityTargetableEntity } from '../types/ActivityTargetableEntity';
// TODO: refactor with recoil callback to avoid rerender
export function useOpenTimelineRightDrawer() {
const { openRightDrawer } = useRightDrawer();
const [, setCommentableEntityArray] = useRecoilState(
commentableEntityArrayState,
const [, setActivityTargetableEntityArray] = useRecoilState(
activityTargetableEntityArrayState,
);
const setHotkeyScope = useSetHotkeyScope();
return function openTimelineRightDrawer(
commentableEntityArray: CommentableEntity[],
activityTargetableEntityArray: ActivityTargetableEntity[],
) {
setHotkeyScope(RightDrawerHotkeyScope.RightDrawer, { goto: false });
setCommentableEntityArray(commentableEntityArray);
setActivityTargetableEntityArray(activityTargetableEntityArray);
openRightDrawer(RightDrawerPages.Timeline);
};
}

View File

@ -45,8 +45,6 @@ export const CREATE_ACTIVITY_WITH_COMMENT = gql`
createdAt
updatedAt
activityId
commentableType
commentableId
companyId
personId
}

View File

@ -1,5 +1,58 @@
import { gql } from '@apollo/client';
export const ACTIVITY_QUERY_FRAGMENT = gql`
fragment ActivityQueryFragment on Activity {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
}
}
activityTargets {
id
companyId
personId
company {
id
name
domainName
}
person {
id
displayName
avatarUrl
}
}
}
`;
export const GET_ACTIVITIES_BY_TARGETS = gql`
query GetActivitiesByTargets(
$activityTargetIds: [String!]!
@ -8,49 +61,17 @@ export const GET_ACTIVITIES_BY_TARGETS = gql`
findManyActivities(
orderBy: $orderBy
where: {
activityTargets: { some: { commentableId: { in: $activityTargetIds } } }
}
) {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
activityTargets: {
some: {
OR: [
{ personId: { in: $activityTargetIds } }
{ companyId: { in: $activityTargetIds } }
]
}
}
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
) {
...ActivityQueryFragment
}
}
`;
@ -61,36 +82,7 @@ export const GET_ACTIVITIES = gql`
$orderBy: [ActivityOrderByWithRelationInput!]
) {
findManyActivities(orderBy: $orderBy, where: $where) {
id
createdAt
title
body
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
...ActivityQueryFragment
}
}
`;
@ -98,46 +90,7 @@ export const GET_ACTIVITIES = gql`
export const GET_ACTIVITY = gql`
query GetActivity($activityId: String!) {
findManyActivities(where: { id: { equals: $activityId } }) {
id
createdAt
body
title
type
completedAt
dueAt
assignee {
id
firstName
lastName
displayName
avatarUrl
}
author {
id
firstName
lastName
displayName
}
comments {
id
body
createdAt
updatedAt
author {
id
displayName
firstName
lastName
avatarUrl
}
}
activityTargets {
id
commentableType
commentableId
companyId
personId
}
...ActivityQueryFragment
}
}
`;

View File

@ -16,8 +16,6 @@ export const ADD_ACTIVITY_TARGETS = gql`
id
createdAt
updatedAt
commentableType
commentableId
companyId
personId
}
@ -43,8 +41,6 @@ export const REMOVE_ACTIVITY_TARGETS = gql`
id
createdAt
updatedAt
commentableType
commentableId
companyId
personId
}

View File

@ -1,19 +1,21 @@
import { useRecoilState } from 'recoil';
import { useRecoilValue } from 'recoil';
import { commentableEntityArrayState } from '@/activities/states/commentableEntityArrayState';
import { activityTargetableEntityArrayState } from '@/activities/states/activityTargetableEntityArrayState';
import { Timeline } from '@/activities/timeline/components/Timeline';
export function RightDrawerTimeline() {
const [commentableEntityArray] = useRecoilState(commentableEntityArrayState);
const activityTargetableEntityArray = useRecoilValue(
activityTargetableEntityArrayState,
);
return (
<>
{commentableEntityArray.map((commentableEntity) => (
{activityTargetableEntityArray.map((targetableEntity) => (
<Timeline
key={commentableEntity.id}
key={targetableEntity.id}
entity={{
id: commentableEntity?.id ?? '',
type: commentableEntity.type,
id: targetableEntity?.id ?? '',
type: targetableEntity.type,
}}
/>
))}

View File

@ -0,0 +1,10 @@
import { atom } from 'recoil';
import { ActivityTargetableEntity } from '../types/ActivityTargetableEntity';
export const activityTargetableEntityArrayState = atom<
ActivityTargetableEntity[]
>({
key: 'activities/targetable-entity-array',
default: [],
});

View File

@ -1,8 +0,0 @@
import { atom } from 'recoil';
import { CommentableEntity } from '../types/CommentableEntity';
export const commentableEntityArrayState = atom<CommentableEntity[]>({
key: 'activities/commentable-entity-array',
default: [],
});

View File

@ -5,7 +5,7 @@ import styled from '@emotion/styled';
import { ActivityCreateButton } from '@/activities/components/ActivityCreateButton';
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { ActivityForDrawer } from '@/activities/types/ActivityForDrawer';
import { CommentableEntity } from '@/activities/types/CommentableEntity';
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
import { IconCircleDot } from '@/ui/icon';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import {
@ -93,7 +93,7 @@ const StyledStartIcon = styled.div`
width: 20px;
`;
export function Timeline({ entity }: { entity: CommentableEntity }) {
export function Timeline({ entity }: { entity: ActivityTargetableEntity }) {
const theme = useTheme();
const { data: queryResult, loading } = useGetActivitiesByTargetsQuery({

View File

@ -0,0 +1,9 @@
export enum ActivityTargetableEntityType {
Person = 'Person',
Company = 'Company',
}
export type ActivityTargetableEntity = {
id: string;
type: ActivityTargetableEntityType;
};

View File

@ -0,0 +1,7 @@
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { ActivityTargetableEntityType } from './ActivityTargetableEntity';
export type ActivityTargetableEntityForSelect = EntityForSelect & {
entityType: ActivityTargetableEntityType;
};

View File

@ -1,6 +0,0 @@
import { CommentableType } from '~/generated/graphql';
export type CommentableEntity = {
id: string;
type: CommentableType;
};

View File

@ -1,6 +0,0 @@
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
import { CommentableType } from '~/generated/graphql';
export type CommentableEntityForSelect = EntityForSelect & {
entityType: CommentableType;
};

View File

@ -1,10 +1,10 @@
import { gql } from '@apollo/client';
import { CommentableEntityForSelect } from '@/activities/types/CommentableEntityForSelect';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { ActivityTargetableEntityForSelect } from '@/activities/types/ActivityTargetableEntityForSelect';
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
import {
CommentableType,
CompanyOrderByWithRelationInput as Companies_Order_By,
CompanyWhereInput as Companies_Bool_Exp,
SortOrder as Order_By,
@ -65,11 +65,11 @@ export function useFilteredSearchCompanyQuery({
mappingFunction: (company) =>
({
id: company.id,
entityType: CommentableType.Company,
entityType: ActivityTargetableEntityType.Company,
name: company.name,
avatarUrl: getLogoUrlFromDomainName(company.domainName),
avatarType: 'squared',
} as CommentableEntityForSelect),
} as ActivityTargetableEntityForSelect),
searchFilter,
limit,
});

View File

@ -1,14 +1,15 @@
import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments';
import { TableActionBarButtonToggleTasks } from '@/ui/table/action-bar/components/TableActionBarButtonOpenTasks';
import { ActivityType, CommentableType } from '~/generated/graphql';
import { ActivityType } from '~/generated/graphql';
export function TableActionBarButtonCreateActivityCompany() {
const openCreateActivityRightDrawer =
useOpenCreateActivityDrawerForSelectedRowIds();
async function handleButtonClick(type: ActivityType) {
openCreateActivityRightDrawer(type, CommentableType.Company);
openCreateActivityRightDrawer(type, ActivityTargetableEntityType.Company);
}
return (

View File

@ -1,10 +1,10 @@
import { gql } from '@apollo/client';
import { CommentableEntityForSelect } from '@/activities/types/CommentableEntityForSelect';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { ActivityTargetableEntityForSelect } from '@/activities/types/ActivityTargetableEntityForSelect';
import { useFilteredSearchEntityQuery } from '@/search/hooks/useFilteredSearchEntityQuery';
import { SelectedSortType } from '@/ui/filter-n-sort/types/interface';
import {
CommentableType,
PersonOrderByWithRelationInput as People_Order_By,
PersonWhereInput as People_Bool_Exp,
SortOrder,
@ -69,11 +69,11 @@ export function useFilteredSearchPeopleQuery({
mappingFunction: (entity) =>
({
id: entity.id,
entityType: CommentableType.Person,
entityType: ActivityTargetableEntityType.Person,
name: `${entity.firstName} ${entity.lastName}`,
avatarUrl: entity.avatarUrl,
avatarType: 'rounded',
} as CommentableEntityForSelect),
} as ActivityTargetableEntityForSelect),
searchFilter,
limit,
});

View File

@ -1,14 +1,15 @@
import { useOpenCreateActivityDrawerForSelectedRowIds } from '@/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { TableActionBarButtonToggleComments } from '@/ui/table/action-bar/components/TableActionBarButtonOpenComments';
import { TableActionBarButtonToggleTasks } from '@/ui/table/action-bar/components/TableActionBarButtonOpenTasks';
import { ActivityType, CommentableType } from '~/generated/graphql';
import { ActivityType } from '~/generated/graphql';
export function TableActionBarButtonCreateActivityPeople() {
const openCreateActivityRightDrawer =
useOpenCreateActivityDrawerForSelectedRowIds();
async function handleButtonClick(type: ActivityType) {
openCreateActivityRightDrawer(type, CommentableType.Person);
openCreateActivityRightDrawer(type, ActivityTargetableEntityType.Person);
}
return (

View File

@ -1,4 +1,5 @@
import { CommentableType, PipelineProgressableType } from '~/generated/graphql';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { PipelineProgressableType } from '~/generated/graphql';
export enum Entity {
Company = 'Company',
@ -7,6 +8,6 @@ export enum Entity {
}
export type EntityTypeForSelect =
| CommentableType
| ActivityTargetableEntityType
| PipelineProgressableType
| Entity;

View File

@ -2,6 +2,7 @@ import { useParams } from 'react-router-dom';
import { useTheme } from '@emotion/react';
import { Timeline } from '@/activities/timeline/components/Timeline';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { CompanyTeam } from '@/companies/components/CompanyTeam';
import { useCompanyQuery } from '@/companies/queries';
import { useFavorites } from '@/favorites/hooks/useFavorites';
@ -15,10 +16,7 @@ import { WithTopBarContainer } from '@/ui/layout/components/WithTopBarContainer'
import { ShowPageLeftContainer } from '@/ui/layout/show-page/components/ShowPageLeftContainer';
import { ShowPageRightContainer } from '@/ui/layout/show-page/components/ShowPageRightContainer';
import { ShowPageSummaryCard } from '@/ui/layout/show-page/components/ShowPageSummaryCard';
import {
CommentableType,
useUpdateOneCompanyMutation,
} from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
import { getLogoUrlFromDomainName } from '~/utils';
import { CompanyNameEditableField } from '../../modules/companies/editable-field/components/CompanyNameEditableField';
@ -85,7 +83,10 @@ export function CompanyShow() {
</ShowPageLeftContainer>
<ShowPageRightContainer>
<Timeline
entity={{ id: company.id ?? '', type: CommentableType.Company }}
entity={{
id: company.id,
type: ActivityTargetableEntityType.Company,
}}
/>
</ShowPageRightContainer>
</ShowPageContainer>

View File

@ -3,6 +3,7 @@ import { getOperationName } from '@apollo/client/utilities';
import { useTheme } from '@emotion/react';
import { Timeline } from '@/activities/timeline/components/Timeline';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { GET_PERSON, usePersonQuery } from '@/people/queries';
import { GenericEditableField } from '@/ui/editable-field/components/GenericEditableField';
@ -16,7 +17,6 @@ import { ShowPageLeftContainer } from '@/ui/layout/show-page/components/ShowPage
import { ShowPageRightContainer } from '@/ui/layout/show-page/components/ShowPageRightContainer';
import { ShowPageSummaryCard } from '@/ui/layout/show-page/components/ShowPageSummaryCard';
import {
CommentableType,
useUpdateOnePersonMutation,
useUploadPersonPictureMutation,
} from '~/generated/graphql';
@ -100,7 +100,10 @@ export function PersonShow() {
</ShowPageLeftContainer>
<ShowPageRightContainer>
<Timeline
entity={{ id: person.id ?? '', type: CommentableType.Person }}
entity={{
id: person.id ?? '',
type: ActivityTargetableEntityType.Person,
}}
/>
</ShowPageRightContainer>
</ShowPageContainer>

View File

@ -3,6 +3,7 @@ import { matchPath, useLocation, useNavigate } from 'react-router-dom';
import { IconCheckbox, IconNotes } from '@tabler/icons-react';
import { useOpenCreateActivityDrawer } from '@/activities/hooks/useOpenCreateActivityDrawer';
import { ActivityTargetableEntityType } from '@/activities/types/ActivityTargetableEntity';
import { useEventTracker } from '@/analytics/hooks/useEventTracker';
import { useOnboardingStatus } from '@/auth/hooks/useOnboardingStatus';
import { OnboardingStatus } from '@/auth/utils/getOnboardingStatus';
@ -16,7 +17,7 @@ import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
import { TableHotkeyScope } from '@/ui/table/types/TableHotkeyScope';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { useGetWorkspaceFromInviteHashLazyQuery } from '~/generated/graphql';
import { ActivityType, CommentableType } from '~/generated/graphql';
import { ActivityType } from '~/generated/graphql';
import { useIsMatchingLocation } from '../hooks/useIsMatchingLocation';
@ -177,7 +178,7 @@ export function AuthAutoRouter() {
)?.params.id;
const entity = !!companyId
? { id: companyId, type: CommentableType.Company }
? { id: companyId, type: ActivityTargetableEntityType.Company }
: undefined;
addToCommandMenu([
@ -211,7 +212,7 @@ export function AuthAutoRouter() {
?.params.id;
const entity = !!personId
? { id: personId, type: CommentableType.Person }
? { id: personId, type: ActivityTargetableEntityType.Person }
: undefined;
addToCommandMenu([

View File

@ -3,7 +3,9 @@ import {
ActivityTarget,
ActivityType,
Comment,
CommentableType,
Company,
Person,
User,
} from '~/generated/graphql';
type MockedActivity = Pick<
@ -33,7 +35,11 @@ type MockedActivity = Pick<
lastName: string;
displayName: string;
};
comments: Array<Pick<Comment, 'body' | 'id'>>;
comments: Array<
Pick<Comment, 'body' | 'id' | 'createdAt' | 'updatedAt'> & {
author: Pick<User, 'id' | 'displayName' | 'avatarUrl'>;
}
>;
activityTargets: Array<
Pick<
ActivityTarget,
@ -42,9 +48,13 @@ type MockedActivity = Pick<
| 'createdAt'
| 'updatedAt'
| 'activityId'
| 'commentableId'
| 'commentableType'
> & { activity: Pick<Activity, 'id' | 'createdAt' | 'updatedAt'> }
| 'personId'
| 'companyId'
> & {
activity: Pick<Activity, 'id' | 'createdAt' | 'updatedAt'>;
person?: Pick<Person, 'id' | 'displayName'>;
company?: Pick<Company, 'id' | 'name' | 'domainName'>;
}
>;
};
@ -106,8 +116,13 @@ export const mockedActivities: Array<MockedActivity> = [
id: '89bb825c-171e-4bcc-9cf7-43448d6fb300',
createdAt: '2023-04-26T10:12:42.33625+00:00',
updatedAt: '2023-04-26T10:23:42.33625+00:00',
commentableType: CommentableType.Company,
commentableId: '89bb825c-171e-4bcc-9cf7-43448d6fb278', // airbnb
personId: null,
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
company: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
name: 'Airbnb',
domainName: 'airbnb.com',
},
activityId: '89bb825c-171e-4bcc-9cf7-43448d6fb230',
activity: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb230',
@ -120,8 +135,13 @@ export const mockedActivities: Array<MockedActivity> = [
id: '89bb825c-171e-4bcc-9cf7-43448d6fb301',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
commentableType: CommentableType.Company,
commentableId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae', // aircall
personId: null,
companyId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae',
company: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
name: 'Aircall',
domainName: 'aircall.io',
},
activityId: '89bb825c-171e-4bcc-9cf7-43448d6fb231',
activity: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb231',
@ -161,8 +181,12 @@ export const mockedActivities: Array<MockedActivity> = [
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
createdAt: '2023-04-26T10:12:42.33625+00:00',
updatedAt: '2023-04-26T10:23:42.33625+00:00',
commentableType: CommentableType.Person,
commentableId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', // Alexandre
personId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b', // Alexandre
person: {
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
displayName: 'Alexandre Test',
},
companyId: null,
activityId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
activity: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
@ -175,8 +199,8 @@ export const mockedActivities: Array<MockedActivity> = [
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
commentableType: CommentableType.Person,
commentableId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6d', // Jean d'Eau
personId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6d', // Jean d'Eau
companyId: null,
activityId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
activity: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',

View File

@ -29,8 +29,7 @@ export class CompanyRelationsResolver {
where: {
activityTargets: {
some: {
commentableType: 'Company',
commentableId: company.id,
companyId: company.id,
},
},
},
@ -51,8 +50,7 @@ export class CompanyRelationsResolver {
activity: {
activityTargets: {
some: {
commentableType: 'Company',
commentableId: company.id,
companyId: company.id,
},
},
},
@ -69,8 +67,7 @@ export class CompanyRelationsResolver {
where: {
activityTargets: {
some: {
commentableType: 'Company',
commentableId: company.id,
companyId: company.id,
},
},
},

View File

@ -29,8 +29,7 @@ export class PersonRelationsResolver {
where: {
activityTargets: {
some: {
commentableType: 'Person',
commentableId: person.id,
personId: person.id,
},
},
},
@ -51,8 +50,7 @@ export class PersonRelationsResolver {
activity: {
activityTargets: {
some: {
commentableType: 'Person',
commentableId: person.id,
personId: person.id,
},
},
},
@ -69,8 +67,7 @@ export class PersonRelationsResolver {
where: {
activityTargets: {
some: {
commentableType: 'Person',
commentableId: person.id,
personId: person.id,
},
},
},

View File

@ -0,0 +1,13 @@
/*
Warnings:
- You are about to drop the column `commentableId` on the `activity_targets` table. All the data in the column will be lost.
- You are about to drop the column `commentableType` on the `activity_targets` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "activity_targets" DROP COLUMN "commentableId",
DROP COLUMN "commentableType";
-- DropEnum
DROP TYPE "CommentableType";

View File

@ -364,11 +364,6 @@ model Activity {
@@map("activities")
}
enum CommentableType {
Person
Company
}
model Comment {
/// @Validator.IsString()
/// @Validator.IsOptional()
@ -400,14 +395,12 @@ model ActivityTarget {
/// @Validator.IsOptional()
id String @id @default(uuid())
activity Activity @relation(fields: [activityId], references: [id], onDelete: Cascade)
activityId String
commentableType CommentableType?
commentableId String?
activity Activity @relation(fields: [activityId], references: [id], onDelete: Cascade)
activityId String
/// @TypeGraphQL.omit(input: true, output: true)
workspace Workspace @relation(fields: [workspaceId], references: [id])
workspace Workspace @relation(fields: [workspaceId], references: [id])
/// @TypeGraphQL.omit(input: true, output: true)
workspaceId String
workspaceId String
personId String?
person Person? @relation(fields: [personId], references: [id], onDelete: Cascade)

View File

@ -18,8 +18,8 @@ export const seedComments = async (prisma: PrismaClient) => {
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb600',
commentableType: 'Company',
commentableId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
personId: null,
companyId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfb400',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
@ -71,8 +71,8 @@ export const seedComments = async (prisma: PrismaClient) => {
update: {},
create: {
id: 'twenty-fe256b39-3ec3-4fe3-8997-a76aa0bfb600',
commentableType: 'Person',
commentableId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
personId: 'twenty-755035db-623d-41fe-92e7-dd45b7c568e1',
companyId: null,
activityId: 'twenty-fe256b39-3ec3-4fe3-8997-b76aa0bfc408',
workspaceId: 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419',
},
@ -108,8 +108,8 @@ export const seedComments = async (prisma: PrismaClient) => {
update: {},
create: {
id: 'twenty-dev-fe256b39-3ec3-4fe3-8997-a76aa0bfba00',
commentableType: 'Company',
commentableId: 'twenty-dev-a674fa6c-1455-4c57-afaf-dd5dc086361e',
personId: null,
companyId: 'twenty-dev-a674fa6c-1455-4c57-afaf-dd5dc086361e',
activityId: 'twenty-dev-fe256b39-3ec3-4fe3-8997-b76aaabfb408',
workspaceId: 'twenty-dev-7ed9d212-1c25-4d02-bf25-6aeccf7ea420',
},