@hippo-digital/hippocampus 1.0.0-rc.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +114 -3
- package/README.md +36 -0
- package/assets/dist/hippocampus.css +1 -1
- package/assets/hippocampus.scss +994 -133
- package/assets/javascript/blueprint.js +21 -0
- package/assets/javascript/trace.js +54 -0
- package/bin/hippocampus.js +9 -3
- package/index.js +2 -1
- package/lib/breadcrumb.js +80 -0
- package/lib/create-router.js +246 -6
- package/lib/discover-projects.js +5 -0
- package/lib/filter.js +81 -0
- package/lib/flow-map.js +214 -0
- package/lib/lint-knowledge.js +31 -0
- package/lib/load-knowledge.js +335 -34
- package/lib/record-links.js +51 -0
- package/lib/schema-version.js +1 -1
- package/lib/templates.js +174 -0
- package/package.json +1 -1
- package/scripts/doctor.js +10 -0
- package/scripts/import-design-actions.js +2 -2
- package/scripts/import-research-batch.js +1 -1
- package/scripts/import-research-deck.js +1 -1
- package/scripts/lib/make-blueprint-template.py +107 -0
- package/scripts/promote-project-context-draft.js +22 -3
- package/scripts/promote-research-draft.js +7 -2
- package/scripts/smoke-routes.js +19 -0
- package/scripts/sync-project-context.js +9 -5
- package/scripts/sync-research-artefacts.js +9 -5
- package/templates/service-blueprint.xlsx +0 -0
- package/views/hippocampus/_layout.html +116 -3
- package/views/hippocampus/blueprint-classic.html +0 -1
- package/views/hippocampus/blueprint.html +0 -1
- package/views/hippocampus/components/_blueprint-cell.njk +6 -3
- package/views/hippocampus/components/_blueprint-controls.njk +2 -1
- package/views/hippocampus/components/_breadcrumb.njk +29 -0
- package/views/hippocampus/components/_connections.njk +38 -0
- package/views/hippocampus/components/_filters.njk +56 -0
- package/views/hippocampus/components/_journey-step.njk +11 -7
- package/views/hippocampus/components/_screen-preview.njk +41 -0
- package/views/hippocampus/doc.html +0 -1
- package/views/hippocampus/docs.html +67 -6
- package/views/hippocampus/evidence-impact.html +66 -33
- package/views/hippocampus/graph.html +137 -31
- package/views/hippocampus/handover-empty.html +0 -1
- package/views/hippocampus/handover.html +0 -1
- package/views/hippocampus/index.html +102 -13
- package/views/hippocampus/journey-flow.html +0 -1
- package/views/hippocampus/journey.html +21 -6
- package/views/hippocampus/journeys.html +63 -0
- package/views/hippocampus/project.html +19 -2
- package/views/hippocampus/record.html +33 -0
- package/views/hippocampus/research.html +14 -2
- package/views/hippocampus/route-review.html +0 -1
- package/views/hippocampus/scenarios.html +21 -3
- package/views/hippocampus/screens.html +45 -0
- package/views/hippocampus/trace.html +35 -22
- package/views/hippocampus/user-needs.html +55 -19
- package/views/hippocampus/user.html +131 -79
- package/views/hippocampus/users.html +33 -19
package/lib/load-knowledge.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require('fs')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const { KnowledgeSchema } = require('./schema')
|
|
4
4
|
const { readMeta, migrateInMemory } = require('./schema-version')
|
|
5
|
+
const { buildFlowMap } = require('./flow-map')
|
|
5
6
|
|
|
6
7
|
const files = {
|
|
7
8
|
project: 'project.json',
|
|
@@ -67,6 +68,152 @@ function getKnowledge () {
|
|
|
67
68
|
return knowledge
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* What is this record connected to?
|
|
73
|
+
*
|
|
74
|
+
* Every detail page asks that same question, so it is answered once. Two things
|
|
75
|
+
* carry the connections and both have to be walked: the foreign keys on the
|
|
76
|
+
* record itself (a need's `evidenceIds`, a screen's `needIds`) and the typed
|
|
77
|
+
* edges in relationships.json, which run in both directions.
|
|
78
|
+
*
|
|
79
|
+
* Returns the record, its entity summary, and its connections grouped by the
|
|
80
|
+
* relationship that produced them - so a page can say "tested by these
|
|
81
|
+
* insights" rather than listing everything adjacent and leaving the reader to
|
|
82
|
+
* work out why each thing is there.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* The name to show for the service this knowledge base describes.
|
|
86
|
+
*
|
|
87
|
+
* `project.name` is whatever the host called the base, and a team modelling one
|
|
88
|
+
* piece of work often names it after that piece - "NCRS patient search" is a
|
|
89
|
+
* single design task, and it was heading the whole knowledge base.
|
|
90
|
+
* `projectContext.title` is the service itself.
|
|
91
|
+
*
|
|
92
|
+
* But an unfilled project context carries a scaffold title ("Project context"),
|
|
93
|
+
* and preferring that replaces a real name with a meaningless one. So the
|
|
94
|
+
* context's title is used only when the context has actually been filled in -
|
|
95
|
+
* a purpose, or any records in it. Placeholder text is not a better title than
|
|
96
|
+
* a narrow one.
|
|
97
|
+
*/
|
|
98
|
+
function getServiceTitle () {
|
|
99
|
+
const knowledge = getKnowledge()
|
|
100
|
+
const context = knowledge.projectContext || {}
|
|
101
|
+
|
|
102
|
+
const populated = Boolean(context.purpose || context.problemStatement || context.vision) ||
|
|
103
|
+
['users', 'channels', 'policies', 'constraints', 'risks', 'milestones', 'facts']
|
|
104
|
+
.some((key) => (context[key] || []).length)
|
|
105
|
+
|
|
106
|
+
return (populated && context.title) || knowledge.project.name
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getRecordDetail (id) {
|
|
110
|
+
const knowledge = getKnowledge()
|
|
111
|
+
const entity = knowledge.index.entities[id]
|
|
112
|
+
if (!entity) return null
|
|
113
|
+
|
|
114
|
+
const groups = new Map()
|
|
115
|
+
const add = (label, targetId) => {
|
|
116
|
+
if (!targetId || targetId === id) return
|
|
117
|
+
const target = knowledge.index.entities[targetId]
|
|
118
|
+
if (!target) return
|
|
119
|
+
if (!groups.has(label)) groups.set(label, new Map())
|
|
120
|
+
groups.get(label).set(target.id, target)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Edges, both directions. The label says what the edge means from THIS
|
|
124
|
+
// record's point of view, which is not the same in each direction:
|
|
125
|
+
// an insight tests a need; a need is tested by an insight.
|
|
126
|
+
for (const rel of knowledge.relationships || []) {
|
|
127
|
+
if (rel.from === id) add(outwardLabel(rel.type), rel.to)
|
|
128
|
+
else if (rel.to === id) add(inwardLabel(rel.type), rel.from)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Foreign keys on the record itself.
|
|
132
|
+
const record = findRecord(knowledge, id)
|
|
133
|
+
if (record) {
|
|
134
|
+
for (const needId of record.needIds || []) add('Needs', needId)
|
|
135
|
+
for (const evidenceId of record.evidenceIds || []) add('Evidence', evidenceId)
|
|
136
|
+
for (const screenId of record.screenIds || []) add('Screens', screenId)
|
|
137
|
+
for (const decisionId of record.decisionIds || []) add('Decisions', decisionId)
|
|
138
|
+
for (const participantId of record.participantIds || []) add('Participants', participantId)
|
|
139
|
+
if (record.userId) add('User', record.userId)
|
|
140
|
+
if (record.scenarioId) add('Scenario', record.scenarioId)
|
|
141
|
+
if (record.roundId) add('Research round', record.roundId)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// A screen or need is reached through journey steps rather than a direct key,
|
|
145
|
+
// and that is exactly the link a content designer is looking for.
|
|
146
|
+
for (const journey of knowledge.journeys || []) {
|
|
147
|
+
for (const step of journey.steps || []) {
|
|
148
|
+
const mentions = [...(step.needIds || []), ...(step.screenIds || []),
|
|
149
|
+
...(step.evidenceIds || []), ...(step.decisionIds || [])]
|
|
150
|
+
if (mentions.includes(id)) add('Journeys', journey.id)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The same connection often arrives twice - once as a typed edge and once as
|
|
155
|
+
// a foreign key on the record. An insight's participants came through both,
|
|
156
|
+
// and the page would have listed the same thirteen people under
|
|
157
|
+
// "Contributors" and again under "Participants". Where one group's items are
|
|
158
|
+
// wholly contained in another's, the more specific label wins.
|
|
159
|
+
const merged = [...groups.entries()].map(([label, items]) => ({ label, items: [...items.values()] }))
|
|
160
|
+
const kept = merged.filter((group, i) => !merged.some((other, j) => {
|
|
161
|
+
if (i === j || other.items.length < group.items.length) return false
|
|
162
|
+
if (other.items.length === group.items.length && j > i) return false
|
|
163
|
+
const ids = new Set(other.items.map((item) => item.id))
|
|
164
|
+
return group.items.every((item) => ids.has(item.id))
|
|
165
|
+
}))
|
|
166
|
+
|
|
167
|
+
return { id, entity, record: record || null, groups: kept }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const OUTWARD = {
|
|
171
|
+
'tests-need': 'Needs this tests',
|
|
172
|
+
'addresses-need': 'Needs this addresses',
|
|
173
|
+
'responds-to-insight': 'Insights this responds to',
|
|
174
|
+
'resolves-action': 'Design actions this resolves',
|
|
175
|
+
'produced-insight': 'Insights produced',
|
|
176
|
+
'has-participant': 'Participants',
|
|
177
|
+
'has-need': 'Needs',
|
|
178
|
+
'has-scenario': 'Scenarios',
|
|
179
|
+
'contributed-to': 'Contributed to',
|
|
180
|
+
'supported-by': 'Supported by',
|
|
181
|
+
'uses-evidence': 'Evidence used',
|
|
182
|
+
'renders-screen': 'Screens rendered',
|
|
183
|
+
'drives-journey': 'Journeys driven',
|
|
184
|
+
'records-decision': 'Decisions recorded'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const INWARD = {
|
|
188
|
+
'tests-need': 'Tested by',
|
|
189
|
+
'addresses-need': 'Addressed by',
|
|
190
|
+
'responds-to-insight': 'Design actions responding to this',
|
|
191
|
+
'resolves-action': 'Resolved by',
|
|
192
|
+
'produced-insight': 'From research round',
|
|
193
|
+
'has-participant': 'Research rounds',
|
|
194
|
+
'has-need': 'Users',
|
|
195
|
+
'has-scenario': 'Users',
|
|
196
|
+
'contributed-to': 'Contributors',
|
|
197
|
+
'supported-by': 'Supports',
|
|
198
|
+
'uses-evidence': 'Used by',
|
|
199
|
+
'renders-screen': 'Rendered by',
|
|
200
|
+
'drives-journey': 'Driven by',
|
|
201
|
+
'records-decision': 'Recorded by'
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function outwardLabel (type) { return OUTWARD[type] || type }
|
|
205
|
+
function inwardLabel (type) { return INWARD[type] || type }
|
|
206
|
+
|
|
207
|
+
function findRecord (knowledge, id) {
|
|
208
|
+
for (const collection of ['needs', 'insights', 'screens', 'users', 'scenarios',
|
|
209
|
+
'journeys', 'evidence', 'decisions', 'assumptions', 'researchRounds',
|
|
210
|
+
'participants', 'designActions']) {
|
|
211
|
+
const found = (knowledge[collection] || []).find((item) => item.id === id)
|
|
212
|
+
if (found) return found
|
|
213
|
+
}
|
|
214
|
+
return null
|
|
215
|
+
}
|
|
216
|
+
|
|
70
217
|
function buildIndex (knowledge) {
|
|
71
218
|
const index = {
|
|
72
219
|
users: byId(knowledge.users),
|
|
@@ -188,11 +335,38 @@ function getGraphExplorer () {
|
|
|
188
335
|
const nodes = [...entityIds].map((id) => knowledge.index.entities[id]).filter(Boolean)
|
|
189
336
|
const relationshipTypes = [...new Set(relationships.map((relationship) => relationship.type))].sort()
|
|
190
337
|
|
|
338
|
+
const counts = {}
|
|
339
|
+
for (const entity of Object.values(knowledge.index.entities)) {
|
|
340
|
+
counts[entity.type] = (counts[entity.type] || 0) + 1
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// A record connected to nothing is not a rendering problem, it is a gap in
|
|
344
|
+
// the knowledge base - and the old page, which drew only the entities that
|
|
345
|
+
// appear in a relationship, was the one view guaranteed never to show one.
|
|
346
|
+
const unconnected = []
|
|
347
|
+
for (const entity of Object.values(knowledge.index.entities)) {
|
|
348
|
+
if (!entityIds.has(entity.id)) unconnected.push(entity)
|
|
349
|
+
}
|
|
350
|
+
|
|
191
351
|
return {
|
|
192
352
|
nodes: sortByLabel(nodes, 'label'),
|
|
193
353
|
relationships,
|
|
194
|
-
relationshipTypes
|
|
354
|
+
relationshipTypes,
|
|
355
|
+
counts,
|
|
356
|
+
connectedCount: nodes.length,
|
|
357
|
+
entityCount: Object.keys(knowledge.index.entities).length,
|
|
358
|
+
flowMap: buildFlowMap({ nodes, relationships, counts }),
|
|
359
|
+
unconnected: groupByType(sortByTypeThenLabel(unconnected))
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function groupByType (entities) {
|
|
364
|
+
const groups = new Map()
|
|
365
|
+
for (const entity of entities) {
|
|
366
|
+
if (!groups.has(entity.type)) groups.set(entity.type, [])
|
|
367
|
+
groups.get(entity.type).push(entity)
|
|
195
368
|
}
|
|
369
|
+
return [...groups].map(([label, items]) => ({ label, items }))
|
|
196
370
|
}
|
|
197
371
|
|
|
198
372
|
function getTraceExplorer (entityType, entityId) {
|
|
@@ -227,42 +401,165 @@ function getTraceExplorer (entityType, entityId) {
|
|
|
227
401
|
}
|
|
228
402
|
}
|
|
229
403
|
|
|
404
|
+
// Relationship types that say where something CAME FROM, or who owns it,
|
|
405
|
+
// rather than what was built on it. A research round did not become wrong
|
|
406
|
+
// because a persona drawn from it did, and a user does not stop existing.
|
|
407
|
+
// Following these is how the old unbounded walk reached most of the graph.
|
|
408
|
+
const PROVENANCE_TYPES = new Set([
|
|
409
|
+
'has-need', 'has-scenario', 'has-participant', 'contributed-to', 'produced-insight'
|
|
410
|
+
])
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* What would need another look if this evidence turned out to be wrong.
|
|
414
|
+
*
|
|
415
|
+
* This used to walk upstream without a limit, so a persona cited by eight
|
|
416
|
+
* needs came back as impacting 67 entities over 602 relationship rows -
|
|
417
|
+
* including thirteen participants and seven research rounds, and 202 edges
|
|
418
|
+
* that did not involve the evidence at all. Reachability is not impact: past
|
|
419
|
+
* the first couple of hops a connected graph reaches everything, and a list
|
|
420
|
+
* that includes everything answers nothing.
|
|
421
|
+
*
|
|
422
|
+
* Two bounded steps instead. What cites this evidence, and what was built on
|
|
423
|
+
* the things that cite it - which for the worst record in the NCRS corpus is
|
|
424
|
+
* 76 entries rather than 663.
|
|
425
|
+
*/
|
|
230
426
|
function getEvidenceImpact (evidenceId) {
|
|
231
427
|
const knowledge = getKnowledge()
|
|
232
428
|
const evidence = knowledge.index.evidence[evidenceId]
|
|
233
429
|
if (!evidence) return null
|
|
234
430
|
|
|
235
|
-
const relationships =
|
|
236
|
-
const
|
|
237
|
-
|
|
431
|
+
const relationships = knowledge.relationships || []
|
|
432
|
+
const entityOf = (id) => knowledge.index.entities[id]
|
|
433
|
+
|
|
434
|
+
// Step one: everything naming this evidence, in either direction. Grouped
|
|
435
|
+
// and labelled by getRecordDetail, so an evidence page reads like every
|
|
436
|
+
// other detail page rather than inventing its own vocabulary.
|
|
437
|
+
const detail = getRecordDetail(evidenceId)
|
|
438
|
+
const citedGroups = detail ? detail.groups.map((g) => ({ ...g, items: [...g.items] })) : []
|
|
439
|
+
const cited = new Set()
|
|
440
|
+
for (const group of citedGroups) {
|
|
441
|
+
for (const item of group.items) cited.add(item.id)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// getRecordDetail walks the record's OWN foreign keys and the typed edges.
|
|
445
|
+
// Evidence is cited the other way round - the need holds `evidenceIds`, the
|
|
446
|
+
// evidence holds nothing - so a citation shows up here only if somebody also
|
|
447
|
+
// wrote a `supported-by` row. This corpus has those rows, which is exactly
|
|
448
|
+
// why the gap would go unnoticed until a project that does not.
|
|
449
|
+
const citedBy = []
|
|
450
|
+
for (const collection of ['needs', 'insights', 'journeys']) {
|
|
451
|
+
for (const record of knowledge[collection] || []) {
|
|
452
|
+
const ids = [
|
|
453
|
+
...(record.evidenceIds || []),
|
|
454
|
+
...(record.steps || []).flatMap((step) => step.evidenceIds || [])
|
|
455
|
+
]
|
|
456
|
+
if (!ids.includes(evidenceId) || cited.has(record.id)) continue
|
|
457
|
+
const entity = entityOf(record.id)
|
|
458
|
+
if (!entity) continue
|
|
459
|
+
cited.add(record.id)
|
|
460
|
+
citedBy.push(entity)
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (citedBy.length) citedGroups.push({ label: 'Cites this', items: sortByTypeThenLabel(citedBy) })
|
|
464
|
+
|
|
465
|
+
// Step two: what was built on those. One hop, and not back out through
|
|
466
|
+
// provenance.
|
|
467
|
+
const reachedIds = new Set()
|
|
468
|
+
for (const rel of relationships) {
|
|
469
|
+
if (PROVENANCE_TYPES.has(rel.type)) continue
|
|
470
|
+
for (const [near, far] of [[rel.to, rel.from], [rel.from, rel.to]]) {
|
|
471
|
+
if (!cited.has(near)) continue
|
|
472
|
+
if (far === evidenceId || cited.has(far)) continue
|
|
473
|
+
reachedIds.add(far)
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const reached = sortByTypeThenLabel([...reachedIds].map(entityOf).filter(Boolean))
|
|
478
|
+
const reachedGroups = [...reached.reduce((map, entity) => {
|
|
479
|
+
if (!map.has(entity.type)) map.set(entity.type, [])
|
|
480
|
+
map.get(entity.type).push(entity)
|
|
481
|
+
return map
|
|
482
|
+
}, new Map())].map(([label, items]) => ({ label, items }))
|
|
238
483
|
|
|
239
484
|
return {
|
|
240
485
|
evidence,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
486
|
+
citedGroups,
|
|
487
|
+
citedCount: cited.size,
|
|
488
|
+
reachedGroups,
|
|
489
|
+
reachedCount: reached.length
|
|
244
490
|
}
|
|
245
491
|
}
|
|
246
492
|
|
|
247
493
|
function getResearchViewModel () {
|
|
248
494
|
const knowledge = getKnowledge()
|
|
249
495
|
|
|
250
|
-
|
|
251
|
-
|
|
496
|
+
// A design action is finished when a decision resolves it. The action's own
|
|
497
|
+
// `status` field says the same thing, but the two can disagree - this corpus
|
|
498
|
+
// has 26 actions all still reading `proposed` while a decision resolves one
|
|
499
|
+
// of them - so both are consulted and the more advanced wins. A round that
|
|
500
|
+
// looks done when work is outstanding is the failure worth avoiding.
|
|
501
|
+
const resolvedActionIds = new Set(
|
|
502
|
+
(knowledge.relationships || [])
|
|
503
|
+
.filter((rel) => rel.type === 'resolves-action')
|
|
504
|
+
.map((rel) => rel.to)
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
const isOutstanding = (action) =>
|
|
508
|
+
!resolvedActionIds.has(action.id) && !['done', 'parked'].includes(action.status)
|
|
509
|
+
|
|
510
|
+
const rounds = knowledge.researchRounds.map((round) => {
|
|
511
|
+
const insights = knowledge.insights.filter((insight) => insight.roundId === round.id)
|
|
512
|
+
const roundInsightIds = new Set(insights.map((insight) => insight.id))
|
|
513
|
+
const designActions = knowledge.designActions.filter((action) =>
|
|
514
|
+
action.insightIds.some((insightId) => roundInsightIds.has(insightId)))
|
|
515
|
+
const outstanding = designActions.filter(isOutstanding)
|
|
516
|
+
|
|
517
|
+
return {
|
|
252
518
|
...round,
|
|
253
519
|
participants: knowledge.participants.filter((participant) => participant.roundIds.includes(round.id)),
|
|
254
|
-
insights
|
|
255
|
-
designActions
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
520
|
+
insights,
|
|
521
|
+
designActions,
|
|
522
|
+
outstanding,
|
|
523
|
+
status: roundStatus(insights, designActions, outstanding)
|
|
524
|
+
}
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
// Newest first. A research page is read to find out what was learned
|
|
528
|
+
// recently; oldest-first makes the reader scroll past two years of history to
|
|
529
|
+
// reach it. Sorted by date rather than by file order, which was neither.
|
|
530
|
+
rounds.sort((a, b) => String(b.date || '').localeCompare(String(a.date || '')))
|
|
531
|
+
|
|
532
|
+
return {
|
|
533
|
+
rounds,
|
|
260
534
|
participants: knowledge.participants,
|
|
261
535
|
insights: knowledge.insights,
|
|
262
|
-
designActions: knowledge.designActions
|
|
536
|
+
designActions: knowledge.designActions,
|
|
537
|
+
outstandingTotal: knowledge.designActions.filter(isOutstanding).length
|
|
263
538
|
}
|
|
264
539
|
}
|
|
265
540
|
|
|
541
|
+
/**
|
|
542
|
+
* Where a round has got to. Four states, each naming the next move rather than
|
|
543
|
+
* grading the round - "no insights yet" is a prompt, not a criticism.
|
|
544
|
+
*/
|
|
545
|
+
function roundStatus (insights, designActions, outstanding) {
|
|
546
|
+
if (!insights.length) {
|
|
547
|
+
return { key: 'not-mined', label: 'No insights yet', tag: 'grey', detail: 'Imported, but nothing has been drawn out of it.' }
|
|
548
|
+
}
|
|
549
|
+
if (!designActions.length) {
|
|
550
|
+
return { key: 'no-actions', label: 'No design actions', tag: 'blue', detail: `${insights.length} insights recorded, none acted on yet.` }
|
|
551
|
+
}
|
|
552
|
+
if (outstanding.length) {
|
|
553
|
+
return {
|
|
554
|
+
key: 'outstanding',
|
|
555
|
+
label: `${outstanding.length} action${outstanding.length === 1 ? '' : 's'} outstanding`,
|
|
556
|
+
tag: 'orange',
|
|
557
|
+
detail: `${designActions.length} design action${designActions.length === 1 ? '' : 's'} arose, ${designActions.length - outstanding.length} resolved.`
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return { key: 'complete', label: 'All actions resolved', tag: 'green', detail: `${designActions.length} resolved by a decision.` }
|
|
561
|
+
}
|
|
562
|
+
|
|
266
563
|
function enrichRelationships (knowledge, relationships) {
|
|
267
564
|
return relationships
|
|
268
565
|
.map((relationship) => {
|
|
@@ -281,21 +578,6 @@ function enrichRelationships (knowledge, relationships) {
|
|
|
281
578
|
.filter(Boolean)
|
|
282
579
|
}
|
|
283
580
|
|
|
284
|
-
function findDependents (entityId, relationships) {
|
|
285
|
-
const dependents = new Set()
|
|
286
|
-
const queue = [entityId]
|
|
287
|
-
|
|
288
|
-
while (queue.length) {
|
|
289
|
-
const current = queue.shift()
|
|
290
|
-
for (const relationship of relationships) {
|
|
291
|
-
if (relationship.to !== current || dependents.has(relationship.from)) continue
|
|
292
|
-
dependents.add(relationship.from)
|
|
293
|
-
queue.push(relationship.from)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return dependents
|
|
298
|
-
}
|
|
299
581
|
|
|
300
582
|
function buildTraceBranches (knowledge, relationships, entityId, direction, visited = new Set([entityId]), depth = 0) {
|
|
301
583
|
if (depth >= 6) return []
|
|
@@ -497,6 +779,22 @@ function truncateForDiagram (value, maxLength = 90) {
|
|
|
497
779
|
return `${value.slice(0, maxLength - 1).trim()}…`
|
|
498
780
|
}
|
|
499
781
|
|
|
782
|
+
// When the knowledge itself last changed, taken from the source files rather
|
|
783
|
+
// than from the clock. A footer that says "checked just now" on every request
|
|
784
|
+
// says nothing - the check runs per page load, so its own timestamp is always
|
|
785
|
+
// now. What a reader actually wants to know is how fresh the data behind the
|
|
786
|
+
// tick is.
|
|
787
|
+
function sourcesUpdatedAt () {
|
|
788
|
+
let newest = null
|
|
789
|
+
for (const filename of Object.values(files)) {
|
|
790
|
+
const filePath = path.join(paths.knowledgeSourceDir, filename)
|
|
791
|
+
if (!fs.existsSync(filePath)) continue
|
|
792
|
+
const { mtime } = fs.statSync(filePath)
|
|
793
|
+
if (!newest || mtime > newest) newest = mtime
|
|
794
|
+
}
|
|
795
|
+
return newest
|
|
796
|
+
}
|
|
797
|
+
|
|
500
798
|
function validateKnowledge () {
|
|
501
799
|
const errors = []
|
|
502
800
|
let knowledge
|
|
@@ -504,7 +802,7 @@ function validateKnowledge () {
|
|
|
504
802
|
try {
|
|
505
803
|
knowledge = loadKnowledgeData()
|
|
506
804
|
} catch (error) {
|
|
507
|
-
return { valid: false, errors: [`Could not load knowledge data: ${error.message}`] }
|
|
805
|
+
return { valid: false, errors: [`Could not load knowledge data: ${error.message}`], sourcesUpdatedAt: sourcesUpdatedAt() }
|
|
508
806
|
}
|
|
509
807
|
|
|
510
808
|
const schemaResult = KnowledgeSchema.safeParse(knowledge)
|
|
@@ -514,7 +812,8 @@ function validateKnowledge () {
|
|
|
514
812
|
errors: schemaResult.error.issues.map((issue) => {
|
|
515
813
|
const fieldPath = issue.path.length ? issue.path.join('.') : 'knowledge'
|
|
516
814
|
return `${fieldPath}: ${issue.message}`
|
|
517
|
-
})
|
|
815
|
+
}),
|
|
816
|
+
sourcesUpdatedAt: sourcesUpdatedAt()
|
|
518
817
|
}
|
|
519
818
|
}
|
|
520
819
|
|
|
@@ -581,7 +880,7 @@ function validateKnowledge () {
|
|
|
581
880
|
requireRef(errors, 'relationship', relationship.id, 'to', relationship.to, index.entities)
|
|
582
881
|
}
|
|
583
882
|
|
|
584
|
-
return { valid: errors.length === 0, errors }
|
|
883
|
+
return { valid: errors.length === 0, errors, sourcesUpdatedAt: sourcesUpdatedAt() }
|
|
585
884
|
}
|
|
586
885
|
|
|
587
886
|
function requireRef (errors, type, id, field, value, lookup) {
|
|
@@ -615,6 +914,8 @@ return {
|
|
|
615
914
|
getGraphExplorer,
|
|
616
915
|
getTraceExplorer,
|
|
617
916
|
getEvidenceImpact,
|
|
917
|
+
getRecordDetail,
|
|
918
|
+
getServiceTitle,
|
|
618
919
|
getResearchViewModel,
|
|
619
920
|
buildBlueprintViewModel,
|
|
620
921
|
buildJourneyFlowDiagram,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Where each kind of record lives in the viewer.
|
|
2
|
+
//
|
|
3
|
+
// The explorer's whole claim is traceability, and until now its biggest pages
|
|
4
|
+
// listed 132 needs and 21 scenarios with no link on any of them - every href on
|
|
5
|
+
// those pages was chrome. This table is what makes a list item clickable, and
|
|
6
|
+
// what tells a detail page which of its connections can be followed and which
|
|
7
|
+
// are still dead ends.
|
|
8
|
+
//
|
|
9
|
+
// A type mapped to null has no page yet. That is deliberate and visible: the
|
|
10
|
+
// viewer renders those as plain text rather than a broken link, and adding a
|
|
11
|
+
// page later is a single line here.
|
|
12
|
+
const ROUTES = {
|
|
13
|
+
User: (id) => `/users/${id}`,
|
|
14
|
+
Need: (id) => `/needs/${id}`,
|
|
15
|
+
Insight: (id) => `/insights/${id}`,
|
|
16
|
+
Screen: (id) => `/screens/${id}`,
|
|
17
|
+
Journey: (id) => `/journeys/${id}`,
|
|
18
|
+
Evidence: (id) => `/evidence/${id}/impact`,
|
|
19
|
+
Scenario: null,
|
|
20
|
+
Decision: null,
|
|
21
|
+
Assumption: null,
|
|
22
|
+
'Research round': null,
|
|
23
|
+
Participant: null,
|
|
24
|
+
'Design action': null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Where a whole TYPE lives, as opposed to one record. Several types have no
|
|
28
|
+
// list page of their own yet - a participant, a decision - and those stay
|
|
29
|
+
// unlinked rather than pointing somewhere that half answers the question.
|
|
30
|
+
const LIST_ROUTES = {
|
|
31
|
+
User: '/users',
|
|
32
|
+
Need: '/user-needs',
|
|
33
|
+
Scenario: '/scenarios',
|
|
34
|
+
Screen: '/screens',
|
|
35
|
+
Journey: '/journeys',
|
|
36
|
+
Insight: '/research',
|
|
37
|
+
'Research round': '/research'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function listHrefFor (type, basePath = '') {
|
|
41
|
+
const route = LIST_ROUTES[type]
|
|
42
|
+
return route ? `${basePath}${route}` : null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function hrefFor (entity, basePath = '') {
|
|
46
|
+
if (!entity || !entity.type) return null
|
|
47
|
+
const route = ROUTES[entity.type]
|
|
48
|
+
return route ? `${basePath}${route(entity.id)}` : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = { hrefFor, listHrefFor, ROUTES, LIST_ROUTES }
|
package/lib/schema-version.js
CHANGED
|
@@ -68,7 +68,7 @@ function migrateInMemory (knowledge, meta) {
|
|
|
68
68
|
version += 1
|
|
69
69
|
warnings.push(
|
|
70
70
|
`Knowledge base read as schemaVersion ${version - 1} and migrated to ${version} in memory. ` +
|
|
71
|
-
'Run `
|
|
71
|
+
'Run `npx hippocampus migrate` to write the upgrade back.'
|
|
72
72
|
)
|
|
73
73
|
}
|
|
74
74
|
|