feat(editor): badge selected-count on findings tree intermediate nodes
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
95d746b555
commit
34acb0cc94
2 files changed
+183
-1
No files matched your search
@@ -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({
|
||||
</li>
|
||||
)
|
||||
}
|
||||
const selectedCount = countSelectedUnder(nodePath)
|
||||
return (
|
||||
<li key={node.id}>
|
||||
<button
|
||||
@@ -193,7 +212,17 @@ export default function FindingsTreePicker({
|
||||
className="flex items-center justify-between w-full text-left text-sm px-2 py-1.5 rounded hover:bg-[var(--color-surface-strong)] text-[var(--color-ink)]"
|
||||
aria-label={`Ouvrir ${node.name_fr}`}
|
||||
>
|
||||
<span>{node.name_fr}</span>
|
||||
<span className="flex items-center gap-2">
|
||||
<span>{node.name_fr}</span>
|
||||
{selectedCount > 0 && (
|
||||
<span
|
||||
aria-label={`${selectedCount} constat${selectedCount > 1 ? 's' : ''} sélectionné${selectedCount > 1 ? 's' : ''}`}
|
||||
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
|
||||
>
|
||||
{selectedCount}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span aria-hidden="true" className="text-[var(--color-ink-muted)]">
|
||||
›
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user