@crowandraven/evalkeeper 0.15.0 → 0.17.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/dist/glossary.d.ts +1 -0
- package/dist/glossary.js +1 -0
- package/dist/glossary.js.map +1 -1
- package/dist/health.d.ts +24 -0
- package/dist/health.js +61 -7
- package/dist/health.js.map +1 -1
- package/dist/react/AnswerKey.js +46 -15
- package/dist/react/AnswerKey.js.map +1 -1
- package/dist/react/ConfirmAnswer.d.ts +25 -4
- package/dist/react/ConfirmAnswer.js +66 -13
- package/dist/react/ConfirmAnswer.js.map +1 -1
- package/dist/react/Fields.d.ts +8 -2
- package/dist/react/Fields.js +22 -6
- package/dist/react/Fields.js.map +1 -1
- package/dist/react/Folded.d.ts +13 -0
- package/dist/react/Folded.js +15 -0
- package/dist/react/Folded.js.map +1 -0
- package/dist/react/HubSections.d.ts +4 -1
- package/dist/react/HubSections.js +30 -12
- package/dist/react/HubSections.js.map +1 -1
- package/dist/react/Readable.d.ts +39 -0
- package/dist/react/Readable.js +136 -0
- package/dist/react/Readable.js.map +1 -0
- package/dist/react/app.d.ts +3 -1
- package/dist/react/app.js.map +1 -1
- package/dist/react/pieces.d.ts +28 -1
- package/dist/react/pieces.js +43 -1
- package/dist/react/pieces.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
- package/src/glossary.ts +2 -0
- package/src/health.ts +81 -9
- package/src/react/AnswerKey.tsx +237 -93
- package/src/react/ConfirmAnswer.tsx +120 -30
- package/src/react/Fields.tsx +28 -20
- package/src/react/Folded.tsx +38 -0
- package/src/react/HubSections.tsx +124 -40
- package/src/react/Readable.tsx +266 -0
- package/src/react/app.ts +3 -2
- package/src/react/pieces.tsx +78 -2
- package/src/types.ts +23 -0
package/src/react/AnswerKey.tsx
CHANGED
|
@@ -20,12 +20,13 @@ import {
|
|
|
20
20
|
FROM_BASE_CASE,
|
|
21
21
|
isShippedReview,
|
|
22
22
|
} from "../index.js";
|
|
23
|
-
import { Check, ChevronRight, CircleAlert, X } from "lucide-react";
|
|
23
|
+
import { Check, ChevronRight, CircleAlert, Eye, X } from "lucide-react";
|
|
24
24
|
import type { EvalAppConfig } from "./app.js";
|
|
25
25
|
import { AnswerInput, FieldValues, Fields } from "./Fields.js";
|
|
26
26
|
import { AddCaseHeader, OpenLinkedCase } from "./AddCase.js";
|
|
27
27
|
import { CaseMenu } from "./CaseMenu.js";
|
|
28
|
-
import { ConfirmAnswer } from "./ConfirmAnswer.js";
|
|
28
|
+
import { CaseStatusChip, ConfirmAnswer } from "./ConfirmAnswer.js";
|
|
29
|
+
import { ReadableValue } from "./Readable.js";
|
|
29
30
|
|
|
30
31
|
/** A suite's cases in use, with each case's answers newest first. */
|
|
31
32
|
async function loadCases(
|
|
@@ -38,11 +39,17 @@ async function loadCases(
|
|
|
38
39
|
}));
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
const CONFIRMED_STATUS = {
|
|
43
|
+
text: "Confirmed",
|
|
44
|
+
tone: "live",
|
|
45
|
+
term: "confirmed",
|
|
46
|
+
} as const satisfies { text: string; tone: ChipTone; term: GlossaryTerm };
|
|
47
|
+
|
|
41
48
|
const STATUS: Record<
|
|
42
49
|
string,
|
|
43
50
|
{ text: string; tone: ChipTone; term: GlossaryTerm }
|
|
44
51
|
> = {
|
|
45
|
-
CONFIRMED:
|
|
52
|
+
CONFIRMED: CONFIRMED_STATUS,
|
|
46
53
|
PROVISIONAL: { text: "Provisional", tone: "warn", term: "provisional" },
|
|
47
54
|
PENDING: { text: "Pending", tone: "warn", term: "pending" },
|
|
48
55
|
};
|
|
@@ -283,6 +290,31 @@ function CaseItem({
|
|
|
283
290
|
const label = (key: string) =>
|
|
284
291
|
suite.checks.find((x) => x.key === key)?.label ?? key;
|
|
285
292
|
const tags = Array.isArray(c.tags) ? c.tags : [];
|
|
293
|
+
// An answer nobody has confirmed: shown first, to check.
|
|
294
|
+
const checking =
|
|
295
|
+
!readOnly &&
|
|
296
|
+
(answer?.status === "PENDING" || answer?.status === "PROVISIONAL");
|
|
297
|
+
const looks: string[] = [];
|
|
298
|
+
let marks: string[] = [];
|
|
299
|
+
try {
|
|
300
|
+
const found = suite.lookAt?.(input, answer?.value ?? null) ?? [];
|
|
301
|
+
looks.push(...found.map((l) => l.note));
|
|
302
|
+
marks = found.flatMap((l) => l.marks ?? []);
|
|
303
|
+
} catch {
|
|
304
|
+
// A suite's pointers are a help, never a reason the case can't show.
|
|
305
|
+
}
|
|
306
|
+
// Models disagreeing with the answer is the surest sign to look closer.
|
|
307
|
+
if (answer && results.length > 1 && right < results.length)
|
|
308
|
+
looks.push(
|
|
309
|
+
right === 0
|
|
310
|
+
? "no model's latest test agrees with this answer"
|
|
311
|
+
: `models split: ${right} of ${results.length} agree with this answer`,
|
|
312
|
+
);
|
|
313
|
+
const inputFallback = suite.describe ? (
|
|
314
|
+
<pre className="whitespace-pre-wrap text-xs">{suite.describe(input)}</pre>
|
|
315
|
+
) : (
|
|
316
|
+
<ReadableValue value={c.input} marks={marks} />
|
|
317
|
+
);
|
|
286
318
|
|
|
287
319
|
return (
|
|
288
320
|
<details
|
|
@@ -302,9 +334,12 @@ function CaseItem({
|
|
|
302
334
|
<span className="readable min-w-0">{suite.title(input)}</span>
|
|
303
335
|
</span>
|
|
304
336
|
<span className="flex shrink-0 items-center gap-1.5">
|
|
305
|
-
<
|
|
306
|
-
|
|
307
|
-
|
|
337
|
+
<CaseStatusChip
|
|
338
|
+
labelId={answer?.id ?? null}
|
|
339
|
+
status={status}
|
|
340
|
+
confirmed={CONFIRMED_STATUS}
|
|
341
|
+
id={`status-${c.id}`}
|
|
342
|
+
/>
|
|
308
343
|
{shipped && (
|
|
309
344
|
<Tip term={shipped.term} id={`reviewed-${c.id}`}>
|
|
310
345
|
<Chip tone="neutral">{shipped.text}</Chip>
|
|
@@ -331,49 +366,92 @@ function CaseItem({
|
|
|
331
366
|
</summary>
|
|
332
367
|
|
|
333
368
|
<div className="relative space-y-5 px-3 pb-4 text-sm">
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
369
|
+
{checking && (
|
|
370
|
+
// What to check first, with its buttons: the answer, and what
|
|
371
|
+
// it turns on. Clear of the case menu's button on the right.
|
|
372
|
+
<section
|
|
373
|
+
aria-label="Check this answer"
|
|
374
|
+
className="space-y-3 rounded-md border border-good/25 bg-good/5 p-3 pr-12"
|
|
375
|
+
>
|
|
376
|
+
<div className="space-y-1">
|
|
377
|
+
<h4 className="text-xs font-medium text-good">
|
|
378
|
+
Check this answer
|
|
379
|
+
</h4>
|
|
380
|
+
{suite.fields ? (
|
|
381
|
+
<FieldValues
|
|
382
|
+
fields={suite.fields.label}
|
|
383
|
+
values={answer.value}
|
|
384
|
+
prefix={`${c.id}-ans-`}
|
|
385
|
+
/>
|
|
386
|
+
) : (
|
|
387
|
+
<ReadableValue value={answer.value} />
|
|
388
|
+
)}
|
|
389
|
+
{shipped && answer.note && (
|
|
390
|
+
<p className="readable text-xs text-muted">{answer.note}</p>
|
|
391
|
+
)}
|
|
392
|
+
</div>
|
|
393
|
+
{looks.length > 0 && (
|
|
394
|
+
<div className="readable text-sm">
|
|
395
|
+
<p className="flex items-center gap-1.5 text-xs font-medium">
|
|
396
|
+
<Eye
|
|
397
|
+
aria-hidden
|
|
398
|
+
className="h-3.5 w-3.5 shrink-0 text-muted"
|
|
399
|
+
/>
|
|
400
|
+
Look at
|
|
401
|
+
</p>
|
|
402
|
+
<ul className="mt-1 list-disc space-y-0.5 pl-5">
|
|
403
|
+
{looks.map((l) => (
|
|
404
|
+
<li key={l}>{l.charAt(0).toUpperCase() + l.slice(1)}</li>
|
|
405
|
+
))}
|
|
406
|
+
</ul>
|
|
407
|
+
</div>
|
|
349
408
|
)}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
409
|
+
{
|
|
410
|
+
<CaseMenu
|
|
411
|
+
suite={suite.key}
|
|
412
|
+
caseId={c.id}
|
|
413
|
+
retire={app.actions.retireCase}
|
|
414
|
+
review={
|
|
415
|
+
<ConfirmAnswer
|
|
416
|
+
action={app.actions.confirmAnswer}
|
|
417
|
+
suite={suite.key}
|
|
418
|
+
labelId={answer.id}
|
|
419
|
+
/>
|
|
420
|
+
}
|
|
421
|
+
editLabel={
|
|
422
|
+
suite.fields &&
|
|
423
|
+
(suite.labelFromForm || app.answerEditors[suite.key])
|
|
424
|
+
? "Edit answer"
|
|
425
|
+
: null
|
|
426
|
+
}
|
|
427
|
+
edit={
|
|
428
|
+
suite.fields && (
|
|
429
|
+
<form
|
|
430
|
+
key={answer.updatedAt.toISOString()}
|
|
431
|
+
action={app.actions.editAnswer}
|
|
432
|
+
className="space-y-4"
|
|
433
|
+
>
|
|
434
|
+
<input type="hidden" name="suite" value={suite.key} />
|
|
435
|
+
<input type="hidden" name="case" value={c.id} />
|
|
436
|
+
<AnswerInput
|
|
437
|
+
fields={suite.fields.label}
|
|
438
|
+
editor={app.answerEditors[suite.key]}
|
|
439
|
+
input={c.input}
|
|
440
|
+
values={answer.value}
|
|
441
|
+
prefix={`${c.id}-`}
|
|
442
|
+
/>
|
|
443
|
+
<p className="readable text-xs text-muted">
|
|
444
|
+
Saves a new confirmed answer and keeps the old one in
|
|
445
|
+
the history. Tests are rescored for free.
|
|
446
|
+
</p>
|
|
447
|
+
<Submit>Save answer</Submit>
|
|
448
|
+
</form>
|
|
449
|
+
)
|
|
450
|
+
}
|
|
360
451
|
/>
|
|
361
|
-
|
|
362
|
-
<pre className="whitespace-pre-wrap text-xs">
|
|
363
|
-
{JSON.stringify(answer?.value ?? null, null, 2)}
|
|
364
|
-
</pre>
|
|
365
|
-
)}
|
|
366
|
-
{shipped && answer?.note && (
|
|
367
|
-
<p className="readable text-xs text-muted">{answer.note}</p>
|
|
368
|
-
)}
|
|
369
|
-
{(tags.length > 0 || c.note) && (
|
|
370
|
-
<p className="readable text-xs text-muted">
|
|
371
|
-
{tags.length > 0 && `Tags: ${tags.join(", ")}. `}
|
|
372
|
-
{c.note}
|
|
373
|
-
</p>
|
|
374
|
-
)}
|
|
452
|
+
}
|
|
375
453
|
</section>
|
|
376
|
-
|
|
454
|
+
)}
|
|
377
455
|
|
|
378
456
|
{results.length > 0 && (
|
|
379
457
|
<section className="space-y-2">
|
|
@@ -422,57 +500,123 @@ function CaseItem({
|
|
|
422
500
|
</section>
|
|
423
501
|
)}
|
|
424
502
|
|
|
425
|
-
{
|
|
426
|
-
<
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
503
|
+
{checking ? (
|
|
504
|
+
<section className="space-y-2">
|
|
505
|
+
<h4 className="text-xs font-semibold uppercase tracking-wide text-muted">
|
|
506
|
+
Input
|
|
507
|
+
</h4>
|
|
508
|
+
{suite.fields ? (
|
|
509
|
+
<FieldValues
|
|
510
|
+
fields={suite.fields.input}
|
|
511
|
+
values={c.input}
|
|
512
|
+
prefix={`${c.id}-in-`}
|
|
513
|
+
marks={marks}
|
|
514
|
+
/>
|
|
515
|
+
) : (
|
|
516
|
+
inputFallback
|
|
517
|
+
)}
|
|
518
|
+
{(tags.length > 0 || c.note) && (
|
|
519
|
+
<p className="readable text-xs text-muted">
|
|
520
|
+
{tags.length > 0 && `Tags: ${tags.join(", ")}. `}
|
|
521
|
+
{c.note}
|
|
522
|
+
</p>
|
|
523
|
+
)}
|
|
524
|
+
</section>
|
|
525
|
+
) : (
|
|
526
|
+
<>
|
|
527
|
+
<div className="grid gap-5 md:grid-cols-2">
|
|
528
|
+
<section className="space-y-2">
|
|
529
|
+
<h4 className="text-xs font-semibold uppercase tracking-wide text-muted">
|
|
530
|
+
Input
|
|
531
|
+
</h4>
|
|
532
|
+
{suite.fields ? (
|
|
533
|
+
<FieldValues
|
|
534
|
+
fields={suite.fields.input}
|
|
535
|
+
values={c.input}
|
|
536
|
+
prefix={`${c.id}-in-`}
|
|
537
|
+
marks={marks}
|
|
538
|
+
/>
|
|
539
|
+
) : (
|
|
540
|
+
inputFallback
|
|
541
|
+
)}
|
|
542
|
+
</section>
|
|
543
|
+
<section className="space-y-2">
|
|
544
|
+
<h4 className="text-xs font-semibold uppercase tracking-wide text-muted">
|
|
545
|
+
Answer
|
|
546
|
+
</h4>
|
|
547
|
+
{answer && suite.fields ? (
|
|
548
|
+
<FieldValues
|
|
461
549
|
fields={suite.fields.label}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
values={answer?.value}
|
|
465
|
-
prefix={`${c.id}-`}
|
|
550
|
+
values={answer.value}
|
|
551
|
+
prefix={`${c.id}-ans-`}
|
|
466
552
|
/>
|
|
553
|
+
) : (
|
|
554
|
+
<ReadableValue value={answer?.value ?? null} />
|
|
555
|
+
)}
|
|
556
|
+
{shipped && answer?.note && (
|
|
557
|
+
<p className="readable text-xs text-muted">{answer.note}</p>
|
|
558
|
+
)}
|
|
559
|
+
{(tags.length > 0 || c.note) && (
|
|
467
560
|
<p className="readable text-xs text-muted">
|
|
468
|
-
|
|
469
|
-
|
|
561
|
+
{tags.length > 0 && `Tags: ${tags.join(", ")}. `}
|
|
562
|
+
{c.note}
|
|
470
563
|
</p>
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
564
|
+
)}
|
|
565
|
+
</section>
|
|
566
|
+
</div>
|
|
567
|
+
{!readOnly && (
|
|
568
|
+
<CaseMenu
|
|
569
|
+
suite={suite.key}
|
|
570
|
+
caseId={c.id}
|
|
571
|
+
retire={app.actions.retireCase}
|
|
572
|
+
startEditing={!answer}
|
|
573
|
+
// Pending or provisional: confirm it as it is, or change it.
|
|
574
|
+
review={
|
|
575
|
+
answer &&
|
|
576
|
+
(answer.status === "PENDING" ||
|
|
577
|
+
answer.status === "PROVISIONAL") && (
|
|
578
|
+
<ConfirmAnswer
|
|
579
|
+
action={app.actions.confirmAnswer}
|
|
580
|
+
suite={suite.key}
|
|
581
|
+
labelId={answer.id}
|
|
582
|
+
/>
|
|
583
|
+
)
|
|
584
|
+
}
|
|
585
|
+
editLabel={
|
|
586
|
+
suite.fields &&
|
|
587
|
+
(suite.labelFromForm || app.answerEditors[suite.key])
|
|
588
|
+
? answer
|
|
589
|
+
? "Edit answer"
|
|
590
|
+
: "Write the answer"
|
|
591
|
+
: null
|
|
592
|
+
}
|
|
593
|
+
edit={
|
|
594
|
+
suite.fields && (
|
|
595
|
+
<form
|
|
596
|
+
key={answer?.updatedAt.toISOString() ?? "none"}
|
|
597
|
+
action={app.actions.editAnswer}
|
|
598
|
+
className="space-y-4"
|
|
599
|
+
>
|
|
600
|
+
<input type="hidden" name="suite" value={suite.key} />
|
|
601
|
+
<input type="hidden" name="case" value={c.id} />
|
|
602
|
+
<AnswerInput
|
|
603
|
+
fields={suite.fields.label}
|
|
604
|
+
editor={app.answerEditors[suite.key]}
|
|
605
|
+
input={c.input}
|
|
606
|
+
values={answer?.value}
|
|
607
|
+
prefix={`${c.id}-`}
|
|
608
|
+
/>
|
|
609
|
+
<p className="readable text-xs text-muted">
|
|
610
|
+
Saves a new confirmed answer and keeps the old one in
|
|
611
|
+
the history. Tests are rescored for free.
|
|
612
|
+
</p>
|
|
613
|
+
<Submit>Save answer</Submit>
|
|
614
|
+
</form>
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
/>
|
|
618
|
+
)}
|
|
619
|
+
</>
|
|
476
620
|
)}
|
|
477
621
|
</div>
|
|
478
622
|
</details>
|
|
@@ -1,13 +1,69 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { useState, useSyncExternalStore, useTransition } from "react";
|
|
4
|
+
import type { GlossaryTerm } from "../index.js";
|
|
3
5
|
import type { FormAction } from "./app.js";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
Button,
|
|
8
|
+
Chip,
|
|
9
|
+
Spinner,
|
|
10
|
+
Tip,
|
|
11
|
+
useNotify,
|
|
12
|
+
type ChipTone,
|
|
13
|
+
} from "./pieces.js";
|
|
14
|
+
|
|
15
|
+
// Answers confirmed here, ahead of the page's refresh.
|
|
16
|
+
const confirmedHere = new Set<string>();
|
|
17
|
+
const listeners = new Set<() => void>();
|
|
18
|
+
function setConfirmedHere(labelId: string, on: boolean) {
|
|
19
|
+
if (on) confirmedHere.add(labelId);
|
|
20
|
+
else confirmedHere.delete(labelId);
|
|
21
|
+
for (const l of listeners) l();
|
|
22
|
+
}
|
|
23
|
+
function useConfirmedHere(labelId: string): boolean {
|
|
24
|
+
return useSyncExternalStore(
|
|
25
|
+
(l) => {
|
|
26
|
+
listeners.add(l);
|
|
27
|
+
return () => listeners.delete(l);
|
|
28
|
+
},
|
|
29
|
+
() => confirmedHere.has(labelId),
|
|
30
|
+
() => false,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Status = { text: string; tone: ChipTone; term: GlossaryTerm };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A case's answer status, which turns to Confirmed the moment someone
|
|
38
|
+
* confirms it there, before the save and the page's refresh finish.
|
|
39
|
+
*/
|
|
40
|
+
export function CaseStatusChip({
|
|
41
|
+
labelId,
|
|
42
|
+
status,
|
|
43
|
+
confirmed,
|
|
44
|
+
id,
|
|
45
|
+
}: {
|
|
46
|
+
/** The answer it describes; null for a case without one. */
|
|
47
|
+
labelId: string | null;
|
|
48
|
+
status: Status;
|
|
49
|
+
/** How a confirmed answer shows. */
|
|
50
|
+
confirmed: Status;
|
|
51
|
+
/** For the tooltip. */
|
|
52
|
+
id: string;
|
|
53
|
+
}) {
|
|
54
|
+
const now = useConfirmedHere(labelId ?? "") && labelId ? confirmed : status;
|
|
55
|
+
return (
|
|
56
|
+
<Tip term={now.term} id={id}>
|
|
57
|
+
<Chip tone={now.tone}>{now.text}</Chip>
|
|
58
|
+
</Tip>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
5
61
|
|
|
6
62
|
/**
|
|
7
|
-
* Confirms a case's pending answer and moves straight on:
|
|
8
|
-
* and the next one waiting for a confirmation opens,
|
|
9
|
-
* the page's refresh finish behind it.
|
|
10
|
-
*
|
|
63
|
+
* Confirms a case's pending answer and moves straight on: the case shows
|
|
64
|
+
* Confirmed and closes, and the next one waiting for a confirmation opens,
|
|
65
|
+
* while the save and the page's refresh finish behind it. If the save
|
|
66
|
+
* fails, the case opens again and says so (or your app's toast does).
|
|
11
67
|
*/
|
|
12
68
|
export function ConfirmAnswer({
|
|
13
69
|
suite,
|
|
@@ -19,31 +75,65 @@ export function ConfirmAnswer({
|
|
|
19
75
|
/** Your confirmAnswer action. */
|
|
20
76
|
action: FormAction;
|
|
21
77
|
}) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
78
|
+
const [saving, start] = useTransition();
|
|
79
|
+
const [failed, setFailed] = useState(false);
|
|
80
|
+
const notify = useNotify();
|
|
81
|
+
|
|
82
|
+
function confirm(button: HTMLElement) {
|
|
83
|
+
setFailed(false);
|
|
84
|
+
setConfirmedHere(labelId, true);
|
|
85
|
+
const here = button.closest("details");
|
|
86
|
+
if (here) {
|
|
87
|
+
here.open = false;
|
|
88
|
+
let next = here.nextElementSibling;
|
|
89
|
+
while (
|
|
90
|
+
next &&
|
|
91
|
+
!(next instanceof HTMLDetailsElement && next.dataset.pending === "true")
|
|
92
|
+
)
|
|
93
|
+
next = next.nextElementSibling;
|
|
94
|
+
if (next instanceof HTMLDetailsElement) {
|
|
95
|
+
next.open = true;
|
|
96
|
+
next.scrollIntoView({ block: "nearest" });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const form = new FormData();
|
|
100
|
+
form.set("suite", suite);
|
|
101
|
+
form.set("label", labelId);
|
|
102
|
+
start(async () => {
|
|
103
|
+
try {
|
|
104
|
+
await action(form);
|
|
105
|
+
notify?.("success", "Answer confirmed");
|
|
106
|
+
} catch {
|
|
107
|
+
setConfirmedHere(labelId, false);
|
|
108
|
+
if (here) {
|
|
109
|
+
here.open = true;
|
|
110
|
+
here.scrollIntoView({ block: "nearest" });
|
|
41
111
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
112
|
+
if (notify)
|
|
113
|
+
notify("error", "Couldn't confirm that answer. Please try again.");
|
|
114
|
+
else setFailed(true);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<>
|
|
121
|
+
<Button
|
|
122
|
+
type="button"
|
|
123
|
+
disabled={saving}
|
|
124
|
+
onClick={(e) => {
|
|
125
|
+
confirm(e.currentTarget);
|
|
126
|
+
}}
|
|
127
|
+
className="inline-flex items-center gap-2 whitespace-nowrap rounded-md bg-accent px-3 py-1.5 text-sm text-white disabled:opacity-60"
|
|
128
|
+
>
|
|
129
|
+
{saving && <Spinner />}
|
|
130
|
+
Confirm this answer
|
|
131
|
+
</Button>
|
|
132
|
+
{failed && (
|
|
133
|
+
<p role="alert" className="w-full text-xs text-bad">
|
|
134
|
+
Couldn't confirm that answer. Please try again.
|
|
135
|
+
</p>
|
|
136
|
+
)}
|
|
137
|
+
</>
|
|
48
138
|
);
|
|
49
139
|
}
|
package/src/react/Fields.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InfoTip, Select, TextArea, TextInput } from "./pieces.js";
|
|
2
|
+
import { ReadableValue } from "./Readable.js";
|
|
2
3
|
import {
|
|
3
4
|
ANSWER_JSON_FIELD,
|
|
4
|
-
asText,
|
|
5
5
|
fieldValue,
|
|
6
6
|
type AnswerEditorProps,
|
|
7
7
|
type FormField,
|
|
@@ -42,7 +42,7 @@ export function Fields({
|
|
|
42
42
|
>
|
|
43
43
|
{f.options?.map((o) => (
|
|
44
44
|
<option key={o} value={o}>
|
|
45
|
-
{o.replace(/_/g, " ")}
|
|
45
|
+
{f.optionLabels?.[o] ?? o.replace(/_/g, " ")}
|
|
46
46
|
</option>
|
|
47
47
|
))}
|
|
48
48
|
</Select>
|
|
@@ -73,19 +73,26 @@ export function Fields({
|
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* A stored input or answer, read with the suite's field labels: objects as
|
|
78
|
+
* labeled rows, long text folded, never raw data. `marks` are highlighted
|
|
79
|
+
* (a suite's `lookAt`).
|
|
80
|
+
*/
|
|
77
81
|
export function FieldValues({
|
|
78
82
|
fields,
|
|
79
83
|
values,
|
|
80
84
|
prefix = "",
|
|
85
|
+
marks,
|
|
81
86
|
}: {
|
|
82
87
|
fields: FormField[];
|
|
83
88
|
values: unknown;
|
|
84
89
|
/** Keeps tooltip ids unique when a page shows several. */
|
|
85
90
|
prefix?: string;
|
|
91
|
+
/** Text to highlight wherever it appears. */
|
|
92
|
+
marks?: string[] | undefined;
|
|
86
93
|
}) {
|
|
87
94
|
return (
|
|
88
|
-
<dl className="space-y-
|
|
95
|
+
<dl className="space-y-3">
|
|
89
96
|
{fields.map((f) => {
|
|
90
97
|
const v = (values as Record<string, unknown> | null)?.[f.name];
|
|
91
98
|
return (
|
|
@@ -94,23 +101,15 @@ export function FieldValues({
|
|
|
94
101
|
{f.label}
|
|
95
102
|
<InfoTip text={f.help} id={`${prefix}${f.name}-read`} />
|
|
96
103
|
</dt>
|
|
97
|
-
<dd className="
|
|
98
|
-
{f.kind === "
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
) :
|
|
103
|
-
v
|
|
104
|
-
<ul className="list-disc pl-5">
|
|
105
|
-
{v.map((x, i) => (
|
|
106
|
-
<li key={i}>{asText(x)}</li>
|
|
107
|
-
))}
|
|
108
|
-
</ul>
|
|
109
|
-
) : (
|
|
110
|
-
<span className="text-muted">None</span>
|
|
111
|
-
)
|
|
104
|
+
<dd className="mt-0.5 break-words">
|
|
105
|
+
{f.kind === "select" &&
|
|
106
|
+
typeof v === "string" &&
|
|
107
|
+
f.optionLabels?.[v] ? (
|
|
108
|
+
f.optionLabels[v]
|
|
109
|
+
) : f.kind === "json" && typeof v === "string" ? (
|
|
110
|
+
<ReadableValue value={parseJson(v)} marks={marks} />
|
|
112
111
|
) : (
|
|
113
|
-
|
|
112
|
+
<ReadableValue value={v} marks={marks} />
|
|
114
113
|
)}
|
|
115
114
|
</dd>
|
|
116
115
|
</div>
|
|
@@ -120,6 +119,15 @@ export function FieldValues({
|
|
|
120
119
|
);
|
|
121
120
|
}
|
|
122
121
|
|
|
122
|
+
/** A JSON field stored as text, parsed when it parses. */
|
|
123
|
+
function parseJson(text: string): unknown {
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(text);
|
|
126
|
+
} catch {
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
123
131
|
/**
|
|
124
132
|
* A suite's answer, for writing or editing it: the app's own answer editor
|
|
125
133
|
* when it registered one for this suite (`answerEditors` in the wiring
|