fix: PatternExplorer tree — extract .tree from API response and compute node paths

The taxonomy endpoint returns {tree, patterns} but the component was casting
the whole response as the root node. Also added enrichTree() to attach computed
path arrays to each node (backend PATTERN_TAXONOMY has no path field).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-22 16:53:54 +02:00
parent 10ffc345d6
commit 5d969d6fdb

View File

@@ -293,11 +293,26 @@ function TreeNodeRow({
)
}
// ── Helper: add computed path arrays to each node ────────────────────────────
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function enrichTree(node: any, parentPath: string[] = []): TaxonomyNode {
const path = [...parentPath, node.id]
return {
...node,
path,
children: (node.children ?? []).map((c: any) => enrichTree(c, path)),
}
}
// ── Tree View ─────────────────────────────────────────────────────────────────
function TreeView({ patterns }: { patterns: Pattern[] }) {
const { data: taxonomyData } = usePatternTaxonomy()
const taxonomy = taxonomyData as TaxonomyNode | undefined
// API returns { tree: {...}, patterns: [...] } — extract the tree and enrich nodes with path arrays
const taxonomy: TaxonomyNode | undefined = useMemo(() => {
const raw = (taxonomyData as any)?.tree
return raw ? enrichTree(raw) : undefined
}, [taxonomyData])
const [selectedPath, setSelectedPath] = useState<string[]>([])
const [nameFilter, setNameFilter] = useState('')