fix: PatternExplorer — exclude root id from node paths so they match taxonomy_path

enrichTree was building paths starting with 'root', but patterns store paths
like ['geopolitical', 'armed_conflict', ...] — no root prefix. Fix: start
enriching root children with parentPath=[] instead of ['root'].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-22 16:56:57 +02:00
parent 5d969d6fdb
commit 7b2e333a9d

View File

@@ -308,10 +308,12 @@ function enrichTree(node: any, parentPath: string[] = []): TaxonomyNode {
function TreeView({ patterns }: { patterns: Pattern[] }) {
const { data: taxonomyData } = usePatternTaxonomy()
// API returns { tree: {...}, patterns: [...] } — extract the tree and enrich nodes with path arrays
// API returns { tree: {...}, patterns: [...] } — extract the tree and enrich nodes with path arrays.
// Start enriching from root's children with [] so paths match pattern taxonomy_path (no "root" prefix).
const taxonomy: TaxonomyNode | undefined = useMemo(() => {
const raw = (taxonomyData as any)?.tree
return raw ? enrichTree(raw) : undefined
if (!raw) return undefined
return { ...raw, path: [], children: (raw.children ?? []).map((c: any) => enrichTree(c, [])) }
}, [taxonomyData])
const [selectedPath, setSelectedPath] = useState<string[]>([])