feat: add sub fields for address (#13566)
https://github.com/user-attachments/assets/8fe9079d-9b66-4b42-8b11-ad713e9de666 --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
+9
-1
@@ -1,4 +1,8 @@
|
||||
import { FieldMetadataType, IsExactly } from 'twenty-shared/types';
|
||||
import {
|
||||
AllowedAddressSubField,
|
||||
FieldMetadataType,
|
||||
IsExactly,
|
||||
} from 'twenty-shared/types';
|
||||
|
||||
import { RelationOnDeleteAction } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-on-delete-action.interface';
|
||||
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
||||
@@ -40,6 +44,9 @@ export type FieldMetadataRelationSettings = {
|
||||
onDelete?: RelationOnDeleteAction;
|
||||
joinColumnName?: string | null;
|
||||
};
|
||||
export type FieldMetadataAddressSettings = {
|
||||
subFields?: AllowedAddressSubField[];
|
||||
};
|
||||
|
||||
type FieldMetadataSettingsMapping = {
|
||||
[FieldMetadataType.NUMBER]: FieldMetadataNumberSettings;
|
||||
@@ -48,6 +55,7 @@ type FieldMetadataSettingsMapping = {
|
||||
[FieldMetadataType.TEXT]: FieldMetadataTextSettings;
|
||||
[FieldMetadataType.RELATION]: FieldMetadataRelationSettings;
|
||||
[FieldMetadataType.MORPH_RELATION]: FieldMetadataRelationSettings;
|
||||
[FieldMetadataType.ADDRESS]: FieldMetadataAddressSettings;
|
||||
};
|
||||
|
||||
export type AllFieldMetadataSettings =
|
||||
|
||||
+19
-2
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { ClassConstructor, plainToInstance } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsOptional,
|
||||
@@ -11,7 +12,11 @@ import {
|
||||
ValidationError,
|
||||
validateOrReject,
|
||||
} from 'class-validator';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import {
|
||||
ALLOWED_ADDRESS_SUBFIELDS,
|
||||
AllowedAddressSubField,
|
||||
FieldMetadataType,
|
||||
} from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
|
||||
@@ -61,7 +66,12 @@ class TextSettingsValidation {
|
||||
@Max(100)
|
||||
displayedMaxRows?: number;
|
||||
}
|
||||
|
||||
class AddressSettingsValidation {
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsEnum(ALLOWED_ADDRESS_SUBFIELDS, { each: true })
|
||||
subFields?: AllowedAddressSubField[];
|
||||
}
|
||||
@Injectable()
|
||||
export class FieldMetadataValidationService {
|
||||
constructor(
|
||||
@@ -90,6 +100,13 @@ export class FieldMetadataValidationService {
|
||||
settings,
|
||||
});
|
||||
break;
|
||||
case FieldMetadataType.ADDRESS:
|
||||
await this.validateSettings({
|
||||
type: FieldMetadataType.ADDRESS,
|
||||
validator: AddressSettingsValidation,
|
||||
settings,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user