feat(app): editor Vérification tab and review submission
This commit is contained in:
1 parent
877bad0021
commit
447d0a4272
12 files changed
+987
-4
No files matched your search
@@ -0,0 +1,131 @@
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
SheetIssue,
|
||||
SheetReport,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { elementLabel } from './sheetDocument'
|
||||
import type { EditorTabId } from './tabs'
|
||||
|
||||
/** The server's cap on the document text (contract §12.2), shown beside the measure. */
|
||||
export const DOCUMENT_BYTES_CAP = 2_097_152
|
||||
/** The submission note bounds of board 06 A (the server decides at submit). */
|
||||
export const NOTE_MAX_LENGTH = 1000
|
||||
|
||||
/** The issue codes the core reports (crates/core/src/domain/sheet), each with a message. */
|
||||
export const ISSUE_CODES: readonly string[] = [
|
||||
'view.main.count',
|
||||
'view.id.duplicate',
|
||||
'view.parent.missing',
|
||||
'view.parent.cycle',
|
||||
'view.unreachable',
|
||||
'view.asset.missing',
|
||||
'view.frame.unknown',
|
||||
'annotation.id.duplicate',
|
||||
'annotation.view.missing',
|
||||
'annotation.category.missing',
|
||||
'annotation.opens_view.invalid',
|
||||
'annotation.finding_zone.missing',
|
||||
'annotation.region.missing',
|
||||
'annotation.no_findings',
|
||||
'annotation.geometry.missing',
|
||||
'annotation.geometry.out_of_frame',
|
||||
'annotation.geometry.too_small',
|
||||
'annotation.geometry.interior_too_small',
|
||||
'region.code.duplicate',
|
||||
'region.count_range.invalid',
|
||||
'category.id.duplicate',
|
||||
'finding_zone.id.duplicate',
|
||||
'finding_zone.unreferenced',
|
||||
'finding.id.duplicate',
|
||||
'finding.reference.missing',
|
||||
'reference.id.duplicate',
|
||||
]
|
||||
|
||||
/** The i18n key of an issue's message; a code the page does not know gets the neutral one. */
|
||||
export function issueMessageKey(code: string): string {
|
||||
return ISSUE_CODES.includes(code)
|
||||
? `editor.verification.issue.${code}`
|
||||
: 'editor.verification.issue.unknown'
|
||||
}
|
||||
|
||||
export function splitIssues(report: SheetReport): {
|
||||
errors: SheetIssue[]
|
||||
warnings: SheetIssue[]
|
||||
} {
|
||||
const { issues } = report
|
||||
return {
|
||||
errors: issues.filter((issue) => issue.severity === 'error'),
|
||||
warnings: issues.filter((issue) => issue.severity === 'warning'),
|
||||
}
|
||||
}
|
||||
|
||||
const ROOT_TAB: Record<string, EditorTabId> = {
|
||||
views: 'views',
|
||||
annotations: 'annotations',
|
||||
finding_zones: 'findings',
|
||||
categories: 'general',
|
||||
references: 'references',
|
||||
}
|
||||
const REGION_PATH = /^vertebral_config\.regions\[(\d+)\]/
|
||||
const ROOT_PATH = /^(\w+)\[(\d+)\]/
|
||||
|
||||
export interface IssueTarget {
|
||||
tab: EditorTabId
|
||||
/** The named element (its label), when the path resolves in the document. */
|
||||
name: string | null
|
||||
}
|
||||
|
||||
function keyOf(
|
||||
doc: AnatomicalSheetDocument,
|
||||
root: string,
|
||||
index: number,
|
||||
): ElementKey | null {
|
||||
switch (root) {
|
||||
case 'views':
|
||||
return idKey('view', doc.views[index])
|
||||
case 'annotations':
|
||||
return idKey('annotation', doc.annotations[index])
|
||||
case 'categories':
|
||||
return idKey('category', doc.categories[index])
|
||||
case 'finding_zones':
|
||||
return idKey('zone', doc.finding_zones[index])
|
||||
case 'references':
|
||||
return idKey('reference', doc.references[index])
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function idKey<
|
||||
K extends 'view' | 'annotation' | 'category' | 'zone' | 'reference',
|
||||
>(kind: K, item: { id: string } | undefined): ElementKey | null {
|
||||
return item ? ({ kind, id: item.id } as ElementKey) : null
|
||||
}
|
||||
|
||||
/** The tab holding the element an issue path names (« Aller à … »); null when none. */
|
||||
export function issueTarget(
|
||||
doc: AnatomicalSheetDocument,
|
||||
path: string,
|
||||
locale: Locale,
|
||||
): IssueTarget | null {
|
||||
const region = REGION_PATH.exec(path)?.[1]
|
||||
if (region !== undefined) {
|
||||
const code = doc.vertebral_config.regions[Number(region)]?.code
|
||||
const name = code
|
||||
? elementLabel(doc, { kind: 'region', code }, locale)
|
||||
: null
|
||||
return { tab: 'vertebrae', name }
|
||||
}
|
||||
const match = ROOT_PATH.exec(path)
|
||||
const tab = match ? ROOT_TAB[match[1]] : undefined
|
||||
if (!match || !tab) return null
|
||||
const key = keyOf(doc, match[1], Number(match[2]))
|
||||
return { tab, name: key ? elementLabel(doc, key, locale) : null }
|
||||
}
|
||||
|
||||
/** « 2 097 152 » with plain spaces, as the plan words the size. */
|
||||
export function groupThousands(value: number): string {
|
||||
return String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
|
||||
}
|
||||
Reference in new issue
Block a user