Skip to content

Commit

Permalink
'subErrorsAt' now only returns actual sub errors
Browse files Browse the repository at this point in the history
Previously 'subErrorsAt' included the errors for the given path itself. However these can
already be determined via 'errorsAt'. This fixes some issues in which errors were
duplicated in the UI.

Closes #1684
Closes #1760
  • Loading branch information
LukasBoll authored Jan 2, 2023
1 parent 506c098 commit 9f045c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,4 @@ const getErrorsAt = (
export const errorAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, path => path === instancePath);
export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath + '.'));
36 changes: 36 additions & 0 deletions packages/core/test/reducers/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,42 @@ test('subErrorsAt filters array inner', t => {
t.deepEqual(filtered[0], state.errors[1]);
});

test('subErrorsAt only returning suberrors', t => {
const ajv = createAjv();
const schema: JsonSchema = {
type: 'object',
properties: {
numbers: {
title: 'Numbers',
type: 'array',
minItems: 1,
items: {
title: 'Type',
type: 'string',
enum: ['One', 'Two', 'Three']
},
}
}
};
const data: { numbers: string[] } = {
numbers: []
};
const v = ajv.compile(schema);
const errors = validate(v, data);

const state: JsonFormsCore = {
data,
schema,
uischema: undefined,
errors
};
const subErrors = subErrorsAt(
'numbers',
schema.properties.numbers.items as JsonSchema
)(state);
t.is(subErrors.length, 0);
});

test('subErrorsAt filters oneOf array inner', t => {
const ajv = createAjv();
const schema: JsonSchema = {
Expand Down

0 comments on commit 9f045c4

Please sign in to comment.