diff --git a/Source/ObjectContentEditor/ObjectContentEditor.tsx b/Source/ObjectContentEditor/ObjectContentEditor.tsx index 93985683..59b1cbff 100644 --- a/Source/ObjectContentEditor/ObjectContentEditor.tsx +++ b/Source/ObjectContentEditor/ObjectContentEditor.tsx @@ -162,9 +162,9 @@ export const ObjectContentEditor = ({ } }, [validationErrors, editMode, onValidationChange]); - const navigateToProperty = useCallback( - (key: string) => { - setNavigationPath([...navigationPath, key]); + const navigateTo = useCallback( + (segments: string[]) => { + setNavigationPath([...navigationPath, ...segments]); }, [navigationPath], ); @@ -185,28 +185,15 @@ export const ObjectContentEditor = ({ return object; } - const lastKey = navigationPath[navigationPath.length - 1]; - const pathToParent = navigationPath.slice(0, -1); + const value = getValueAtPath(object, navigationPath); + return value !== null && typeof value === 'object' ? value : null; + }, [object, navigationPath]); - const parentValue = - pathToParent.length > 0 ? getValueAtPath(object, pathToParent) : object; - - if ( - parentValue && - typeof parentValue === 'object' && - !Array.isArray(parentValue) - ) { - const value = (parentValue as { [k: string]: Json })[lastKey]; - - if (Array.isArray(value)) { - return value; - } else if (value && typeof value === 'object') { - return value; - } + useEffect(() => { + if (navigationPath.length > 0 && currentData === null) { + setNavigationPath([]); } - - return object; - }, [object, navigationPath, getValueAtPath]); + }, [currentData, navigationPath]); const currentProperties = useMemo(() => { const properties = schema.properties || {}; @@ -447,7 +434,11 @@ export const ObjectContentEditor = ({ ); }; - const renderValue = (value: Json, propertyName: string) => { + const renderValue = ( + value: Json, + propertyName: string, + pathSegments: string[], + ) => { if (value === null || value === undefined) return ''; if (Array.isArray(value)) { @@ -455,7 +446,7 @@ export const ObjectContentEditor = ({