Prevent relation update from settings (#13099)

## Expected behavior

Described behavior regarding: (update | create) x (custom | standard) x
(icon, label, name, isSynced)

**Custom:**
- Field RELATION create: name, label, isSynced, icon should be editable
- Field RELATION update: name should not, icon label, isSynced should
- For other fields, icon, label, name, isSynced should be editable at
field creation | update

To simplify: Field RELATION name should not be editable at update

**Standards**
- Field: create does not makes sense
- Field: name should not, icon label, isSynced should (this will end up
in overrides)

To simplify, no Field RELATION edge case, name should not be editable at
update

**Note:** the FE logic is quite different as the UI is hiding some
details behind the syncWithLabel. See my comments and TODO there


## What I've tested:
(update | create) x (custom | standard) x (icon, label, name, isSynced,
description)
This commit is contained in:
Charles Bochet
2025-07-08 21:03:38 +02:00
committed by GitHub
parent c8ec44eeaf
commit 39f6f3c4bb
13 changed files with 615 additions and 150 deletions
@@ -141,33 +141,6 @@ describe('BeforeUpdateOneField', () => {
).rejects.toThrow(ValidationError);
});
it('should throw ValidationError when trying to update label when it is synced with name', async () => {
const instance: UpdateOneInputType<UpdateFieldInputForTest> = {
id: mockFieldId,
update: {
label: 'New Label',
},
};
const mockField: Partial<FieldMetadataEntity> = {
id: mockFieldId,
isCustom: false,
isLabelSyncedWithName: true,
label: 'Old Label',
};
jest
.spyOn(fieldMetadataService, 'findOneWithinWorkspace')
.mockResolvedValue(mockField as FieldMetadataEntity);
await expect(
hook.run(instance as UpdateOneInputType<UpdateFieldInput>, {
workspaceId: mockWorkspaceId,
locale: undefined,
}),
).rejects.toThrow(ValidationError);
});
it('should handle isActive updates for standard fields', async () => {
const instance: UpdateOneInputType<UpdateFieldInputForTest> = {
id: mockFieldId,
@@ -89,18 +89,6 @@ export class BeforeUpdateOneField<T extends UpdateFieldInput>
!updatableFields.includes(key) && !overridableFields.includes(key),
);
const isUpdatingLabelWhenSynced =
instance.update.label &&
fieldMetadata.isLabelSyncedWithName &&
instance.update.isLabelSyncedWithName !== false &&
instance.update.label !== fieldMetadata.label;
if (isUpdatingLabelWhenSynced) {
throw new ValidationError(
'Cannot update label when it is synced with name',
);
}
if (nonUpdatableFields.length > 0) {
throw new ValidationError(
`Only isActive, isLabelSyncedWithName, label, icon, description and defaultValue fields can be updated for standard fields. Invalid fields: ${nonUpdatableFields.join(', ')}`,
@@ -390,13 +378,6 @@ export class BeforeUpdateOneField<T extends UpdateFieldInput>
update: StandardFieldUpdate,
locale?: keyof typeof APP_LOCALES,
): void {
if (
fieldMetadata.isLabelSyncedWithName ||
update.isLabelSyncedWithName === true
) {
return;
}
if (!isDefined(instance.update.label)) {
return;
}