Skip to content

Commit e5a61cf

Browse files
author
Bradley Marques
authored
Allow users to add titles and descriptions for references (#68)
Allows users to set title and descriptions per $ref
1 parent 208ff68 commit e5a61cf

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

src/formBuilder/CardGeneralParameterInputs.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export default function CardGeneralParameterInputs({
107107
onChange({ ...parameters, title: ev.target.value });
108108
}}
109109
className='card-text'
110-
readOnly={parameters.$ref !== undefined}
111110
/>
112111
</div>
113112
<div className={`card-entry ${parameters.$ref ? 'disabled-input' : ''}`}>
@@ -136,7 +135,6 @@ export default function CardGeneralParameterInputs({
136135
onChange({ ...parameters, description: ev.target.value });
137136
}}
138137
className='card-text'
139-
readOnly={parameters.$ref !== undefined}
140138
/>
141139
</div>
142140
<div className='card-entry'>

src/formBuilder/FormBuilder.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ const props = {
1212
onChange: (newSchema, newUiSchema) => mockEvent(newSchema, newUiSchema),
1313
};
1414

15+
const schemaWithDefinitions = {
16+
type: 'object',
17+
definitions: {
18+
exampleDefinition: {
19+
type: 'string',
20+
},
21+
},
22+
properties: {
23+
exampleField: {
24+
$ref: '#/definitions/exampleDefinition',
25+
title: 'Custom Title',
26+
description: 'Custom Description',
27+
},
28+
},
29+
};
30+
31+
const propsWithDefinitions = {
32+
schema: JSON.stringify(schemaWithDefinitions),
33+
uiSchema: '',
34+
onChange: (newSchema, newUiSchema) => mockEvent(newSchema, newUiSchema),
35+
};
36+
1537
describe('FormBuilder', () => {
1638
it('renders without error', () => {
1739
const div = document.createElement('div');
@@ -87,6 +109,7 @@ describe('FormBuilder', () => {
87109
'Property Parameter: badSideProp in obj2',
88110
]);
89111
});
112+
90113
it('renders the cards in the correct order according to ui:order', () => {
91114
const modProps = {
92115
...props,
@@ -175,4 +198,18 @@ describe('FormBuilder', () => {
175198
expect(wrapper.exists('.form-body')).toBeTruthy();
176199
expect(wrapper.exists('[data-test="form-head"]')).toBeFalsy();
177200
});
201+
202+
it('renders $refs with custom titles and descriptions', () => {
203+
const div = document.createElement('div');
204+
document.body.appendChild(div);
205+
const wrapper = mount(<FormBuilder {...propsWithDefinitions} />, {
206+
attachTo: div,
207+
});
208+
209+
expect(wrapper.exists('.form-body')).toBeTruthy();
210+
211+
const cardInputs = wrapper.find('.card-container').first().find('input');
212+
expect(cardInputs.at(1).props().value).toEqual('Custom Title');
213+
expect(cardInputs.at(2).props().value).toEqual('Custom Description');
214+
});
178215
});

src/formBuilder/defaults/defaultInputs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ const defaultInputs = {
237237
],
238238
defaultDataSchema: {
239239
$ref: '',
240+
title: '',
241+
description: '',
240242
},
241243
defaultUiSchema: {},
242244
type: null,

src/formBuilder/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ export function generateElementPropsFromSchemas(parameters: {
461461
definitionData[pathArr[2]]
462462
) {
463463
elementDetails = {
464-
...elementDetails,
465464
...definitionData[pathArr[2]],
465+
...elementDetails,
466466
};
467467
}
468468

@@ -673,6 +673,8 @@ function generateSchemaElementFromElement(element: ElementProps) {
673673
if (element.$ref !== undefined) {
674674
return {
675675
$ref: element.$ref,
676+
title: element.dataOptions.title,
677+
description: element.dataOptions.description,
676678
};
677679
} else if (element.propType === 'card') {
678680
if (element.dataOptions.category === 'section') {

0 commit comments

Comments
 (0)