@edjbarron/ux-guard 0.6.1 → 0.7.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/README.md +264 -104
- package/docs/cli-reference.md +38 -0
- package/docs/scoring-and-backslide.md +40 -0
- package/docs/test-suite.md +69 -2
- package/docs/use-case-review-design.md +284 -0
- package/docs/use-case-review.md +368 -0
- package/lib/catalog.mjs +46 -7
- package/lib/cli.mjs +288 -46
- package/lib/config.mjs +36 -1
- package/lib/review-app/app.css +697 -0
- package/lib/review-app/app.js +1899 -0
- package/lib/review-app/index.html +44 -0
- package/lib/review-audit.mjs +514 -0
- package/lib/review-command.mjs +409 -0
- package/lib/review-server.mjs +233 -0
- package/lib/review-store.mjs +554 -0
- package/lib/review.mjs +1385 -0
- package/lib/run-contract.mjs +1 -1
- package/package.json +1 -1
- package/skills/ux-guard/SKILL.md +131 -1
|
@@ -0,0 +1,1899 @@
|
|
|
1
|
+
// The review app is a view over server-computed state. Decisions are edited
|
|
2
|
+
// locally, evaluated by the local ux-guard process, and saved only on request.
|
|
3
|
+
|
|
4
|
+
const TOKEN_KEY = 'ux-guard-review-token';
|
|
5
|
+
const TABS = ['summary', 'use-cases', 'coverage', 'preview'];
|
|
6
|
+
const ACTION_LABELS = {
|
|
7
|
+
pending: 'Undecided',
|
|
8
|
+
approve: 'Approved use case',
|
|
9
|
+
revise: 'Approved use case',
|
|
10
|
+
reject: 'Rejected',
|
|
11
|
+
merge: 'Merged',
|
|
12
|
+
split: 'Split',
|
|
13
|
+
add: 'Added during review',
|
|
14
|
+
};
|
|
15
|
+
const STATUS_LABELS = {
|
|
16
|
+
mapped: 'Mapped to definition',
|
|
17
|
+
proposed: 'Awaiting a use-case decision',
|
|
18
|
+
excluded: 'Excluded',
|
|
19
|
+
unresolved: 'Unresolved',
|
|
20
|
+
};
|
|
21
|
+
const DISPOSITION_LABELS = {
|
|
22
|
+
'existing-use-case': 'existing use case',
|
|
23
|
+
'proposed-use-case': 'proposed use case',
|
|
24
|
+
excluded: 'excluded',
|
|
25
|
+
unresolved: 'unresolved',
|
|
26
|
+
};
|
|
27
|
+
const TIERS = ['primary', 'secondary', 'tertiary'];
|
|
28
|
+
const EFFECTS = ['read', 'create', 'change'];
|
|
29
|
+
const TEXT_FIELDS = [
|
|
30
|
+
['title', 'Title', 'input'],
|
|
31
|
+
['persona', 'Persona', 'input'],
|
|
32
|
+
['goal', 'Goal', 'textarea'],
|
|
33
|
+
['success', 'Success outcome', 'textarea'],
|
|
34
|
+
['rationale', 'Rationale', 'textarea'],
|
|
35
|
+
];
|
|
36
|
+
const FIELD_LABELS = Object.fromEntries(TEXT_FIELDS.map(([field, label]) => [field, label]));
|
|
37
|
+
Object.assign(FIELD_LABELS, { tier: 'Tier', effect: 'Effect' });
|
|
38
|
+
const USE_CASE_ID = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
39
|
+
const NAV_ID = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
|
|
40
|
+
|
|
41
|
+
const session = {
|
|
42
|
+
token: null,
|
|
43
|
+
data: null,
|
|
44
|
+
review: null,
|
|
45
|
+
dirty: false,
|
|
46
|
+
tab: 'summary',
|
|
47
|
+
useCase: null,
|
|
48
|
+
subject: null,
|
|
49
|
+
raw: new Map(),
|
|
50
|
+
fieldErrors: new Map(),
|
|
51
|
+
open: new Set(),
|
|
52
|
+
filters: {
|
|
53
|
+
useCases: { text: '', status: 'all', outcome: 'all' },
|
|
54
|
+
subjects: { text: '', status: 'all', type: 'all' },
|
|
55
|
+
},
|
|
56
|
+
evalTimer: null,
|
|
57
|
+
evalSequence: 0,
|
|
58
|
+
evalController: null,
|
|
59
|
+
closed: false,
|
|
60
|
+
saveButtonTimer: null,
|
|
61
|
+
saveButtonText: 'Save review',
|
|
62
|
+
lastSave: null,
|
|
63
|
+
mergeFor: null,
|
|
64
|
+
mergeTargetSearch: '',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function h(tag, props = {}, ...children) {
|
|
68
|
+
const element = document.createElement(tag);
|
|
69
|
+
for (const [key, value] of Object.entries(props)) {
|
|
70
|
+
if (value === undefined || value === null || value === false) continue;
|
|
71
|
+
if (key === 'class') element.className = value;
|
|
72
|
+
else if (key === 'text') element.textContent = value;
|
|
73
|
+
else if (key === 'value' || key === 'checked') continue;
|
|
74
|
+
else if (key.startsWith('on')) element.addEventListener(key.slice(2), value);
|
|
75
|
+
else element.setAttribute(key, value === true ? '' : String(value));
|
|
76
|
+
}
|
|
77
|
+
for (const child of children.flat(Infinity)) {
|
|
78
|
+
if (child === null || child === undefined || child === false) continue;
|
|
79
|
+
element.append(child instanceof Node ? child : String(child));
|
|
80
|
+
}
|
|
81
|
+
if (props.value !== undefined) element.value = props.value;
|
|
82
|
+
if (props.checked !== undefined) element.checked = Boolean(props.checked);
|
|
83
|
+
return element;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// rerender replaces a region and restores focus and caret by data-focus-key,
|
|
87
|
+
// so keyboard and screen-reader users keep their place after each evaluation.
|
|
88
|
+
function rerender(container, build) {
|
|
89
|
+
const active = document.activeElement;
|
|
90
|
+
const key = active && container.contains(active) ? active.dataset.focusKey : null;
|
|
91
|
+
const selection =
|
|
92
|
+
key && typeof active.selectionStart === 'number' ? [active.selectionStart, active.selectionEnd] : null;
|
|
93
|
+
const scrolls = [...container.querySelectorAll('[data-scroll-key]')].map((node) => [node.dataset.scrollKey, node.scrollTop]);
|
|
94
|
+
container.replaceChildren(...build().flat(Infinity).filter((child) => child !== null && child !== undefined && child !== false));
|
|
95
|
+
for (const [scrollKey, top] of scrolls) {
|
|
96
|
+
const node = container.querySelector(`[data-scroll-key="${CSS.escape(scrollKey)}"]`);
|
|
97
|
+
if (node) node.scrollTop = top;
|
|
98
|
+
}
|
|
99
|
+
if (!key) return;
|
|
100
|
+
const next = container.querySelector(`[data-focus-key="${CSS.escape(key)}"]`);
|
|
101
|
+
if (!next) return;
|
|
102
|
+
next.focus({ preventScroll: true });
|
|
103
|
+
if (selection && typeof next.setSelectionRange === 'function') {
|
|
104
|
+
try {
|
|
105
|
+
next.setSelectionRange(...selection);
|
|
106
|
+
} catch {
|
|
107
|
+
// Some input types do not support selection ranges.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function api(path, body, { signal } = {}) {
|
|
113
|
+
const response = await fetch(path, {
|
|
114
|
+
method: body ? 'POST' : 'GET',
|
|
115
|
+
headers: {
|
|
116
|
+
'X-UX-Guard-Token': session.token,
|
|
117
|
+
...(body ? { 'Content-Type': 'application/json' } : {}),
|
|
118
|
+
},
|
|
119
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
120
|
+
cache: 'no-store',
|
|
121
|
+
credentials: 'omit',
|
|
122
|
+
signal,
|
|
123
|
+
});
|
|
124
|
+
const data = await response.json().catch(() => ({ error: 'the local review returned an unreadable response' }));
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
const error = new Error(data.error ?? response.statusText);
|
|
127
|
+
error.status = response.status;
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function announce(message) {
|
|
134
|
+
const status = document.getElementById('status');
|
|
135
|
+
status.textContent = '';
|
|
136
|
+
window.setTimeout(() => {
|
|
137
|
+
status.textContent = message;
|
|
138
|
+
}, 30);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function showError(message) {
|
|
142
|
+
const error = document.getElementById('error');
|
|
143
|
+
error.textContent = message;
|
|
144
|
+
error.hidden = false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function hideError() {
|
|
148
|
+
document.getElementById('error').hidden = true;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function state() {
|
|
152
|
+
return session.data.state;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function decisionFor(id) {
|
|
156
|
+
return session.review.proposals[id] ?? { action: 'pending' };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function addedEntry(id) {
|
|
160
|
+
return session.review.added.find((entry) => entry.id === id);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function itemById(id) {
|
|
164
|
+
return state().useCases.find((item) => item.id === id) ?? null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function actionOf(item) {
|
|
168
|
+
return item.origin === 'candidate' ? item.action : 'add';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function actionLabel(item, action = actionOf(item)) {
|
|
172
|
+
if (action === 'revise') {
|
|
173
|
+
return item.definitionStatus === 'draft'
|
|
174
|
+
? 'Accepted completed use case'
|
|
175
|
+
: 'Approved this use case';
|
|
176
|
+
}
|
|
177
|
+
if (action === 'approve') return 'Approved this use case';
|
|
178
|
+
return ACTION_LABELS[action];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function stopEvaluation() {
|
|
182
|
+
window.clearTimeout(session.evalTimer);
|
|
183
|
+
session.evalTimer = null;
|
|
184
|
+
session.evalSequence += 1;
|
|
185
|
+
session.evalController?.abort();
|
|
186
|
+
session.evalController = null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function endSession() {
|
|
190
|
+
if (session.closed) return;
|
|
191
|
+
session.closed = true;
|
|
192
|
+
stopEvaluation();
|
|
193
|
+
window.clearTimeout(session.saveButtonTimer);
|
|
194
|
+
session.saveButtonTimer = null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function changed(message) {
|
|
198
|
+
if (session.closed) return;
|
|
199
|
+
session.dirty = true;
|
|
200
|
+
session.lastSave = null;
|
|
201
|
+
session.saveButtonText = 'Save review';
|
|
202
|
+
window.clearTimeout(session.saveButtonTimer);
|
|
203
|
+
document.getElementById('save-confirmation').hidden = true;
|
|
204
|
+
renderHeader();
|
|
205
|
+
window.clearTimeout(session.evalTimer);
|
|
206
|
+
session.evalTimer = window.setTimeout(evaluate, 250);
|
|
207
|
+
if (message) announce(message);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function evaluate() {
|
|
211
|
+
session.evalTimer = null;
|
|
212
|
+
if (session.closed) return;
|
|
213
|
+
const sequence = ++session.evalSequence;
|
|
214
|
+
session.evalController?.abort();
|
|
215
|
+
const controller = new AbortController();
|
|
216
|
+
session.evalController = controller;
|
|
217
|
+
try {
|
|
218
|
+
const data = await api('/api/evaluate', { review: session.review }, { signal: controller.signal });
|
|
219
|
+
if (session.closed || controller.signal.aborted || sequence !== session.evalSequence) return;
|
|
220
|
+
session.data = data;
|
|
221
|
+
hideError();
|
|
222
|
+
renderAll();
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (!session.closed && !controller.signal.aborted && sequence === session.evalSequence) {
|
|
225
|
+
showError(`These decisions could not be checked: ${error.message}`);
|
|
226
|
+
}
|
|
227
|
+
} finally {
|
|
228
|
+
if (session.evalController === controller) session.evalController = null;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async function save() {
|
|
233
|
+
if (!session.dirty) return;
|
|
234
|
+
if (session.fieldErrors.size) {
|
|
235
|
+
const first = session.fieldErrors.keys().next().value;
|
|
236
|
+
const field = first.slice(first.lastIndexOf(':') + 1);
|
|
237
|
+
const control = document.getElementById(`field-${field}`);
|
|
238
|
+
control?.focus();
|
|
239
|
+
announce('Fix the invalid definition field before saving.');
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
window.clearTimeout(session.evalTimer);
|
|
243
|
+
const button = document.getElementById('save');
|
|
244
|
+
session.saveButtonText = 'Saving…';
|
|
245
|
+
button.textContent = session.saveButtonText;
|
|
246
|
+
button.disabled = true;
|
|
247
|
+
try {
|
|
248
|
+
const data = await api('/api/save', { review: session.review });
|
|
249
|
+
session.data = data;
|
|
250
|
+
session.review = structuredClone(data.review);
|
|
251
|
+
session.dirty = false;
|
|
252
|
+
session.lastSave = data.saved;
|
|
253
|
+
session.saveButtonText = 'Saved ✓';
|
|
254
|
+
hideError();
|
|
255
|
+
renderAll();
|
|
256
|
+
const confirmation = document.getElementById('save-confirmation');
|
|
257
|
+
confirmation.textContent =
|
|
258
|
+
`Saved revision ${data.saved.revision} at ${data.saved.savedAt} to ${data.saved.path}. ` +
|
|
259
|
+
'Status: unapproved. Nothing was approved, adopted, checked in, or enforced.';
|
|
260
|
+
confirmation.hidden = false;
|
|
261
|
+
confirmation.focus();
|
|
262
|
+
announce(confirmation.textContent);
|
|
263
|
+
window.clearTimeout(session.saveButtonTimer);
|
|
264
|
+
session.saveButtonTimer = window.setTimeout(() => {
|
|
265
|
+
if (session.dirty) return;
|
|
266
|
+
session.saveButtonText = 'Save review';
|
|
267
|
+
button.textContent = session.saveButtonText;
|
|
268
|
+
button.disabled = true;
|
|
269
|
+
}, 1800);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
session.saveButtonText = 'Save review';
|
|
272
|
+
renderHeader();
|
|
273
|
+
if (error.status === 409) {
|
|
274
|
+
showError(`${error.message} Your unsaved decisions remain in this tab; reload only after copying anything you need.`);
|
|
275
|
+
} else {
|
|
276
|
+
showError(`The review was not saved: ${error.message}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function closeReview() {
|
|
282
|
+
if (
|
|
283
|
+
session.dirty &&
|
|
284
|
+
!window.confirm('You have unsaved changes. Close this review and discard those unsaved changes?')
|
|
285
|
+
) {
|
|
286
|
+
announce('Close cancelled. Your unsaved changes are still here.');
|
|
287
|
+
document.getElementById('save').focus();
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
endSession();
|
|
291
|
+
try {
|
|
292
|
+
await api('/api/close', {});
|
|
293
|
+
} catch {
|
|
294
|
+
// The process may already be stopping.
|
|
295
|
+
}
|
|
296
|
+
session.dirty = false;
|
|
297
|
+
document.body.replaceChildren(
|
|
298
|
+
h(
|
|
299
|
+
'main',
|
|
300
|
+
{ id: 'main', class: 'closed', tabindex: '-1' },
|
|
301
|
+
h('h1', { text: 'The review is closed' }),
|
|
302
|
+
h('p', { text: 'The local ux-guard review process has stopped. You can close this tab.' }),
|
|
303
|
+
),
|
|
304
|
+
);
|
|
305
|
+
document.getElementById('main').focus();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function selectTab(name, { focus = false } = {}) {
|
|
309
|
+
session.tab = name;
|
|
310
|
+
for (const tab of TABS) {
|
|
311
|
+
const button = document.getElementById(`tab-${tab}`);
|
|
312
|
+
const panel = document.getElementById(`panel-${tab}`);
|
|
313
|
+
const selected = tab === name;
|
|
314
|
+
button.setAttribute('aria-selected', String(selected));
|
|
315
|
+
button.tabIndex = selected ? 0 : -1;
|
|
316
|
+
panel.hidden = !selected;
|
|
317
|
+
}
|
|
318
|
+
if (focus) document.getElementById(`tab-${name}`).focus();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function wireTabs() {
|
|
322
|
+
const list = document.querySelector('[role="tablist"]');
|
|
323
|
+
for (const tab of TABS) {
|
|
324
|
+
document.getElementById(`tab-${tab}`).addEventListener('click', () => selectTab(tab));
|
|
325
|
+
}
|
|
326
|
+
list.addEventListener('keydown', (event) => {
|
|
327
|
+
const index = TABS.indexOf(session.tab);
|
|
328
|
+
const moves = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: TABS.length - 1 };
|
|
329
|
+
if (!(event.key in moves)) return;
|
|
330
|
+
event.preventDefault();
|
|
331
|
+
selectTab(TABS[(moves[event.key] + TABS.length) % TABS.length], { focus: true });
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// List navigation: arrow keys move between the item buttons of one inbox,
|
|
336
|
+
// across outcome groups.
|
|
337
|
+
function listKeys(event) {
|
|
338
|
+
const buttons = [...event.currentTarget.querySelectorAll('button[data-list-item]')];
|
|
339
|
+
const index = buttons.indexOf(document.activeElement);
|
|
340
|
+
if (index === -1) return;
|
|
341
|
+
const moves = { ArrowDown: index + 1, ArrowUp: index - 1, Home: 0, End: buttons.length - 1 };
|
|
342
|
+
if (!(event.key in moves)) return;
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
buttons[Math.max(0, Math.min(buttons.length - 1, moves[event.key]))].focus();
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function badge(text, tone) {
|
|
348
|
+
return h('span', { class: `badge ${tone ?? ''}`, text });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function actionTone(action) {
|
|
352
|
+
return { pending: 'warn', reject: 'muted', merge: 'info', split: 'info' }[action] ?? 'ok';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function statusTone(status) {
|
|
356
|
+
return { mapped: 'ok', excluded: 'muted', proposed: 'info', unresolved: 'warn' }[status];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function goToScope(scope) {
|
|
360
|
+
if (scope.startsWith('use-case:')) {
|
|
361
|
+
session.useCase = scope.slice('use-case:'.length);
|
|
362
|
+
selectTab('use-cases');
|
|
363
|
+
renderUseCases();
|
|
364
|
+
document.querySelector(`[data-focus-key="use-case:${CSS.escape(session.useCase)}"]`)?.focus();
|
|
365
|
+
} else if (scope.startsWith('surface:') || scope.startsWith('workflow:')) {
|
|
366
|
+
session.subject = scope;
|
|
367
|
+
selectTab('coverage');
|
|
368
|
+
renderCoverage();
|
|
369
|
+
document.querySelector(`[data-focus-key="subject:${CSS.escape(scope)}"]`)?.focus();
|
|
370
|
+
} else {
|
|
371
|
+
selectTab('preview');
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function renderAll() {
|
|
376
|
+
renderHeader();
|
|
377
|
+
renderIdentity();
|
|
378
|
+
renderSummary();
|
|
379
|
+
renderUseCases();
|
|
380
|
+
renderCoverage();
|
|
381
|
+
renderPreview();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function renderHeader() {
|
|
385
|
+
if (!session.data) return;
|
|
386
|
+
const { paths } = session.data;
|
|
387
|
+
document.getElementById('repo-line').textContent =
|
|
388
|
+
`Candidate ${paths.candidate} · Review decisions ${paths.review} · Catalog ${paths.catalog}`;
|
|
389
|
+
const saveState = document.getElementById('save-state');
|
|
390
|
+
saveState.className = 'save-state';
|
|
391
|
+
if (session.dirty) {
|
|
392
|
+
saveState.textContent = '● Unsaved changes';
|
|
393
|
+
saveState.classList.add('unsaved');
|
|
394
|
+
} else if (session.data.saved) {
|
|
395
|
+
saveState.textContent = `Saved revision ${session.review.revision} · unapproved`;
|
|
396
|
+
saveState.classList.add('saved');
|
|
397
|
+
} else {
|
|
398
|
+
saveState.textContent = 'Not saved yet';
|
|
399
|
+
}
|
|
400
|
+
const save = document.getElementById('save');
|
|
401
|
+
save.textContent = session.saveButtonText;
|
|
402
|
+
save.disabled = !session.dirty || session.fieldErrors.size > 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function renderIdentity() {
|
|
406
|
+
const banner = document.getElementById('identity-banner');
|
|
407
|
+
const identity = state().identity;
|
|
408
|
+
banner.className = 'banner';
|
|
409
|
+
if (identity.status === 'current') {
|
|
410
|
+
banner.hidden = true;
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
banner.hidden = false;
|
|
414
|
+
if (identity.status === 'stale') {
|
|
415
|
+
banner.classList.add('danger');
|
|
416
|
+
banner.replaceChildren(
|
|
417
|
+
h('strong', { text: 'This candidate is stale. ' }),
|
|
418
|
+
'You can keep reviewing and saving, but adoption is blocked until a fresh candidate is prepared. ',
|
|
419
|
+
h('ul', {}, identity.reasons.map((reason) => h('li', { text: reason }))),
|
|
420
|
+
);
|
|
421
|
+
} else if (identity.status === 'moved') {
|
|
422
|
+
banner.classList.add('info');
|
|
423
|
+
banner.textContent =
|
|
424
|
+
'The repository has new commits since the assessment, but every assessed file is unchanged.';
|
|
425
|
+
} else {
|
|
426
|
+
banner.classList.add('warn');
|
|
427
|
+
banner.textContent =
|
|
428
|
+
'Repository identity could not be verified because Git history is unavailable. Assessed file contents still match.';
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function renderSummary() {
|
|
433
|
+
const panel = document.getElementById('panel-summary');
|
|
434
|
+
rerender(panel, () => {
|
|
435
|
+
const { summary, unresolved, issues, questions } = state();
|
|
436
|
+
const cards = [
|
|
437
|
+
['discovered', 'Discovered', summary.discovered, 'Surfaces and workflows found by the assessment and navigation source.', 'all'],
|
|
438
|
+
['mapped', 'Definition-mapped', summary.mapped, 'Mapped to an accepted or existing use-case definition; this is not implementation measurement.', 'mapped'],
|
|
439
|
+
['proposed', 'Awaiting decision', summary.proposed, 'Mapped only to proposals that are still undecided.', 'proposed'],
|
|
440
|
+
['excluded', 'Excluded', summary.excluded, 'Explicitly out of scope, with a rationale.', 'excluded'],
|
|
441
|
+
['unresolved', 'Unresolved', summary.unresolved, 'Needs a mapping, an exclusion rationale, or a fix.', 'unresolved'],
|
|
442
|
+
];
|
|
443
|
+
const ready = summary.readyForOwnerApproval;
|
|
444
|
+
return [
|
|
445
|
+
h('h2', { text: 'Summary' }),
|
|
446
|
+
h(
|
|
447
|
+
'p',
|
|
448
|
+
{ class: ready ? 'callout ok' : 'callout warn' },
|
|
449
|
+
ready
|
|
450
|
+
? 'No unresolved decisions or blocking issues remain. The owner can now decide whether to approve and adopt this catalog; saving alone changes nothing.'
|
|
451
|
+
: `${summary.unresolvedDecisions} unresolved decision${summary.unresolvedDecisions === 1 ? '' : 's'} and ${summary.blockingIssues} blocking issue${summary.blockingIssues === 1 ? '' : 's'} remain. Unknowns stay visible until someone decides them.`,
|
|
452
|
+
),
|
|
453
|
+
h(
|
|
454
|
+
'ul',
|
|
455
|
+
{ class: 'cards', 'aria-label': 'Coverage totals' },
|
|
456
|
+
cards.map(([key, label, count, help, filter]) =>
|
|
457
|
+
h(
|
|
458
|
+
'li',
|
|
459
|
+
{ class: `card ${key}` },
|
|
460
|
+
h('span', { class: 'card-count', text: String(count) }),
|
|
461
|
+
h('span', { class: 'card-label', text: label }),
|
|
462
|
+
h('span', { class: 'card-help', text: help }),
|
|
463
|
+
h('button', {
|
|
464
|
+
type: 'button',
|
|
465
|
+
class: 'link',
|
|
466
|
+
'data-focus-key': `summary-card:${key}`,
|
|
467
|
+
text: `Show ${label.toLowerCase()}`,
|
|
468
|
+
onclick: () => {
|
|
469
|
+
session.filters.subjects.status = filter;
|
|
470
|
+
selectTab('coverage');
|
|
471
|
+
renderCoverage();
|
|
472
|
+
document.querySelector('[data-focus-key="subjects-status"]')?.focus();
|
|
473
|
+
},
|
|
474
|
+
}),
|
|
475
|
+
),
|
|
476
|
+
),
|
|
477
|
+
),
|
|
478
|
+
h('h3', { text: 'Discovered use-case definitions' }),
|
|
479
|
+
h(
|
|
480
|
+
'p',
|
|
481
|
+
{ class: 'muted' },
|
|
482
|
+
`${summary.definitions.completeProposals} complete proposal${summary.definitions.completeProposals === 1 ? '' : 's'} · `,
|
|
483
|
+
`${summary.definitions.incompleteDrafts} incomplete draft${summary.definitions.incompleteDrafts === 1 ? '' : 's'} · `,
|
|
484
|
+
`${summary.definitions.decisionsNeeded} decision${summary.definitions.decisionsNeeded === 1 ? '' : 's'} still needed`,
|
|
485
|
+
),
|
|
486
|
+
h(
|
|
487
|
+
'div',
|
|
488
|
+
{ class: 'progress-row' },
|
|
489
|
+
h('label', { for: 'proposal-progress', text: `${summary.proposals.decided} of ${summary.proposals.total} definitions decided` }),
|
|
490
|
+
h('progress', { id: 'proposal-progress', max: String(Math.max(1, summary.proposals.total)), value: String(summary.proposals.decided) }),
|
|
491
|
+
),
|
|
492
|
+
h(
|
|
493
|
+
'ul',
|
|
494
|
+
{ class: 'inline-list' },
|
|
495
|
+
h(
|
|
496
|
+
'li',
|
|
497
|
+
{},
|
|
498
|
+
badge(
|
|
499
|
+
`Approved use cases: ${summary.proposals.approve + summary.definitions.approvedRevisedProposals}`,
|
|
500
|
+
actionTone('approve'),
|
|
501
|
+
),
|
|
502
|
+
),
|
|
503
|
+
['reject', 'merge', 'split', 'pending'].map((action) =>
|
|
504
|
+
h('li', {}, badge(`${ACTION_LABELS[action]}: ${summary.proposals[action]}`, actionTone(action))),
|
|
505
|
+
),
|
|
506
|
+
h(
|
|
507
|
+
'li',
|
|
508
|
+
{},
|
|
509
|
+
badge(`Accepted completed drafts: ${summary.definitions.acceptedCompletedDrafts}`, actionTone('revise')),
|
|
510
|
+
),
|
|
511
|
+
h('li', {}, badge(`Added during review: ${summary.proposals.added}`, 'ok')),
|
|
512
|
+
h('li', {}, badge(`Split parts: ${summary.proposals.splitParts}`, 'info')),
|
|
513
|
+
),
|
|
514
|
+
h('h3', { text: `Unresolved decisions (${unresolved.length})` }),
|
|
515
|
+
unresolved.length
|
|
516
|
+
? h(
|
|
517
|
+
'ul',
|
|
518
|
+
{ class: 'task-list' },
|
|
519
|
+
unresolved.slice(0, 200).map((item, index) =>
|
|
520
|
+
h(
|
|
521
|
+
'li',
|
|
522
|
+
{},
|
|
523
|
+
h('span', { text: item.message }),
|
|
524
|
+
h('button', {
|
|
525
|
+
type: 'button',
|
|
526
|
+
class: 'link',
|
|
527
|
+
'data-focus-key': `unresolved:${index}`,
|
|
528
|
+
text: 'Go to item',
|
|
529
|
+
'aria-label': `Go to: ${item.message}`,
|
|
530
|
+
onclick: () => goToScope(item.scope),
|
|
531
|
+
}),
|
|
532
|
+
),
|
|
533
|
+
),
|
|
534
|
+
)
|
|
535
|
+
: h('p', { text: 'Every definition and discovered item has a decision.' }),
|
|
536
|
+
h('h3', { text: `Validation and conflicts (${issues.length})` }),
|
|
537
|
+
issues.length
|
|
538
|
+
? h(
|
|
539
|
+
'ul',
|
|
540
|
+
{ class: 'issue-list' },
|
|
541
|
+
[...issues]
|
|
542
|
+
.sort((a, b) => (a.severity === b.severity ? 0 : a.severity === 'error' ? -1 : 1))
|
|
543
|
+
.map((issue) =>
|
|
544
|
+
h(
|
|
545
|
+
'li',
|
|
546
|
+
{ class: issue.severity },
|
|
547
|
+
badge(issue.severity === 'error' ? 'Blocking' : 'Warning', issue.severity === 'error' ? 'danger' : 'warn'),
|
|
548
|
+
' ',
|
|
549
|
+
issue.message,
|
|
550
|
+
),
|
|
551
|
+
),
|
|
552
|
+
)
|
|
553
|
+
: h('p', { text: 'No validation problems were found.' }),
|
|
554
|
+
questions.length ? h('h3', { text: 'Open questions from the assessment' }) : null,
|
|
555
|
+
questions.length
|
|
556
|
+
? h(
|
|
557
|
+
'ul',
|
|
558
|
+
{ class: 'question-list' },
|
|
559
|
+
questions.map((question) =>
|
|
560
|
+
h('li', {}, h('strong', { text: question.question }), question.impact ? h('p', { class: 'muted', text: question.impact }) : null),
|
|
561
|
+
),
|
|
562
|
+
)
|
|
563
|
+
: null,
|
|
564
|
+
];
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function useCaseMatches(item) {
|
|
569
|
+
const filter = session.filters.useCases;
|
|
570
|
+
const action = actionOf(item);
|
|
571
|
+
if (filter.status === 'issues' && !item.issues.length && !item.omitted.length) return false;
|
|
572
|
+
if (filter.status === 'approved') {
|
|
573
|
+
if (!['approve', 'revise'].includes(action)) return false;
|
|
574
|
+
} else if (!['all', 'issues'].includes(filter.status) && action !== filter.status) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
if (filter.outcome !== 'all' && (item.effective.outcome ?? '') !== filter.outcome) return false;
|
|
578
|
+
const text = filter.text.trim().toLowerCase();
|
|
579
|
+
if (text && !`${item.id} ${item.effective.title ?? ''} ${item.effective.persona ?? ''}`.toLowerCase().includes(text)) {
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function renderUseCases() {
|
|
586
|
+
const panel = document.getElementById('panel-use-cases');
|
|
587
|
+
rerender(panel, () => {
|
|
588
|
+
const { useCases, outcomes, summary } = state();
|
|
589
|
+
if (!session.useCase || !useCases.some(({ id }) => id === session.useCase)) {
|
|
590
|
+
session.useCase = useCases.find((item) => actionOf(item) === 'pending')?.id ?? useCases[0]?.id ?? null;
|
|
591
|
+
}
|
|
592
|
+
const filter = session.filters.useCases;
|
|
593
|
+
const visible = useCases.filter(useCaseMatches);
|
|
594
|
+
const groups = outcomes
|
|
595
|
+
.map((group) => ({ ...group, items: visible.filter((item) => group.useCaseIds.includes(item.id)) }))
|
|
596
|
+
.filter((group) => group.items.length);
|
|
597
|
+
const filters = h(
|
|
598
|
+
'div',
|
|
599
|
+
{ class: 'filters', role: 'group', 'aria-label': 'Filter use cases' },
|
|
600
|
+
h('label', { for: 'use-case-search', text: 'Search' }),
|
|
601
|
+
h('input', {
|
|
602
|
+
id: 'use-case-search',
|
|
603
|
+
type: 'search',
|
|
604
|
+
'data-focus-key': 'use-case-search',
|
|
605
|
+
value: filter.text,
|
|
606
|
+
oninput: (event) => {
|
|
607
|
+
filter.text = event.target.value;
|
|
608
|
+
renderUseCases();
|
|
609
|
+
},
|
|
610
|
+
}),
|
|
611
|
+
h('label', { for: 'use-case-status', text: 'Decision' }),
|
|
612
|
+
h(
|
|
613
|
+
'select',
|
|
614
|
+
{
|
|
615
|
+
id: 'use-case-status',
|
|
616
|
+
'data-focus-key': 'use-case-status',
|
|
617
|
+
value: filter.status,
|
|
618
|
+
onchange: (event) => {
|
|
619
|
+
filter.status = event.target.value;
|
|
620
|
+
renderUseCases();
|
|
621
|
+
},
|
|
622
|
+
},
|
|
623
|
+
h('option', { value: 'all', text: 'All decisions' }),
|
|
624
|
+
h('option', { value: 'issues', text: 'Has warnings or blockers' }),
|
|
625
|
+
h('option', { value: 'pending', text: ACTION_LABELS.pending }),
|
|
626
|
+
h('option', { value: 'approved', text: 'Approved use case' }),
|
|
627
|
+
['reject', 'merge', 'split'].map((value) => h('option', { value, text: ACTION_LABELS[value] })),
|
|
628
|
+
),
|
|
629
|
+
outcomes.length > 1
|
|
630
|
+
? [
|
|
631
|
+
h('label', { for: 'use-case-outcome', text: 'User outcome' }),
|
|
632
|
+
h(
|
|
633
|
+
'select',
|
|
634
|
+
{
|
|
635
|
+
id: 'use-case-outcome',
|
|
636
|
+
'data-focus-key': 'use-case-outcome',
|
|
637
|
+
value: filter.outcome,
|
|
638
|
+
onchange: (event) => {
|
|
639
|
+
filter.outcome = event.target.value;
|
|
640
|
+
renderUseCases();
|
|
641
|
+
},
|
|
642
|
+
},
|
|
643
|
+
h('option', { value: 'all', text: 'All outcomes' }),
|
|
644
|
+
outcomes.map((group) => h('option', { value: group.id, text: group.title })),
|
|
645
|
+
),
|
|
646
|
+
]
|
|
647
|
+
: null,
|
|
648
|
+
);
|
|
649
|
+
const inbox = h(
|
|
650
|
+
'div',
|
|
651
|
+
{ class: 'inbox', 'data-scroll-key': 'use-case-inbox', onkeydown: listKeys },
|
|
652
|
+
h(
|
|
653
|
+
'div',
|
|
654
|
+
{ class: 'progress-row' },
|
|
655
|
+
h('label', {
|
|
656
|
+
for: 'inbox-progress',
|
|
657
|
+
text: `${summary.proposals.decided} of ${summary.proposals.total} definitions decided · showing ${visible.length}`,
|
|
658
|
+
}),
|
|
659
|
+
h('progress', { id: 'inbox-progress', max: String(Math.max(1, summary.proposals.total)), value: String(summary.proposals.decided) }),
|
|
660
|
+
),
|
|
661
|
+
h('button', { type: 'button', class: 'secondary', 'data-focus-key': 'add-use-case', text: 'Add a missed use case', onclick: addUseCase }),
|
|
662
|
+
groups.length === 0 ? h('p', { text: 'No use cases match these filters.' }) : null,
|
|
663
|
+
groups.map((group) =>
|
|
664
|
+
h(
|
|
665
|
+
'section',
|
|
666
|
+
{ class: 'group', 'aria-labelledby': `outcome-${group.id || 'none'}` },
|
|
667
|
+
h('h3', { id: `outcome-${group.id || 'none'}`, text: group.title }),
|
|
668
|
+
group.summary ? h('p', { class: 'muted', text: group.summary }) : null,
|
|
669
|
+
h(
|
|
670
|
+
'ul',
|
|
671
|
+
{ class: 'item-list', 'aria-label': `${group.title} use cases` },
|
|
672
|
+
group.items.map((item) =>
|
|
673
|
+
h(
|
|
674
|
+
'li',
|
|
675
|
+
{},
|
|
676
|
+
h(
|
|
677
|
+
'button',
|
|
678
|
+
{
|
|
679
|
+
type: 'button',
|
|
680
|
+
class: 'item',
|
|
681
|
+
'data-list-item': true,
|
|
682
|
+
'data-focus-key': `use-case:${item.id}`,
|
|
683
|
+
'aria-current': item.id === session.useCase ? 'true' : null,
|
|
684
|
+
onclick: () => {
|
|
685
|
+
session.useCase = item.id;
|
|
686
|
+
renderUseCases();
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
h('span', { class: 'item-title', text: item.effective.title ?? item.id }),
|
|
690
|
+
h(
|
|
691
|
+
'span',
|
|
692
|
+
{ class: 'item-meta' },
|
|
693
|
+
item.definitionStatus === 'draft' && actionOf(item) === 'pending'
|
|
694
|
+
? badge('Incomplete draft', 'warn')
|
|
695
|
+
: null,
|
|
696
|
+
badge(actionLabel(item), actionTone(actionOf(item))),
|
|
697
|
+
item.issues.some(({ severity }) => severity === 'error') || item.omitted.length ? badge('Needs attention', 'danger') : null),
|
|
698
|
+
),
|
|
699
|
+
),
|
|
700
|
+
),
|
|
701
|
+
),
|
|
702
|
+
),
|
|
703
|
+
),
|
|
704
|
+
);
|
|
705
|
+
const selected = useCases.find(({ id }) => id === session.useCase);
|
|
706
|
+
return [
|
|
707
|
+
h('h2', { text: 'Use cases' }),
|
|
708
|
+
h('p', {
|
|
709
|
+
class: 'muted',
|
|
710
|
+
text: 'Complete proposals and incomplete discovery drafts are grouped by the user outcome they serve. Choose one to review it.',
|
|
711
|
+
}),
|
|
712
|
+
filters,
|
|
713
|
+
h('div', { class: 'master-detail' }, inbox, selected ? useCaseDetail(selected) : h('p', { text: 'There are no use cases to review.' })),
|
|
714
|
+
];
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function rawKey(id, field) {
|
|
719
|
+
return `${id}:${field}`;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function fieldValue(item, field) {
|
|
723
|
+
if (item.origin === 'candidate') {
|
|
724
|
+
const fields = decisionFor(item.id).fields ?? {};
|
|
725
|
+
return Object.hasOwn(fields, field) ? fields[field] : item.proposed[field];
|
|
726
|
+
}
|
|
727
|
+
return addedEntry(item.id)?.[field];
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function editableItem(item) {
|
|
731
|
+
return item.origin !== 'candidate' || ['pending', 'approve', 'revise'].includes(decisionFor(item.id).action);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function sameValue(left, right) {
|
|
735
|
+
return JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
function setField(item, field, value) {
|
|
739
|
+
if (item.origin === 'candidate') {
|
|
740
|
+
const previous = decisionFor(item.id);
|
|
741
|
+
if (!['pending', 'approve', 'revise'].includes(previous.action)) return;
|
|
742
|
+
const decision = session.review.proposals[item.id] ?? { action: 'pending' };
|
|
743
|
+
const preserveApproval =
|
|
744
|
+
item.definitionStatus === 'proposal' && ['approve', 'revise'].includes(decision.action);
|
|
745
|
+
const returnedCompletedDraft = item.definitionStatus === 'draft' && decision.action === 'revise';
|
|
746
|
+
if (returnedCompletedDraft) decision.action = 'pending';
|
|
747
|
+
decision.fields ??= {};
|
|
748
|
+
if (value === undefined || sameValue(value, item.proposed[field])) delete decision.fields[field];
|
|
749
|
+
else decision.fields[field] = value;
|
|
750
|
+
if (Object.keys(decision.fields).length === 0) delete decision.fields;
|
|
751
|
+
if (preserveApproval) decision.action = decision.fields ? 'revise' : 'approve';
|
|
752
|
+
if (decision.action === 'pending' && !decision.fields && !decision.note) delete session.review.proposals[item.id];
|
|
753
|
+
else session.review.proposals[item.id] = decision;
|
|
754
|
+
changed(
|
|
755
|
+
preserveApproval
|
|
756
|
+
? decision.action === 'revise'
|
|
757
|
+
? 'Approval now applies to the edited definition shown.'
|
|
758
|
+
: 'Approval now applies to the assessment proposal.'
|
|
759
|
+
: returnedCompletedDraft
|
|
760
|
+
? 'The completed draft changed and is Undecided again until you explicitly accept it.'
|
|
761
|
+
: undefined,
|
|
762
|
+
);
|
|
763
|
+
return;
|
|
764
|
+
} else {
|
|
765
|
+
const entry = addedEntry(item.id);
|
|
766
|
+
if (!entry) return;
|
|
767
|
+
if (value === undefined) delete entry[field];
|
|
768
|
+
else entry[field] = value;
|
|
769
|
+
}
|
|
770
|
+
changed();
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function parseStarts(text) {
|
|
774
|
+
const starts = [];
|
|
775
|
+
const errors = [];
|
|
776
|
+
text.split('\n').forEach((raw, index) => {
|
|
777
|
+
const line = raw.trim();
|
|
778
|
+
if (!line) return;
|
|
779
|
+
const direct = /^route:\s*(.+)$/i.exec(line);
|
|
780
|
+
if (direct) {
|
|
781
|
+
const route = direct[1].trim();
|
|
782
|
+
if (isCanonicalDirectRoute(route)) starts.push({ entry: 'route', route });
|
|
783
|
+
else errors.push(`Line ${index + 1}: a direct route must be canonical, for example “route: /login”.`);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
const assistant = /^assistant:\s*(.+)$/i.exec(line);
|
|
787
|
+
if (assistant) {
|
|
788
|
+
starts.push({ entry: 'assistant', prompt: assistant[1].trim() });
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const parts = line.split(/\s+/);
|
|
792
|
+
if (parts.length === 2 && NAV_ID.test(parts[0]) && parts[1].startsWith('/')) {
|
|
793
|
+
starts.push({ nav_id: parts[0], route: parts[1] });
|
|
794
|
+
} else {
|
|
795
|
+
errors.push(
|
|
796
|
+
`Line ${index + 1}: write “route: /direct-path”, “navigation-id /route”, or “assistant: prompt”.`,
|
|
797
|
+
);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
return { starts, errors };
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function isCanonicalDirectRoute(value) {
|
|
804
|
+
if (
|
|
805
|
+
value !== value.trim() ||
|
|
806
|
+
!value.startsWith('/') ||
|
|
807
|
+
value.startsWith('//') ||
|
|
808
|
+
value.includes('//') ||
|
|
809
|
+
/[\s\\?#]/.test(value) ||
|
|
810
|
+
/%(?:2e|2f|5c)/i.test(value)
|
|
811
|
+
) {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
if (value !== '/' && value.endsWith('/')) return false;
|
|
815
|
+
return value.split('/').every((segment) => segment !== '.' && segment !== '..');
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function formatStarts(starts = []) {
|
|
819
|
+
return starts
|
|
820
|
+
.map((start) => {
|
|
821
|
+
if (start.entry === 'assistant') return `assistant: ${start.prompt}`;
|
|
822
|
+
if (start.entry === 'route') return `route: ${start.route}`;
|
|
823
|
+
return `${start.nav_id} ${start.route}`;
|
|
824
|
+
})
|
|
825
|
+
.join('\n');
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function fieldControl(item, field, label, kind) {
|
|
829
|
+
const id = `field-${field}`;
|
|
830
|
+
const key = rawKey(item.id, field);
|
|
831
|
+
const editable = editableItem(item);
|
|
832
|
+
const error = session.fieldErrors.get(key);
|
|
833
|
+
const proposed = item.origin === 'candidate' ? item.proposed[field] : undefined;
|
|
834
|
+
const current = fieldValue(item, field);
|
|
835
|
+
const value = session.raw.has(key) ? session.raw.get(key) : current ?? '';
|
|
836
|
+
const describedBy = [error ? `${id}-error` : null, item.origin === 'candidate' && !sameValue(current, proposed) ? `${id}-proposed` : null]
|
|
837
|
+
.filter(Boolean)
|
|
838
|
+
.join(' ');
|
|
839
|
+
const onInput = (event) => {
|
|
840
|
+
const text = event.target.value;
|
|
841
|
+
session.raw.set(key, text);
|
|
842
|
+
if (!text.trim()) {
|
|
843
|
+
if (field === 'title' && item.origin !== 'candidate') {
|
|
844
|
+
session.fieldErrors.set(key, 'A use case needs a title.');
|
|
845
|
+
renderUseCases();
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
session.fieldErrors.delete(key);
|
|
849
|
+
setField(item, field, field === 'rationale' && item.origin !== 'candidate' ? '' : undefined);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
session.fieldErrors.delete(key);
|
|
853
|
+
setField(item, field, text);
|
|
854
|
+
};
|
|
855
|
+
return h(
|
|
856
|
+
'div',
|
|
857
|
+
{ class: 'field' },
|
|
858
|
+
h('label', { for: id, text: label }),
|
|
859
|
+
h(kind, {
|
|
860
|
+
id,
|
|
861
|
+
'data-focus-key': id,
|
|
862
|
+
value,
|
|
863
|
+
readonly: !editable,
|
|
864
|
+
'aria-invalid': error ? 'true' : null,
|
|
865
|
+
'aria-describedby': describedBy || null,
|
|
866
|
+
rows: kind === 'textarea' ? '2' : null,
|
|
867
|
+
oninput: onInput,
|
|
868
|
+
}),
|
|
869
|
+
item.origin === 'candidate' && !sameValue(current, proposed)
|
|
870
|
+
? h('p', { id: `${id}-proposed`, class: 'hint', text: `Proposed: ${proposed ?? '(not provided)'}` })
|
|
871
|
+
: null,
|
|
872
|
+
error ? h('p', { id: `${id}-error`, class: 'field-error', text: error }) : null,
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function choiceControl(item, field, label, values) {
|
|
877
|
+
const id = `field-${field}`;
|
|
878
|
+
const current = fieldValue(item, field) ?? '';
|
|
879
|
+
return h(
|
|
880
|
+
'div',
|
|
881
|
+
{ class: 'field' },
|
|
882
|
+
h('label', { for: id, text: label }),
|
|
883
|
+
h(
|
|
884
|
+
'select',
|
|
885
|
+
{
|
|
886
|
+
id,
|
|
887
|
+
'data-focus-key': id,
|
|
888
|
+
value: current,
|
|
889
|
+
disabled: !editableItem(item),
|
|
890
|
+
onchange: (event) => setField(item, field, event.target.value || undefined),
|
|
891
|
+
},
|
|
892
|
+
h('option', { value: '', text: 'Not set' }),
|
|
893
|
+
values.map(([value, text]) => h('option', { value, text })),
|
|
894
|
+
),
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function listControl(item, field, label, help) {
|
|
899
|
+
const id = `field-${field}`;
|
|
900
|
+
const key = rawKey(item.id, field);
|
|
901
|
+
const error = session.fieldErrors.get(key);
|
|
902
|
+
const current = fieldValue(item, field);
|
|
903
|
+
const formatted = field === 'starts' ? formatStarts(current) : (current ?? []).join('\n');
|
|
904
|
+
return h(
|
|
905
|
+
'div',
|
|
906
|
+
{ class: 'field' },
|
|
907
|
+
h('label', { for: id, text: label }),
|
|
908
|
+
h('p', { id: `${id}-help`, class: 'hint', text: help }),
|
|
909
|
+
h('textarea', {
|
|
910
|
+
id,
|
|
911
|
+
rows: '3',
|
|
912
|
+
'data-focus-key': id,
|
|
913
|
+
value: session.raw.has(key) ? session.raw.get(key) : formatted,
|
|
914
|
+
readonly: !editableItem(item),
|
|
915
|
+
'aria-invalid': error ? 'true' : null,
|
|
916
|
+
'aria-describedby': [`${id}-help`, error ? `${id}-error` : null].filter(Boolean).join(' '),
|
|
917
|
+
oninput: (event) => {
|
|
918
|
+
session.raw.set(key, event.target.value);
|
|
919
|
+
if (field === 'starts') {
|
|
920
|
+
const parsed = parseStarts(event.target.value);
|
|
921
|
+
if (parsed.errors.length) {
|
|
922
|
+
session.fieldErrors.set(key, parsed.errors.join(' '));
|
|
923
|
+
renderUseCases();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
session.fieldErrors.delete(key);
|
|
927
|
+
setField(item, field, parsed.starts);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const values = event.target.value.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
931
|
+
setField(item, field, values.length ? values : undefined);
|
|
932
|
+
},
|
|
933
|
+
}),
|
|
934
|
+
error ? h('p', { id: `${id}-error`, class: 'field-error', text: error }) : null,
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
function outcomeTitle(id) {
|
|
939
|
+
return state().outcomes.find((outcome) => outcome.id === id)?.title ?? '';
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function mergeTargets(source) {
|
|
943
|
+
const targets = state().existingUseCases.map((entry) => ({
|
|
944
|
+
...entry,
|
|
945
|
+
status: 'Active catalog',
|
|
946
|
+
selectable: true,
|
|
947
|
+
outcome: '',
|
|
948
|
+
}));
|
|
949
|
+
for (const item of state().useCases) {
|
|
950
|
+
if (item.id === source.id) continue;
|
|
951
|
+
const action = actionOf(item);
|
|
952
|
+
if (['reject', 'split', 'merge'].includes(action) || item.invalidDecision || !item.draftCompleteness.complete) continue;
|
|
953
|
+
const subjects = state().subjects.filter((subject) => item.subjects.includes(subject.key));
|
|
954
|
+
targets.push({
|
|
955
|
+
id: item.id,
|
|
956
|
+
title: fieldValue(item, 'title') ?? item.id,
|
|
957
|
+
goal: fieldValue(item, 'goal') ?? '',
|
|
958
|
+
success: fieldValue(item, 'success') ?? '',
|
|
959
|
+
outcome: outcomeTitle(fieldValue(item, 'outcome')),
|
|
960
|
+
starts: fieldValue(item, 'starts') ?? [],
|
|
961
|
+
entryPoints: (fieldValue(item, 'starts') ?? []).length,
|
|
962
|
+
surfaces: subjects.filter(({ type }) => type === 'surface').length,
|
|
963
|
+
workflows: subjects.filter(({ type }) => type === 'workflow').length,
|
|
964
|
+
status: ['approve', 'revise', 'add'].includes(action)
|
|
965
|
+
? actionLabel(item, action)
|
|
966
|
+
: 'Must first be accepted',
|
|
967
|
+
selectable: ['approve', 'revise', 'add'].includes(action),
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
return targets.sort((left, right) => left.title.localeCompare(right.title) || left.id.localeCompare(right.id));
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function mergePreview(item, target) {
|
|
974
|
+
const mapped = state().subjects.filter((subject) => item.subjects.includes(subject.key));
|
|
975
|
+
const surfaceBindings = mapped.filter(({ type, route }) => type === 'surface' && route);
|
|
976
|
+
const manualBindings = fieldValue(item, 'starts') ?? [];
|
|
977
|
+
const movingBindings = [
|
|
978
|
+
...manualBindings,
|
|
979
|
+
...surfaceBindings.map((subject) => ({ nav_id: subject.id, route: subject.route })),
|
|
980
|
+
];
|
|
981
|
+
const targetBindings = target.starts ?? [];
|
|
982
|
+
const requirements = fieldValue(item, 'requirements') ?? [];
|
|
983
|
+
const gaps = fieldValue(item, 'gaps') ?? [];
|
|
984
|
+
const targetItem = itemById(target.id);
|
|
985
|
+
const targetRequirements = targetItem ? fieldValue(targetItem, 'requirements') ?? [] : [];
|
|
986
|
+
const targetGaps = targetItem ? fieldValue(targetItem, 'gaps') ?? [] : [];
|
|
987
|
+
const duplicateRequirements = requirements.filter((value) => targetRequirements.includes(value)).length;
|
|
988
|
+
const duplicateGaps = gaps.filter((value) => targetGaps.includes(value)).length;
|
|
989
|
+
const duplicateBindings = movingBindings.filter((binding) =>
|
|
990
|
+
targetBindings.some((targetBinding) => JSON.stringify(targetBinding) === JSON.stringify(binding)),
|
|
991
|
+
).length;
|
|
992
|
+
const conflictingBindings = movingBindings.filter(
|
|
993
|
+
(binding) =>
|
|
994
|
+
binding.nav_id &&
|
|
995
|
+
targetBindings.some(
|
|
996
|
+
(targetBinding) => targetBinding.nav_id === binding.nav_id && targetBinding.route !== binding.route,
|
|
997
|
+
),
|
|
998
|
+
).length;
|
|
999
|
+
return h(
|
|
1000
|
+
'section',
|
|
1001
|
+
{ class: 'merge-preview', 'aria-labelledby': 'merge-preview-title' },
|
|
1002
|
+
h('h4', { id: 'merge-preview-title', text: `Merge preview: ${item.id} → ${target.id}` }),
|
|
1003
|
+
h(
|
|
1004
|
+
'ul',
|
|
1005
|
+
{},
|
|
1006
|
+
h('li', {
|
|
1007
|
+
text: `${mapped.filter(({ type }) => type === 'surface').length} surface mapping(s) and ${
|
|
1008
|
+
mapped.filter(({ type }) => type === 'workflow').length
|
|
1009
|
+
} workflow mapping(s) will resolve to the target.`,
|
|
1010
|
+
}),
|
|
1011
|
+
h('li', {
|
|
1012
|
+
text: `${manualBindings.length} manual entry point(s) and ${surfaceBindings.length} mapped navigation binding(s) will move.`,
|
|
1013
|
+
}),
|
|
1014
|
+
h('li', {
|
|
1015
|
+
text: `${requirements.length} requirement(s) and ${gaps.length} gap(s) will be combined; exact duplicates are removed.`,
|
|
1016
|
+
}),
|
|
1017
|
+
duplicateBindings || duplicateRequirements || duplicateGaps
|
|
1018
|
+
? h('li', {
|
|
1019
|
+
text: `${duplicateBindings} duplicate binding(s), ${duplicateRequirements} duplicate requirement(s), and ${duplicateGaps} duplicate gap(s) already exist on the target.`,
|
|
1020
|
+
})
|
|
1021
|
+
: h('li', { text: 'No binding, requirement, or gap duplicates were found.' }),
|
|
1022
|
+
conflictingBindings
|
|
1023
|
+
? h('li', {
|
|
1024
|
+
class: 'field-error',
|
|
1025
|
+
text: `${conflictingBindings} navigation binding conflict(s) use the same navigation id with a different route.`,
|
|
1026
|
+
})
|
|
1027
|
+
: h('li', { text: 'No navigation binding conflicts were found.' }),
|
|
1028
|
+
h('li', { text: 'The source title, persona, goal, success outcome, tier, and effect do not replace the target definition.' }),
|
|
1029
|
+
),
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function openMerge(item) {
|
|
1034
|
+
session.mergeFor = item.id;
|
|
1035
|
+
session.mergeTargetSearch = '';
|
|
1036
|
+
renderUseCases();
|
|
1037
|
+
document.getElementById('merge-target-search')?.focus();
|
|
1038
|
+
announce(`Choose the use case that ${fieldValue(item, 'title') ?? item.id} should merge into.`);
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
function chooseMergeTarget(item, target) {
|
|
1042
|
+
if (!target.selectable) return;
|
|
1043
|
+
const note = decisionFor(item.id).note;
|
|
1044
|
+
session.review.proposals[item.id] = { action: 'merge', into: target.id, ...(note ? { note } : {}) };
|
|
1045
|
+
session.mergeFor = item.id;
|
|
1046
|
+
changed(`${fieldValue(item, 'title') ?? item.id}: merge into ${target.title}.`);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function uniqueId(base) {
|
|
1050
|
+
const taken = new Set([...state().useCases.map(({ id }) => id), ...state().existingUseCases.map(({ id }) => id), ...session.review.added.map(({ id }) => id)]);
|
|
1051
|
+
let index = 1;
|
|
1052
|
+
while (taken.has(`${base}-${index}`)) index += 1;
|
|
1053
|
+
return `${base}-${index}`;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function removeParts(parentId) {
|
|
1057
|
+
const parts = session.review.added.filter((entry) => entry.origin === 'split' && entry.from === parentId).map(({ id }) => id);
|
|
1058
|
+
session.review.added = session.review.added.filter((entry) => !parts.includes(entry.id));
|
|
1059
|
+
for (const mapping of Object.values(session.review.mappings)) {
|
|
1060
|
+
mapping.useCaseIds = mapping.useCaseIds.filter((id) => !parts.includes(id));
|
|
1061
|
+
}
|
|
1062
|
+
return parts.length;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function setAction(item, action) {
|
|
1066
|
+
const previous = decisionFor(item.id);
|
|
1067
|
+
const note = previous.note;
|
|
1068
|
+
if (action === 'approve' && !item.proposedCompleteness.complete) return;
|
|
1069
|
+
if (action === 'revise' && (!item.changedFields.length || !item.draftCompleteness.complete)) return;
|
|
1070
|
+
session.mergeFor = null;
|
|
1071
|
+
let message = `${fieldValue(item, 'title') ?? item.id}: ${actionLabel(item, action)}.`;
|
|
1072
|
+
if (previous.action === 'split' && action !== 'split') {
|
|
1073
|
+
const removed = removeParts(item.id);
|
|
1074
|
+
message += ` Removed ${removed} split part${removed === 1 ? '' : 's'}.`;
|
|
1075
|
+
}
|
|
1076
|
+
let decision = { action };
|
|
1077
|
+
if (action === 'revise') decision.fields = structuredClone(previous.fields ?? {});
|
|
1078
|
+
if (action === 'pending' && previous.fields) decision.fields = structuredClone(previous.fields);
|
|
1079
|
+
if (action === 'split') {
|
|
1080
|
+
const parts = [uniqueId(`${item.id}-part`)];
|
|
1081
|
+
session.review.added.push(splitPart(item, parts[0], 1));
|
|
1082
|
+
parts.push(uniqueId(`${item.id}-part`));
|
|
1083
|
+
session.review.added.push(splitPart(item, parts[1], 2));
|
|
1084
|
+
decision.parts = parts;
|
|
1085
|
+
message += ' Created two parts to edit below.';
|
|
1086
|
+
}
|
|
1087
|
+
if (note) decision.note = note;
|
|
1088
|
+
if (action === 'pending' && !note && !decision.fields) delete session.review.proposals[item.id];
|
|
1089
|
+
else session.review.proposals[item.id] = decision;
|
|
1090
|
+
for (const key of [...session.raw.keys()]) if (key.startsWith(`${item.id}:`)) session.raw.delete(key);
|
|
1091
|
+
changed(message);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function approveCurrentDefinition(item) {
|
|
1095
|
+
setAction(item, item.changedFields.length ? 'revise' : 'approve');
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function splitPart(item, id, index) {
|
|
1099
|
+
const part = { id, origin: 'split', from: item.id, title: `${fieldValue(item, 'title') ?? item.id} (part ${index})` };
|
|
1100
|
+
for (const field of ['persona', 'tier', 'effect', 'goal', 'success', 'outcome']) {
|
|
1101
|
+
const value = fieldValue(item, field);
|
|
1102
|
+
if (value !== undefined) part[field] = value;
|
|
1103
|
+
}
|
|
1104
|
+
const starts = fieldValue(item, 'starts');
|
|
1105
|
+
if (starts?.length) part.starts = structuredClone(starts);
|
|
1106
|
+
return part;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function addUseCase() {
|
|
1110
|
+
const id = uniqueId('new-use-case');
|
|
1111
|
+
const outcome = session.filters.useCases.outcome !== 'all' ? session.filters.useCases.outcome : undefined;
|
|
1112
|
+
session.review.added.push({ id, origin: 'added', title: 'New use case', ...(outcome ? { outcome } : {}) });
|
|
1113
|
+
session.useCase = id;
|
|
1114
|
+
changed('Added a new use case. Fill in its details.');
|
|
1115
|
+
window.setTimeout(() => document.getElementById('field-title')?.focus(), 300);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function renameAdded(item, next) {
|
|
1119
|
+
const entry = addedEntry(item.id);
|
|
1120
|
+
entry.id = next;
|
|
1121
|
+
for (const mapping of Object.values(session.review.mappings)) {
|
|
1122
|
+
mapping.useCaseIds = mapping.useCaseIds.map((id) => (id === item.id ? next : id));
|
|
1123
|
+
}
|
|
1124
|
+
for (const decision of Object.values(session.review.proposals)) {
|
|
1125
|
+
if (decision.into === item.id) decision.into = next;
|
|
1126
|
+
if (decision.parts) decision.parts = decision.parts.map((id) => (id === item.id ? next : id));
|
|
1127
|
+
}
|
|
1128
|
+
session.useCase = next;
|
|
1129
|
+
changed(`Renamed to ${next}.`);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
function removeAdded(item) {
|
|
1133
|
+
session.review.added = session.review.added.filter((entry) => entry.id !== item.id);
|
|
1134
|
+
for (const mapping of Object.values(session.review.mappings)) {
|
|
1135
|
+
mapping.useCaseIds = mapping.useCaseIds.filter((id) => id !== item.id);
|
|
1136
|
+
}
|
|
1137
|
+
if (item.from) {
|
|
1138
|
+
const parent = session.review.proposals[item.from];
|
|
1139
|
+
if (parent?.parts) parent.parts = parent.parts.filter((id) => id !== item.id);
|
|
1140
|
+
}
|
|
1141
|
+
session.useCase = null;
|
|
1142
|
+
changed(`Removed ${item.id}.`);
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
function addSplitPart(parent) {
|
|
1146
|
+
const decision = session.review.proposals[parent.id];
|
|
1147
|
+
const id = uniqueId(`${parent.id}-part`);
|
|
1148
|
+
session.review.added.push(splitPart(parent, id, decision.parts.length + 1));
|
|
1149
|
+
decision.parts.push(id);
|
|
1150
|
+
changed(`Added split part ${id}.`);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function resetDraft(item) {
|
|
1154
|
+
const previous = decisionFor(item.id);
|
|
1155
|
+
const preserveApproval =
|
|
1156
|
+
item.definitionStatus === 'proposal' && ['approve', 'revise'].includes(previous.action);
|
|
1157
|
+
const decision = {
|
|
1158
|
+
action: preserveApproval ? 'approve' : 'pending',
|
|
1159
|
+
...(previous.note ? { note: previous.note } : {}),
|
|
1160
|
+
};
|
|
1161
|
+
if (preserveApproval || previous.note) session.review.proposals[item.id] = decision;
|
|
1162
|
+
else delete session.review.proposals[item.id];
|
|
1163
|
+
for (const key of [...session.raw.keys()]) if (key.startsWith(`${item.id}:`)) session.raw.delete(key);
|
|
1164
|
+
for (const key of [...session.fieldErrors.keys()]) if (key.startsWith(`${item.id}:`)) session.fieldErrors.delete(key);
|
|
1165
|
+
changed(
|
|
1166
|
+
`${fieldValue(item, 'title') ?? item.id}: draft changes reset to the assessment ${
|
|
1167
|
+
item.definitionStatus === 'draft' ? 'draft' : 'proposal'
|
|
1168
|
+
}.${preserveApproval ? ' Approval now applies to the assessment proposal.' : ''}`,
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function focusDefinitionField(field) {
|
|
1173
|
+
document.getElementById(`field-${field}`)?.focus();
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function missingFieldGuidance(completeness, prefix) {
|
|
1177
|
+
if (completeness.complete) return null;
|
|
1178
|
+
return h(
|
|
1179
|
+
'span',
|
|
1180
|
+
{ class: 'decision-guidance' },
|
|
1181
|
+
`${prefix} `,
|
|
1182
|
+
completeness.missing.map((field, index) => [
|
|
1183
|
+
index ? ', ' : '',
|
|
1184
|
+
h('button', {
|
|
1185
|
+
type: 'button',
|
|
1186
|
+
class: 'link inline',
|
|
1187
|
+
'data-focus-key': `missing:${field}`,
|
|
1188
|
+
text: completeness.missingLabels[index],
|
|
1189
|
+
onclick: () => focusDefinitionField(field),
|
|
1190
|
+
}),
|
|
1191
|
+
]),
|
|
1192
|
+
completeness.missing.length === 1 ? ' is provided.' : ' are provided.',
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
function mergeTargetPicker(item) {
|
|
1197
|
+
const all = mergeTargets(item);
|
|
1198
|
+
const text = session.mergeTargetSearch.trim().toLowerCase();
|
|
1199
|
+
const visible = all.filter((target) =>
|
|
1200
|
+
`${target.title} ${target.id} ${target.status} ${target.goal} ${target.success} ${target.outcome}`
|
|
1201
|
+
.toLowerCase()
|
|
1202
|
+
.includes(text),
|
|
1203
|
+
);
|
|
1204
|
+
const selectedId = actionOf(item) === 'merge' ? decisionFor(item.id).into : null;
|
|
1205
|
+
const selected = all.find(({ id }) => id === selectedId) ?? null;
|
|
1206
|
+
return h(
|
|
1207
|
+
'section',
|
|
1208
|
+
{ class: 'merge-picker', 'aria-labelledby': 'merge-picker-title' },
|
|
1209
|
+
h('h4', { id: 'merge-picker-title', text: 'Merge this proposal into …' }),
|
|
1210
|
+
h('p', {
|
|
1211
|
+
class: 'hint',
|
|
1212
|
+
text: 'Choose an accepted target. Complete but undecided proposals are shown for context and must first be accepted.',
|
|
1213
|
+
}),
|
|
1214
|
+
h('label', { for: 'merge-target-search', text: 'Search merge targets' }),
|
|
1215
|
+
h('input', {
|
|
1216
|
+
id: 'merge-target-search',
|
|
1217
|
+
type: 'search',
|
|
1218
|
+
'data-focus-key': 'merge-target-search',
|
|
1219
|
+
value: session.mergeTargetSearch,
|
|
1220
|
+
oninput: (event) => {
|
|
1221
|
+
session.mergeTargetSearch = event.target.value;
|
|
1222
|
+
renderUseCases();
|
|
1223
|
+
},
|
|
1224
|
+
}),
|
|
1225
|
+
h(
|
|
1226
|
+
'ul',
|
|
1227
|
+
{ class: 'merge-targets', 'aria-label': 'Eligible merge targets' },
|
|
1228
|
+
visible.length
|
|
1229
|
+
? visible.map((target) =>
|
|
1230
|
+
h(
|
|
1231
|
+
'li',
|
|
1232
|
+
{ class: target.selectable ? '' : 'unavailable' },
|
|
1233
|
+
h(
|
|
1234
|
+
'button',
|
|
1235
|
+
{
|
|
1236
|
+
type: 'button',
|
|
1237
|
+
class: 'merge-target',
|
|
1238
|
+
'data-focus-key': `merge-target:${target.id}`,
|
|
1239
|
+
disabled: !target.selectable,
|
|
1240
|
+
'aria-pressed': selectedId === target.id ? 'true' : 'false',
|
|
1241
|
+
onclick: () => chooseMergeTarget(item, target),
|
|
1242
|
+
},
|
|
1243
|
+
h('strong', { text: target.title }),
|
|
1244
|
+
h('span', { class: 'muted', text: `${target.id} · ${target.status}` }),
|
|
1245
|
+
h('span', {
|
|
1246
|
+
text: target.goal || target.outcome || target.success || 'No concise goal or outcome is recorded.',
|
|
1247
|
+
}),
|
|
1248
|
+
h('span', {
|
|
1249
|
+
class: 'muted',
|
|
1250
|
+
text: `${target.surfaces} surface(s) · ${target.workflows} workflow(s) · ${target.entryPoints} entry point(s)`,
|
|
1251
|
+
}),
|
|
1252
|
+
),
|
|
1253
|
+
),
|
|
1254
|
+
)
|
|
1255
|
+
: h('li', { text: 'No merge targets match this search.' }),
|
|
1256
|
+
),
|
|
1257
|
+
selected ? mergePreview(item, selected) : h('p', { class: 'callout warn', text: 'No merge target selected. No merge decision has been completed.' }),
|
|
1258
|
+
actionOf(item) !== 'merge'
|
|
1259
|
+
? h('button', {
|
|
1260
|
+
type: 'button',
|
|
1261
|
+
class: 'secondary',
|
|
1262
|
+
'data-focus-key': 'cancel-merge',
|
|
1263
|
+
text: 'Cancel merge',
|
|
1264
|
+
onclick: () => {
|
|
1265
|
+
session.mergeFor = null;
|
|
1266
|
+
renderUseCases();
|
|
1267
|
+
document
|
|
1268
|
+
.getElementById(
|
|
1269
|
+
item.definitionStatus === 'proposal' && ['approve', 'revise'].includes(actionOf(item))
|
|
1270
|
+
? 'decision-approve'
|
|
1271
|
+
: `decision-${actionOf(item)}`,
|
|
1272
|
+
)
|
|
1273
|
+
?.focus();
|
|
1274
|
+
},
|
|
1275
|
+
})
|
|
1276
|
+
: null,
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
function useCaseDetail(item) {
|
|
1281
|
+
const action = actionOf(item);
|
|
1282
|
+
const title = fieldValue(item, 'title') ?? item.id;
|
|
1283
|
+
const targets = item.origin === 'candidate' ? mergeTargets(item) : [];
|
|
1284
|
+
const decisionNote = item.origin === 'candidate' ? decisionFor(item.id).note ?? '' : '';
|
|
1285
|
+
const subjects = state().subjects.filter((subject) => item.subjects.includes(subject.key));
|
|
1286
|
+
const idKey = rawKey(item.id, 'id');
|
|
1287
|
+
const idError = session.fieldErrors.get(idKey);
|
|
1288
|
+
const hasFieldErrors = [...session.fieldErrors.keys()].some((key) => key.startsWith(`${item.id}:`));
|
|
1289
|
+
const mergeOpen = session.mergeFor === item.id || action === 'merge';
|
|
1290
|
+
const incompleteSource = item.definitionStatus === 'draft';
|
|
1291
|
+
const actions = [
|
|
1292
|
+
{
|
|
1293
|
+
value: 'pending',
|
|
1294
|
+
label: 'Keep undecided',
|
|
1295
|
+
help: incompleteSource
|
|
1296
|
+
? 'Continue completing this discovery draft without accepting or rejecting it.'
|
|
1297
|
+
: 'Continue editing a draft revision without accepting or rejecting the proposal.',
|
|
1298
|
+
},
|
|
1299
|
+
...(incompleteSource
|
|
1300
|
+
? [
|
|
1301
|
+
{
|
|
1302
|
+
value: 'revise',
|
|
1303
|
+
label: 'Accept completed use case',
|
|
1304
|
+
help:
|
|
1305
|
+
item.changedFields.length && item.draftCompleteness.complete
|
|
1306
|
+
? `Accept the completed definition with ${item.changedFields.map((field) => FIELD_LABELS[field] ?? field).join(', ')} added or changed.`
|
|
1307
|
+
: item.changedFields.length
|
|
1308
|
+
? null
|
|
1309
|
+
: 'Complete the missing definition fields below before accepting this use case.',
|
|
1310
|
+
guidance: missingFieldGuidance(item.draftCompleteness, 'Available when'),
|
|
1311
|
+
disabled: hasFieldErrors || !item.changedFields.length || !item.draftCompleteness.complete,
|
|
1312
|
+
},
|
|
1313
|
+
]
|
|
1314
|
+
: [
|
|
1315
|
+
{
|
|
1316
|
+
value: 'approve',
|
|
1317
|
+
label: 'Approve this use case',
|
|
1318
|
+
help: item.changedFields.length
|
|
1319
|
+
? `Accept the complete definition currently shown, including changes to ${item.changedFields.map((field) => FIELD_LABELS[field] ?? field).join(', ')}.`
|
|
1320
|
+
: 'Accept the complete definition currently shown. It matches the assessment proposal.',
|
|
1321
|
+
disabled: hasFieldErrors || !item.draftCompleteness.complete,
|
|
1322
|
+
},
|
|
1323
|
+
]),
|
|
1324
|
+
{
|
|
1325
|
+
value: 'reject',
|
|
1326
|
+
label: incompleteSource ? 'Reject this draft' : 'Reject this proposal',
|
|
1327
|
+
help: 'Do not add this use case. Its mapped surfaces and workflows become unresolved.',
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
value: 'merge',
|
|
1331
|
+
label: incompleteSource ? 'Merge this draft into …' : 'Merge this proposal into …',
|
|
1332
|
+
help: targets.length
|
|
1333
|
+
? 'Choose the accepted use case that should receive this proposal’s mappings and implementation details.'
|
|
1334
|
+
: 'No complete, non-rejected merge targets are available.',
|
|
1335
|
+
disabled: targets.length === 0,
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
value: 'split',
|
|
1339
|
+
label: incompleteSource ? 'Split this draft into separate use cases' : 'Split into separate use cases',
|
|
1340
|
+
help: 'Create two draft parts. Mapped items stay unresolved until you assign them to accepted parts.',
|
|
1341
|
+
},
|
|
1342
|
+
];
|
|
1343
|
+
return h(
|
|
1344
|
+
'article',
|
|
1345
|
+
{ class: 'detail', 'aria-labelledby': 'detail-title' },
|
|
1346
|
+
h(
|
|
1347
|
+
'header',
|
|
1348
|
+
{ class: 'detail-header' },
|
|
1349
|
+
h('h3', { id: 'detail-title', text: title }),
|
|
1350
|
+
h(
|
|
1351
|
+
'p',
|
|
1352
|
+
{ class: 'muted' },
|
|
1353
|
+
`${item.id} · `,
|
|
1354
|
+
item.origin === 'candidate'
|
|
1355
|
+
? incompleteSource
|
|
1356
|
+
? 'Incomplete draft from the assessment'
|
|
1357
|
+
: 'Complete proposal from the assessment'
|
|
1358
|
+
: item.origin === 'split'
|
|
1359
|
+
? `Split from ${item.from}`
|
|
1360
|
+
: 'Added during review',
|
|
1361
|
+
' · ',
|
|
1362
|
+
badge(actionLabel(item, action), actionTone(action)),
|
|
1363
|
+
),
|
|
1364
|
+
item.catalogEntry
|
|
1365
|
+
? h(
|
|
1366
|
+
'p',
|
|
1367
|
+
{ class: 'muted' },
|
|
1368
|
+
item.implementationCoverage.status === 'bound'
|
|
1369
|
+
? badge(`${item.implementationCoverage.entryPoints} entry point${item.implementationCoverage.entryPoints === 1 ? '' : 's'} bound`, 'ok')
|
|
1370
|
+
: badge('Entry points unbound · implementation coverage unknown', 'warn'),
|
|
1371
|
+
)
|
|
1372
|
+
: null,
|
|
1373
|
+
item.origin === 'candidate' && item.proposed.rationale
|
|
1374
|
+
? h('p', { class: 'rationale' }, h('strong', { text: 'Why it was proposed: ' }), item.proposed.rationale)
|
|
1375
|
+
: null,
|
|
1376
|
+
item.capability !== 'unknown' ? h('p', { class: 'muted', text: `Product capability: ${item.capability}` }) : null,
|
|
1377
|
+
),
|
|
1378
|
+
item.origin === 'candidate' && incompleteSource && action === 'pending'
|
|
1379
|
+
? h(
|
|
1380
|
+
'section',
|
|
1381
|
+
{
|
|
1382
|
+
class: `callout ${item.draftCompleteness.complete ? 'ok' : 'warn'}`,
|
|
1383
|
+
'aria-labelledby': 'complete-draft-title',
|
|
1384
|
+
},
|
|
1385
|
+
h('h4', { id: 'complete-draft-title', text: 'Complete this draft' }),
|
|
1386
|
+
item.draftCompleteness.complete
|
|
1387
|
+
? h('p', {
|
|
1388
|
+
text: 'The definition is now complete. It remains Undecided until you choose “Accept completed use case.”',
|
|
1389
|
+
})
|
|
1390
|
+
: h(
|
|
1391
|
+
'p',
|
|
1392
|
+
{},
|
|
1393
|
+
'Discovery did not have enough evidence for a directly approvable proposal. ',
|
|
1394
|
+
missingFieldGuidance(item.draftCompleteness, 'This draft can be accepted when'),
|
|
1395
|
+
),
|
|
1396
|
+
)
|
|
1397
|
+
: null,
|
|
1398
|
+
item.origin === 'candidate' && item.changedFields.length
|
|
1399
|
+
? h(
|
|
1400
|
+
'section',
|
|
1401
|
+
{ class: `draft-revision ${action === 'pending' ? 'pending' : 'accepted'}`, 'aria-labelledby': 'draft-revision-title' },
|
|
1402
|
+
h('h4', {
|
|
1403
|
+
id: 'draft-revision-title',
|
|
1404
|
+
text:
|
|
1405
|
+
action === 'pending'
|
|
1406
|
+
? incompleteSource
|
|
1407
|
+
? 'Draft completion · still Undecided'
|
|
1408
|
+
: 'Draft revision · still Undecided'
|
|
1409
|
+
: incompleteSource
|
|
1410
|
+
? 'Accepted completed use case'
|
|
1411
|
+
: 'Approved definition',
|
|
1412
|
+
}),
|
|
1413
|
+
h('p', {
|
|
1414
|
+
text: `Changed fields: ${item.changedFields.map((field) => FIELD_LABELS[field] ?? field).join(', ')}.`,
|
|
1415
|
+
}),
|
|
1416
|
+
action === 'pending'
|
|
1417
|
+
? h('p', { class: 'hint', text: 'Saving preserves this draft but does not approve it.' })
|
|
1418
|
+
: null,
|
|
1419
|
+
h('button', {
|
|
1420
|
+
type: 'button',
|
|
1421
|
+
class: 'secondary',
|
|
1422
|
+
'data-focus-key': 'reset-draft',
|
|
1423
|
+
text: incompleteSource ? 'Reset to discovery draft' : 'Reset to assessment proposal',
|
|
1424
|
+
onclick: () => resetDraft(item),
|
|
1425
|
+
}),
|
|
1426
|
+
)
|
|
1427
|
+
: null,
|
|
1428
|
+
item.issues.length || item.omitted.length
|
|
1429
|
+
? h(
|
|
1430
|
+
'ul',
|
|
1431
|
+
{ class: 'issue-list' },
|
|
1432
|
+
item.issues.map((issue) => h('li', { class: issue.severity }, badge(issue.severity === 'error' ? 'Blocking' : 'Warning', issue.severity === 'error' ? 'danger' : 'warn'), ' ', issue.message)),
|
|
1433
|
+
item.omitted.map((reason) => h('li', { class: 'error' }, badge('Not in catalog', 'danger'), ` ${reason}`)),
|
|
1434
|
+
)
|
|
1435
|
+
: null,
|
|
1436
|
+
item.origin === 'candidate'
|
|
1437
|
+
? h(
|
|
1438
|
+
'fieldset',
|
|
1439
|
+
{ class: 'decision' },
|
|
1440
|
+
h('legend', { text: 'Decision' }),
|
|
1441
|
+
actions.map(({ value, label, help, guidance, disabled }) =>
|
|
1442
|
+
h(
|
|
1443
|
+
'div',
|
|
1444
|
+
{ class: 'radio' },
|
|
1445
|
+
h('input', {
|
|
1446
|
+
type: 'radio',
|
|
1447
|
+
name: 'decision',
|
|
1448
|
+
id: `decision-${value}`,
|
|
1449
|
+
value,
|
|
1450
|
+
'data-focus-key': `decision-${value}`,
|
|
1451
|
+
checked:
|
|
1452
|
+
value === 'merge'
|
|
1453
|
+
? mergeOpen
|
|
1454
|
+
: !mergeOpen &&
|
|
1455
|
+
(value === 'approve' && !incompleteSource
|
|
1456
|
+
? ['approve', 'revise'].includes(action)
|
|
1457
|
+
: action === value),
|
|
1458
|
+
disabled,
|
|
1459
|
+
'aria-describedby': `decision-${value}-help`,
|
|
1460
|
+
onchange: () =>
|
|
1461
|
+
value === 'merge'
|
|
1462
|
+
? openMerge(item)
|
|
1463
|
+
: value === 'approve' && !incompleteSource
|
|
1464
|
+
? approveCurrentDefinition(item)
|
|
1465
|
+
: setAction(item, value),
|
|
1466
|
+
}),
|
|
1467
|
+
h('label', { for: `decision-${value}`, text: label }),
|
|
1468
|
+
h(
|
|
1469
|
+
'p',
|
|
1470
|
+
{ id: `decision-${value}-help`, class: disabled ? 'hint unavailable' : 'hint' },
|
|
1471
|
+
help,
|
|
1472
|
+
guidance,
|
|
1473
|
+
),
|
|
1474
|
+
),
|
|
1475
|
+
),
|
|
1476
|
+
mergeOpen ? mergeTargetPicker(item) : null,
|
|
1477
|
+
action === 'split'
|
|
1478
|
+
? h(
|
|
1479
|
+
'div',
|
|
1480
|
+
{ class: 'split-parts' },
|
|
1481
|
+
h('p', { text: `Parts: ${decisionFor(item.id).parts.join(', ')}` }),
|
|
1482
|
+
h(
|
|
1483
|
+
'ul',
|
|
1484
|
+
{ class: 'inline-list' },
|
|
1485
|
+
decisionFor(item.id).parts.map((part) =>
|
|
1486
|
+
h('li', {}, h('button', { type: 'button', class: 'link', 'data-focus-key': `open-part:${part}`, text: `Edit ${part}`, onclick: () => { session.useCase = part; renderUseCases(); document.getElementById('detail-title')?.focus(); } })),
|
|
1487
|
+
),
|
|
1488
|
+
),
|
|
1489
|
+
h('button', { type: 'button', class: 'secondary', 'data-focus-key': 'add-part', text: 'Add another part', onclick: () => addSplitPart(item) }),
|
|
1490
|
+
)
|
|
1491
|
+
: null,
|
|
1492
|
+
h(
|
|
1493
|
+
'div',
|
|
1494
|
+
{ class: 'field' },
|
|
1495
|
+
h('label', { for: 'decision-note', text: 'Decision note (optional)' }),
|
|
1496
|
+
h('textarea', {
|
|
1497
|
+
id: 'decision-note',
|
|
1498
|
+
rows: '2',
|
|
1499
|
+
'data-focus-key': 'decision-note',
|
|
1500
|
+
value: decisionNote,
|
|
1501
|
+
oninput: (event) => {
|
|
1502
|
+
const decision = session.review.proposals[item.id] ?? { action: 'pending' };
|
|
1503
|
+
if (event.target.value) decision.note = event.target.value;
|
|
1504
|
+
else delete decision.note;
|
|
1505
|
+
if (decision.action === 'pending' && !decision.note && !decision.fields) delete session.review.proposals[item.id];
|
|
1506
|
+
else session.review.proposals[item.id] = decision;
|
|
1507
|
+
changed();
|
|
1508
|
+
},
|
|
1509
|
+
}),
|
|
1510
|
+
),
|
|
1511
|
+
)
|
|
1512
|
+
: h(
|
|
1513
|
+
'div',
|
|
1514
|
+
{ class: 'decision' },
|
|
1515
|
+
h('div', { class: 'field' },
|
|
1516
|
+
h('label', { for: 'field-id', text: 'Use-case id' }),
|
|
1517
|
+
h('input', {
|
|
1518
|
+
id: 'field-id',
|
|
1519
|
+
'data-focus-key': 'field-id',
|
|
1520
|
+
value: session.raw.has(idKey) ? session.raw.get(idKey) : item.id,
|
|
1521
|
+
'aria-invalid': idError ? 'true' : null,
|
|
1522
|
+
'aria-describedby': idError ? 'field-id-error' : 'field-id-help',
|
|
1523
|
+
onchange: (event) => {
|
|
1524
|
+
const next = event.target.value.trim();
|
|
1525
|
+
session.raw.set(idKey, next);
|
|
1526
|
+
const taken = new Set([...state().useCases.map(({ id }) => id), ...state().existingUseCases.map(({ id }) => id)]);
|
|
1527
|
+
if (!USE_CASE_ID.test(next)) session.fieldErrors.set(idKey, 'Use lowercase words separated by hyphens.');
|
|
1528
|
+
else if (next !== item.id && taken.has(next)) session.fieldErrors.set(idKey, `${next} is already used.`);
|
|
1529
|
+
else {
|
|
1530
|
+
session.fieldErrors.delete(idKey);
|
|
1531
|
+
session.raw.delete(idKey);
|
|
1532
|
+
if (next !== item.id) renameAdded(item, next);
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
renderUseCases();
|
|
1536
|
+
},
|
|
1537
|
+
}),
|
|
1538
|
+
h('p', { id: 'field-id-help', class: 'hint', text: 'Lowercase words separated by hyphens. Changes apply when you leave the field.' }),
|
|
1539
|
+
idError ? h('p', { id: 'field-id-error', class: 'field-error', text: idError }) : null,
|
|
1540
|
+
),
|
|
1541
|
+
h('button', { type: 'button', class: 'danger', 'data-focus-key': 'remove-added', text: item.origin === 'split' ? 'Remove this split part' : 'Remove this added use case', onclick: () => removeAdded(item) }),
|
|
1542
|
+
),
|
|
1543
|
+
h(
|
|
1544
|
+
'fieldset',
|
|
1545
|
+
{ class: 'fields', disabled: ['reject', 'merge', 'split'].includes(action) },
|
|
1546
|
+
h('legend', {
|
|
1547
|
+
text:
|
|
1548
|
+
item.origin === 'candidate' && editableItem(item)
|
|
1549
|
+
? action === 'pending'
|
|
1550
|
+
? 'Definition draft'
|
|
1551
|
+
: 'Definition'
|
|
1552
|
+
: 'Catalog details',
|
|
1553
|
+
}),
|
|
1554
|
+
item.origin === 'candidate' && editableItem(item)
|
|
1555
|
+
? h('p', {
|
|
1556
|
+
class: 'hint',
|
|
1557
|
+
text: incompleteSource
|
|
1558
|
+
? action === 'pending'
|
|
1559
|
+
? 'Complete this definition while it remains Undecided. Saving preserves your work; acceptance requires “Accept completed use case.” Blank fields keep the assessment value.'
|
|
1560
|
+
: 'This completed definition is accepted. Further edits return it to Undecided until you accept it again.'
|
|
1561
|
+
: action === 'pending'
|
|
1562
|
+
? 'Edit the definition while it remains Undecided, then choose “Approve this use case.” Blank fields keep the assessment value.'
|
|
1563
|
+
: 'The complete definition shown is approved. Further edits keep this approval choice and update the definition it applies to.',
|
|
1564
|
+
})
|
|
1565
|
+
: null,
|
|
1566
|
+
TEXT_FIELDS.slice(0, 3).map(([field, label, kind]) => fieldControl(item, field, label, kind)),
|
|
1567
|
+
h('div', { class: 'field-row' },
|
|
1568
|
+
choiceControl(item, 'tier', 'Tier', TIERS.map((tier) => [tier, tier])),
|
|
1569
|
+
choiceControl(item, 'effect', 'Effect', EFFECTS.map((effect) => [effect, effect])),
|
|
1570
|
+
state().outcomes.some(({ id }) => id)
|
|
1571
|
+
? choiceControl(item, 'outcome', 'User outcome', state().outcomes.filter(({ id }) => id).map(({ id, title: text }) => [id, text]))
|
|
1572
|
+
: null,
|
|
1573
|
+
),
|
|
1574
|
+
TEXT_FIELDS.slice(3).map(([field, label, kind]) => fieldControl(item, field, label, kind)),
|
|
1575
|
+
listControl(
|
|
1576
|
+
item,
|
|
1577
|
+
'starts',
|
|
1578
|
+
'Entry points (optional)',
|
|
1579
|
+
'Leave blank when the implementation binding is not known yet. One per line. Direct route: “route: /login”. Navigation: “navigation-id /route”. Assistant: “assistant: prompt”. Mapped navigation surfaces are added automatically.',
|
|
1580
|
+
),
|
|
1581
|
+
listControl(item, 'requirements', 'Requirements', 'One requirement per line.'),
|
|
1582
|
+
listControl(item, 'gaps', 'Known gaps', 'One gap per line.'),
|
|
1583
|
+
),
|
|
1584
|
+
h(
|
|
1585
|
+
'div',
|
|
1586
|
+
{ class: 'side-by-side' },
|
|
1587
|
+
h(
|
|
1588
|
+
'section',
|
|
1589
|
+
{ 'aria-labelledby': 'sources-title' },
|
|
1590
|
+
h('h4', { id: 'sources-title', text: `Source surfaces and workflows (${subjects.length})` }),
|
|
1591
|
+
subjects.length
|
|
1592
|
+
? h('ul', { class: 'subject-list' }, subjects.map((subject) =>
|
|
1593
|
+
h('li', {},
|
|
1594
|
+
h('button', { type: 'button', class: 'link', 'data-focus-key': `source:${subject.key}`, text: subject.label, onclick: () => goToScope(subject.key) }),
|
|
1595
|
+
' ', badge(subject.type === 'surface' ? 'Surface' : 'Workflow', 'muted'), ' ', badge(STATUS_LABELS[subject.status], statusTone(subject.status)),
|
|
1596
|
+
h('p', { class: 'muted', text: [subject.route ?? subject.entry, subject.sources.join(', ')].filter(Boolean).join(' · ') }),
|
|
1597
|
+
),
|
|
1598
|
+
))
|
|
1599
|
+
: h('p', { class: 'muted', text: 'Nothing is mapped to this use case yet.' }),
|
|
1600
|
+
),
|
|
1601
|
+
h(
|
|
1602
|
+
'section',
|
|
1603
|
+
{ 'aria-labelledby': 'entry-title' },
|
|
1604
|
+
h('h4', { id: 'entry-title', text: 'Resulting catalog entry' }),
|
|
1605
|
+
item.catalogEntry
|
|
1606
|
+
? h('pre', { class: 'code', tabindex: '0', 'aria-label': 'Resulting catalog entry', text: entryText(item.catalogEntry) })
|
|
1607
|
+
: h('p', { class: 'muted', text: item.omitted.length ? `Not included: ${item.omitted.join('; ')}` : action === 'pending' ? 'Not included until a decision is made.' : 'Not included in the catalog.' }),
|
|
1608
|
+
),
|
|
1609
|
+
),
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function entryText(entry) {
|
|
1614
|
+
const lines = [];
|
|
1615
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
1616
|
+
if (Array.isArray(value)) {
|
|
1617
|
+
lines.push(`${key}:`);
|
|
1618
|
+
for (const item of value) {
|
|
1619
|
+
if (typeof item === 'string') lines.push(` - ${item}`);
|
|
1620
|
+
else lines.push(` - ${Object.entries(item).map(([k, v]) => `${k}: ${v}`).join(', ')}`);
|
|
1621
|
+
}
|
|
1622
|
+
} else {
|
|
1623
|
+
lines.push(`${key}: ${value}`);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
return lines.join('\n');
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
function subjectMatches(subject) {
|
|
1630
|
+
const filter = session.filters.subjects;
|
|
1631
|
+
if (filter.status !== 'all' && subject.status !== filter.status) return false;
|
|
1632
|
+
if (filter.type !== 'all' && subject.type !== filter.type) return false;
|
|
1633
|
+
const text = filter.text.trim().toLowerCase();
|
|
1634
|
+
if (text && !`${subject.id} ${subject.label} ${subject.route ?? ''} ${subject.entry ?? ''}`.toLowerCase().includes(text)) return false;
|
|
1635
|
+
return true;
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
function renderCoverage() {
|
|
1639
|
+
const panel = document.getElementById('panel-coverage');
|
|
1640
|
+
rerender(panel, () => {
|
|
1641
|
+
const { subjects, summary } = state();
|
|
1642
|
+
const filter = session.filters.subjects;
|
|
1643
|
+
const visible = subjects.filter(subjectMatches);
|
|
1644
|
+
if (!session.subject || !subjects.some(({ key }) => key === session.subject)) {
|
|
1645
|
+
session.subject = subjects.find(({ status }) => status === 'unresolved')?.key ?? subjects[0]?.key ?? null;
|
|
1646
|
+
}
|
|
1647
|
+
const selected = subjects.find(({ key }) => key === session.subject);
|
|
1648
|
+
return [
|
|
1649
|
+
h('h2', { text: 'Surfaces and workflows' }),
|
|
1650
|
+
h('p', { class: 'muted', text: `Map each discovered item to a use case or exclude it with a reason. ${summary.mapped} mapped, ${summary.proposed} awaiting a decision, ${summary.excluded} excluded, ${summary.unresolved} unresolved.` }),
|
|
1651
|
+
h(
|
|
1652
|
+
'div',
|
|
1653
|
+
{ class: 'filters', role: 'group', 'aria-label': 'Filter surfaces and workflows' },
|
|
1654
|
+
h('label', { for: 'subjects-search', text: 'Search' }),
|
|
1655
|
+
h('input', { id: 'subjects-search', type: 'search', 'data-focus-key': 'subjects-search', value: filter.text, oninput: (event) => { filter.text = event.target.value; renderCoverage(); } }),
|
|
1656
|
+
h('label', { for: 'subjects-status', text: 'Status' }),
|
|
1657
|
+
h('select', { id: 'subjects-status', 'data-focus-key': 'subjects-status', value: filter.status, onchange: (event) => { filter.status = event.target.value; renderCoverage(); } },
|
|
1658
|
+
h('option', { value: 'all', text: 'All statuses' }),
|
|
1659
|
+
Object.entries(STATUS_LABELS).map(([value, label]) => h('option', { value, text: label })),
|
|
1660
|
+
),
|
|
1661
|
+
h('label', { for: 'subjects-type', text: 'Type' }),
|
|
1662
|
+
h('select', { id: 'subjects-type', 'data-focus-key': 'subjects-type', value: filter.type, onchange: (event) => { filter.type = event.target.value; renderCoverage(); } },
|
|
1663
|
+
h('option', { value: 'all', text: 'Surfaces and workflows' }),
|
|
1664
|
+
h('option', { value: 'surface', text: 'Navigation surfaces' }),
|
|
1665
|
+
h('option', { value: 'workflow', text: 'Workflows' }),
|
|
1666
|
+
),
|
|
1667
|
+
),
|
|
1668
|
+
h(
|
|
1669
|
+
'div',
|
|
1670
|
+
{ class: 'master-detail' },
|
|
1671
|
+
h(
|
|
1672
|
+
'div',
|
|
1673
|
+
{ class: 'inbox', 'data-scroll-key': 'subject-inbox' },
|
|
1674
|
+
h('p', { class: 'muted', text: `Showing ${visible.length} of ${subjects.length}` }),
|
|
1675
|
+
visible.length
|
|
1676
|
+
? h('ul', { class: 'item-list', onkeydown: listKeys, 'aria-label': 'Surfaces and workflows' }, visible.map((subject) =>
|
|
1677
|
+
h('li', {}, h('button', {
|
|
1678
|
+
type: 'button',
|
|
1679
|
+
class: 'item',
|
|
1680
|
+
'data-list-item': true,
|
|
1681
|
+
'data-focus-key': `subject:${subject.key}`,
|
|
1682
|
+
'aria-current': subject.key === session.subject ? 'true' : null,
|
|
1683
|
+
onclick: () => { session.subject = subject.key; renderCoverage(); },
|
|
1684
|
+
},
|
|
1685
|
+
h('span', { class: 'item-title', text: subject.label }),
|
|
1686
|
+
h('span', { class: 'item-meta' }, badge(subject.type === 'surface' ? 'Surface' : 'Workflow', 'muted'), badge(STATUS_LABELS[subject.status], statusTone(subject.status))),
|
|
1687
|
+
)),
|
|
1688
|
+
))
|
|
1689
|
+
: h('p', { text: 'Nothing matches these filters.' }),
|
|
1690
|
+
),
|
|
1691
|
+
selected ? subjectDetail(selected) : h('p', { text: 'There is nothing to map.' }),
|
|
1692
|
+
),
|
|
1693
|
+
];
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
function mappingFor(subject) {
|
|
1698
|
+
return session.review.mappings[subject.key] ?? structuredClone(subject.effective);
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
// An exclusion needs its own reason; the assessment's rationale for mapping
|
|
1702
|
+
// the item must not silently satisfy it.
|
|
1703
|
+
function inheritedRationale(subject, mapping, disposition) {
|
|
1704
|
+
const proposed = subject.proposed;
|
|
1705
|
+
if (disposition !== 'excluded' || proposed.disposition === 'excluded') return {};
|
|
1706
|
+
return mapping.rationale === proposed.rationale ? { rationale: '' } : {};
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
function setMapping(subject, patch, message) {
|
|
1710
|
+
session.review.mappings[subject.key] = { ...mappingFor(subject), ...patch };
|
|
1711
|
+
changed(message);
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
function subjectDetail(subject) {
|
|
1715
|
+
const mapping = mappingFor(subject);
|
|
1716
|
+
const choices = [
|
|
1717
|
+
...state().existingUseCases.map(({ id, title }) => ({ id, title, note: 'active catalog' })),
|
|
1718
|
+
...state().useCases.map((item) => ({
|
|
1719
|
+
id: item.id,
|
|
1720
|
+
title: fieldValue(item, 'title') ?? item.id,
|
|
1721
|
+
note: actionLabel(item).toLowerCase(),
|
|
1722
|
+
})),
|
|
1723
|
+
];
|
|
1724
|
+
const rationaleRequired = mapping.disposition === 'excluded';
|
|
1725
|
+
const rationaleMissing = rationaleRequired && !mapping.rationale.trim();
|
|
1726
|
+
const proposed = subject.proposed;
|
|
1727
|
+
return h(
|
|
1728
|
+
'article',
|
|
1729
|
+
{ class: 'detail', 'aria-labelledby': 'subject-title' },
|
|
1730
|
+
h('header', { class: 'detail-header' },
|
|
1731
|
+
h('h3', { id: 'subject-title', text: subject.label }),
|
|
1732
|
+
h('p', { class: 'muted' }, `${subject.type === 'surface' ? 'Navigation surface' : 'Workflow'} ${subject.id} · `, badge(STATUS_LABELS[subject.status], statusTone(subject.status))),
|
|
1733
|
+
h('dl', { class: 'facts' },
|
|
1734
|
+
subject.route ? [h('dt', { text: 'Route' }), h('dd', { text: subject.route })] : null,
|
|
1735
|
+
subject.entry ? [h('dt', { text: 'Entry' }), h('dd', { text: subject.entry })] : null,
|
|
1736
|
+
subject.kind ? [h('dt', { text: 'Kind' }), h('dd', { text: subject.kind })] : null,
|
|
1737
|
+
subject.capability ? [h('dt', { text: 'Product capability' }), h('dd', { text: subject.capability })] : null,
|
|
1738
|
+
[h('dt', { text: 'Sources' }), h('dd', { text: subject.sources.join(', ') || 'none recorded' })],
|
|
1739
|
+
[h('dt', { text: 'Assessment proposed' }), h('dd', { text: `${DISPOSITION_LABELS[proposed.disposition]}${proposed.useCaseIds.length ? `: ${proposed.useCaseIds.join(', ')}` : ''}${proposed.rationale ? ` — ${proposed.rationale}` : ''}` })],
|
|
1740
|
+
),
|
|
1741
|
+
),
|
|
1742
|
+
subject.issues.length ? h('ul', { class: 'issue-list' }, subject.issues.map((message) => h('li', { class: subject.status === 'unresolved' ? 'error' : 'warning' }, badge(subject.status === 'unresolved' ? 'Unresolved' : 'Warning', subject.status === 'unresolved' ? 'danger' : 'warn'), ` ${message}`))) : null,
|
|
1743
|
+
h('fieldset', { class: 'decision' },
|
|
1744
|
+
h('legend', { text: 'Decision' }),
|
|
1745
|
+
[
|
|
1746
|
+
['use-case', 'Covered by use cases'],
|
|
1747
|
+
['excluded', 'Excluded from the catalog'],
|
|
1748
|
+
['unresolved', 'Leave unresolved'],
|
|
1749
|
+
].map(([value, label]) =>
|
|
1750
|
+
h('div', { class: 'radio' },
|
|
1751
|
+
h('input', { type: 'radio', name: 'disposition', id: `disposition-${value}`, value, 'data-focus-key': `disposition-${value}`, checked: mapping.disposition === value, onchange: () => setMapping(subject, { disposition: value, ...inheritedRationale(subject, mapping, value) }, `${subject.label}: ${label.toLowerCase()}.`) }),
|
|
1752
|
+
h('label', { for: `disposition-${value}`, text: label }),
|
|
1753
|
+
),
|
|
1754
|
+
),
|
|
1755
|
+
),
|
|
1756
|
+
mapping.disposition === 'use-case'
|
|
1757
|
+
? h('fieldset', { class: 'choices', 'data-scroll-key': 'subject-choices' },
|
|
1758
|
+
h('legend', { text: `Use cases (${mapping.useCaseIds.length} selected)` }),
|
|
1759
|
+
choices.map((choice) =>
|
|
1760
|
+
h('div', { class: 'checkbox' },
|
|
1761
|
+
h('input', {
|
|
1762
|
+
type: 'checkbox',
|
|
1763
|
+
id: `map-${choice.id}`,
|
|
1764
|
+
'data-focus-key': `map-${choice.id}`,
|
|
1765
|
+
checked: mapping.useCaseIds.includes(choice.id),
|
|
1766
|
+
onchange: (event) => {
|
|
1767
|
+
const ids = mapping.useCaseIds.filter((id) => id !== choice.id);
|
|
1768
|
+
if (event.target.checked) ids.push(choice.id);
|
|
1769
|
+
setMapping(subject, { useCaseIds: ids }, `${event.target.checked ? 'Mapped to' : 'Removed'} ${choice.title}.`);
|
|
1770
|
+
},
|
|
1771
|
+
}),
|
|
1772
|
+
h('label', { for: `map-${choice.id}` }, choice.title, h('span', { class: 'muted', text: ` (${choice.id}, ${choice.note})` })),
|
|
1773
|
+
),
|
|
1774
|
+
),
|
|
1775
|
+
)
|
|
1776
|
+
: null,
|
|
1777
|
+
h('div', { class: 'field' },
|
|
1778
|
+
h('label', { for: 'mapping-rationale', text: rationaleRequired ? 'Exclusion rationale (required)' : 'Rationale (optional)' }),
|
|
1779
|
+
h('textarea', {
|
|
1780
|
+
id: 'mapping-rationale',
|
|
1781
|
+
rows: '3',
|
|
1782
|
+
'data-focus-key': 'mapping-rationale',
|
|
1783
|
+
value: mapping.rationale,
|
|
1784
|
+
required: rationaleRequired,
|
|
1785
|
+
'aria-invalid': rationaleMissing ? 'true' : null,
|
|
1786
|
+
'aria-describedby': rationaleMissing ? 'mapping-rationale-error' : null,
|
|
1787
|
+
oninput: (event) => setMapping(subject, { rationale: event.target.value }),
|
|
1788
|
+
}),
|
|
1789
|
+
rationaleMissing ? h('p', { id: 'mapping-rationale-error', class: 'field-error', text: 'Explain why this is out of scope so the exclusion can be reviewed later.' }) : null,
|
|
1790
|
+
),
|
|
1791
|
+
subject.decided
|
|
1792
|
+
? h('button', { type: 'button', class: 'secondary', 'data-focus-key': 'reset-mapping', text: 'Reset to the assessment’s proposal', onclick: () => { delete session.review.mappings[subject.key]; changed(`${subject.label}: reset to the assessment’s proposal.`); } })
|
|
1793
|
+
: null,
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
function renderPreview() {
|
|
1798
|
+
const panel = document.getElementById('panel-preview');
|
|
1799
|
+
rerender(panel, () => {
|
|
1800
|
+
const { catalog, summary } = state();
|
|
1801
|
+
const copy = (text, label) => async () => {
|
|
1802
|
+
try {
|
|
1803
|
+
await navigator.clipboard.writeText(text);
|
|
1804
|
+
announce(`${label} copied.`);
|
|
1805
|
+
} catch {
|
|
1806
|
+
announce(`Copying is unavailable here; select the ${label.toLowerCase()} text instead.`);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
return [
|
|
1810
|
+
h('h2', { text: 'Catalog preview' }),
|
|
1811
|
+
h('dl', { class: 'facts' },
|
|
1812
|
+
h('dt', { text: 'Catalog path' }), h('dd', { text: catalog.path }),
|
|
1813
|
+
h('dt', { text: 'Status' }), h('dd', { text: catalog.exists ? 'An active catalog exists; the diff is against it.' : 'No catalog exists yet; the diff creates it.' }),
|
|
1814
|
+
h('dt', { text: 'Inventory' }), h('dd', { text: `${catalog.inventory} (unchanged; enforcement is a separate decision)` }),
|
|
1815
|
+
h('dt', { text: 'Generated use cases' }), h('dd', { text: String(catalog.entries) }),
|
|
1816
|
+
h('dt', { text: 'Unbound use cases' }),
|
|
1817
|
+
h('dd', {
|
|
1818
|
+
text: catalog.unbound.length
|
|
1819
|
+
? `${catalog.unbound.join(', ')} — implementation coverage unknown`
|
|
1820
|
+
: 'None; every generated use case has an entry-point binding.',
|
|
1821
|
+
}),
|
|
1822
|
+
),
|
|
1823
|
+
catalog.omitted.length
|
|
1824
|
+
? [h('h3', { text: `Not included (${catalog.omitted.length})` }), h('ul', { class: 'issue-list' }, catalog.omitted.map((entry) => h('li', { class: 'error' }, h('button', { type: 'button', class: 'link', 'data-focus-key': `omitted:${entry.id}`, text: entry.id, onclick: () => goToScope(`use-case:${entry.id}`) }), `: ${entry.reasons.join('; ')}`)))]
|
|
1825
|
+
: null,
|
|
1826
|
+
h('h3', { text: 'Exact catalog diff' }),
|
|
1827
|
+
catalog.text === null
|
|
1828
|
+
? h('p', { text: 'No catalog can be generated yet. Approve or add at least one complete use case.' })
|
|
1829
|
+
: catalog.diff
|
|
1830
|
+
? [
|
|
1831
|
+
h('button', { type: 'button', class: 'secondary', 'data-focus-key': 'copy-diff', text: 'Copy diff', onclick: copy(catalog.diff, 'Diff') }),
|
|
1832
|
+
h('pre', { class: 'diff', tabindex: '0', 'aria-label': 'Catalog diff', 'data-scroll-key': 'diff' },
|
|
1833
|
+
catalog.diff.trimEnd().split('\n').map((line) =>
|
|
1834
|
+
h('span', { class: line.startsWith('@@') ? 'hunk' : line.startsWith('+') && !line.startsWith('+++') ? 'add' : line.startsWith('-') && !line.startsWith('---') ? 'remove' : 'context', text: `${line}\n` }),
|
|
1835
|
+
),
|
|
1836
|
+
),
|
|
1837
|
+
]
|
|
1838
|
+
: h('p', { text: 'The generated catalog is identical to the active catalog.' }),
|
|
1839
|
+
catalog.text !== null
|
|
1840
|
+
? h('details', { 'data-detail-key': 'full-catalog', open: session.open.has('full-catalog'), ontoggle: (event) => (event.target.open ? session.open.add('full-catalog') : session.open.delete('full-catalog')) },
|
|
1841
|
+
h('summary', { text: 'Full generated catalog' }),
|
|
1842
|
+
h('pre', { class: 'code', tabindex: '0', 'aria-label': 'Full generated catalog', text: catalog.text }),
|
|
1843
|
+
)
|
|
1844
|
+
: null,
|
|
1845
|
+
h('section', { class: 'adoption', 'aria-labelledby': 'adoption-title' },
|
|
1846
|
+
h('h3', { id: 'adoption-title', text: 'After explicit owner approval' }),
|
|
1847
|
+
h('ol', {},
|
|
1848
|
+
h('li', { text: session.dirty ? 'Save this review. The command below uses the saved review and its saved preview, not unsaved edits.' : session.data.saved ? `The review is saved (revision ${session.review.revision}).` : 'Save this review first.' }),
|
|
1849
|
+
h('li', { text: summary.blockingIssues ? `Resolve the ${summary.blockingIssues} blocking issue${summary.blockingIssues === 1 ? '' : 's'}; adoption refuses while any remain.` : 'No blocking issues remain.' }),
|
|
1850
|
+
h('li', {}, 'The owner runs this command in a terminal. This app never runs it.',
|
|
1851
|
+
h('pre', { class: 'code', tabindex: '0', 'aria-label': 'Adoption command', text: session.data.adoptCommand }),
|
|
1852
|
+
h('button', { type: 'button', class: 'secondary', 'data-focus-key': 'copy-command', text: 'Copy command', onclick: copy(session.data.adoptCommand, 'Command') }),
|
|
1853
|
+
),
|
|
1854
|
+
h('li', { text: 'Checking in the catalog and changing enforcement are separate decisions after adoption.' }),
|
|
1855
|
+
),
|
|
1856
|
+
),
|
|
1857
|
+
];
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
async function init() {
|
|
1862
|
+
const match = /token=([0-9a-f]+)/.exec(window.location.hash);
|
|
1863
|
+
if (match) {
|
|
1864
|
+
window.sessionStorage.setItem(TOKEN_KEY, match[1]);
|
|
1865
|
+
window.history.replaceState(null, '', window.location.pathname);
|
|
1866
|
+
}
|
|
1867
|
+
session.token = window.sessionStorage.getItem(TOKEN_KEY);
|
|
1868
|
+
wireTabs();
|
|
1869
|
+
document.getElementById('save').addEventListener('click', save);
|
|
1870
|
+
document.getElementById('close').addEventListener('click', closeReview);
|
|
1871
|
+
document.addEventListener('keydown', (event) => {
|
|
1872
|
+
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 's') {
|
|
1873
|
+
event.preventDefault();
|
|
1874
|
+
save();
|
|
1875
|
+
}
|
|
1876
|
+
});
|
|
1877
|
+
window.addEventListener('beforeunload', (event) => {
|
|
1878
|
+
if (session.dirty) {
|
|
1879
|
+
event.preventDefault();
|
|
1880
|
+
event.returnValue = '';
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
window.addEventListener('pagehide', endSession);
|
|
1884
|
+
if (!session.token) {
|
|
1885
|
+
showError('Open the address printed by “ux-guard review” in your terminal; this page needs its session link.');
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
try {
|
|
1889
|
+
const data = await api('/api/state');
|
|
1890
|
+
session.data = data;
|
|
1891
|
+
session.review = structuredClone(data.review);
|
|
1892
|
+
renderAll();
|
|
1893
|
+
announce(`Review loaded: ${data.state.summary.unresolvedDecisions} unresolved decisions.`);
|
|
1894
|
+
} catch (error) {
|
|
1895
|
+
showError(`The review could not be loaded: ${error.message}`);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
init();
|