Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/util/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
arrayDefaultTranslations,
ArrayTranslations,
} from '../i18n/arrayTranslations';
import { resolveSchema } from './resolvers';

const isRequired = (
schema: JsonSchema,
Expand Down Expand Up @@ -617,7 +618,11 @@ export const mapStateToMultiEnumControlProps = (
ownProps: OwnPropsOfControl & OwnPropsOfEnum
): StatePropsOfControl & OwnPropsOfEnum => {
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
const items = props.schema.items as JsonSchema;
let items = props.schema.items as JsonSchema;
items =
items && items.$ref
? resolveSchema(props.rootSchema, items.$ref, props.rootSchema)
: items;
const options: EnumOption[] =
ownProps.options ||
(items?.oneOf &&
Expand Down
44 changes: 44 additions & 0 deletions packages/core/test/util/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,50 @@ test('mapStateToMultiEnumControlProps - enum items', (t) => {
]);
});

test('mapStateToMultiEnumControlProps - enum with ref', (t) => {
const uischema: ControlElement = {
type: 'Control',
scope: '#/properties/colors',
};
const state = {
jsonforms: {
core: {
schema: {
definitions: {
colors: {
type: 'string',
enum: ['red', 'green', 'pink'],
},
},
type: 'object',
properties: {
colors: {
type: 'array',
items: {
$ref: '#/definitions/colors',
},
uniqueItems: true,
},
},
},
data: {},
uischema,
errors: [] as ErrorObject[],
},
},
};
const ownProps = {
uischema,
path: 'colors',
};
const props = mapStateToMultiEnumControlProps(state, ownProps);
t.deepEqual(props.options, [
{ label: 'red', value: 'red' },
{ label: 'green', value: 'green' },
{ label: 'pink', value: 'pink' },
]);
});

test('mapDispatchToMultiEnumProps - enum schema - addItem', (t) => {
const uischema: ControlElement = {
type: 'Control',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Paths,
RankedTester,
rankWith,
resolveSchema,
schemaMatches,
schemaSubPathMatches,
uiTypeIs,
Expand Down Expand Up @@ -99,8 +100,11 @@ export const materialEnumArrayRendererTester: RankedTester = rankWith(
!Array.isArray(schema.items) &&
schema.uniqueItems === true
),
schemaSubPathMatches('items', (schema) => {
return hasOneOfItems(schema) || hasEnumItems(schema);
schemaSubPathMatches('items', (schema, rootSchema) => {
const resolvedSchema = schema.$ref
? resolveSchema(rootSchema, schema.$ref, rootSchema)
: schema;
return hasOneOfItems(resolvedSchema) || hasEnumItems(resolvedSchema);
})
)
)
Expand Down