feat(editor): unified spine picker — show all regions, click opens own tab
The vertebra picker now edits the whole spine at once instead of a single zone. Seed it with the union of vertebrae across every spine zone of the observation (collectSpineVertebrae) so switching tabs reveals selections made on other zones. Clicking a zone always opens its own region tab (initialRegion now takes priority over the first existing selection). On confirm, syncSpineZones reconciles authoritatively per region: replace each region's vertebrae (deselection sticks), prune a spine zone whose region drops to zero, spawn a zone for a newly picked region. Non-spine zones and their order are preserved untouched. Supersedes the additive distribute model. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fc7069c2cb
commit
38888cb3d1
5 files changed
+137
-96
No files matched your search
@@ -63,7 +63,7 @@ describe('VertebraPicker', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('region of first existing selection wins over initialRegion', () => {
|
||||
it('opens on initialRegion even when other regions are pre-selected', () => {
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
@@ -71,11 +71,11 @@ describe('VertebraPicker', () => {
|
||||
onConfirm={() => {}}
|
||||
initial={[{ region: 'S', index: 2 }]}
|
||||
formula={EQUINE_VERTEBRAL_FORMULA}
|
||||
title="Vertèbres sacrales"
|
||||
title="Vertèbres cervicales"
|
||||
initialRegion="C"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: /Sacrales/ })).toHaveAttribute(
|
||||
expect(screen.getByRole('tab', { name: /Cervicales/ })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
findSpineZoneId,
|
||||
distributeVertebraeToZones,
|
||||
collectSpineVertebrae,
|
||||
syncSpineZones,
|
||||
} from '@/lib/spineZones'
|
||||
import type { Bone } from '@/anatomy/types'
|
||||
import type { ObservationZone, Vertebra } from '@/domain/schema/observation'
|
||||
@@ -36,52 +37,84 @@ describe('findSpineZoneId', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('distributeVertebraeToZones', () => {
|
||||
it('keeps same-region vertebrae on the target zone', () => {
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l' }]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1), v('L', 2)], BONES)
|
||||
expect(next).toHaveLength(1)
|
||||
expect(next[0].vertebrae).toEqual([v('L', 1), v('L', 2)])
|
||||
describe('collectSpineVertebrae', () => {
|
||||
it('unions vertebrae across all spine zones', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1), v('L', 2)] },
|
||||
{ boneId: 'z-c', vertebrae: [v('C', 3)] },
|
||||
]
|
||||
expect(collectSpineVertebrae(zones, BONES)).toEqual([v('L', 1), v('L', 2), v('C', 3)])
|
||||
})
|
||||
|
||||
it('spawns a new zone for cross-region vertebrae', () => {
|
||||
it('lists the priority zone vertebrae first', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-c', vertebrae: [v('C', 3)] },
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1)] },
|
||||
]
|
||||
expect(collectSpineVertebrae(zones, BONES, 'z-l')).toEqual([v('L', 1), v('C', 3)])
|
||||
})
|
||||
|
||||
it('ignores non-spine zones and dedups', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-shoulder' },
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1), v('L', 1)] },
|
||||
]
|
||||
expect(collectSpineVertebrae(zones, BONES)).toEqual([v('L', 1)])
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncSpineZones', () => {
|
||||
it('keeps same-region vertebrae on the existing zone', () => {
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l' }]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1), v('C', 3)], BONES)
|
||||
const next = syncSpineZones(zones, [v('L', 1), v('L', 2)], BONES)
|
||||
expect(next).toEqual([{ boneId: 'z-l', vertebrae: [v('L', 1), v('L', 2)] }])
|
||||
})
|
||||
|
||||
it('spawns a new zone for a newly picked region', () => {
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l' }]
|
||||
const next = syncSpineZones(zones, [v('L', 1), v('C', 3)], BONES)
|
||||
expect(next).toHaveLength(2)
|
||||
expect(next[0]).toEqual({ boneId: 'z-l', vertebrae: [v('L', 1)] })
|
||||
expect(next[1]).toEqual({ boneId: 'z-c', vertebrae: [v('C', 3)] })
|
||||
})
|
||||
|
||||
it('merges (does not wipe) a pre-existing other-region zone', () => {
|
||||
it('replaces a region authoritatively (deselection sticks)', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1)] },
|
||||
{ boneId: 'z-c', vertebrae: [v('C', 2)] },
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1), v('L', 2)] },
|
||||
{ boneId: 'z-c', vertebrae: [v('C', 2), v('C', 3)] },
|
||||
]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1), v('C', 4)], BONES)
|
||||
const next = syncSpineZones(zones, [v('L', 1), v('C', 3)], BONES)
|
||||
expect(next).toHaveLength(2)
|
||||
expect(next[0].vertebrae).toEqual([v('L', 1)])
|
||||
expect(next[1].vertebrae).toEqual([v('C', 2), v('C', 4)])
|
||||
expect(next[1].vertebrae).toEqual([v('C', 3)])
|
||||
})
|
||||
|
||||
it('replaces the target region so deselection within it sticks', () => {
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l', vertebrae: [v('L', 1), v('L', 2)] }]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1)], BONES)
|
||||
expect(next[0].vertebrae).toEqual([v('L', 1)])
|
||||
it('prunes a spine zone whose region dropped to zero', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1)] },
|
||||
{ boneId: 'z-c', vertebrae: [v('C', 1)] },
|
||||
]
|
||||
const next = syncSpineZones(zones, [v('C', 1)], BONES)
|
||||
expect(next).toEqual([{ boneId: 'z-c', vertebrae: [v('C', 1)] }])
|
||||
})
|
||||
|
||||
it('falls back to dumping all vertebrae on a non-spine target zone', () => {
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-shoulder' }]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1), v('C', 2)], BONES)
|
||||
expect(next).toHaveLength(1)
|
||||
expect(next[0].vertebrae).toEqual([v('L', 1), v('C', 2)])
|
||||
it('preserves non-spine zones untouched', () => {
|
||||
const zones: ObservationZone[] = [
|
||||
{ boneId: 'z-shoulder' },
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 1)] },
|
||||
]
|
||||
const next = syncSpineZones(zones, [v('L', 2)], BONES)
|
||||
expect(next).toEqual([
|
||||
{ boneId: 'z-shoulder' },
|
||||
{ boneId: 'z-l', vertebrae: [v('L', 2)] },
|
||||
])
|
||||
})
|
||||
|
||||
it('routes vertebrae of an unmapped region back onto the target zone', () => {
|
||||
it('drops vertebrae of a region with no spine zone in the SVG', () => {
|
||||
const noCervical = new Map(BONES)
|
||||
noCervical.delete('z-c')
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l' }]
|
||||
const next = distributeVertebraeToZones(zones, 0, [v('L', 1), v('C', 2)], noCervical)
|
||||
expect(next).toHaveLength(1)
|
||||
expect(next[0].vertebrae).toEqual([v('L', 1), v('C', 2)])
|
||||
const zones: ObservationZone[] = [{ boneId: 'z-l', vertebrae: [v('L', 1)] }]
|
||||
const next = syncSpineZones(zones, [v('L', 1), v('C', 2)], noCervical)
|
||||
expect(next).toEqual([{ boneId: 'z-l', vertebrae: [v('L', 1)] }])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user