The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { msg } from '@lingui/core/macro';
import { i18nLabel } from 'src/engine/workspace-manager/twenty-standard-application/utils/i18n-label.util';
import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
import {
DateDisplayFormat,
FieldMetadataType,
RelationOnDeleteAction,
RelationType,
} from 'twenty-shared/types';
import { STANDARD_RELATION_FIELD_PROPERTIES_BY_RELATION_OBJECT } from 'src/engine/metadata-modules/object-metadata/constants/standard-relation-field-properties.constant';
import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';
import { type AllStandardObjectFieldName } from 'src/engine/workspace-manager/twenty-standard-application/types/all-standard-object-field-name.type';
import {
type CreateStandardFieldArgs,
createStandardFieldFlatMetadata,
} from 'src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/create-standard-field-flat-metadata.util';
import { createStandardRelationFieldFlatMetadata } from 'src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/create-standard-relation-field-flat-metadata.util';
export const buildTaskStandardFlatFieldMetadatas = ({
now,
objectName,
workspaceId,
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
}: Omit<CreateStandardFieldArgs<'task', FieldMetadataType>, 'context'>): Record<
AllStandardObjectFieldName<'task'>,
FlatFieldMetadata
> => ({
id: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'id',
type: FieldMetadataType.UUID,
label: i18nLabel(msg({ message: `ID`, context: 'fieldMetadata.label' })),
description: i18nLabel(
msg({ message: `ID`, context: 'fieldMetadata.description' }),
),
icon: 'Icon123',
isSystem: true,
isNullable: false,
isUIEditable: false,
defaultValue: 'uuid',
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
createdAt: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'createdAt',
type: FieldMetadataType.DATE_TIME,
label: i18nLabel(
msg({ message: `Creation date`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Creation date`, context: 'fieldMetadata.description' }),
),
icon: 'IconCalendar',
isSystem: true,
isNullable: false,
isUIEditable: false,
defaultValue: 'now',
settings: {
displayFormat: DateDisplayFormat.RELATIVE,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
updatedAt: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'updatedAt',
type: FieldMetadataType.DATE_TIME,
label: i18nLabel(
msg({ message: `Last update`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `Last time the record was changed`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconCalendarClock',
isSystem: true,
isNullable: false,
isUIEditable: false,
defaultValue: 'now',
settings: {
displayFormat: DateDisplayFormat.RELATIVE,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
deletedAt: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'deletedAt',
type: FieldMetadataType.DATE_TIME,
label: i18nLabel(
msg({ message: `Deleted at`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `Date when the record was deleted`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconCalendarMinus',
isSystem: true,
isNullable: true,
isUIEditable: false,
settings: {
displayFormat: DateDisplayFormat.RELATIVE,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
position: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'position',
type: FieldMetadataType.POSITION,
label: i18nLabel(
msg({ message: `Position`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `Task record position`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconHierarchy2',
isSystem: true,
isNullable: false,
defaultValue: 0,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
title: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'title',
type: FieldMetadataType.TEXT,
label: i18nLabel(
msg({ message: `Title`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task title`, context: 'fieldMetadata.description' }),
),
icon: 'IconNotes',
isNullable: true,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
bodyV2: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'bodyV2',
type: FieldMetadataType.RICH_TEXT,
label: i18nLabel(
msg({ message: `Body`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task body`, context: 'fieldMetadata.description' }),
),
icon: 'IconFilePencil',
isNullable: true,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
dueAt: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'dueAt',
type: FieldMetadataType.DATE_TIME,
label: i18nLabel(
msg({ message: `Due Date`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task due date`, context: 'fieldMetadata.description' }),
),
icon: 'IconCalendarEvent',
isNullable: true,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
status: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'status',
type: FieldMetadataType.SELECT,
label: i18nLabel(
msg({ message: `Status`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task status`, context: 'fieldMetadata.description' }),
),
icon: 'IconCheck',
isNullable: true,
defaultValue: "'TODO'",
options: [
{
id: '20202020-3d31-4860-ad07-5c4603d44887',
value: 'TODO',
label: i18nLabel(
msg({ message: `To do`, context: 'fieldMetadata.label' }),
),
position: 0,
color: 'sky',
},
{
id: '20202020-c559-4f8e-8b8e-21136da8684d',
value: 'IN_PROGRESS',
label: i18nLabel(
msg({ message: `In progress`, context: 'fieldMetadata.label' }),
),
position: 1,
color: 'purple',
},
{
id: '20202020-c7a7-43ff-8226-f6a97a32759e',
value: 'DONE',
label: i18nLabel(
msg({ message: `Done`, context: 'fieldMetadata.label' }),
),
position: 2,
color: 'green',
},
],
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
createdBy: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'createdBy',
type: FieldMetadataType.ACTOR,
label: i18nLabel(
msg({ message: `Created by`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `The creator of the record`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconCreativeCommonsSa',
isSystem: true,
isUIEditable: false,
isNullable: false,
defaultValue: {
source: "'MANUAL'",
name: "'System'",
workspaceMemberId: null,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
updatedBy: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'updatedBy',
type: FieldMetadataType.ACTOR,
label: i18nLabel(
msg({ message: `Updated by`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `The workspace member who last updated the record`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconUserCircle',
isSystem: true,
isUIEditable: false,
isNullable: false,
defaultValue: {
source: "'MANUAL'",
name: "'System'",
workspaceMemberId: null,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
searchVector: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'searchVector',
type: FieldMetadataType.TS_VECTOR,
label: i18nLabel(
msg({ message: `Search vector`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({
message: `Field used for full-text search`,
context: 'fieldMetadata.description',
}),
),
icon: 'IconUser',
isSystem: true,
isNullable: true,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
taskTargets: createStandardRelationFieldFlatMetadata({
objectName,
workspaceId,
context: {
type: FieldMetadataType.RELATION,
morphId: null,
fieldName: 'taskTargets',
label: i18nLabel(
msg({ message: `Relations`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task targets`, context: 'fieldMetadata.description' }),
),
icon: 'IconArrowUpRight',
isNullable: true,
targetObjectName: 'taskTarget',
targetFieldName: 'task',
settings: {
relationType: RelationType.ONE_TO_MANY,
},
junctionTargetFieldUniversalIdentifier:
STANDARD_OBJECTS.taskTarget.fields.targetPerson.universalIdentifier,
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
attachments: createStandardRelationFieldFlatMetadata({
objectName,
workspaceId,
context: {
type: FieldMetadataType.RELATION,
morphId: null,
fieldName: 'attachments',
isSystemSideEffect: true,
label: i18nLabel(
STANDARD_RELATION_FIELD_PROPERTIES_BY_RELATION_OBJECT.attachment.label,
),
description: i18nLabel(
msg({
message: `Task attachments`,
context: 'fieldMetadata.description',
}),
),
icon: STANDARD_RELATION_FIELD_PROPERTIES_BY_RELATION_OBJECT.attachment
.icon,
isNullable: true,
targetObjectName: 'attachment',
targetFieldName: 'targetTask',
settings: {
relationType: RelationType.ONE_TO_MANY,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
assignee: createStandardRelationFieldFlatMetadata({
objectName,
workspaceId,
context: {
type: FieldMetadataType.RELATION,
morphId: null,
fieldName: 'assignee',
label: i18nLabel(
msg({ message: `Assignee`, context: 'fieldMetadata.label' }),
),
description: i18nLabel(
msg({ message: `Task assignee`, context: 'fieldMetadata.description' }),
),
icon: 'IconUserCircle',
isNullable: true,
targetObjectName: 'workspaceMember',
targetFieldName: 'assignedTasks',
settings: {
relationType: RelationType.MANY_TO_ONE,
onDelete: RelationOnDeleteAction.SET_NULL,
joinColumnName: 'assigneeId',
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
timelineActivities: createStandardRelationFieldFlatMetadata({
objectName,
workspaceId,
context: {
type: FieldMetadataType.RELATION,
morphId: null,
fieldName: 'timelineActivities',
isSystemSideEffect: true,
label: i18nLabel(
STANDARD_RELATION_FIELD_PROPERTIES_BY_RELATION_OBJECT.timelineActivity
.label,
),
description: i18nLabel(
msg({
message: `Timeline Activities linked to the task.`,
context: 'fieldMetadata.description',
}),
),
icon: STANDARD_RELATION_FIELD_PROPERTIES_BY_RELATION_OBJECT
.timelineActivity.icon,
isNullable: true,
targetObjectName: 'timelineActivity',
targetFieldName: 'targetTask',
settings: {
relationType: RelationType.ONE_TO_MANY,
},
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
});