From 7ccb8f6a1e7be71791d1a069ef45a4bf5c7dd522 Mon Sep 17 00:00:00 2001 From: Enki Pontvianne Date: Thu, 12 Sep 2024 16:11:10 +0200 Subject: [PATCH] fix: default values --- .../agent/src/utils/forest-schema/generator-actions.ts | 2 ++ .../test/routes/modification/action/action.test.ts | 10 ++++++++-- .../generator-action-field-widget.test.ts | 3 --- .../src/decorators/actions/collection.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/agent/src/utils/forest-schema/generator-actions.ts b/packages/agent/src/utils/forest-schema/generator-actions.ts index 10783bd8b2..866a738edb 100644 --- a/packages/agent/src/utils/forest-schema/generator-actions.ts +++ b/packages/agent/src/utils/forest-schema/generator-actions.ts @@ -145,6 +145,8 @@ export default class SchemaGeneratorActions { const fields: ActionField[] = []; let layout: ActionLayoutElement[] = []; + if (!formElements) return { fields: [], layout: [] }; + formElements.forEach(element => { if (element.type === 'Layout') { hasLayout = true; diff --git a/packages/agent/test/routes/modification/action/action.test.ts b/packages/agent/test/routes/modification/action/action.test.ts index 4bec432366..789111ea6b 100644 --- a/packages/agent/test/routes/modification/action/action.test.ts +++ b/packages/agent/test/routes/modification/action/action.test.ts @@ -573,7 +573,10 @@ describe('ActionRoute', () => { }, ); - expect(context.response.body).toEqual({ fields: [{ field: 'firstname', type: 'String' }] }); + expect(context.response.body).toEqual({ + fields: [{ field: 'firstname', type: 'String' }], + layout: [], + }); }); test('handleHook should generate the form if called with changehook params', async () => { @@ -620,7 +623,10 @@ describe('ActionRoute', () => { }, ); - expect(context.response.body).toEqual({ fields: [{ field: 'firstname', type: 'String' }] }); + expect(context.response.body).toEqual({ + fields: [{ field: 'firstname', type: 'String' }], + layout: [], + }); }); }); diff --git a/packages/agent/test/utils/forest-schema/generator-action-field-widget.test.ts b/packages/agent/test/utils/forest-schema/generator-action-field-widget.test.ts index 62866e02f6..055611737e 100644 --- a/packages/agent/test/utils/forest-schema/generator-action-field-widget.test.ts +++ b/packages/agent/test/utils/forest-schema/generator-action-field-widget.test.ts @@ -13,7 +13,6 @@ describe('GeneratorActionFieldWidget', () => { }); it('should return null when the field type is Collection', () => { - // @ts-expect-error Collection type does not support widget const result = GeneratorActionFieldWidget.buildWidgetOptions({ type: 'Collection', label: 'Label', @@ -25,7 +24,6 @@ describe('GeneratorActionFieldWidget', () => { }); it('should return null when the field type is Enum', () => { - // @ts-expect-error Collection type does not support widget const result = GeneratorActionFieldWidget.buildWidgetOptions({ type: 'Enum', label: 'Label', @@ -38,7 +36,6 @@ describe('GeneratorActionFieldWidget', () => { }); it('should return null when the field type is EnumList', () => { - // @ts-expect-error Collection type does not support widget const result = GeneratorActionFieldWidget.buildWidgetOptions({ type: 'EnumList', label: 'Label', diff --git a/packages/datasource-customizer/src/decorators/actions/collection.ts b/packages/datasource-customizer/src/decorators/actions/collection.ts index 3a0be4aba2..1ba1ecc77f 100644 --- a/packages/datasource-customizer/src/decorators/actions/collection.ts +++ b/packages/datasource-customizer/src/decorators/actions/collection.ts @@ -162,7 +162,7 @@ export default class ActionCollectionDecorator extends CollectionDecorator { field: DynamicField, data: Record, ): Promise { - if (field.label === undefined) { + if (data[field.label] === undefined) { const defaultValue = await this.evaluate(context, null, field.defaultValue); data[field.label] = defaultValue; }