Skip to content

Commit

Permalink
Try and fix search again for multi-nested struct nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadrian committed Oct 14, 2024
1 parent 65e72db commit a26ebf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 14 additions & 8 deletions frontend/src/js/concept-trees/ConceptTreeFolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConceptIdT[]>((acc, childId) => {
const child = trees[childId];
return acc.concat(getNonFolderChildren(trees, child));
}, []);
return node.children.reduce<ConceptIdT[]>(
(acc, childId) => {
const child = trees[childId];
return acc.concat(getNonFolderChildren(trees, child, childId));
},
[conceptId],
);
};

const ConceptTreeFolder = ({
Expand Down Expand Up @@ -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 (
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/js/concept-trees/ConceptTreeListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a26ebf4

Please sign in to comment.