Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixMalfait committed Apr 17, 2024
1 parent 908783e commit 8ea1c33
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Tooltip } from 'react-tooltip';
import styled from '@emotion/styled';
import { useRecoilValue } from 'recoil';
import {
IconCheckbox,
IconCirclePlus,
IconEditCircle,
IconFocusCentered,
IconNotes,
useIcons,
} from 'twenty-ui';

import { EventUpdateProperty } from '@/activities/events/components/EventUpdateProperty';
import { TimelineActivity } from '@/activities/events/types/TimelineActivity';
import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector';
import { useLinkedObject } from '@/activities/timeline/hooks/useLinkedObject';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useIcons } from '@/ui/display/icon/hooks/useIcons';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import {
beautifyExactDateTime,
Expand Down Expand Up @@ -153,12 +152,7 @@ export const EventRow = ({

const { getIcon } = useIcons();

const linkedObjectMetadata = useRecoilValue(
objectMetadataItemFamilySelector({
objectName: event.linkedObjectMetadataId,
objectNameType: 'id',
}),
);
const linkedObjectMetadata = useLinkedObject(event.linkedObjectMetadataId);

const linkedObjectLabel = event.name.includes('Note')
? 'Note'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export type TimelineActivity = {
createdAt: string;
updatedAt: string;
deletedAt: string | null;
opportunityId: string | null;
companyId: string | null;
personId: string | null;
workspaceMemberId: string;
workspaceMember: WorkspaceMember;
properties: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { mockedEvents } from '~/testing/mock-data/events';
import { TimelineActivity } from '@/activities/events/types/TimelineActivity';
import { mockedTimelineActivities } from '~/testing/mock-data/timeline-activities';

import { groupEventsByMonth } from '../groupEventsByMonth';

describe('groupEventsByMonth', () => {
it('should group activities by month', () => {
const grouped = groupEventsByMonth(mockedEvents as unknown as Event[]);
const grouped = groupEventsByMonth(
mockedTimelineActivities as unknown as TimelineActivity[],
);

expect(grouped).toHaveLength(2);
expect(grouped[0].items).toHaveLength(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useRecoilValue } from 'recoil';

import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';

export const useLinkedObject = (id: string) => {
const objectMetadataItems: ObjectMetadataItem[] = useRecoilValue(
objectMetadataItemsState,
);

return (
objectMetadataItems.find(
(objectMetadataItem) => objectMetadataItem.id === id,
) ?? null
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';

type ObjectMetadataItemSelector = {
objectName: string;
objectNameType: 'singular' | 'plural' | 'id';
objectNameType: 'singular' | 'plural';
};

export const objectMetadataItemFamilySelector = selectorFamily<
Expand All @@ -32,14 +32,7 @@ export const objectMetadataItemFamilySelector = selectorFamily<
objectMetadataItem.namePlural === objectName,
) ?? null
);
} else if (objectNameType === 'id') {
return (
objectMetadataItems.find(
(objectMetadataItem) => objectMetadataItem.id === objectName,
) ?? null
);
}

return null;
},
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { TimelineActivity } from '@/activities/events/types/TimelineActivity';

export const mockedEvents: Array<TimelineActivity> = [
export const mockedTimelineActivities: Array<TimelineActivity> = [
{
properties: '{"diff": {"address": {"after": "TEST", "before": ""}}}',
updatedAt: '2023-04-26T10:12:42.33625+00:00',
id: '79f84835-b2f9-4ab5-8ab9-17dbcc45dda3',
personId: null,
companyId: 'ce40eca0-8f4b-4bba-ba91-5cbd870c64d0',
linkedObjectMetadataId: '1ad72a42-6ab4-4474-a62a-a57cae3c0298',
linkedRecordCachedName: 'Test',
linkedRecordId: 'ce40eca0-8f4b-4bba-ba91-5cbd870c64d0',
name: 'updated.company',
opportunityId: null,
createdAt: '2023-04-26T10:12:42.33625+00:00',
workspaceMember: {
__typename: 'WorkspaceMember',
Expand All @@ -30,10 +30,10 @@ export const mockedEvents: Array<TimelineActivity> = [
'{"after": {"id": "ce40eca0-8f4b-4bba-ba91-5cbd870c64d0", "name": "", "xLink": {"url": "", "label": ""}, "events": {"edges": [], "__typename": "eventConnection"}, "people": {"edges": [], "__typename": "personConnection"}, "address": "", "position": 0.5, "createdAt": "2024-03-24T21:33:45.765295", "employees": null, "favorites": {"edges": [], "__typename": "favoriteConnection"}, "updatedAt": "2024-03-24T21:33:45.765295", "__typename": "company", "domainName": "", "attachments": {"edges": [], "__typename": "attachmentConnection"}, "accountOwner": null, "linkedinLink": {"url": "", "label": ""}, "opportunities": {"edges": [], "__typename": "opportunityConnection"}, "accountOwnerId": null, "activityTargets": {"edges": [], "__typename": "activityTargetConnection"}, "idealCustomerProfile": false, "annualRecurringRevenue": {"amountMicros": null, "currencyCode": ""}}}',
updatedAt: new Date().toISOString(),
id: '1ad72a42-6ab4-4474-a62a-a57cae3c0298',
personId: null,
companyId: 'ce40eca0-8f4b-4bba-ba91-5cbd870c64d0',
name: 'created.company',
opportunityId: null,
linkedObjectMetadataId: '1ad72a42-6ab4-4474-a62a-a57cae3c0298',
linkedRecordCachedName: 'Test',
linkedRecordId: 'ce40eca0-8f4b-4bba-ba91-5cbd870c64d0',
createdAt: new Date().toISOString(),
workspaceMember: {
__typename: 'WorkspaceMember',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const mockObjectMetadata: ObjectMetadataInterface = {
isCustom: false,
isActive: true,
isRemote: false,
isAuditLogged: true,
};

describe('objectRecordChangedValues', () => {
Expand Down Expand Up @@ -79,6 +80,7 @@ it('correctly handles a mix of changed, unchanged, and special case values', ()
};
const expectedChanges = {
name: { before: 'Original', after: 'Updated' },
config: { before: { theme: 'dark' }, after: { theme: 'light' } },
};

const result = objectRecordChangedValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,11 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
return;
}

const { timelineActivityObjectMetadata } = await this.createEventRelation(
objectMetadataInput.workspaceId,
createdObjectMetadata,
);
const { timelineActivityObjectMetadata } =
await this.createTimelineActivityRelation(
objectMetadataInput.workspaceId,
createdObjectMetadata,
);

const { activityTargetObjectMetadata } =
await this.createActivityTargetRelation(
Expand Down Expand Up @@ -708,13 +709,13 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
return { attachmentObjectMetadata };
}

private async createEventRelation(
private async createTimelineActivityRelation(
workspaceId: string,
createdObjectMetadata: ObjectMetadataEntity,
) {
const timelineActivityObjectMetadata =
await this.objectMetadataRepository.findOneByOrFail({
nameSingular: 'event',
nameSingular: 'timelineActivity',
workspaceId: workspaceId,
});

Expand Down Expand Up @@ -747,7 +748,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
type: FieldMetadataType.RELATION,
name: createdObjectMetadata.nameSingular,
label: createdObjectMetadata.labelSingular,
description: `Event ${createdObjectMetadata.labelSingular}`,
description: `Timeline Activity ${createdObjectMetadata.labelSingular}`,
icon: 'IconBuildingSkyscraper',
isNullable: true,
},
Expand All @@ -764,7 +765,7 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
type: FieldMetadataType.UUID,
name: `${createdObjectMetadata.nameSingular}Id`,
label: `${createdObjectMetadata.labelSingular} ID (foreign key)`,
description: `Event ${createdObjectMetadata.labelSingular} id foreign key`,
description: `Timeline Activity ${createdObjectMetadata.labelSingular} id foreign key`,
icon: undefined,
isNullable: true,
isSystem: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export class UpsertTimelineActivityFromInternalEvent
};
}

// If data.objectMetadata.nameSingular is not activityTarget, company
if (
data.objectMetadata.isSystem &&
data.objectMetadata.nameSingular !== 'activityTarget' &&
data.objectMetadata.nameSingular !== 'activity'
) {
return;
}

await this.timelineActivityRepository.upsert(
data.name,
data.details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class TimelineActivityRepository {
properties,
workspaceMemberId,
objectId,
linkedRecordCachedName,
linkedRecordCachedName ?? '',
linkedRecordId,
linkedObjectMetadataId,
],
Expand Down

0 comments on commit 8ea1c33

Please sign in to comment.