Skip to content

Commit fda1838

Browse files
committed
path to array
1 parent 3f706fe commit fda1838

38 files changed

+182
-152
lines changed

packages/angular-material/src/layouts/array-layout.renderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export class ArrayLayoutRenderer
129129
removeTooltip: string;
130130
removeAriaLabel: string;
131131
noData: boolean;
132-
addItem: (path: string, value: any) => () => void;
133-
removeItems: (path: string, toDelete: number[]) => () => void;
132+
addItem: (path: string[], value: any) => () => void;
133+
removeItems: (path: string[], toDelete: number[]) => () => void;
134134
uischemas: {
135135
tester: UISchemaTester;
136136
uischema: UISchemaElement;

packages/angular-material/src/other/master-detail/master.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646

4747
const keywords = ['#', 'properties', 'items'];
4848

49-
export const removeSchemaKeywords = (path: string) => {
49+
export const removeSchemaKeywords = (path: string[]) => {
5050
return path
5151
.split('/')
5252
.filter(s => !some(keywords, key => key === s))
@@ -141,9 +141,9 @@ export class MasterListComponent extends JsonFormsArrayControl {
141141
masterItems: any[];
142142
selectedItem: any;
143143
selectedItemIdx: number;
144-
addItem: (path: string, value: any) => () => void;
145-
removeItems: (path: string, toDelete: number[]) => () => void;
146-
propsPath: string;
144+
addItem: (path: string[], value: any) => () => void;
145+
removeItems: (path: string[], toDelete: number[]) => () => void;
146+
propsPath: string[];
147147
highlightedIdx: number;
148148

149149
constructor(jsonformsService: JsonFormsAngularService, private changeDetectorRef: ChangeDetectorRef) {

packages/angular-material/src/other/table.renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class TableRenderer extends JsonFormsArrayControl {
9797
}
9898
generateCells = (
9999
schema: JsonSchema,
100-
rowPath: string
100+
rowPath: string[]
101101
): ColumnDescription[] => {
102102
if (schema.type === 'object') {
103103
return this.getValidColumnProps(schema).map(prop => {

packages/angular/src/abstract-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export abstract class JsonFormsAbstractControl<
6363
rootSchema: JsonSchema;
6464
enabled: boolean;
6565
hidden: boolean;
66-
propsPath: string;
66+
propsPath: string[];
6767

6868
constructor(protected jsonFormsService: JsonFormsAngularService) {
6969
super();

packages/angular/src/base.renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
export class JsonFormsBaseRenderer<T extends UISchemaElement> {
3434
@Input() uischema: T;
3535
@Input() schema: JsonSchema;
36-
@Input() path: string;
36+
@Input() path: string[];
3737

3838
protected getOwnProps(): OwnPropsOfRenderer {
3939
return {

packages/core/src/actions/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export type CoreActions =
7171

7272
export interface UpdateAction {
7373
type: 'jsonforms/UPDATE';
74-
path: string;
74+
path: string[];
7575
updater(existingData?: any): any;
7676
}
7777

@@ -166,7 +166,7 @@ export const setAjv = (ajv: AJV) => ({
166166
});
167167

168168
export const update = (
169-
path: string,
169+
path: string[],
170170
updater: (existingData: any) => any
171171
): UpdateAction => ({
172172
type: UPDATE_DATA,

packages/core/src/reducers/core.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
UPDATE_CORE,
4545
UpdateCoreAction
4646
} from '../actions';
47-
import { createAjv, Reducer } from '../util';
47+
import { contains, createAjv, Reducer } from '../util';
4848
import { JsonSchema, UISchemaElement } from '../models';
4949

5050
export const validate = (validator: ValidateFunction | undefined, data: any): ErrorObject[] => {
@@ -230,7 +230,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
230230
case UPDATE_DATA: {
231231
if (action.path === undefined || action.path === null) {
232232
return state;
233-
} else if (action.path === '') {
233+
} else if (action.path === []) {
234234
// empty path is ok
235235
const result = action.updater(cloneDeep(state.data));
236236
const errors = validate(state.validator, result);
@@ -333,9 +333,9 @@ export const getControlPath = (error: ErrorObject) => {
333333
}
334334

335335
export const errorsAt = (
336-
instancePath: string,
336+
instancePath: string[],
337337
schema: JsonSchema,
338-
matchPath: (path: string) => boolean
338+
matchPath: (path: string[]) => boolean
339339
) => (errors: ErrorObject[]): ErrorObject[] => {
340340
// Get data paths of oneOf and anyOf errors to later determine whether an error occurred inside a subschema of oneOf or anyOf.
341341
const combinatorPaths = filter(
@@ -360,7 +360,7 @@ export const errorsAt = (
360360
// because the parent schema can never match the property schema (e.g. for 'required' checks).
361361
const parentSchema: JsonSchema | undefined = error.parentSchema;
362362
if (result && !isObjectSchema(parentSchema)
363-
&& combinatorPaths.findIndex(p => instancePath.startsWith(p)) !== -1) {
363+
&& combinatorPaths.findIndex(p => contains(instancePath,p)) !== -1) {
364364
result = result && isEqual(parentSchema, schema);
365365
}
366366
return result;
@@ -388,13 +388,13 @@ const isObjectSchema = (schema?: JsonSchema): boolean => {
388388
const filteredErrorKeywords = ['additionalProperties', 'allOf', 'anyOf', 'oneOf'];
389389

390390
const getErrorsAt = (
391-
instancePath: string,
391+
instancePath: string[],
392392
schema: JsonSchema,
393-
matchPath: (path: string) => boolean
393+
matchPath: (path: string[]) => boolean
394394
) => (state: JsonFormsCore): ErrorObject[] =>
395395
errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide' ? [] : state.errors);
396396

397-
export const errorAt = (instancePath: string, schema: JsonSchema) =>
397+
export const errorAt = (instancePath: string[], schema: JsonSchema) =>
398398
getErrorsAt(instancePath, schema, path => path === instancePath);
399-
export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
400-
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
399+
export const subErrorsAt = (instancePath: string[], schema: JsonSchema) =>
400+
getErrorsAt(instancePath, schema, path => contains(path,instancePath));

packages/core/src/reducers/reducers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const findUISchema = (
9191
uischemas: JsonFormsUISchemaRegistryEntry[],
9292
schema: JsonSchema,
9393
schemaPath: string,
94-
path: string,
94+
path: string[],
9595
fallbackLayoutType = 'VerticalLayout',
9696
control?: ControlElement,
9797
rootSchema?: JsonSchema
@@ -121,15 +121,15 @@ export const findUISchema = (
121121
return uiSchema;
122122
};
123123

124-
export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
124+
export const getErrorAt = (instancePath: string[], schema: JsonSchema) => (
125125
state: JsonFormsState
126126
) => {
127127
return errorAt(instancePath, schema)(state.jsonforms.core);
128128
};
129129

130130
export { errorsAt, getControlPath };
131131

132-
export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
132+
export const getSubErrorsAt = (instancePath: string[], schema: JsonSchema) => (
133133
state: JsonFormsState
134134
) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
135135

packages/core/src/reducers/uischemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Reducer } from '../util';
3333
export type UISchemaTester = (
3434
schema: JsonSchema,
3535
schemaPath: string,
36-
path: string
36+
path: string[]
3737
) => number;
3838

3939
export interface JsonFormsUISchemaRegistryEntry {
@@ -64,7 +64,7 @@ export const findMatchingUISchema = (
6464
) => (
6565
jsonSchema: JsonSchema,
6666
schemaPath: string,
67-
path: string
67+
path: string[]
6868
): UISchemaElement => {
6969
const match = maxBy(state, entry =>
7070
entry.tester(jsonSchema, schemaPath, path)

packages/core/src/testers/testers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const schemaMatches = (
9696
};
9797

9898
export const schemaSubPathMatches = (
99-
subPath: string,
99+
subPath: string[],
100100
predicate: (schema: JsonSchema) => boolean
101101
): Tester => (uischema: UISchemaElement, schema: JsonSchema): boolean => {
102102
if (isEmpty(uischema) || !isControl(uischema)) {
@@ -382,7 +382,7 @@ export const isObjectArray = and(
382382
schemaMatches(
383383
schema => hasType(schema, 'array') && !Array.isArray(schema.items) // we don't care about tuples
384384
),
385-
schemaSubPathMatches('items', schema => hasType(schema, 'object'))
385+
schemaSubPathMatches(['items'], schema => hasType(schema, 'object'))
386386
);
387387

388388
/**
@@ -481,7 +481,7 @@ export const isPrimitiveArrayControl = and(
481481
schemaMatches(
482482
schema => deriveTypes(schema).length !== 0 && !Array.isArray(schema.items) // we don't care about tuples
483483
),
484-
schemaSubPathMatches('items', schema => {
484+
schemaSubPathMatches(['items'], schema => {
485485
const types = deriveTypes(schema);
486486
return (
487487
types.length === 1 &&

0 commit comments

Comments
 (0)