Skip to content

Commit bfd6144

Browse files
committed
Fixed nested tuples
1 parent 37822bb commit bfd6144

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

__tests__/v2/JSchema.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,55 @@ describe('JSchema', () => {
900900
expect(result.component.getArguments()).deep.eq({ test: {} });
901901
expect(result.component.unsavedChanges).toEqual(true);
902902
});
903+
904+
it('nested tuple', async function () {
905+
const result = renderSchema({
906+
title: 'TaskFunction',
907+
type: 'object',
908+
properties: {
909+
arg_A: {
910+
type: 'array',
911+
minItems: 1,
912+
maxItems: 1,
913+
items: [
914+
{
915+
type: 'array',
916+
minItems: 1,
917+
maxItems: 1,
918+
items: [
919+
{
920+
type: 'array',
921+
minItems: 1,
922+
maxItems: 1,
923+
items: [
924+
{
925+
type: 'string'
926+
}
927+
]
928+
}
929+
]
930+
}
931+
]
932+
}
933+
},
934+
required: ['arg_A'],
935+
additionalProperties: false
936+
});
937+
938+
expect(result.component.getArguments()).deep.eq({ arg_A: [[]] });
939+
expect(result.component.unsavedChanges).toEqual(false);
940+
await fireEvent.click(result.getByRole('button', { name: 'Add tuple' }));
941+
expect(result.component.getArguments()).deep.eq({ arg_A: [[[]]] });
942+
expect(result.component.unsavedChanges).toEqual(true);
943+
expect(result.getAllByRole('button', { name: 'Remove tuple' }).length).toEqual(1);
944+
await fireEvent.click(result.getByRole('button', { name: 'Add tuple' }));
945+
expect(result.component.getArguments()).deep.eq({ arg_A: [[[null]]] });
946+
expect(result.getAllByRole('button', { name: 'Remove tuple' }).length).toEqual(2);
947+
await fireEvent.input(result.getByRole('textbox'), { target: { value: 'foo' } });
948+
expect(result.component.getArguments()).deep.eq({ arg_A: [[['foo']]] });
949+
await fireEvent.click(result.getByRole('button', { name: 'Clear' }));
950+
expect(result.component.getArguments()).deep.eq({ arg_A: [[[undefined]]] });
951+
});
903952
});
904953

905954
/**

src/lib/components/common/jschema/ArrayProperty.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
>
215215
Remove
216216
</button>
217-
{:else}
217+
{:else if nestedProperties[index].type !== 'array' && nestedProperties[index].type !== 'object'}
218218
<button
219219
class="btn btn-warning"
220220
type="button"

src/lib/components/common/jschema/schema_management.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ export class SchemaProperty {
333333
if ('required' in items) {
334334
propertySchema.required = items.required;
335335
}
336+
if ('minItems' in items) {
337+
propertySchema.minItems = items.minItems;
338+
}
339+
if ('maxItems' in items) {
340+
propertySchema.maxItems = items.maxItems;
341+
}
336342

337343
const nestedProperty = new SchemaProperty(propertySchema, this.manager);
338344
this.manager.setDefaultValue(nestedProperty.key, nestedProperty.value);

0 commit comments

Comments
 (0)