From 9101bbbb1b713a3a058005e593d62b07a6633015 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Tue, 25 Apr 2023 19:31:16 +0800 Subject: [PATCH] chore: skip sync overriding field default value (#1762) * chore: skip sync overriding field default value * chore: test * chore: override field does not allow setting default values --------- Co-authored-by: katherinehhh --- .../Configuration/EditFieldAction.tsx | 2 +- .../OverridingCollectionField.tsx | 1 + .../inherits/inherited-collection.test.ts | 50 +++++++++++++++++++ .../collection-manager/src/models/field.ts | 5 ++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx b/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx index 7c5ebe953..7b589ed87 100644 --- a/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx +++ b/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx @@ -45,6 +45,7 @@ const getSchema = (schema: IField, record: any, compile, getContainer): ISchema }, }, }; + properties['defaultValue']['x-disabled'] = record.overriding; } return { @@ -143,7 +144,6 @@ export const EditFieldAction = (props) => { const { t } = useTranslation(); const compile = useCompile(); const [data, setData] = useState({}); - return ( diff --git a/packages/core/client/src/collection-manager/Configuration/OverridingCollectionField.tsx b/packages/core/client/src/collection-manager/Configuration/OverridingCollectionField.tsx index 73088f33a..2cb24618b 100644 --- a/packages/core/client/src/collection-manager/Configuration/OverridingCollectionField.tsx +++ b/packages/core/client/src/collection-manager/Configuration/OverridingCollectionField.tsx @@ -25,6 +25,7 @@ const getSchema = (schema: IField, record: any, compile, getContainer): ISchema properties['defaultValue'] = cloneDeep(schema.default.uiSchema); properties['defaultValue']['title'] = compile('{{ t("Default value") }}'); properties['defaultValue']['x-decorator'] = 'FormItem'; + properties['defaultValue']['x-disabled'] = true; } return { type: 'object', diff --git a/packages/plugins/collection-manager/src/__tests__/inherits/inherited-collection.test.ts b/packages/plugins/collection-manager/src/__tests__/inherits/inherited-collection.test.ts index 18a248110..1bc419bb8 100644 --- a/packages/plugins/collection-manager/src/__tests__/inherits/inherited-collection.test.ts +++ b/packages/plugins/collection-manager/src/__tests__/inherits/inherited-collection.test.ts @@ -24,6 +24,56 @@ pgOnly()('Inherited Collection', () => { await app.destroy(); }); + it('should update overridden multiple select field', async () => { + await collectionRepository.create({ + values: { + name: 'parent', + fields: [ + { type: 'string', name: 'name' }, + { + type: 'array', + name: 'selectors', + uiSchema: { + enum: [{ value: '123', label: '123' }], + }, + }, + ], + }, + context: {}, + }); + + await collectionRepository.create({ + values: { + name: 'child', + inherits: ['parent'], + fields: [ + { + type: 'array', + name: 'selectors', + uiSchema: { + enum: [{ value: '123', label: '123' }], + }, + overriding: true, + }, + ], + }, + context: {}, + }); + + await fieldsRepository.update({ + filter: { + name: 'selectors', + collectionName: 'child', + }, + values: { + uiSchema: { + enum: [{ value: '223', label: '223' }], + }, + defaultValue: [], + }, + }); + }); + it("should not delete child's field when parent field delete that inherits from multiple table", async () => { await collectionRepository.create({ values: { diff --git a/packages/plugins/collection-manager/src/models/field.ts b/packages/plugins/collection-manager/src/models/field.ts index 1199f098a..669457840 100644 --- a/packages/plugins/collection-manager/src/models/field.ts +++ b/packages/plugins/collection-manager/src/models/field.ts @@ -163,6 +163,11 @@ export class FieldModel extends MagicAttributeModel { const field = collection.getField(this.get('name')); + // overriding field should not sync default value + if (field.get('overriding')) { + return; + } + const queryInterface = collection.db.sequelize.getQueryInterface(); await queryInterface.changeColumn(