Add field isLabelSyncedWithName (#8829)
## Context
The recent addition of object renaming introduced issues with enum
names. Enum names should follow the pattern
`${schemaName}.${tableName}_${columnName}_enum`. To address this, and to
allow users to customize the API name (which is included in the enum
name, columnName), this PR implements behavior similar to object
renaming by introducing a `isLabelSyncedWithName` boolean.
<img width="624" alt="Screenshot 2024-12-02 at 11 58 49"
src="https://github.com/user-attachments/assets/690fb71c-83f0-4922-80c0-946c92dacc30">
<img width="596" alt="Screenshot 2024-12-02 at 11 58 39"
src="https://github.com/user-attachments/assets/af9a0037-7cf5-40c3-9ed5-d51b340c8087">
This commit is contained in:
@ -24,10 +24,12 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
const input = {
|
||||
defaultValue: "'OPTION_1'",
|
||||
label: 'Example Label',
|
||||
name: 'exampleLabel',
|
||||
icon: 'example-icon',
|
||||
type: FieldMetadataType.Select,
|
||||
description: 'Example description',
|
||||
options,
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const expected = {
|
||||
@ -37,6 +39,7 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
name: 'exampleLabel',
|
||||
options,
|
||||
defaultValue: "'OPTION_1'",
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const result = formatFieldMetadataItemInput(input);
|
||||
@ -47,9 +50,11 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
it('should handle input without options', () => {
|
||||
const input = {
|
||||
label: 'Example Label',
|
||||
name: 'exampleLabel',
|
||||
icon: 'example-icon',
|
||||
type: FieldMetadataType.Select,
|
||||
description: 'Example description',
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const expected = {
|
||||
@ -59,6 +64,7 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
name: 'exampleLabel',
|
||||
options: undefined,
|
||||
defaultValue: undefined,
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const result = formatFieldMetadataItemInput(input);
|
||||
@ -86,10 +92,12 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
const input = {
|
||||
defaultValue: ["'OPTION_1'", "'OPTION_2'"],
|
||||
label: 'Example Label',
|
||||
name: 'exampleLabel',
|
||||
icon: 'example-icon',
|
||||
type: FieldMetadataType.MultiSelect,
|
||||
description: 'Example description',
|
||||
options,
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const expected = {
|
||||
@ -99,6 +107,7 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
name: 'exampleLabel',
|
||||
options,
|
||||
defaultValue: ["'OPTION_1'", "'OPTION_2'"],
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const result = formatFieldMetadataItemInput(input);
|
||||
@ -109,9 +118,11 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
it('should handle multi select input without options', () => {
|
||||
const input = {
|
||||
label: 'Example Label',
|
||||
name: 'exampleLabel',
|
||||
icon: 'example-icon',
|
||||
type: FieldMetadataType.MultiSelect,
|
||||
description: 'Example description',
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const expected = {
|
||||
@ -121,6 +132,7 @@ describe('formatFieldMetadataItemInput', () => {
|
||||
name: 'exampleLabel',
|
||||
options: undefined,
|
||||
defaultValue: undefined,
|
||||
isLabelSyncedWithName: true,
|
||||
};
|
||||
|
||||
const result = formatFieldMetadataItemInput(input);
|
||||
|
||||
@ -1,29 +1,29 @@
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
||||
|
||||
export const formatFieldMetadataItemInput = (
|
||||
input: Partial<
|
||||
Pick<
|
||||
FieldMetadataItem,
|
||||
| 'type'
|
||||
| 'name'
|
||||
| 'label'
|
||||
| 'defaultValue'
|
||||
| 'icon'
|
||||
| 'description'
|
||||
| 'defaultValue'
|
||||
| 'type'
|
||||
| 'options'
|
||||
| 'settings'
|
||||
| 'isLabelSyncedWithName'
|
||||
>
|
||||
>,
|
||||
) => {
|
||||
const label = input.label?.trim();
|
||||
|
||||
return {
|
||||
defaultValue: input.defaultValue,
|
||||
description: input.description?.trim() ?? null,
|
||||
icon: input.icon,
|
||||
label,
|
||||
name: label ? computeMetadataNameFromLabel(label) : undefined,
|
||||
label: input.label?.trim(),
|
||||
name: input.name?.trim(),
|
||||
options: input.options,
|
||||
settings: input.settings,
|
||||
isLabelSyncedWithName: input.isLabelSyncedWithName,
|
||||
};
|
||||
};
|
||||
|
||||
@ -10,10 +10,10 @@ import { formatFieldMetadataItemInput } from './formatFieldMetadataItemInput';
|
||||
|
||||
export type FormatRelationMetadataInputParams = {
|
||||
relationType: RelationType;
|
||||
field: Pick<Field, 'label' | 'icon' | 'description'>;
|
||||
field: Pick<Field, 'label' | 'icon' | 'description' | 'name'>;
|
||||
objectMetadataId: string;
|
||||
connect: {
|
||||
field: Pick<Field, 'label' | 'icon'>;
|
||||
field: Pick<Field, 'label' | 'icon' | 'name'>;
|
||||
objectMetadataId: string;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user