Files
twenty/packages/twenty-server/src/modules/timeline/standard-objects/timeline-activity.object-metadata.ts
Félix Malfait d145684966 New Timeline (#4936)
Refactored the code to introduce two different concepts:
- AuditLogs (immutable, raw data)
- TimelineActivities (user-friendly, transformed data)

Still some work needed:
- Add message, files, calendar events to timeline (~2 hours if done
naively)
- Refactor repository to try to abstract concept when we can (tbd, wait
for Twenty ORM)
- Introduce ability to display child timelines on parent timeline with
filtering (~2 days)
- Improve UI: add links to open note/task, improve diff display, etc
(half a day)
- Decide the path forward for Task vs Notes: either introduce a new
field type "Record Type" and start going into that direction ; or split
in two objects?
- Trigger updates when a field is changed (will be solved by real-time /
websockets: 2 weeks)
- Integrate behavioral events (1 day for POC, 1 week for
clean/documented)

<img width="1248" alt="Screenshot 2024-04-12 at 09 24 49"
src="https://github.com/twentyhq/twenty/assets/6399865/9428db1a-ab2b-492c-8b0b-d4d9a36e81fa">
2024-04-19 17:52:57 +02:00

149 lines
5.8 KiB
TypeScript

import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { timelineActivityStandardFieldIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { standardObjectIds } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { DynamicRelationFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/dynamic-field-metadata.interface';
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
import { IsNotAuditLogged } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-not-audit-logged.decorator';
import { IsNullable } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-nullable.decorator';
import { IsSystem } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-system.decorator';
import { ObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/object-metadata.decorator';
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
import { CompanyObjectMetadata } from 'src/modules/company/standard-objects/company.object-metadata';
import { OpportunityObjectMetadata } from 'src/modules/opportunity/standard-objects/opportunity.object-metadata';
import { PersonObjectMetadata } from 'src/modules/person/standard-objects/person.object-metadata';
import { WorkspaceMemberObjectMetadata } from 'src/modules/workspace-member/standard-objects/workspace-member.object-metadata';
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { Gate } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/gate.decorator';
import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
@ObjectMetadata({
standardId: standardObjectIds.timelineActivity,
namePlural: 'timelineActivities',
labelSingular: 'Timeline Activity',
labelPlural: 'Timeline Activities',
description: 'Aggregated / filtered event to be displayed on the timeline',
icon: 'IconIconTimelineEvent',
})
@IsSystem()
@IsNotAuditLogged()
@Gate({
featureFlag: FeatureFlagKeys.IsEventObjectEnabled,
})
export class TimelineActivityObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.happensAt,
type: FieldMetadataType.DATE_TIME,
label: 'Creation date',
description: 'Creation date',
icon: 'IconCalendar',
defaultValue: 'now',
})
happensAt: Date;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.name,
type: FieldMetadataType.TEXT,
label: 'Event name',
description: 'Event name',
icon: 'IconAbc',
})
name: string;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.properties,
type: FieldMetadataType.RAW_JSON,
label: 'Event details',
description: 'Json value for event details',
icon: 'IconListDetails',
})
@IsNullable()
properties: JSON;
// Who made the action
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.workspaceMember,
type: FieldMetadataType.RELATION,
label: 'Workspace Member',
description: 'Event workspace member',
icon: 'IconCircleUser',
joinColumn: 'workspaceMemberId',
})
@IsNullable()
workspaceMember: Relation<WorkspaceMemberObjectMetadata>;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.person,
type: FieldMetadataType.RELATION,
label: 'Person',
description: 'Event person',
icon: 'IconUser',
joinColumn: 'personId',
})
@IsNullable()
person: Relation<PersonObjectMetadata>;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.company,
type: FieldMetadataType.RELATION,
label: 'Company',
description: 'Event company',
icon: 'IconBuildingSkyscraper',
joinColumn: 'companyId',
})
@IsNullable()
company: Relation<CompanyObjectMetadata>;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.opportunity,
type: FieldMetadataType.RELATION,
label: 'Opportunity',
description: 'Events opportunity',
icon: 'IconTargetArrow',
joinColumn: 'opportunityId',
})
@IsNullable()
opportunity: Relation<OpportunityObjectMetadata>;
@DynamicRelationFieldMetadata((oppositeObjectMetadata) => ({
standardId: timelineActivityStandardFieldIds.custom,
name: oppositeObjectMetadata.nameSingular,
label: oppositeObjectMetadata.labelSingular,
description: `Event ${oppositeObjectMetadata.labelSingular}`,
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
icon: 'IconTimeline',
}))
custom: Relation<CustomObjectMetadata>;
// Special objects that don't have their own timeline and are 'link' to the main object
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.linkedRecordCachedName,
type: FieldMetadataType.TEXT,
label: 'Linked Record cached name',
description: 'Cached record name',
icon: 'IconAbc',
})
linkedRecordCachedName: string;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.linkedRecordId,
type: FieldMetadataType.UUID,
label: 'Linked Record id',
description: 'Linked Record id',
icon: 'IconAbc',
})
@IsNullable()
linkedRecordId: string;
@FieldMetadata({
standardId: timelineActivityStandardFieldIds.linkedObjectMetadataId,
type: FieldMetadataType.UUID,
label: 'Linked Object Metadata Id',
description: 'inked Object Metadata Id',
icon: 'IconAbc',
})
@IsNullable()
linkedObjectMetadataId: string;
}