Skip to content

Commit 4872810

Browse files
committed
fix(next): take x-jsf-presentation options into account when generating options property
1 parent 3ea8314 commit 4872810

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

next/src/field/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ function convertToOptions(nodeOptions: JsfSchema[]): Array<FieldOption> {
147147
* Get field options from schema
148148
*/
149149
function getFieldOptions(schema: NonBooleanJsfSchema) {
150+
if (schema['x-jsf-presentation']?.options) {
151+
return schema['x-jsf-presentation'].options
152+
}
153+
150154
if (schema.oneOf) {
151155
return convertToOptions(schema.oneOf || [])
152156
}

next/test/fields.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,45 @@ describe('fields', () => {
235235
])
236236
})
237237

238+
it('creates options from an enum inside items (deprecated)', () => {
239+
const schema: JsfSchema = {
240+
type: 'object',
241+
properties: {
242+
currency: {
243+
'type': 'array',
244+
'items': {
245+
type: 'string',
246+
enum: ['usd', 'eur', 'gbp'],
247+
},
248+
'x-jsf-presentation': {
249+
options: [
250+
{
251+
label: 'USD',
252+
value: 'usd',
253+
},
254+
{
255+
label: 'EUR',
256+
value: 'eur',
257+
},
258+
{
259+
label: 'GBP',
260+
value: 'gbp',
261+
},
262+
],
263+
},
264+
},
265+
},
266+
}
267+
268+
const fields = buildFieldSchema(schema, 'root', true)!.fields!
269+
270+
expect(fields[0].options).toEqual([
271+
{ label: 'USD', value: 'usd' },
272+
{ label: 'EUR', value: 'eur' },
273+
{ label: 'GBP', value: 'gbp' },
274+
])
275+
})
276+
238277
describe('radio field', () => {
239278
it('builds a radio field with options', () => {
240279
const schema: JsfSchema = {

0 commit comments

Comments
 (0)