@biolibs/bionet-tools 0.0.0-stage → 0.1.1

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.
Files changed (48) hide show
  1. package/README.md +104 -2
  2. package/dist/digest-tool.d.ts +30 -0
  3. package/dist/digest-tool.d.ts.map +1 -0
  4. package/dist/digest-tool.js +84 -0
  5. package/dist/digest-tool.js.map +1 -0
  6. package/dist/digest.d.ts +94 -0
  7. package/dist/digest.d.ts.map +1 -0
  8. package/dist/digest.js +115 -0
  9. package/dist/digest.js.map +1 -0
  10. package/dist/index.d.ts +29 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +29 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/pcr-bench.d.ts +94 -0
  15. package/dist/pcr-bench.d.ts.map +1 -0
  16. package/dist/pcr-bench.js +187 -0
  17. package/dist/pcr-bench.js.map +1 -0
  18. package/dist/pcr-scene.d.ts +247 -0
  19. package/dist/pcr-scene.d.ts.map +1 -0
  20. package/dist/pcr-scene.js +287 -0
  21. package/dist/pcr-scene.js.map +1 -0
  22. package/dist/pcr-tool.d.ts +18 -0
  23. package/dist/pcr-tool.d.ts.map +1 -0
  24. package/dist/pcr-tool.js +73 -0
  25. package/dist/pcr-tool.js.map +1 -0
  26. package/dist/pcr.d.ts +59 -0
  27. package/dist/pcr.d.ts.map +1 -0
  28. package/dist/pcr.js +79 -0
  29. package/dist/pcr.js.map +1 -0
  30. package/dist/run.d.ts +161 -0
  31. package/dist/run.d.ts.map +1 -0
  32. package/dist/run.js +143 -0
  33. package/dist/run.js.map +1 -0
  34. package/dist/tools.d.ts +27 -0
  35. package/dist/tools.d.ts.map +1 -0
  36. package/dist/tools.js +45 -0
  37. package/dist/tools.js.map +1 -0
  38. package/package.json +61 -4
  39. package/src/digest-tool.tsx +199 -0
  40. package/src/digest.ts +136 -0
  41. package/src/index.ts +28 -0
  42. package/src/pcr-bench.tsx +350 -0
  43. package/src/pcr-scene.ts +408 -0
  44. package/src/pcr-tool.tsx +160 -0
  45. package/src/pcr.ts +87 -0
  46. package/src/run.ts +234 -0
  47. package/src/tools.tsx +64 -0
  48. package/tools.css +50 -0
