Add label identifier to object decorator (#6227)

## Context
LabelIdentifier and ImageIdentifier are metadata info attached to
objectMetadata that are used to display a record in a more readable way.
Those columns point to existing fields that are part of the object.
For example, for a relation picker of a person, we will show a record
using the "name" labelIdentifier and the "avatarUrl" imageIdentifier.
<img width="215" alt="Screenshot 2024-07-11 at 18 45 51"
src="https://github.com/twentyhq/twenty/assets/1834158/488f8294-0d7c-4209-b763-2499716ef29d">

Currently, the FE has a specific logic for company and people objects
and we have a way to update this value via the API for custom objects,
but the code is not flexible enough to change other standard objects.

This PR updates the WorkspaceEntity API so we can now provide the
labelIdentifier and imageIdentifier in the WorkspaceEntity decorator.

Example:
```typescript
@WorkspaceEntity({
  standardId: STANDARD_OBJECT_IDS.activity,
  namePlural: 'activities',
  labelSingular: 'Activity',
  labelPlural: 'Activities',
  description: 'An activity',
  icon: 'IconCheckbox',
  labelIdentifierStandardId: ACTIVITY_STANDARD_FIELD_IDS.title,
})
@WorkspaceIsSystem()
export class ActivityWorkspaceEntity extends BaseWorkspaceEntity {
  @WorkspaceField({
    standardId: ACTIVITY_STANDARD_FIELD_IDS.title,
    type: FieldMetadataType.TEXT,
    label: 'Title',
    description: 'Activity title',
    icon: 'IconNotes',
  })
  title: string;
...
```
This commit is contained in:
Weiko
2024-07-19 14:24:04 +02:00
committed by GitHub
parent 8a1af3a2ff
commit 67e2d5c73a
29 changed files with 355 additions and 110 deletions

View File

@ -1,4 +1,5 @@
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
import { BASE_OBJECT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util';
import { TypedReflect } from 'src/utils/typed-reflect';
@ -9,6 +10,8 @@ interface WorkspaceEntityOptions {
labelPlural: string;
description?: string;
icon?: string;
labelIdentifierStandardId?: string;
imageIdentifierStandardId?: string;
}
export function WorkspaceEntity(
@ -37,6 +40,9 @@ export function WorkspaceEntity(
labelSingular: options.labelSingular,
labelPlural: options.labelPlural,
description: options.description,
labelIdentifierStandardId:
options.labelIdentifierStandardId ?? BASE_OBJECT_STANDARD_FIELD_IDS.id,
imageIdentifierStandardId: options.imageIdentifierStandardId ?? null,
icon: options.icon,
isAuditLogged,
isSystem,

View File

@ -50,4 +50,16 @@ export interface WorkspaceEntityMetadataArgs {
* Entity gate.
*/
readonly gate?: Gate;
/**
* Label identifier.
*/
readonly labelIdentifierStandardId: string | null;
/**
* Image identifier.
*/
readonly imageIdentifierStandardId: string | null;
}