Skip to content

Commit b0b704e

Browse files
Sabanturaymond-lam
authored andcommitted
Ensure a section Column Size is not subsequently overwritten when a child card's column size is configured.
1 parent 8f71bf4 commit b0b704e

File tree

2 files changed

+99
-5
lines changed

2 files changed

+99
-5
lines changed

src/formBuilder/FormBuilder.test.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,104 @@ describe('FormBuilder', () => {
297297
expect(errors).toEqual([]);
298298
});
299299

300+
it('supports column size on sections', () => {
301+
const jsonSchema = {
302+
definitions: {
303+
first_names: {
304+
title: 'First Names',
305+
type: 'string',
306+
},
307+
last_names: {
308+
title: 'Last Names',
309+
type: 'string',
310+
},
311+
residential_address: {
312+
title: 'Residential Address',
313+
type: 'object',
314+
properties: {
315+
country: {
316+
title: 'Country',
317+
type: 'string',
318+
},
319+
street_address_line: {
320+
title: 'Street Address Line',
321+
type: 'string',
322+
},
323+
},
324+
dependencies: {},
325+
required: [],
326+
},
327+
},
328+
properties: {
329+
user_first_names: {
330+
$ref: '#/definitions/first_names',
331+
title: 'User First Names',
332+
description: '',
333+
},
334+
user_last_name: {
335+
$ref: '#/definitions/last_names',
336+
title: 'User Last Name',
337+
description: '',
338+
},
339+
user_residential_address: {
340+
$ref: '#/definitions/residential_address',
341+
title: 'User Residential Address',
342+
description: '',
343+
},
344+
},
345+
dependencies: {},
346+
required: [],
347+
type: 'object',
348+
};
349+
350+
const uischema = {
351+
definitions: {
352+
residential_address: {
353+
'ui:order': ['country', 'street_address_line'],
354+
},
355+
},
356+
'ui:order': [
357+
'user_first_names',
358+
'user_last_name',
359+
'user_residential_address',
360+
],
361+
user_first_names: {
362+
'ui:column': '25',
363+
},
364+
user_last_name: {
365+
'ui:column': '25',
366+
},
367+
user_residential_address: {
368+
'ui:order': ['country', 'address_line'],
369+
'ui:column': '50',
370+
country: {
371+
'ui:column': '30',
372+
},
373+
street_address_line: {
374+
'ui:column': '70',
375+
},
376+
},
377+
};
378+
379+
const props = {
380+
schema: JSON.stringify(jsonSchema),
381+
uiSchema: JSON.stringify(uischema),
382+
onChange: jest.fn(() => {}),
383+
mods: {},
384+
className: 'my-form-builder',
385+
};
386+
387+
const div = document.createElement('div');
388+
document.body.appendChild(div);
389+
const wrapper = mount(<FormBuilder {...props} />, { attachTo: div });
390+
const errors = wrapper
391+
.find('.alert-warning')
392+
.first()
393+
.find('li')
394+
.map((error) => error.text());
395+
expect(errors).toEqual([]);
396+
});
397+
300398
it('validates additionalProperties as a valid property', () => {
301399
const jsonSchema = {
302400
$schema: `http://json-schema.org/draft-07/schema#`,

src/formBuilder/utils.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,9 @@ export function updateSchemas(
864864
},
865865
) {
866866
const { schema, uischema, onChange, definitionUi } = parameters;
867-
const definedUi = (uischema || {}).definitions
868-
? { definitions: uischema.definitions }
869-
: {};
870867

871868
const newUiSchema = Object.assign(
872-
definedUi,
869+
{ ...uischema },
873870
generateUiSchemaFromElementProps(elementArr, definitionUi),
874871
);
875872
const newSchema = Object.assign(
@@ -879,7 +876,6 @@ export function updateSchemas(
879876

880877
// mandate that the type is an object if not already done
881878
newSchema.type = 'object';
882-
883879
onChange(newSchema, newUiSchema);
884880
}
885881

0 commit comments

Comments
 (0)