Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try and fix search again for multi-nested struct nodes #3604

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading