fix(editor): load the core's defaults-filled document, trial guide fixes
This commit is contained in:
1 parent
0d167df271
commit
bb99edd2dd
5 files changed
+48
-54
No files matched your search
@@ -157,34 +157,9 @@ function categoryItems(zone: FindingZone, zoneItemId: string): FindingItem[] {
|
||||
})
|
||||
}
|
||||
|
||||
// shortcut: the serde defaults of the core's FindingNode and FindingCategory (schema.rs),
|
||||
// applied here because the page reads the stored text and the equine import omits them
|
||||
// (a node without `children` or `reference_ids` blanked the Constats tab). Upgrade path:
|
||||
// the loader hands the page the core's canonical document and this goes away.
|
||||
const filledNode = (node: FindingNode): FindingNode => ({
|
||||
...node,
|
||||
description: node.description ?? {},
|
||||
requires_vet_referral: node.requires_vet_referral ?? false,
|
||||
reference_ids: node.reference_ids ?? [],
|
||||
review_status: node.review_status ?? 'inherited',
|
||||
children: (node.children ?? []).map(filledNode),
|
||||
})
|
||||
|
||||
const filledCategory = (category: FindingCategory): FindingCategory => ({
|
||||
...category,
|
||||
description: category.description ?? {},
|
||||
reference_ids: category.reference_ids ?? [],
|
||||
review_status: category.review_status ?? 'inherited',
|
||||
children: (category.children ?? []).map(filledNode),
|
||||
})
|
||||
|
||||
/** Every element of the findings tree in document order, collapsed or not. */
|
||||
export function buildItems(doc: AnatomicalSheetDocument): FindingItem[] {
|
||||
return doc.finding_zones.flatMap((stored, index) => {
|
||||
const zone: FindingZone = {
|
||||
...stored,
|
||||
categories: (stored.categories ?? []).map(filledCategory),
|
||||
}
|
||||
return doc.finding_zones.flatMap((zone, index) => {
|
||||
const id = itemId(zone.id, [])
|
||||
const self: FindingItem = {
|
||||
id,
|
||||
|
||||
@@ -52,7 +52,13 @@ async function loadDraft(client: FaunosteoClient, versionId: string): Promise<Lo
|
||||
preview.free()
|
||||
return { ok: false, failure: coreFailure(state.kind) }
|
||||
}
|
||||
const loaded = { version: read.version, text, preview, state: state.value, attached }
|
||||
const loaded = {
|
||||
version: read.version,
|
||||
text: JSON.stringify(state.value.document),
|
||||
preview,
|
||||
state: state.value,
|
||||
attached,
|
||||
}
|
||||
return { ok: true, loaded }
|
||||
}
|
||||
|
||||
@@ -190,9 +196,10 @@ function applyReload(
|
||||
}
|
||||
const attached = attachDrawings(preview, read.drawings)
|
||||
const next = preview.state()
|
||||
const filled = next.ok ? next.value : replaced.state
|
||||
removeCopy(state.userId ?? '', state.versionId ?? '')
|
||||
api.set({
|
||||
...reloadPatch(state, text, next.ok ? next.value : replaced.state, read.revision),
|
||||
...reloadPatch(state, JSON.stringify(filled.document), filled, read.revision),
|
||||
drawings: [...state.drawings, ...attached.held],
|
||||
drawingFailures: { ...state.drawingFailures, ...attached.failures },
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user