mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-02 22:43:44 +00:00
Merge pull request #3601 from overleaf/ta-file-tree-open-doc-null
[ReactFileTree] Fix Possible Entities Not Found Error GitOrigin-RevId: 15fd8c0ad115cc30427114330e2a6e960fd2e9a2
This commit is contained in:
parent
ecd42944ad
commit
4955231abf
2 changed files with 11 additions and 2 deletions
|
@ -130,11 +130,14 @@ export function FileTreeSelectableProvider({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// listen for `editor.openDoc` and selected that doc
|
// listen for `editor.openDoc` and selected that doc
|
||||||
function handleOpenDoc(ev) {
|
function handleOpenDoc(ev) {
|
||||||
dispatch({ type: ACTION_TYPES.SELECT, id: ev.detail })
|
const found = findInTree(fileTreeData, ev.detail)
|
||||||
|
if (!found) return
|
||||||
|
|
||||||
|
dispatch({ type: ACTION_TYPES.SELECT, id: found.entity._id })
|
||||||
}
|
}
|
||||||
window.addEventListener('editor.openDoc', handleOpenDoc)
|
window.addEventListener('editor.openDoc', handleOpenDoc)
|
||||||
return () => window.removeEventListener('editor.openDoc', handleOpenDoc)
|
return () => window.removeEventListener('editor.openDoc', handleOpenDoc)
|
||||||
}, [])
|
}, [fileTreeData])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FileTreeSelectableContext.Provider
|
<FileTreeSelectableContext.Provider
|
||||||
|
|
|
@ -183,6 +183,12 @@ describe('<FileTreeRoot/>', function() {
|
||||||
|
|
||||||
screen.getByRole('treeitem', { name: 'main.tex', selected: true })
|
screen.getByRole('treeitem', { name: 'main.tex', selected: true })
|
||||||
|
|
||||||
|
// entities not found should be ignored
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent('editor.openDoc', { detail: 'not-an-id' })
|
||||||
|
)
|
||||||
|
screen.getByRole('treeitem', { name: 'main.tex', selected: true })
|
||||||
|
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent('editor.openDoc', { detail: '789ghi' })
|
new CustomEvent('editor.openDoc', { detail: '789ghi' })
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue