From 34acb0cc9483415e249c9d7e08150d1b4504f05b Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Wed, 20 May 2026 04:45:45 +0200 Subject: [PATCH] feat(editor): badge selected-count on findings tree intermediate nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When drilling through the findings catalog, intermediate categories and sub-categories now carry a rounded accent-coloured badge that counts every selected leaf in their subtree. Sibling nodes with no descendant selections stay badge-free, so the practitioner can scan a level and see at a glance which branches already hold findings without re-opening each one. Implementation is a small `pathStartsWith` helper plus a `countSelectedUnder` lookup against the current observation's findings — restricted to the picker's `zoneId` so two parallel pickers on the same card never cross-contaminate counts. 5 new tests cover: count of 2 visible at root, the same 2 visible one level deeper on the right sub-branch, no badge on un-selected siblings, singular aria label for 1 selection, and zone isolation. Co-Authored-By: Claude --- .../observation/FindingsTreePicker.tsx | 31 +++- .../components.FindingsTreePicker.test.tsx | 153 ++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-) diff --git a/src/components/observation/FindingsTreePicker.tsx b/src/components/observation/FindingsTreePicker.tsx index 125cccbd..d072e882 100644 --- a/src/components/observation/FindingsTreePicker.tsx +++ b/src/components/observation/FindingsTreePicker.tsx @@ -25,6 +25,14 @@ function samePath(a: string[], b: string[]): boolean { return true } +function pathStartsWith(full: string[], prefix: string[]): boolean { + if (full.length < prefix.length) return false + for (let i = 0; i < prefix.length; i += 1) { + if (full[i] !== prefix[i]) return false + } + return true +} + function findNode( categories: FindingNode[], path: string[], @@ -79,6 +87,16 @@ export default function FindingsTreePicker({ ) } + function countSelectedUnder(nodePath: string[]): number { + let n = 0 + for (const f of selected) { + if (f.zoneId !== zoneId) continue + if (!pathStartsWith(f.path, nodePath)) continue + n += 1 + } + return n + } + function toggleLeaf(leafPath: string[], leaf: FindingNode) { if (isLeafSelected(leafPath)) { onChange( @@ -185,6 +203,7 @@ export default function FindingsTreePicker({ ) } + const selectedCount = countSelectedUnder(nodePath) return (