@@ -46,7 +46,13 @@ import {
46
46
UPDATE_CORE ,
47
47
UpdateCoreAction ,
48
48
} from '../actions' ;
49
- import { createAjv , decode , isOneOfEnumSchema , Reducer } from '../util' ;
49
+ import {
50
+ composePaths ,
51
+ createAjv ,
52
+ isOneOfEnumSchema ,
53
+ Reducer ,
54
+ toLodashSegments ,
55
+ } from '../util' ;
50
56
import type { JsonSchema , UISchemaElement } from '../models' ;
51
57
52
58
export const validate = (
@@ -284,18 +290,19 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
284
290
errors,
285
291
} ;
286
292
} else {
287
- const oldData : any = get ( state . data , action . path ) ;
293
+ const lodashDataPathSegments = toLodashSegments ( action . path ) ;
294
+ const oldData : any = get ( state . data , lodashDataPathSegments ) ;
288
295
const newData = action . updater ( cloneDeep ( oldData ) ) ;
289
296
let newState : any ;
290
297
if ( newData !== undefined ) {
291
298
newState = setFp (
292
- action . path ,
299
+ lodashDataPathSegments ,
293
300
newData ,
294
301
state . data === undefined ? { } : state . data
295
302
) ;
296
303
} else {
297
304
newState = unsetFp (
298
- action . path ,
305
+ lodashDataPathSegments ,
299
306
state . data === undefined ? { } : state . data
300
307
) ;
301
308
}
@@ -369,19 +376,11 @@ export const getControlPath = (error: ErrorObject) => {
369
376
// With AJV v8 the property was renamed to 'instancePath'
370
377
let controlPath = ( error as any ) . dataPath || error . instancePath || '' ;
371
378
372
- // change '/' chars to '.'
373
- controlPath = controlPath . replace ( / \/ / g, '.' ) ;
374
-
375
379
const invalidProperty = getInvalidProperty ( error ) ;
376
380
if ( invalidProperty !== undefined && ! controlPath . endsWith ( invalidProperty ) ) {
377
- controlPath = ` ${ controlPath } . ${ invalidProperty } ` ;
381
+ controlPath = composePaths ( controlPath , invalidProperty ) ;
378
382
}
379
383
380
- // remove '.' chars at the beginning of paths
381
- controlPath = controlPath . replace ( / ^ ./ , '' ) ;
382
-
383
- // decode JSON Pointer escape sequences
384
- controlPath = decode ( controlPath ) ;
385
384
return controlPath ;
386
385
} ;
387
386
@@ -479,5 +478,5 @@ export const errorAt = (instancePath: string, schema: JsonSchema) =>
479
478
getErrorsAt ( instancePath , schema , ( path ) => path === instancePath ) ;
480
479
export const subErrorsAt = ( instancePath : string , schema : JsonSchema ) =>
481
480
getErrorsAt ( instancePath , schema , ( path ) =>
482
- path . startsWith ( instancePath + '. ' )
481
+ path . startsWith ( instancePath + '/ ' )
483
482
) ;
0 commit comments