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 },
|
||||
})
|
||||
|
||||
@@ -96,28 +96,34 @@ describe('findings tree model', () => {
|
||||
expect(shown.map((i) => i.kind)).toEqual(['zone', 'category', 'zone'])
|
||||
})
|
||||
|
||||
it('reads nodes that omit their defaulted fields (the equine import)', () => {
|
||||
it('loads a stored draft whose nodes omit defaulted fields, filled and clean', async () => {
|
||||
const stored = JSON.parse(baseText()) as Record<string, unknown>
|
||||
const bare = {
|
||||
id: 'n1',
|
||||
name: name('N1'),
|
||||
children: [{ id: 'n2', name: name('N2') }],
|
||||
}
|
||||
const stored = {
|
||||
finding_zones: [
|
||||
{
|
||||
id: 'z',
|
||||
name: name('Z'),
|
||||
categories: [
|
||||
{ id: 'c', kind: 'dysfunction', name: name('C'), children: [bare] },
|
||||
],
|
||||
},
|
||||
],
|
||||
} as unknown as AnatomicalSheetDocument
|
||||
const all = buildItems(stored)
|
||||
expect(all.map((i) => i.level)).toEqual([1, 2, 3, 4])
|
||||
expect(all[3].element).toMatchObject({
|
||||
value: { reference_ids: [], children: [], review_status: 'inherited' },
|
||||
stored.finding_zones = [
|
||||
{
|
||||
id: 'z',
|
||||
name: name('Z'),
|
||||
categories: [
|
||||
{ id: 'c', kind: 'dysfunction', name: name('C'), children: [bare] },
|
||||
],
|
||||
},
|
||||
]
|
||||
await openReady({ text: JSON.stringify(stored) })
|
||||
const { documentText, savedText, unsaved } = store.getState()
|
||||
expect(unsaved).toBe(false)
|
||||
expect(documentText).toBe(savedText)
|
||||
const n2 = doc().finding_zones[0].categories[0].children[0].children[0]
|
||||
expect(n2).toMatchObject({
|
||||
reference_ids: [],
|
||||
children: [],
|
||||
review_status: 'inherited',
|
||||
})
|
||||
render(<FindingsTab {...props} />)
|
||||
expect(screen.getAllByRole('treeitem').length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('maps the WAI-ARIA keys', async () => {
|
||||
|
||||
@@ -7,7 +7,8 @@ import base from '../vite.config'
|
||||
* forwarded to the trial gateway on loopback, so no CORS rule is involved.
|
||||
*/
|
||||
const target = process.env.FAUNOSTEO_TRIAL_GATEWAY
|
||||
if (!target || new URL(target).hostname !== '127.0.0.1')
|
||||
const url = target ? new URL(target) : null
|
||||
if (!url || url.protocol !== 'http:' || url.hostname !== '127.0.0.1')
|
||||
throw new Error('FAUNOSTEO_TRIAL_GATEWAY must be an http://127.0.0.1:<port> URL')
|
||||
|
||||
const SUPABASE_ROUTES = ['/auth/v1', '/rest/v1', '/storage/v1']
|
||||
|
||||
Reference in new issue
Block a user