Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): preserve entire subtree of title-matching nodes in TreeSelect filter (#18561)

chanx16980735185b
diff --git a/web/src/components/tree-select.tsx b/web/src/components/tree-select.tsx
index 6dc770e4ce..4e90c0f861 100644
--- a/web/src/components/tree-select.tsx
+++ b/web/src/components/tree-select.tsx
@@ -145,11 +145,18 @@ export const TreeSelect = forwardRef<HTMLButtonElement, TreeSelectProps>(
const titleMatch = node.title
.toLowerCase()
.includes(term.toLowerCase());
+ // A matching parent keeps its entire subtree so its children stay
+ // visible; otherwise only branches containing matching descendants
+ // are kept.
+ if (titleMatch) {
+ acc.push(node);
+ return acc;
+ }
const filteredChildren = node.children
? filterTree(node.children, term)
: undefined;
- if (titleMatch || filteredChildren?.length) {
- acc.push({ ...node, children: filteredChildren ?? node.children });
+ if (filteredChildren?.length) {
+ acc.push({ ...node, children: filteredChildren });
}
return acc;
}, []);