Skip to content

Commit

Permalink
fix: default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Enki Pontvianne committed Sep 12, 2024
1 parent b099557 commit 7ccb8f6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/agent/src/utils/forest-schema/generator-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions packages/agent/test/routes/modification/action/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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: [],
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class ActionCollectionDecorator extends CollectionDecorator {
field: DynamicField,
data: Record<string, unknown>,
): Promise<DynamicField> {
if (field.label === undefined) {
if (data[field.label] === undefined) {
const defaultValue = await this.evaluate(context, null, field.defaultValue);
data[field.label] = defaultValue;
}
Expand Down

0 comments on commit 7ccb8f6

Please sign in to comment.