feat: allow backend to rename field of custom object (#4097)

* feat: allow backend to rename field of custom object

* feat: allow custom field label edition in Settings

Closes #4080

* fix: avoid renaming standard fields

---------

Co-authored-by: Thaïs Guigon <guigon.thais@gmail.com>
This commit is contained in:
Jérémy M 2024-02-21 18:59:51 +01:00 committed by GitHub
parent 140d3460eb
commit e69c462b70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import { Section } from '@/ui/layout/section/components/Section';
type SettingsObjectFieldFormSectionProps = {
disabled?: boolean;
disableNameEdition?: boolean;
name?: string;
description?: string;
iconKey?: string;
@ -31,7 +30,6 @@ const StyledInputsContainer = styled.div`
export const SettingsObjectFieldFormSection = ({
disabled,
disableNameEdition,
name = '',
description = '',
iconKey = 'IconUsers',
@ -57,7 +55,7 @@ export const SettingsObjectFieldFormSection = ({
onChange?.({ label: value });
}
}}
disabled={disabled || disableNameEdition}
disabled={disabled}
fullWidth
/>
</StyledInputsContainer>

View File

@ -209,7 +209,6 @@ export const SettingsObjectFieldEdit = () => {
</SettingsHeaderContainer>
<SettingsObjectFieldFormSection
disabled={!activeMetadataField.isCustom}
disableNameEdition
name={formValues.label}
description={formValues.description}
iconKey={formValues.icon}

View File

@ -228,9 +228,23 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
)
: fieldMetadataInput;
const updatedFieldMetadata = await super.updateOne(id, updatableFieldInput);
const updatedFieldMetadata = await super.updateOne(id, {
...updatableFieldInput,
// If the name is updated, the targetColumnMap should be updated as well
targetColumnMap: updatableFieldInput.name
? generateTargetColumnMap(
existingFieldMetadata.type,
existingFieldMetadata.isCustom,
updatableFieldInput.name,
)
: existingFieldMetadata.targetColumnMap,
});
if (updatableFieldInput.options || updatableFieldInput.defaultValue) {
if (
fieldMetadataInput.name ||
updatableFieldInput.options ||
updatableFieldInput.defaultValue
) {
await this.workspaceMigrationService.createCustomMigration(
generateMigrationName(`update-${updatedFieldMetadata.name}`),
existingFieldMetadata.workspaceId,