diff --git a/frontend/src/js/concept-trees/ConceptTreeFolder.tsx b/frontend/src/js/concept-trees/ConceptTreeFolder.tsx index 0dd4c3571a..952e0f31d4 100644 --- a/frontend/src/js/concept-trees/ConceptTreeFolder.tsx +++ b/frontend/src/js/concept-trees/ConceptTreeFolder.tsx @@ -35,16 +35,20 @@ const sumMatchingEntries = (children: string[], initSum: number) => { export const getNonFolderChildren = ( trees: TreesT, node: LoadedConcept, + conceptId: ConceptIdT, ): string[] => { - if (node.detailsAvailable) return node.children || []; + if (node.detailsAvailable) return [conceptId, ...(node.children || [])]; - if (!node.children) return []; + if (!node.children) return [conceptId]; // collect all non-folder children, recursively - return node.children.reduce((acc, childId) => { - const child = trees[childId]; - return acc.concat(getNonFolderChildren(trees, child)); - }, []); + return node.children.reduce( + (acc, childId) => { + const child = trees[childId]; + return acc.concat(getNonFolderChildren(trees, child, childId)); + }, + [conceptId], + ); }; const ConceptTreeFolder = ({ @@ -73,8 +77,10 @@ const ConceptTreeFolder = ({ const nonFolderChildren = useMemo( () => - tree.detailsAvailable ? tree.children : getNonFolderChildren(trees, tree), - [trees, tree], + tree.detailsAvailable + ? tree.children + : getNonFolderChildren(trees, tree, conceptId), + [trees, tree, conceptId], ); if ( diff --git a/frontend/src/js/concept-trees/ConceptTreeListItem.tsx b/frontend/src/js/concept-trees/ConceptTreeListItem.tsx index 31a4d2f8c7..e0668a91c3 100644 --- a/frontend/src/js/concept-trees/ConceptTreeListItem.tsx +++ b/frontend/src/js/concept-trees/ConceptTreeListItem.tsx @@ -22,8 +22,10 @@ const ConceptTreeListItem = ({ const nonFolderChildren = useMemo( () => - tree.detailsAvailable ? tree.children : getNonFolderChildren(trees, tree), - [trees, tree], + tree.detailsAvailable + ? tree.children + : getNonFolderChildren(trees, tree, conceptId), + [trees, tree, conceptId], ); if (!isNodeInSearchResult(conceptId, search, nonFolderChildren)) return null;