@@ -0,0 +1,350 @@
1
+ "use client";
2
+
3
+ /**
4
+ * A PCR at the machine: everything beside the scene, and what the scene is told to show.
5
+ *
6
+ * It knows nothing of three dimensions. It holds what has been chosen and which view is showing,
7
+ * works out what the machine would show and what is in the tube, and hands those to whatever draws
8
+ * the instrument as plain data. The scene package's `InstrumentStage` takes them as they are.
9
+ *
10
+ * What is beside the scene keeps four things apart: what the **machine** shows, what is true of this
11
+ * **run**, the **checks** a careful operator would make, and, for somebody new, what is going on.
12
+ */
13
+ import { useEffect, useMemo, useState, type ReactNode } from "react";
14
+ import { bandsOf, gelById, ladderBands, ladderById } from "@biolibs/gel";
15
+ import { useAct, useLab } from "@biolibs/bionet-react";
16
+ import { Glossed } from "@biolibs/glossary-react";
17
+ import { Gel } from "./digest-tool.js";
18
+ import { primerTm } from "./pcr.js";
19
+ import { primerBinding, programmeChecks, screenOf, strandCounts, suggestProgramme, tubeLens, tubeView,
20
+ type PcrProgramme, type PcrStepName, type TubeLens, type TubeStrand } from "./pcr-scene.js";
21
+ import { pcrRun, pcrTubes, type TubeChoice } from "./run.js";
22
+
23
+ /** The views of the machine, in the order a person meets them. */
24
+ export type BenchView = "machine" | "block" | "screen" | "tube" | "result";
25
+
26
+ /** What the scene is told to show. It is shaped to be spread onto `InstrumentStage`. */
27
+ export interface BenchStage {
28
+ model: "thermocycler";
29
+ name: string;
30
+ view: BenchView;
31
+ onView: (view: BenchView) => void;
32
+ screen: { text: string; lit?: boolean }[];
33
+ well?: { row: number; column: number };
34
+ tube?: { length: number; strands: TubeStrand[] };
35
+ /** The real bases at the primer being looked at, for any moment of the step showing. */
36
+ lens?: (through: number) => (TubeLens & { rows: [number, number] }) | null;
37
+ legend: Partial<Record<TubeStrand["kind"], string>>;
38
+ /** How long the step showing should take to play, when the bench is setting the pace. */
39
+ seconds?: number;
40
+ /** Called when the step showing has finished playing. */
41
+ onPlayed: () => void;
42
+ }
43
+
44
+ /**
45
+ * A cycle's temperatures as a line, with a mark on the step it is at.
46
+ *
47
+ * @param props - `programme` is the programme; `step` is the step it is on.
48
+ */
49
+ export function TemperatureTrace({ programme, step }: { programme: PcrProgramme; step: PcrStepName }) {
50
+ const total = programme.steps.reduce((sum, one) => sum + one.seconds, 0);
51
+ const y = (celsius: number): number => 58 - ((celsius - 40) / 60) * 50;
52
+ let x = 8;
53
+ const spans = programme.steps.map((one) => { const from = x; x += (one.seconds / total) * 204; return { one, from, to: x }; });
54
+ const line = spans.flatMap(({ one, from, to }) => [`${from},${y(one.celsius)}`, `${to},${y(one.celsius)}`]).join(" ");
55
+ const now = spans.find(({ one }) => one.name === step)!;
56
+ return (
57
+ <svg className="trace" viewBox="0 0 220 70" role="img"
58
+ aria-label={`One cycle: ${programme.steps.map((one) => `${one.name} at ${one.celsius} degrees for ${one.seconds} seconds`).join(", ")}. It is on ${step}.`}>
59
+ <polyline points={line} fill="none" className="line" />
60
+ <rect x={now.from} y={4} width={now.to - now.from} height={60} className="now" />
61
+ {spans.map(({ one, from, to }) => <text key={one.name} x={(from + to) / 2} y={y(one.celsius) - 5} textAnchor="middle" className={one.name === step ? "on" : undefined}>{one.celsius}°</text>)}
62
+ </svg>
63
+ );
64
+ }
65
+
66
+ /**
67
+ * How many strands of each kind there are, as bars.
68
+ *
69
+ * The bars are on a doubling scale, since the product doubles: each step along is twice as many.
70
+ *
71
+ * @param props - `counts` is how many there are; `cycles` is how many cycles the programme runs,
72
+ * which sets how long a full bar is.
73
+ */
74
+ export function StrandBars({ counts, cycles }: { counts: { template: number; long: number; product: number }; cycles: number }) {
75
+ const rows: [string, number, string][] = [["Template", counts.template, "template"], ["Too long", counts.long, "long"], ["Product", counts.product, "product"]];
76
+ return (
77
+ <div className="bars" role="img" aria-label={rows.map(([label, count]) => `${label}: ${count.toLocaleString("en-US")} strands`).join(". ")}>
78
+ {rows.map(([label, count, kind]) => (
79
+ <div key={kind} className="bar">
80
+ <span>{label}</span>
81
+ <span className="track"><span className={`fill ${kind}`} style={{ width: `${Math.min(100, (Math.log2(count + 1) / (cycles + 1)) * 100)}%` }} /></span>
82
+ <span className="count">{count.toLocaleString("en-US")}</span>
83
+ </div>
84
+ ))}
85
+ </div>
86
+ );
87
+ }
88
+
89
+ const STEPS: readonly PcrStepName[] = ["denature", "anneal", "extend"];
90
+ const whole = (text: string): number | undefined => (text.trim() === "" || !Number.isFinite(Number(text)) ? undefined : Math.round(Number(text)));
91
+
92
+ function Pick({ label, choices, value, onChange }: { label: string; choices: TubeChoice[]; value: string; onChange: (item: string) => void }) {
93
+ return (
94
+ <label>{label}
95
+ <select value={value} onChange={(event) => onChange(event.target.value)} aria-label={label}>
96
+ <option value="">Choose a tube…</option>
97
+ {choices.map((one) => <option key={one.item} value={one.item}>{one.label}</option>)}
98
+ </select>
99
+ </label>
100
+ );
101
+ }
102
+
103
+ /**
104
+ * A PCR at the machine.
105
+ *
106
+ * @param options - `instrument` is the thermocycler it is run on, if the lab has placed one;
107
+ * `onDone` adds a way to leave.
108
+ * @returns `stage`, to spread onto whatever draws the instrument, and `panel`, to put beside it.
109
+ *
110
+ * @example
111
+ * ```tsx
112
+ * import { usePcrBench } from "@biolibs/bionet-tools";
113
+ *
114
+ * const bench = usePcrBench({ instrument });
115
+ * // InstrumentStage is the scene package's; anything that draws an instrument from this data will do.
116
+ * <InstrumentStage {...bench.stage}>{bench.panel}</InstrumentStage>
117
+ * ```
118
+ */
119
+ export function usePcrBench({ instrument = null, onDone }: { instrument?: { id: string; name: string } | null; onDone?: () => void } = {}): { stage: BenchStage; panel: ReactNode } {
120
+ const lab = useLab()?.lab;
121
+ const act = useAct();
122
+ const [view, setView] = useState<BenchView>("machine");
123
+ const [template, setTemplate] = useState("");
124
+ const [forward, setForward] = useState("");
125
+ const [reverse, setReverse] = useState("");
126
+ const [least, setLeast] = useState("18");
127
+ const [set, setSet] = useState<PcrProgramme | null>(null);
128
+ const [step, setStep] = useState<PcrStepName>("denature");
129
+ const [cycle, setCycle] = useState(1);
130
+ const [name, setName] = useState("");
131
+ const [amount, setAmount] = useState("50");
132
+ const [note, setNote] = useState("");
133
+ const [busy, setBusy] = useState(false);
134
+ const [said, setSaid] = useState<string | null>(null);
135
+ const [running, setRunning] = useState(false);
136
+ const [site, setSite] = useState<"top" | "bottom">("top");
137
+
138
+ const tubes = useMemo(() => (lab === null || lab === undefined ? { templates: [], primers: [] } : pcrTubes(lab)), [lab]);
139
+ const partOf = (item: string) => [...tubes.templates, ...tubes.primers].find((one) => one.item === item)?.part;
140
+ const [templatePart, forwardPart, reversePart] = [partOf(template), partOf(forward), partOf(reverse)];
141
+ const annealAtLeast = whole(least) ?? 18;
142
+
143
+ // What is true of this run: what the engine says the primers make, and where each binds.
144
+ const drafted = useMemo(() => (lab === null || lab === undefined ? null : pcrRun(lab, { template, forward, reverse, annealAtLeast })), [lab, template, forward, reverse, annealAtLeast]);
145
+ const product = drafted?.plan?.problem === null ? drafted.plan.products[0]! : null;
146
+ const bindings = useMemo(() => {
147
+ if (templatePart === undefined || forwardPart === undefined || reversePart === undefined) return null;
148
+ const found = [primerBinding(templatePart.sequence, forwardPart.sequence, annealAtLeast), primerBinding(templatePart.sequence, reversePart.sequence, annealAtLeast)];
149
+ const top = found.find((one) => one?.reads === "top");
150
+ const bottom = found.find((one) => one?.reads === "bottom");
151
+ return top === undefined || top === null || bottom === undefined || bottom === null ? null : { top, bottom };
152
+ }, [templatePart, forwardPart, reversePart, annealAtLeast]);
153
+ const reaction = useMemo(() => ({
154
+ length: product?.length ?? 0,
155
+ primers: [forwardPart, reversePart].flatMap((part) => (part === undefined ? [] : [{ name: part.name, tm: primerTm(part.sequence) ?? 60 }])),
156
+ }), [product, forwardPart, reversePart]);
157
+ const suggested = useMemo(() => suggestProgramme(reaction), [reaction]);
158
+ // A new choice of tubes is a new reaction, so what was set for the last one is let go.
159
+ useEffect(() => { setSet(null); setSaid(null); }, [template, forward, reverse]);
160
+ const programme = set ?? suggested;
161
+ const checks = product === null ? [] : programmeChecks(programme, reaction);
162
+ const run = useMemo(() => (lab === null || lab === undefined ? null : pcrRun(lab, {
163
+ template, forward, reverse, annealAtLeast, instrument: instrument?.id ?? null, name, note, programme, ...(whole(amount) === undefined ? {} : { amount: whole(amount)! }),
164
+ })), [lab, template, forward, reverse, annealAtLeast, instrument, name, note, programme, amount]);
165
+
166
+ // The real bases, at whichever primer is being looked at.
167
+ const lens = useMemo(() => {
168
+ if (bindings === null || templatePart === undefined || forwardPart === undefined || reversePart === undefined) return undefined;
169
+ const binding = bindings[site];
170
+ const primer = [forwardPart, reversePart].find((part) => primerBinding(templatePart.sequence, part.sequence, annealAtLeast)?.reads === site)!;
171
+ // Heating parts the template's own two strands; after that a primer is with the strand beside it.
172
+ const rows: [number, number] = step === "denature" ? [0, 3] : site === "top" ? [2, 3] : [0, 1];
173
+ return (through: number) => ({ ...tubeLens(templatePart.sequence, primer.sequence, binding, step, through, { primer: primer.name, template: templatePart.name }), rows });
174
+ }, [bindings, templatePart, forwardPart, reversePart, annealAtLeast, site, step]);
175
+ const inTube = bindings === null || templatePart === undefined ? undefined : tubeView(templatePart.length, bindings.top, bindings.bottom, step, cycle);
176
+ // Running the programme: each step plays into the next, and each cycle into the next, as the
177
+ // machine would. The first three cycles are played at the pace chosen, since each shows something
178
+ // new. After that every cycle looks alike, so they go by quickly and the counts are what to watch.
179
+ const onward = (): void => {
180
+ const next = STEPS[STEPS.indexOf(step) + 1];
181
+ if (next !== undefined) { setStep(next); return; }
182
+ if (cycle >= programme.cycles) { setRunning(false); return; }
183
+ setCycle(cycle + 1);
184
+ setStep("denature");
185
+ };
186
+ const played = (): void => { if (running) onward(); };
187
+ const onMachine = (line: { text: string; step?: PcrStepName }, at: number): { text: string; lit?: boolean } =>
188
+ (at === 1 ? { text: `Cycle ${Math.min(cycle, programme.cycles)} of ${programme.cycles}`, ...(running ? { lit: true } : {}) }
189
+ : { text: line.text, ...(line.step === step ? { lit: true } : {}) });
190
+ const stage: BenchStage = {
191
+ model: "thermocycler", name: instrument?.name ?? "Thermocycler", view, onView: (to) => { setView(to); if (to !== "tube") setRunning(false); },
192
+ onPlayed: played, ...(running && cycle > 3 ? { seconds: 0.22 } : {}),
193
+ screen: product === null ? [{ text: "No programme" }] : screenOf(programme).map(onMachine),
194
+ ...(templatePart === undefined ? {} : { well: { row: 0, column: 0 } }),
195
+ ...(inTube === undefined || templatePart === undefined ? {} : { tube: { length: templatePart.length, strands: inTube.strands } }),
196
+ ...(lens === undefined || cycle > 3 ? {} : { lens }),
197
+ legend: { template: "the template's two strands", primer: "a primer", long: "a copy that runs on too far", product: "the product, at its exact length" },
198
+ };
199
+
200
+ const change = (edit: (programme: PcrProgramme) => void): void => { const next = structuredClone(programme); edit(next); setSet(next); };
201
+ const record = async (what: Record<string, unknown> | null, done: string): Promise<void> => {
202
+ if (what === null) return;
203
+ setBusy(true);
204
+ const answer = await act("recordRun", what);
205
+ setBusy(false);
206
+ if (answer.ok) { setSaid(done); setName(""); setNote(""); }
207
+ };
208
+ const chosen = templatePart !== undefined && forwardPart !== undefined && reversePart !== undefined;
209
+
210
+ const panel = lab === null || lab === undefined ? null : (
211
+ <div className="bionet benchpanel">
212
+ <section className="card">
213
+ <div className="toolhead">
214
+ <h2>PCR</h2>
215
+ {onDone !== undefined && <button type="button" className="quiet" onClick={onDone}>Back to the lab</button>}
216
+ </div>
217
+ {tubes.templates.length === 0 ? <p className="empty">There are no tubes to run a PCR from. Add a part and a tube of it on the Freezer tab.</p> : (
218
+ <fieldset disabled={busy} className="stack">
219
+ <Pick label="Template" choices={tubes.templates} value={template} onChange={setTemplate} />
220
+ <Pick label="Forward primer" choices={tubes.primers} value={forward} onChange={setForward} />
221
+ <Pick label="Reverse primer" choices={tubes.primers} value={reverse} onChange={setReverse} />
222
+ </fieldset>
223
+ )}
224
+ {chosen && drafted?.plan?.problem !== null && drafted?.plan !== null && <p className="trouble" role="status">{drafted?.plan?.problem}</p>}
225
+ </section>
226
+
227
+ {view === "machine" && (
228
+ <section className="card">
229
+ <h2>At the machine</h2>
230
+ <p className="small"><Glossed text="PCR copies the stretch of a template that lies between two primers, over and over, by heating and cooling it." /></p>
231
+ <p className="dim small">A thermocycler shows its programme, the block's temperature and which cycle it is on. It shows nothing of the DNA. The first three views are what it shows; the last two are what you have to picture.</p>
232
+ </section>
233
+ )}
234
+
235
+ {view === "block" && (
236
+ <section className="card">
237
+ <h2>The block</h2>
238
+ <p className="voice">The machine</p>
239
+ <p className="small">96 wells under a heated lid, which presses on the tubes so nothing condenses on their caps.</p>
240
+ <p className="voice">This run</p>
241
+ <p className="small">{templatePart === undefined ? "No tube is in the block yet. Choose a template above." : "Your reaction is in well A1, at the back left."}</p>
242
+ </section>
243
+ )}
244
+
245
+ {view === "screen" && (
246
+ <section className="card">
247
+ <h2>The programme</h2>
248
+ {product === null ? <p className="dim small">Choose tubes that make one product and a programme is suggested for it.</p> : (
249
+ <>
250
+ <p className="voice">The machine</p>
251
+ <fieldset disabled={busy} className="programme">
252
+ <label>Anneal at<input type="number" min={30} max={80} step={1} value={programme.steps[1].celsius} onChange={(event) => change((p) => { p.steps[1].celsius = whole(event.target.value) ?? p.steps[1].celsius; })} /> °C</label>
253
+ <label>Extend for<input type="number" min={5} max={1800} step={5} value={programme.steps[2].seconds} onChange={(event) => change((p) => { p.steps[2].seconds = whole(event.target.value) ?? p.steps[2].seconds; })} /> s</label>
254
+ <label>Cycles<input type="number" min={1} max={60} step={1} value={programme.cycles} onChange={(event) => change((p) => { p.cycles = whole(event.target.value) ?? p.cycles; })} /></label>
255
+ {set !== null && <button type="button" className="plain" onClick={() => setSet(null)}>back to what was suggested</button>}
256
+ </fieldset>
257
+ <p className="voice">This run</p>
258
+ <p className="small">
259
+ {reaction.primers.map((one) => `${one.name} melts near ${Math.round(one.tm)} °C`).join("; ")}. The product is {product.length.toLocaleString("en-US")} bases.
260
+ </p>
261
+ <p className="voice">Checks</p>
262
+ {checks.length === 0 ? <p className="small good">Nothing in this programme looks wrong for this reaction.</p> : (
263
+ <ul className="checks">{checks.map((check) => <li key={check.says} className={check.weight}>{check.says}</li>)}</ul>
264
+ )}
265
+ </>
266
+ )}
267
+ </section>
268
+ )}
269
+
270
+ {view === "tube" && (
271
+ <section className="card">
272
+ <h2>In the tube</h2>
273
+ {inTube === undefined ? <p className="dim small">{chosen ? "These primers do not each bind this template in one place, so there is nothing to draw." : "Choose a template and two primers to see what happens to them."}</p> : (
274
+ <>
275
+ <div className="row tight pick" role="group" aria-label="Step of the cycle">
276
+ {STEPS.map((one) => <button key={one} type="button" aria-pressed={one === step} className={one === step ? "" : "quiet"} onClick={() => setStep(one)}>{one[0]!.toUpperCase()}{one.slice(1)}</button>)}
277
+ </div>
278
+ <div className="row tight pick" role="group" aria-label="Cycle">
279
+ <span className="dim small">Cycle</span>
280
+ {[1, 2, 3].map((one) => <button key={one} type="button" aria-pressed={one === cycle} className={one === cycle ? "" : "quiet"} onClick={() => { setRunning(false); setCycle(one); }}>{one}</button>)}
281
+ {cycle > 3 && <span className="small">{cycle} of {programme.cycles}</span>}
282
+ </div>
283
+ <div className="row tight pick" role="group" aria-label="Which primer to read the bases at">
284
+ <span className="dim small">Read the bases at</span>
285
+ {(["top", "bottom"] as const).map((one) => {
286
+ const part = [forwardPart, reversePart].find((each) => each !== undefined && templatePart !== undefined && primerBinding(templatePart.sequence, each.sequence, annealAtLeast)?.reads === one);
287
+ return <button key={one} type="button" aria-pressed={one === site} className={one === site ? "" : "quiet"} onClick={() => setSite(one)}>{part?.name ?? one}</button>;
288
+ })}
289
+ </div>
290
+ <div className="row tight pick">
291
+ <button type="button" onClick={() => {
292
+ if (running) { setRunning(false); return; }
293
+ setRunning(true);
294
+ // The step showing has usually finished playing, so a run starts by moving on from it.
295
+ if (cycle >= programme.cycles && step === "extend") { setCycle(1); setStep("denature"); } else onward();
296
+ }}>
297
+ {running ? "Stop" : cycle >= programme.cycles && step === "extend" ? "Run it again" : "Run the programme"}
298
+ </button>
299
+ <span className="dim small">{running ? "Each step plays into the next." : "Or press a step to see it alone."}</span>
300
+ </div>
301
+ <p className="voice">The machine</p>
302
+ <p className="small"><code>{screenOf(programme).find((line) => line.step === step)?.text.trim()}</code> · cycle {Math.min(cycle, programme.cycles)} of {programme.cycles}</p>
303
+ <TemperatureTrace programme={programme} step={step} />
304
+ <p className="voice">What is going on</p>
305
+ <p className="small"><Glossed text={inTube.says} /></p>
306
+ <p className="voice">This run</p>
307
+ <StrandBars counts={inTube.counts} cycles={programme.cycles} />
308
+ <p className="dim small">
309
+ Strands in the tube now, from one double-stranded template. Each step along a bar is twice as many. The copies that run on too far
310
+ grow by two a cycle; the product doubles, and after {programme.cycles} cycles there are {strandCounts(programme.cycles).product.toLocaleString("en-US")}.
311
+ </p>
312
+ </>
313
+ )}
314
+ </section>
315
+ )}
316
+
317
+ {view === "result" && (
318
+ <section className="card">
319
+ <h2>The result</h2>
320
+ {product === null ? <p className="dim small">Choose tubes that make one product.</p> : (
321
+ <>
322
+ <p className="voice">This run</p>
323
+ <p><strong>{product.length.toLocaleString("en-US")} bp</strong> <span className="dim">linear</span></p>
324
+ <code className="wrap">{product.length <= 96 ? product.sequence : `${product.sequence.slice(0, 44)} … ${product.sequence.slice(-44)}`}</code>
325
+ <Gel ladder={ladderBands(ladderById(product.length < 1500 ? "100bp" : "1kb").sizes, gelById(product.length < 1500 ? "1.5" : "1.0"))}
326
+ bands={bandsOf([product.length], gelById(product.length < 1500 ? "1.5" : "1.0"))} name={run?.name ?? "product"} />
327
+ {checks.length > 0 && (
328
+ <>
329
+ <p className="voice">Checks</p>
330
+ <ul className="checks">{checks.map((check) => <li key={check.says} className={check.weight}>{check.says}</li>)}</ul>
331
+ </>
332
+ )}
333
+ <fieldset disabled={busy} className="stack">
334
+ <label>Call the product<input value={name} onChange={(event) => setName(event.target.value)} placeholder={run?.name ?? ""} maxLength={200} /></label>
335
+ <label>Amount, in µL<input type="number" min={0} step={1} value={amount} onChange={(event) => setAmount(event.target.value)} /></label>
336
+ <label>Note<input value={note} onChange={(event) => setNote(event.target.value)} maxLength={2000} /></label>
337
+ <div className="row">
338
+ <button type="button" onClick={() => void record(run?.worked ?? null, `Recorded. There is a new tube of ${run?.name ?? "the product"}, not yet put anywhere.`)}>Record the run</button>
339
+ <button type="button" className="quiet" onClick={() => void record(run?.failed ?? null, "Recorded as a run that gave nothing. The tubes were used all the same.")}>It gave nothing</button>
340
+ </div>
341
+ </fieldset>
342
+ </>
343
+ )}
344
+ {said !== null && <p className="small" role="status">{said}</p>}
345
+ </section>
346
+ )}
347
+ </div>
348
+ );
349
+ return { stage, panel };
350
+ }