Some checks failed
CI / Unit & Component Tests (push) Failing after 2m33s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 3m42s
CI / fail2ban Regex (push) Successful in 43s
CI / Semgrep Security Scan (push) Successful in 22s
CI / Compose Bucket Idempotency (push) Successful in 1m7s
Review follow-up (Sara, fast-follow): the t no-active-region guard and the draw-cue arm/disarm rule lived inline in the page with no direct coverage. Extracted to pure resolveTrainingMark() (no-op when no region; recognition enrolled flip) and canArmDraw()/shouldDisarmDraw(), each with unit tests (10 cases total). The page now arms the draw cue only via canArmDraw and disarms via shouldDisarmDraw, and routes t through resolveTrainingMark. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
/**
|
|
* "Mark for training" (the `t` shortcut) decision logic — issue #327.
|
|
*
|
|
* Training enrollment is document-level — two fixed script-type chips
|
|
* (KURRENT_RECOGNITION / KURRENT_SEGMENTATION); there is no per-region training
|
|
* flag yet (that arrives with #321). `t` toggles the primary recognition
|
|
* enrollment and is a silent no-op unless a region is active, so it reads as an
|
|
* action on the region the transcriber is working on.
|
|
*
|
|
* Pure so the no-op-when-no-region guard and the enrolled flip are testable
|
|
* without mounting the page.
|
|
*/
|
|
export const RECOGNITION_TRAINING_LABEL = 'KURRENT_RECOGNITION';
|
|
|
|
export type TrainingMarkToggle = { label: string; enrolled: boolean };
|
|
|
|
/**
|
|
* Decide the recognition-training toggle for the active region, or null when no
|
|
* region is active (the `t` shortcut is then a silent no-op).
|
|
*
|
|
* @param activeAnnotationId the currently active region, or null
|
|
* @param currentLabels the document's currently enrolled training labels
|
|
*/
|
|
export function resolveTrainingMark(
|
|
activeAnnotationId: string | null,
|
|
currentLabels: readonly string[]
|
|
): TrainingMarkToggle | null {
|
|
if (!activeAnnotationId) return null;
|
|
const enrolled = !currentLabels.includes(RECOGNITION_TRAINING_LABEL);
|
|
return { label: RECOGNITION_TRAINING_LABEL, enrolled };
|
|
}
|