From 447d0a427234db355d171c6c849d87e05ed44376 Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 4 Nov 2026 13:59:16 +0100 Subject: [PATCH] =?UTF-8?q?feat(app):=20editor=20V=C3=A9rification=20tab?= =?UTF-8?q?=20and=20review=20submission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-11-03-v1-2-6-label-proposals.md | 67 ++++++ apps/app/src/components/editor/EditorTabs.tsx | 21 ++ .../editor/tabs/VerificationTab.tsx | 83 ++++++- .../editor/verification/IssueList.tsx | 61 +++++ .../editor/verification/ReviewFigures.tsx | 123 ++++++++++ .../editor/verification/SubmitPanel.tsx | 80 +++++++ .../verification/VerificationSummary.tsx | 36 +++ .../editor/verification/useSubmission.ts | 49 ++++ apps/app/src/editor/verification.ts | 131 +++++++++++ apps/app/src/i18n/en.ts | 62 +++++ apps/app/src/i18n/fr.ts | 62 +++++ .../tests/unit/editor-verification.test.tsx | 216 ++++++++++++++++++ 12 files changed, 987 insertions(+), 4 deletions(-) create mode 100644 apps/app/src/components/editor/verification/IssueList.tsx create mode 100644 apps/app/src/components/editor/verification/ReviewFigures.tsx create mode 100644 apps/app/src/components/editor/verification/SubmitPanel.tsx create mode 100644 apps/app/src/components/editor/verification/VerificationSummary.tsx create mode 100644 apps/app/src/components/editor/verification/useSubmission.ts create mode 100644 apps/app/src/editor/verification.ts create mode 100644 apps/app/tests/unit/editor-verification.test.tsx diff --git a/.claude/audits/2026-11-03-v1-2-6-label-proposals.md b/.claude/audits/2026-11-03-v1-2-6-label-proposals.md index 6ad7d204..ed146051 100644 --- a/.claude/audits/2026-11-03-v1-2-6-label-proposals.md +++ b/.claude/audits/2026-11-03-v1-2-6-label-proposals.md @@ -380,3 +380,70 @@ Every key below is a proposal for the owner's separate review; none is declared | `editor.annotations.geometry.unapplied_tag` | non appliqué | not applied | Marker on a field of an unapplied group | plan wording FR; EN proposal | | `editor.annotations.geometry.revert` | Revenir aux valeurs enregistrées | Back to the saved values | Geometry group after a refusal | plan wording FR; EN proposal | | `editor.annotations.geometry.number` | Chaque champ doit contenir un nombre. | Each field must hold a number. | Geometry group, input shape | proposal | + +## Lot J (Vérification, submission) + +| Key | FR | EN | Where | Origin | +|---|---|---|---|---| +| `editor.verification.title` | Contrôle du brouillon | Draft check | Panel title (L27) | L27 FR/EN | +| `editor.verification.errors` | {count} erreurs bloquantes | {count} blocking errors | Badge | L28 FR/EN | +| `editor.verification.warnings` | {count} avertissements | {count} warnings | Badge | L28 FR/EN | +| `editor.verification.to_confirm` | {count} éléments à confirmer | {count} items to confirm | Badge | L28 FR/EN | +| `editor.verification.none` | Aucun problème détecté | No issues found | Panel, no issue | L27 FR/EN | +| `editor.verification.warnings_title` | Avertissements | Warnings | Heading over the warnings | proposal | +| `editor.verification.goto` | Aller à {tab} | Go to {tab} | Issue button (tab name filled in) | plan wording « Aller à … »; form proposal | +| `editor.verification.to_confirm_info` | Des éléments restent à confirmer : cela n'empêche pas la soumission. | Some items are still to confirm: this does not prevent submission. | Info notice on to_confirm elements | proposal | +| `editor.verification.completeness` | Complétude | Completeness | Section heading | proposal | +| `editor.verification.vet_referrals` | {count} renvoi(s) vers un vétérinaire | {count} veterinary referral(s) | Completeness line | proposal | +| `editor.verification.uncited` | {count} constat(s) sans référence citée | {count} finding(s) citing no reference | Completeness line | proposal | +| `editor.verification.groups` | Statuts par groupe | Statuses per group | Section heading | proposal | +| `editor.verification.group_removed` | supprimé | removed | Group row tag | proposal | +| `editor.verification.status.to_confirm` | À confirmer | To confirm | Status count label | ratified status wording | +| `editor.verification.status.reviewed` | Relu | Reviewed | Status count label | ratified status wording | +| `editor.verification.status.inherited` | Hérité, non relu | Inherited, not reviewed | Status count label | ratified status wording | +| `editor.verification.size_title` | Taille du document | Document size | Section heading | proposal | +| `editor.verification.size` | {bytes} o sur {cap} o | {bytes} B of {cap} B | Document size against the cap | plan wording FR; EN proposal | +| `editor.verification.caps_exceeded` | Limites dépassées : {caps}. | Limits exceeded: {caps}. | Caps exceeded, named | proposal | +| `editor.verification.cap.views` | vues | views | Cap name | proposal | +| `editor.verification.cap.annotations` | annotations | annotations | Cap name | proposal | +| `editor.verification.cap.finding_nodes` | catégories et nœuds de constats | finding categories and nodes | Cap name | proposal | +| `editor.verification.cap.finding_depth` | profondeur des constats | finding depth | Cap name | proposal | +| `editor.verification.cap.label_length` | longueur des noms | name length | Cap name | proposal | +| `editor.verification.cap.drawings` | illustrations | drawings | Cap name | proposal | +| `editor.verification.cap.drawing_bytes` | taille d'une illustration | size of a drawing | Cap name | proposal | +| `editor.verification.cap.drawings_total_bytes` | taille totale des illustrations | total size of the drawings | Cap name | proposal | +| `editor.verification.cap.document_bytes` | taille du document | document size | Cap name | proposal | +| `editor.verification.note_hint` | 1 à {max} caractères. | 1 to {max} characters. | Note field hint | proposal | +| `editor.verification.note` | Note de soumission (obligatoire) | Submission note (required) | Field | plan wording FR; EN proposal | +| `editor.verification.submit_title` | Soumission | Submission | Section accessible name | proposal | +| `editor.verification.submit` | Soumettre à la revue | Submit for review | Button | plan wording FR; EN proposal | +| `editor.verification.hint.errors` | Corrigez les {count} erreurs bloquantes pour soumettre. | Fix the {count} blocking errors to submit. | Hint under the disabled button | plan wording FR; EN proposal | +| `editor.verification.hint.unsaved` | Enregistrez le brouillon avant de le soumettre. | Save the draft before submitting it. | Hint under the disabled button (unsaved or stale base) | plan wording FR; EN proposal | +| `editor.verification.hint.note` | Saisissez la note de soumission pour soumettre. | Enter the submission note to submit. | Hint under the disabled button | proposal | +| `editor.verification.issue.unknown` | Ce point ne respecte pas une règle de la fiche. Corrigez l'élément indiqué. | This item breaks a rule of the sheet. Fix the item shown. | Fallback for a code without a message | proposal | +| `editor.verification.issue.view.main.count` | La fiche doit avoir exactement une vue principale. | The sheet must have exactly one main view. | Issue | proposal | +| `editor.verification.issue.view.id.duplicate` | Deux vues ont le même identifiant. | Two views have the same id. | Issue | proposal | +| `editor.verification.issue.view.parent.missing` | Le parent de cette vue détaillée n'existe pas. | The parent of this detail view does not exist. | Issue | proposal | +| `editor.verification.issue.view.parent.cycle` | Les vues détaillées se renvoient en boucle. | The detail views refer to each other in a loop. | Issue | proposal | +| `editor.verification.issue.view.unreachable` | Aucun accès d'une annotation n'ouvre cette vue détaillée. | No link of an annotation opens this detail view. | Issue | proposal | +| `editor.verification.issue.view.asset.missing` | Cette vue n'a ni illustration ni cadrage. | This view has neither a drawing nor a crop. | Issue | proposal | +| `editor.verification.issue.view.frame.unknown` | Le cadre de cette vue est inconnu : ni cadrage ni viewBox de l'illustration utilisables. | The frame of this view is unknown: no usable crop or drawing viewBox. | Issue | proposal | +| `editor.verification.issue.annotation.id.duplicate` | Deux annotations ont le même identifiant. | Two annotations have the same id. | Issue | proposal | +| `editor.verification.issue.annotation.view.missing` | Cette annotation est placée sur une vue qui n'existe pas. | This annotation sits on a view that does not exist. | Issue | proposal | +| `editor.verification.issue.annotation.category.missing` | La catégorie de cette annotation n'existe pas. | The category of this annotation does not exist. | Issue | proposal | +| `editor.verification.issue.annotation.opens_view.invalid` | La vue ouverte par cet accès n'est pas une vue détaillée de sa propre vue. | The view this link opens is not a detail view of its own view. | Issue | proposal | +| `editor.verification.issue.annotation.finding_zone.missing` | La zone de constats de cette annotation n'existe pas. | The findings zone of this annotation does not exist. | Issue | proposal | +| `editor.verification.issue.annotation.region.missing` | La région vertébrale de cette annotation n'est pas définie. | The vertebral region of this annotation is not defined. | Issue | proposal | +| `editor.verification.issue.annotation.no_findings` | Cette annotation n'est liée à aucune zone de constats : un clic dessus ne proposera rien. | This annotation is linked to no findings zone: a click on it will offer nothing. | Warning | proposal | +| `editor.verification.issue.annotation.geometry.missing` | Cette annotation n'a pas de géométrie. | This annotation has no geometry. | Issue | proposal | +| `editor.verification.issue.annotation.geometry.out_of_frame` | Cette annotation n'est pas entièrement dans le cadre de sa vue. | This annotation is not entirely inside the frame of its view. | Issue | proposal | +| `editor.verification.issue.annotation.geometry.too_small` | Cette annotation s'affiche trop petite sur l'aperçu téléphone. | This annotation shows too small on the phone preview. | Issue | proposal | +| `editor.verification.issue.annotation.geometry.interior_too_small` | L'intérieur de cette zone est trop étroit pour être touché sur l'aperçu téléphone. | The inside of this zone is too narrow to tap on the phone preview. | Issue | proposal | +| `editor.verification.issue.region.code.duplicate` | Deux régions vertébrales ont le même code. | Two vertebral regions have the same code. | Issue | proposal | +| `editor.verification.issue.region.count_range.invalid` | Le nombre habituel de cette région n'est pas dans la variation indiquée. | The usual count of this region is outside the stated variation. | Issue | proposal | +| `editor.verification.issue.category.id.duplicate` | Deux catégories d'annotation ont le même identifiant. | Two annotation categories have the same id. | Issue | proposal | +| `editor.verification.issue.finding_zone.id.duplicate` | Deux zones de constats ont le même identifiant. | Two findings zones have the same id. | Issue | proposal | +| `editor.verification.issue.finding_zone.unreferenced` | Aucune annotation ne pointe vers cette zone de constats. | No annotation points to this findings zone. | Warning | proposal | +| `editor.verification.issue.finding.id.duplicate` | Deux constats voisins ont le même identifiant. | Two sibling findings have the same id. | Issue | proposal | +| `editor.verification.issue.finding.reference.missing` | Ce constat cite une référence qui n'est pas déclarée. | This finding cites a reference that is not declared. | Issue | proposal | +| `editor.verification.issue.reference.id.duplicate` | Deux références ont le même identifiant. | Two references have the same id. | Issue | proposal | diff --git a/apps/app/src/components/editor/EditorTabs.tsx b/apps/app/src/components/editor/EditorTabs.tsx index a211693b..35659f01 100644 --- a/apps/app/src/components/editor/EditorTabs.tsx +++ b/apps/app/src/components/editor/EditorTabs.tsx @@ -1,4 +1,5 @@ import { useState, type KeyboardEvent } from 'react' +import { useEditorStore } from '@/editor/state/editorStore' import { tabsFor, type EditorTabId } from '@/editor/tabs' import type { TabTier } from '@/editor/useViewport' import { useT } from '@/i18n/useT' @@ -13,6 +14,24 @@ const ACTIVE = const IDLE = 'border-transparent text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]' +/** The blocking-error count on the Vérification tab; absent at zero. */ +function ErrorCount({ tab }: { tab: EditorTabId }) { + const count = useEditorStore( + (s) => + s.previewState?.report.issues.filter((i) => i.severity === 'error') + .length ?? 0, + ) + if (tab !== 'verification' || count === 0) return null + return ( + + ) +} + interface EditorTabsProps { active: EditorTabId tier: TabTier @@ -70,6 +89,7 @@ export default function EditorTabs({ className={`-mb-px ${BASE} ${tab === active ? ACTIVE : IDLE}`} > {t(`editor.tab.${tab}`)} + ))} @@ -100,6 +120,7 @@ export default function EditorTabs({ className={`rounded-md px-3 ${BASE} border-b-0 ${tab === active ? ACTIVE : IDLE}`} > {t(`editor.tab.${tab}`)} + ))} diff --git a/apps/app/src/components/editor/tabs/VerificationTab.tsx b/apps/app/src/components/editor/tabs/VerificationTab.tsx index 11c97f42..3b5cbc75 100644 --- a/apps/app/src/components/editor/tabs/VerificationTab.tsx +++ b/apps/app/src/components/editor/tabs/VerificationTab.tsx @@ -1,14 +1,89 @@ +import type { + AnatomicalSheetDocument, + SheetReport, +} from '@faunosteo/core-wasm/types' +import IssueList from '@/components/editor/verification/IssueList' +import { + Completeness, + GroupStatuses, + SizeAndCaps, +} from '@/components/editor/verification/ReviewFigures' +import SubmitPanel from '@/components/editor/verification/SubmitPanel' +import VerificationSummary from '@/components/editor/verification/VerificationSummary' +import Notice from '@/components/ui/Notice' +import { useEditorStore } from '@/editor/state/editorStore' +import { useSheetDocument } from '@/editor/sheetDocument' import type { EditorTabProps } from '@/editor/tabs' +import { splitIssues } from '@/editor/verification' import { useT } from '@/i18n/useT' -/** Placeholder: Lot J replaces the body and keeps the props contract (`EditorTabProps`). */ -export default function VerificationTab(_props: EditorTabProps) { +interface PanelProps extends EditorTabProps { + report: SheetReport + doc: AnatomicalSheetDocument +} + +function Panel({ + report, + doc, + readOnly, + onSelectTab, + reloadSheet, +}: PanelProps) { const t = useT() + const { errors, warnings } = splitIssues(report) + const { to_confirm } = report.completeness.statuses + return ( + <> + + {errors.length + warnings.length === 0 && ( + {t('editor.verification.none')} + )} + + {warnings.length > 0 && ( +

+ {t('editor.verification.warnings_title')} +

+ )} + + {to_confirm > 0 && ( + {t('editor.verification.to_confirm_info')} + )} + + + + {!readOnly && ( + + )} + + ) +} + +/** Vérification: the in-page check of the draft (not the server's verdict) and its submission. */ +export default function VerificationTab(props: EditorTabProps) { + const t = useT() + const report = useEditorStore((s) => s.previewState?.report) + const doc = useSheetDocument() return (
+ className="min-h-24 space-y-4" + > + {report && doc && } +
) } diff --git a/apps/app/src/components/editor/verification/IssueList.tsx b/apps/app/src/components/editor/verification/IssueList.tsx new file mode 100644 index 00000000..d2d085d6 --- /dev/null +++ b/apps/app/src/components/editor/verification/IssueList.tsx @@ -0,0 +1,61 @@ +import type { + AnatomicalSheetDocument, + SheetIssue, +} from '@faunosteo/core-wasm/types' +import Button from '@/components/ui/Button' +import Notice from '@/components/ui/Notice' +import { issueMessageKey, issueTarget } from '@/editor/verification' +import type { EditorTabId } from '@/editor/tabs' +import { useT } from '@/i18n/useT' +import { useLocaleStore } from '@/state/localeStore' + +interface IssueListProps { + issues: readonly SheetIssue[] + tone: 'error' | 'info' + doc: AnatomicalSheetDocument + onSelectTab: (tab: EditorTabId) => void +} + +/** One notice per issue: the page's own message, the element's name, « Aller à … ». */ +export default function IssueList({ + issues, + tone, + doc, + onSelectTab, +}: IssueListProps) { + const t = useT() + const locale = useLocaleStore((s) => s.locale) + if (issues.length === 0) return null + return ( +
    + {issues.map((issue, index) => { + const target = issueTarget(doc, issue.path, locale) + return ( +
  • + +

    + {target?.name && {target.name}} + {target?.name ? ' : ' : ''} + {t(issueMessageKey(issue.code))} +

    + {target && ( + + )} +
    +
  • + ) + })} +
+ ) +} diff --git a/apps/app/src/components/editor/verification/ReviewFigures.tsx b/apps/app/src/components/editor/verification/ReviewFigures.tsx new file mode 100644 index 00000000..538693b8 --- /dev/null +++ b/apps/app/src/components/editor/verification/ReviewFigures.tsx @@ -0,0 +1,123 @@ +import type { + AnatomicalSheetDocument, + ReviewGroup, + SheetReport, + StatusCounts, +} from '@faunosteo/core-wasm/types' +import { elementLabel } from '@/editor/sheetDocument' +import { DOCUMENT_BYTES_CAP, groupThousands } from '@/editor/verification' +import { useT } from '@/i18n/useT' +import type { Locale } from '@/i18n/types' +import { useLocaleStore } from '@/state/localeStore' + +type Translate = ReturnType + +function statusLine(t: Translate, counts: StatusCounts): string { + return (['to_confirm', 'reviewed', 'inherited'] as const) + .map( + (status) => + `${t(`editor.verification.status.${status}`)} ${counts[status]}`, + ) + .join(' · ') +} + +/** The group key the core builds (`general`, `view:`, `zone:`) as a readable name. */ +function groupName( + t: Translate, + doc: AnatomicalSheetDocument, + key: string, + locale: Locale, +): string { + if (key === 'general') return t('editor.tab.general') + const [kind, id] = key.split(/:(.*)/s) + if (kind === 'view') return elementLabel(doc, { kind: 'view', id }, locale) + if (kind === 'zone') return elementLabel(doc, { kind: 'zone', id }, locale) + return key +} + +function GroupRow({ group, label }: { group: ReviewGroup; label: string }) { + const t = useT() + return ( +
  • + + {label} + {group.removed && ` (${t('editor.verification.group_removed')})`} + + + {statusLine(t, group.statuses)} + +
  • + ) +} + +export function Completeness({ report }: { report: SheetReport }) { + const t = useT() + const { statuses, vet_referrals, uncited } = report.completeness + const count = (key: string, n: number) => t(key).replace('{count}', String(n)) + return ( +
    +

    {t('editor.verification.completeness')}

    +

    {statusLine(t, statuses)}

    +

    {count('editor.verification.vet_referrals', vet_referrals)}

    +

    {count('editor.verification.uncited', uncited)}

    +
    + ) +} + +export function GroupStatuses({ + report, + doc, +}: { + report: SheetReport + doc: AnatomicalSheetDocument +}) { + const t = useT() + const locale = useLocaleStore((s) => s.locale) + return ( +
    +

    {t('editor.verification.groups')}

    +
      + {report.groups.map((group) => ( + + ))} +
    +
    + ) +} + +export function SizeAndCaps({ report }: { report: SheetReport }) { + const t = useT() + const { exceeded } = report.caps + const size = t('editor.verification.size') + .replace('{bytes}', groupThousands(report.document_bytes)) + .replace('{cap}', groupThousands(DOCUMENT_BYTES_CAP)) + return ( +
    +

    {t('editor.verification.size_title')}

    +

    {size}

    + {exceeded.length > 0 && ( +

    + {t('editor.verification.caps_exceeded').replace( + '{caps}', + exceeded + .map((cap) => t(`editor.verification.cap.${cap}`)) + .join(', '), + )} +

    + )} +
    + ) +} diff --git a/apps/app/src/components/editor/verification/SubmitPanel.tsx b/apps/app/src/components/editor/verification/SubmitPanel.tsx new file mode 100644 index 00000000..308cac69 --- /dev/null +++ b/apps/app/src/components/editor/verification/SubmitPanel.tsx @@ -0,0 +1,80 @@ +import Button from '@/components/ui/Button' +import FormField from '@/components/ui/FormField' +import Textarea from '@/components/ui/Textarea' +import { useEditorStore } from '@/editor/state/editorStore' +import { NOTE_MAX_LENGTH } from '@/editor/verification' +import { useT } from '@/i18n/useT' +import { useSubmission } from './useSubmission' + +interface SubmitPanelProps { + errorCount: number + reloadSheet: () => void +} + +/** The hint that explains why the button is off, strongest reason first. */ +function useBlockingHint( + errorCount: number, + noteBlank: boolean, +): string | null { + const t = useT() + const unsaved = useEditorStore((s) => s.unsaved || s.staleBase) + if (errorCount > 0) { + return t('editor.verification.hint.errors').replace( + '{count}', + String(errorCount), + ) + } + if (unsaved) return t('editor.verification.hint.unsaved') + return noteBlank ? t('editor.verification.hint.note') : null +} + +/** « Note de soumission (obligatoire) » and « Soumettre à la revue » (board 06 A). */ +export default function SubmitPanel({ + errorCount, + reloadSheet, +}: SubmitPanelProps) { + const t = useT() + const submitting = useEditorStore((s) => s.submitting) + const { note, setNote, submit, message } = useSubmission(reloadSheet) + const noteBlank = note.trim() === '' + const hint = useBlockingHint(errorCount, noteBlank) + return ( +
    + +