Skip to content

Commit

Permalink
fix(core): tree editing dialog open issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Jun 24, 2024
1 parent 6fbfcdc commit f8ab1ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,7 @@ export function TreeEditingDialog(props: TreeEditingDialogProps): JSX.Element |
openPathRef.current = undefined
}, [debouncedBuildTreeEditingState, onPathOpen])

// if the path is outside of the current window, we want to use the openPath
const pathToUse = openPath.some((path) => treeState.relativePath.includes(path))
? treeState.relativePath
: openPath

const open = useMemo(() => shouldArrayDialogOpen(schemaType, pathToUse), [schemaType, pathToUse])
const open = useMemo(() => shouldArrayDialogOpen(schemaType, openPath), [schemaType, openPath])

const onHandlePathSelect = useCallback(
(path: Path) => {
Expand Down Expand Up @@ -196,7 +191,7 @@ export function TreeEditingDialog(props: TreeEditingDialogProps): JSX.Element |
})

return () => {
// Cancel any debounced state building when navigating.
// Cancel any debounced state building on unmount.
debouncedBuildTreeEditingState.cancel()
}
}, [schemaType, value, debouncedBuildTreeEditingState, openPath, handleBuildTreeEditingState])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {type Path} from 'sanity'
*
* Example:
* ```js
* const rootPath = getRootPath(['object', 'array', { _key: '123'}])
* const rootPath = getRootPath(['object', 'array', { _key: '123' }])
* // => ['object','array']
* ```
*/
export function getRootPath(path: Path): Path {
const keyedSegmentIndex = path.findIndex((seg) => seg?.hasOwnProperty('_key'))

if (!keyedSegmentIndex) return path
if (keyedSegmentIndex === -1) return path

return path.slice(0, keyedSegmentIndex)
}

0 comments on commit f8ab1ad

Please sign in to comment.