feat(editor): VertebraPicker preselects region tab inferred from zone label
When opened from a spine zone, the picker now lands on the matching region tab instead of defaulting to Cervicales every time. Inference is substring-based on the FR label first, EN as fallback (cervic→C, thorac/dors→T, lombair/lumbar→L, sacral/sacre→S, caudal/coccyg→Cd), case- and accent-insensitive. An existing selection still wins over the inferred region so re-opening lands where the user left off. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
6a0ab22f76
commit
b3bd75d2e2
3 files changed
+94
-3
No files matched your search
@@ -13,6 +13,26 @@ const REGION_LABELS: Record<VertebralRegion, string> = {
|
||||
Cd: 'Caudales',
|
||||
}
|
||||
|
||||
/**
|
||||
* Infers the matching vertebral region from a free-form anatomical label
|
||||
* (zone name in FR or EN). Matches on substring roots, case-insensitive,
|
||||
* accent-insensitive. Returns undefined when no root matches.
|
||||
*/
|
||||
export function regionFromLabel(label: string): VertebralRegion | undefined {
|
||||
const norm = label
|
||||
.normalize('NFD')
|
||||
.replace(/\p{Diacritic}/gu, '')
|
||||
.toLowerCase()
|
||||
// Order matters: 'caudal'/'coccyg' before 'cervic' is fine; just be
|
||||
// explicit so no root subsumes another.
|
||||
if (norm.includes('cervic')) return 'C'
|
||||
if (norm.includes('thorac') || norm.includes('dors')) return 'T'
|
||||
if (norm.includes('lombair') || norm.includes('lumbar')) return 'L'
|
||||
if (norm.includes('sacral') || norm.includes('sacre')) return 'S'
|
||||
if (norm.includes('caudal') || norm.includes('coccyg')) return 'Cd'
|
||||
return undefined
|
||||
}
|
||||
|
||||
export interface VertebraPickerProps {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
@@ -20,6 +40,8 @@ export interface VertebraPickerProps {
|
||||
initial: Vertebra[]
|
||||
formula: VertebralFormula
|
||||
title: string
|
||||
/** Preselected tab. Overridden by the region of the first existing selection. */
|
||||
initialRegion?: VertebralRegion
|
||||
}
|
||||
|
||||
export default function VertebraPicker({
|
||||
@@ -29,9 +51,12 @@ export default function VertebraPicker({
|
||||
initial,
|
||||
formula,
|
||||
title,
|
||||
initialRegion,
|
||||
}: VertebraPickerProps) {
|
||||
const [selected, setSelected] = useState<Vertebra[]>(initial)
|
||||
const [activeRegion, setActiveRegion] = useState<VertebralRegion>('C')
|
||||
const [activeRegion, setActiveRegion] = useState<VertebralRegion>(
|
||||
() => initial[0]?.region ?? initialRegion ?? 'C',
|
||||
)
|
||||
|
||||
const has = (r: VertebralRegion, i: number) =>
|
||||
selected.some((v) => v.region === r && v.index === i)
|
||||
|
||||
Reference in new issue
Block a user