@biolibs/bionet-panels 0.0.0-stage → 0.2.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 +89 -2
- package/dist/freezer.d.ts +21 -0
- package/dist/freezer.d.ts.map +1 -0
- package/dist/freezer.js +32 -0
- package/dist/freezer.js.map +1 -0
- package/dist/history.d.ts +14 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +48 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/parts.d.ts +36 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +61 -0
- package/dist/parts.js.map +1 -0
- package/dist/people.d.ts +3 -0
- package/dist/people.d.ts.map +1 -0
- package/dist/people.js +15 -0
- package/dist/people.js.map +1 -0
- package/dist/public.d.ts +77 -0
- package/dist/public.d.ts.map +1 -0
- package/dist/public.js +73 -0
- package/dist/public.js.map +1 -0
- package/dist/sharing.d.ts +12 -0
- package/dist/sharing.d.ts.map +1 -0
- package/dist/sharing.js +35 -0
- package/dist/sharing.js.map +1 -0
- package/dist/window.d.ts +21 -0
- package/dist/window.d.ts.map +1 -0
- package/dist/window.js +72 -0
- package/dist/window.js.map +1 -0
- package/package.json +55 -4
- package/panels.css +61 -0
- package/src/freezer.tsx +101 -0
- package/src/history.tsx +70 -0
- package/src/index.ts +30 -0
- package/src/parts.tsx +80 -0
- package/src/people.tsx +52 -0
- package/src/public.tsx +175 -0
- package/src/sharing.tsx +71 -0
- package/src/window.tsx +136 -0
package/dist/public.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { settled } from "@biolibs/bionet";
|
|
3
|
+
import { Mark } from "@biolibs/bionet-react";
|
|
4
|
+
/**
|
|
5
|
+
* The parts in one list whose checksums are not in another.
|
|
6
|
+
*
|
|
7
|
+
* @param mine - What this lab holds.
|
|
8
|
+
* @param theirs - What the other lab holds.
|
|
9
|
+
* @returns What they have that this lab does not. Names play no part: a part is its checksum.
|
|
10
|
+
*/
|
|
11
|
+
export function onlyTheirs(mine, theirs) {
|
|
12
|
+
const have = new Set(mine.map((part) => part.checksum));
|
|
13
|
+
return theirs.filter((part) => !have.has(part.checksum));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The parts two lists both hold, by checksum.
|
|
17
|
+
*
|
|
18
|
+
* @param mine - What this lab holds.
|
|
19
|
+
* @param theirs - What the other lab holds.
|
|
20
|
+
* @returns This lab's entries for the parts both have.
|
|
21
|
+
*/
|
|
22
|
+
export function heldByBoth(mine, theirs) {
|
|
23
|
+
const have = new Set(theirs.map((part) => part.checksum));
|
|
24
|
+
return mine.filter((part) => have.has(part.checksum));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The frame of a lab's public page: the mark, the lab's name, and a line about what it is.
|
|
28
|
+
*
|
|
29
|
+
* @param props - `name` and `note` are the lab's; `children` is the rest of the page.
|
|
30
|
+
*/
|
|
31
|
+
export function LabPage({ name, note, children }) {
|
|
32
|
+
return (_jsx("div", { className: "bionet", children: _jsxs("main", { className: "page", children: [_jsxs("div", { className: "title", children: [_jsx(Mark, { size: 40 }), _jsx("h1", { children: name })] }), note !== null && note !== undefined && _jsx("p", { className: "dim", children: note }), _jsxs("p", { className: "small dim", children: ["This lab publishes what it holds at", " ", _jsx("a", { href: "/.well-known/bionet.json", children: _jsx("code", { children: "/.well-known/bionet.json" }) }), ", signed, so that a cloning plan can be acted on and not just read. Parts are named by checksum, because a name agrees with nothing."] }), children] }) }));
|
|
33
|
+
}
|
|
34
|
+
/** A table of parts: name, length, and whether each is on offer. `checksums` adds that column. */
|
|
35
|
+
export function PartsTable({ parts, checksums = false }) {
|
|
36
|
+
return (_jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Part" }), _jsx("th", { children: "Length" }), checksums && _jsx("th", { children: "Checksum" }), _jsx("th", { children: "On offer" })] }) }), _jsx("tbody", { children: parts.map((part) => (_jsxs("tr", { children: [_jsxs("td", { children: [part.name, part.note !== null && _jsxs(_Fragment, { children: [_jsx("br", {}), _jsx("span", { className: "dim small", children: part.note })] })] }), _jsx("td", { className: "nowrap", children: _jsxs("code", { children: [part.length, " bp", part.circular ? " ○" : ""] }) }), checksums && _jsx("td", { className: "dim", children: _jsxs("code", { children: [part.checksum.slice(0, 22), "\u2026"] }) }), _jsx("td", { className: part.available ? "good" : "bad", children: part.available ? "yes" : "no" })] }, part.checksum))) })] }));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* What this lab holds, and what the signature over that list settles.
|
|
40
|
+
*
|
|
41
|
+
* @param props - `parts` is the published list; `checks` is one check per signature over it;
|
|
42
|
+
* `origin` is the address this page is served from; `bound` is whether the list names that address.
|
|
43
|
+
*/
|
|
44
|
+
export function Held({ parts, checks, origin, bound }) {
|
|
45
|
+
const holds = checks.length > 0 && checks.every((check) => check.ok);
|
|
46
|
+
return (_jsxs("section", { children: [_jsx("h2", { children: "What we hold" }), parts.length === 0 ? _jsx("p", { className: "dim", children: "Nothing is listed at the moment." }) : _jsx(PartsTable, { parts: parts, checksums: true }), _jsxs("p", { className: "small dim", children: [checks.length === 0 ? "This list is not signed, so it claims nothing about who published it." : (_jsxs(_Fragment, { children: ["Signed by ", checks.map((check) => _jsxs("code", { children: [check.fingerprint, " "] }, check.public_key)), holds ? "— the signature holds over this list as served." : "— the signature does not hold."] })), " ", "Bound to ", _jsx("code", { children: origin }), ": ", bound ? "yes" : "no", "."] })] }));
|
|
47
|
+
}
|
|
48
|
+
/** The caveat every reader is owed, in the same words everywhere. */
|
|
49
|
+
export function WhatASignatureSettles() {
|
|
50
|
+
return (_jsx("p", { className: "small dim", children: "None of that says this lab is who it says it is. The address does that work, and only as far as whoever typed it already trusted it. What a signature settles is that this list has not changed since it was published, and that it was published by whoever holds that key." }));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Another lab that answered, beside what this lab holds.
|
|
54
|
+
*
|
|
55
|
+
* @param props - `found` is what was fetched from the other lab and checked; `mine` is this lab's list.
|
|
56
|
+
*/
|
|
57
|
+
export function PeerAnswered({ found, mine }) {
|
|
58
|
+
const theirs = found.signed.inventory.parts;
|
|
59
|
+
const only = onlyTheirs(mine, theirs);
|
|
60
|
+
const both = heldByBoth(mine, theirs);
|
|
61
|
+
return (_jsxs(_Fragment, { children: [_jsxs("p", { children: [_jsx("strong", { children: found.signed.inventory.lab.name }), " answered at ", _jsx("code", { children: found.origin }), " with", " ", theirs.length, " ", theirs.length === 1 ? "part" : "parts", ".", " ", settled(found)
|
|
62
|
+
? _jsx("span", { className: "good", children: "Its signature holds and it was served from the address it names." })
|
|
63
|
+
: _jsx("span", { className: "bad", children: "Its signature or its address does not check out, so nothing below is settled." })] }), _jsx(WhatASignatureSettles, {}), _jsx("h3", { children: "What they have that we do not" }), only.length === 0 ? _jsx("p", { className: "small", children: "Nothing. Everything they list, we hold too." }) : _jsx(PartsTable, { parts: only }), _jsx("h3", { children: "What we both have" }), both.length === 0 ? _jsx("p", { className: "small", children: "Nothing in common, by checksum." }) : (_jsxs("p", { className: "small", children: [both.map((part) => _jsxs("code", { children: [part.name, " "] }, part.checksum)), "\u2014 matched by checksum, so it does not matter what either of us calls them."] })), _jsx("p", { className: "small dim", children: "Fetched from that lab when this page was drawn, not copied. Nothing here fetches a part: finding out who has a plasmid is as far as software goes, and the rest is an email and a padded envelope." })] }));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Another lab that did not answer.
|
|
67
|
+
*
|
|
68
|
+
* @param props - `address` is where it was asked for; `why` is what went wrong.
|
|
69
|
+
*/
|
|
70
|
+
export function PeerSilent({ address, why }) {
|
|
71
|
+
return (_jsxs(_Fragment, { children: [_jsxs("p", { children: ["We point at ", _jsx("code", { children: address }), " and it did not answer."] }), _jsxs("p", { className: "small dim", children: ["The reason given was: ", why, ". A lab that cannot be reached is not a lab that is lying \u2014 it may be down, or moved, or never have existed. All this page can honestly say is that the address did not answer when it was asked."] })] }));
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../src/public.tsx"],"names":[],"mappings":";AAWA,OAAO,EAAE,OAAO,EAA6C,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAA8B,EAAE,MAAgC;IACzF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,IAA8B,EAAE,MAAgC;IACzF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAA+D;IAC3G,OAAO,CACL,cAAK,SAAS,EAAC,QAAQ,YACrB,gBAAM,SAAS,EAAC,MAAM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,WAAW,uCACC,GAAG,8MAGxB,IACH,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ItemState, PartState } from "@biolibs/bionet";
|
|
2
|
+
/**
|
|
3
|
+
* The parts other labs would be shown: those with a tube that has not been retired and is not empty.
|
|
4
|
+
*
|
|
5
|
+
* @param parts - Every part.
|
|
6
|
+
* @param items - Every item.
|
|
7
|
+
* @returns The parts that would be listed, in order.
|
|
8
|
+
*/
|
|
9
|
+
export declare function listedParts(parts: readonly PartState[], items: readonly ItemState[]): PartState[];
|
|
10
|
+
/** What would be published, a button to publish it, and the peer's settings. Draws nothing until the lab has arrived. */
|
|
11
|
+
export declare function Sharing(): import("react").JSX.Element | null;
|
|
12
|
+
//# sourceMappingURL=sharing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing.d.ts","sourceRoot":"","sources":["../src/sharing.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,EAAE,CAGjG;AAED,yHAAyH;AACzH,wBAAgB,OAAO,uCAiDtB"}
|
package/dist/sharing.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/** Sharing: what other labs are shown, and the lab's web peer. */
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
6
|
+
import { Ask, Copy } from "./parts.js";
|
|
7
|
+
/**
|
|
8
|
+
* The parts other labs would be shown: those with a tube that has not been retired and is not empty.
|
|
9
|
+
*
|
|
10
|
+
* @param parts - Every part.
|
|
11
|
+
* @param items - Every item.
|
|
12
|
+
* @returns The parts that would be listed, in order.
|
|
13
|
+
*/
|
|
14
|
+
export function listedParts(parts, items) {
|
|
15
|
+
const inStock = new Set(items.filter((item) => !item.retired && item.amount > 0).map((item) => item.part));
|
|
16
|
+
return parts.filter((part) => inStock.has(part.checksum));
|
|
17
|
+
}
|
|
18
|
+
/** What would be published, a button to publish it, and the peer's settings. Draws nothing until the lab has arrived. */
|
|
19
|
+
export function Sharing() {
|
|
20
|
+
const state = useLab();
|
|
21
|
+
const act = useAct();
|
|
22
|
+
const [said, setSaid] = useState(null);
|
|
23
|
+
const lab = state?.lab;
|
|
24
|
+
if (state === null || lab === null || lab === undefined)
|
|
25
|
+
return null;
|
|
26
|
+
const listed = listedParts(lab.parts, lab.items);
|
|
27
|
+
const publish = async () => {
|
|
28
|
+
setSaid("Publishing…");
|
|
29
|
+
const answer = await act("publish");
|
|
30
|
+
const result = answer.ok ? answer.result : { ok: false, reason: answer.error, parts: 0 };
|
|
31
|
+
setSaid(result.ok ? `Published: ${result.parts} ${result.parts === 1 ? "part" : "parts"}, signed by this device.` : `Not published. ${result.reason ?? ""}`);
|
|
32
|
+
};
|
|
33
|
+
return (_jsxs(_Fragment, { children: [_jsxs("section", { className: "card", children: [_jsx("h2", { children: "What other labs are shown" }), _jsx("p", { className: "dim small", children: "Only this: which parts the lab has in stock, and whether each can be asked for. Tubes, amounts and who did what stay inside the lab." }), listed.length === 0 ? _jsx("p", { className: "dim", children: "Nothing would be listed: no part has a tube with anything in it." }) : (_jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Part" }), _jsx("th", { children: "Length" }), _jsx("th", { children: "Other labs may ask for it" })] }) }), _jsx("tbody", { children: listed.map((part) => _jsxs("tr", { children: [_jsx("td", { children: part.name }), _jsxs("td", { children: [part.length, " bp"] }), _jsx("td", { children: part.offered ? "yes" : "no" })] }, part.checksum)) })] })), _jsxs("div", { className: "row", children: [_jsx("button", { type: "button", onClick: () => void publish(), disabled: state.peer.url === null, children: "Publish this" }), said !== null && _jsx("span", { className: "small", children: said })] }), _jsxs("p", { className: "dim small", children: [state.peer.origin === null ? "Set the lab's web peer below to have somewhere to publish." : _jsxs(_Fragment, { children: ["Published at ", _jsxs("code", { children: [state.peer.origin, "/.well-known/bionet.json"] }), ", signed by this device's key."] }), state.published !== null && _jsxs(_Fragment, { children: [" Last published from this device ", new Date(state.published).toLocaleString(), "."] })] })] }), _jsxs("section", { className: "card", children: [_jsx("h2", { children: "The lab's web peer" }), _jsx("p", { className: "dim small", children: "A server at the lab's address that holds a copy of the lab and passes changes between members who are never online together. It has no key, so it cannot change anything." }), _jsxs(Ask, { onAsk: (data) => act("setPeer", String(data.get("peer") ?? "")), className: "row", children: [_jsx("input", { name: "peer", placeholder: "wss://your-lab.example/sync", defaultValue: state.peer.url ?? "", spellCheck: false }), _jsx("button", { type: "submit", className: "quiet", children: "Use this peer" })] }), state.peer.problem !== null && _jsx("p", { className: "note", children: state.peer.problem }), _jsxs("div", { className: "keybox", children: [_jsxs("div", { children: [_jsx("span", { className: "label", children: "This lab's ID" }), lab.id !== null && _jsx(Copy, { words: lab.id, label: "Copy ID" })] }), _jsx("code", { className: "wrap", children: lab.id }), _jsxs("p", { className: "dim small", children: ["Whoever runs the lab's peer sets this as ", _jsx("code", { children: "BIONET_LAB" }), ", so that it serves this lab and no other."] })] })] })] }));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=sharing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharing.js","sourceRoot":"","sources":["../src/sharing.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,kEAAkE;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC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|
+
export declare const TABS: readonly ["freezer", "people", "history", "sharing"];
|
|
3
|
+
/** One of them. */
|
|
4
|
+
export type Tab = (typeof TABS)[number];
|
|
5
|
+
/**
|
|
6
|
+
* The window.
|
|
7
|
+
*
|
|
8
|
+
* @param props - `tab` is which view to open on; `copy` puts words on the clipboard, for a host that
|
|
9
|
+
* cannot use the browser's own way.
|
|
10
|
+
*/
|
|
11
|
+
export declare function LabWindow({ tab: first, copy }: {
|
|
12
|
+
tab?: Tab;
|
|
13
|
+
copy?: (words: string) => Promise<void>;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
/** Asking who is at this device, before anything else. */
|
|
16
|
+
export declare function Who(): import("react").JSX.Element;
|
|
17
|
+
/** Founding a lab, or joining one. */
|
|
18
|
+
export declare function NoLab(): import("react").JSX.Element | null;
|
|
19
|
+
/** Waiting for a keeper to add this device. */
|
|
20
|
+
export declare function Waiting(): import("react").JSX.Element | null;
|
|
21
|
+
//# sourceMappingURL=window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../src/window.tsx"],"names":[],"mappings":"AAoBA,yCAAyC;AACzC,eAAO,MAAM,IAAI,sDAAuD,CAAC;AAEzE,mBAAmB;AACnB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,GAAG,EAAE,KAAiB,EAAE,IAAI,EAAE,EAAE;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,+BAGjH;AA2CD,0DAA0D;AAC1D,wBAAgB,GAAG,gCAYlB;AAED,sCAAsC;AACtC,wBAAgB,KAAK,uCA0BpB;AAED,+CAA+C;AAC/C,wBAAgB,OAAO,uCAYtB"}
|
package/dist/window.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* A whole lab application, in one component.
|
|
5
|
+
*
|
|
6
|
+
* It holds no state of its own about the lab. It is told the lab as it stands, every time it
|
|
7
|
+
* changes, and draws it; a button asks for one thing to be done and waits to be told how the lab
|
|
8
|
+
* changed. So what is on screen is always what the signed logs say, and never what a form hoped.
|
|
9
|
+
*
|
|
10
|
+
* It walks a person through the three places they can be: nobody has said who is at this device,
|
|
11
|
+
* the device is in no lab, the device is waiting to be let into one — and then the lab itself.
|
|
12
|
+
*/
|
|
13
|
+
import { useState } from "react";
|
|
14
|
+
import { Logo, Mark, useAct, useLab } from "@biolibs/bionet-react";
|
|
15
|
+
import { Freezer } from "./freezer.js";
|
|
16
|
+
import { History } from "./history.js";
|
|
17
|
+
import { Ask, CopyContext, DeviceKey, SyncStatus, Trouble } from "./parts.js";
|
|
18
|
+
import { People } from "./people.js";
|
|
19
|
+
import { Sharing } from "./sharing.js";
|
|
20
|
+
/** The four things a member looks at. */
|
|
21
|
+
export const TABS = ["freezer", "people", "history", "sharing"];
|
|
22
|
+
/**
|
|
23
|
+
* The window.
|
|
24
|
+
*
|
|
25
|
+
* @param props - `tab` is which view to open on; `copy` puts words on the clipboard, for a host that
|
|
26
|
+
* cannot use the browser's own way.
|
|
27
|
+
*/
|
|
28
|
+
export function LabWindow({ tab: first = "freezer", copy }) {
|
|
29
|
+
const window = _jsx(Body, { first: first });
|
|
30
|
+
return _jsx("div", { className: "bionet", children: copy === undefined ? window : _jsx(CopyContext.Provider, { value: copy, children: window }) });
|
|
31
|
+
}
|
|
32
|
+
function Body({ first }) {
|
|
33
|
+
const state = useLab();
|
|
34
|
+
const [tab, setTab] = useState(first);
|
|
35
|
+
if (state === null)
|
|
36
|
+
return _jsx("main", { className: "centre", children: _jsx("p", { className: "dim", children: "Opening the lab\u2026" }) });
|
|
37
|
+
if (state.device.person === null)
|
|
38
|
+
return _jsxs("main", { className: "centre", children: [_jsx(Logo, {}), _jsx(Trouble, {}), _jsx(Who, {})] });
|
|
39
|
+
if (state.lab === null)
|
|
40
|
+
return _jsxs("main", { className: "centre", children: [_jsx(Logo, {}), _jsx(Trouble, {}), _jsx(NoLab, {})] });
|
|
41
|
+
if (!state.lab.member)
|
|
42
|
+
return _jsxs("main", { className: "centre", children: [_jsx(Logo, {}), _jsx(Trouble, {}), _jsx(Waiting, {})] });
|
|
43
|
+
const lab = state.lab;
|
|
44
|
+
const label = {
|
|
45
|
+
freezer: `Freezer · ${lab.items.filter((item) => !item.retired).length}`,
|
|
46
|
+
people: `People · ${lab.roster.filter((key) => key.removed === null).length}`,
|
|
47
|
+
history: `History · ${lab.entries.length}`,
|
|
48
|
+
sharing: "Sharing",
|
|
49
|
+
};
|
|
50
|
+
return (_jsxs("div", { className: "shell", children: [_jsxs("header", { children: [_jsxs("div", { className: "title", children: [_jsx(Mark, { size: 34 }), _jsxs("div", { children: [_jsx("h1", { children: lab.name ?? "A lab" }), _jsxs("p", { className: "dim small", children: [state.device.person, " \u00B7 ", lab.keeper ? "keeper" : "member", " \u00B7 this device ", _jsx("code", { children: state.device.fingerprint })] })] })] }), _jsx(SyncStatus, { peer: state.peer })] }), _jsx("nav", { children: TABS.map((one) => _jsx("button", { type: "button", className: one === tab ? "tab on" : "tab", onClick: () => setTab(one), children: label[one] }, one)) }), _jsxs("main", { children: [_jsx(Trouble, {}), tab === "freezer" && _jsx(Freezer, {}), tab === "people" && _jsx(People, {}), tab === "history" && _jsx(History, {}), tab === "sharing" && _jsx(Sharing, {})] })] }));
|
|
51
|
+
}
|
|
52
|
+
/** Asking who is at this device, before anything else. */
|
|
53
|
+
export function Who() {
|
|
54
|
+
const act = useAct();
|
|
55
|
+
return (_jsxs("section", { className: "card narrow", children: [_jsx("h1", { children: "Who is at this device?" }), _jsx("p", { className: "dim", children: "Every change you make is signed by a key made on this device, and shown to your lab under this name. The key never leaves this computer." }), _jsxs(Ask, { onAsk: (data) => act("setPerson", String(data.get("name") ?? "")), className: "row", children: [_jsx("input", { name: "name", placeholder: "Your name", autoFocus: true, required: true, maxLength: 200 }), _jsx("button", { type: "submit", children: "Continue" })] })] }));
|
|
56
|
+
}
|
|
57
|
+
/** Founding a lab, or joining one. */
|
|
58
|
+
export function NoLab() {
|
|
59
|
+
const state = useLab();
|
|
60
|
+
const act = useAct();
|
|
61
|
+
if (state === null)
|
|
62
|
+
return null;
|
|
63
|
+
return (_jsxs("div", { className: "pair", children: [_jsxs("section", { className: "card", children: [_jsx("h2", { children: "Found a lab" }), _jsx("p", { className: "dim", children: "You become its first keeper. It works on this device straight away, with or without a network." }), _jsxs(Ask, { onAsk: (data) => act("found", { name: String(data.get("name") ?? ""), peer: String(data.get("peer") ?? "") }), className: "stack", children: [_jsxs("label", { children: ["What is it called?", _jsx("input", { name: "name", placeholder: "The Wren Lab", required: true, maxLength: 200 })] }), _jsxs("label", { children: [_jsx("span", { children: "Its web peer, if it has one (optional)" }), _jsx("input", { name: "peer", placeholder: "wss://your-lab.example/sync" })] }), _jsx("button", { type: "submit", children: "Found the lab" })] })] }), _jsxs("section", { className: "card", children: [_jsx("h2", { children: "Join a lab" }), _jsx("p", { className: "dim", children: "Send a keeper this device's key, and paste the invitation they send back. The lab arrives once they have added you." }), _jsx(DeviceKey, { device: state.device }), _jsxs(Ask, { onAsk: (data) => act("join", String(data.get("invite") ?? "")), className: "stack", children: [_jsxs("label", { children: ["Invitation", _jsx("input", { name: "invite", placeholder: "wss://your-lab.example/sync#\u2026", required: true })] }), _jsx("button", { type: "submit", children: "Join" })] })] })] }));
|
|
64
|
+
}
|
|
65
|
+
/** Waiting for a keeper to add this device. */
|
|
66
|
+
export function Waiting() {
|
|
67
|
+
const state = useLab();
|
|
68
|
+
if (state === null)
|
|
69
|
+
return null;
|
|
70
|
+
return (_jsxs("section", { className: "card narrow", children: [_jsx("h1", { children: "Waiting to be let in" }), _jsx("p", { children: "This device has asked to join a lab, and none of the lab has been sent to it yet. A keeper has to add this device's key, and then it arrives on its own." }), _jsx(DeviceKey, { device: state.device }), _jsx(SyncStatus, { peer: state.peer }), state.peer.problem !== null && _jsx("p", { className: "dim small", children: state.peer.problem })] }));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window.js","sourceRoot":"","sources":["../src/window.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,yCAAyC;AACzC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAKzE;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,GAAG,SAAS,EAAE,IAAI,EAA0D;IAChH,MAAM,MAAM,GAAG,KAAC,IAAI,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;IACtC,OAAO,cAAK,SAAS,EAAC,QAAQ,YAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,YAAG,MA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.0",
|
|
8
|
+
"@biolibs/bionet-react": "^0.1.1",
|
|
9
|
+
"@biolibs/opencloning": "^2.0.0"
|
|
10
|
+
},
|
|
11
|
+
"description": "The parts of a Bionet lab application, ready to place: the freezer, the people, the history, what other labs are shown, and a whole window that puts them together, in a light theme and a dark one",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./panels.css": "./panels.css"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"panels.css"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://github.com/matthewlovestocode/biolibs/tree/main/packages/bionet-panels#readme",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"bionet",
|
|
30
|
+
"react",
|
|
31
|
+
"components",
|
|
32
|
+
"inventory",
|
|
33
|
+
"local-first",
|
|
34
|
+
"biology"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"main": "dist/index.js",
|
|
2
38
|
"name": "@biolibs/bionet-panels",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@biolibs/bionet-theme": "^0.1.0",
|
|
41
|
+
"react": ">=18"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/matthewlovestocode/biolibs.git",
|
|
49
|
+
"directory": "packages/bionet-panels"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": [
|
|
52
|
+
"*.css"
|
|
53
|
+
],
|
|
54
|
+
"type": "module",
|
|
55
|
+
"types": "dist/index.d.ts",
|
|
56
|
+
"version": "0.2.0"
|
|
57
|
+
}
|
package/panels.css
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* The panels' styles. Every rule is inside .bionet, so nothing here reaches the page around it, and
|
|
2
|
+
every colour is one of the theme's variables, so it follows a light or dark theme. */
|
|
3
|
+
.bionet { background: var(--bionet-ground); color: var(--bionet-ink); height: 100%;
|
|
4
|
+
font: 14px/1.5 "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
|
|
5
|
+
.bionet * { box-sizing: border-box }
|
|
6
|
+
.bionet h1 { font-size: 1.35rem; margin: 0 } .bionet h2 { font-size: 1.02rem; margin: 0 0 .35rem }
|
|
7
|
+
.bionet p { margin: .35rem 0 .8rem }
|
|
8
|
+
.bionet code { font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em }
|
|
9
|
+
.bionet .dim { color: var(--bionet-dim) } .bionet .small { font-size: .86rem } .bionet .nowrap { white-space: nowrap }
|
|
10
|
+
.bionet .wrap { display: block; overflow-wrap: anywhere }
|
|
11
|
+
.bionet .shell { display: flex; flex-direction: column; height: 100% }
|
|
12
|
+
.bionet header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.5rem .6rem }
|
|
13
|
+
.bionet header p { margin: .1rem 0 0 }
|
|
14
|
+
.bionet .title { display: flex; align-items: center; gap: .8rem } .bionet .title svg { display: block; flex: none }
|
|
15
|
+
.bionet nav { display: flex; gap: .25rem; padding: 0 1.5rem; border-bottom: 1px solid var(--bionet-rule) }
|
|
16
|
+
.bionet .tab { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--bionet-dim); padding: .55rem .8rem; font: inherit; cursor: pointer; border-radius: 0 }
|
|
17
|
+
.bionet .tab.on { color: var(--bionet-ink); border-bottom-color: var(--bionet-yours); font-weight: 600 }
|
|
18
|
+
.bionet main { flex: 1; overflow: auto; padding: 1.25rem 1.5rem 3rem }
|
|
19
|
+
.bionet main.centre { display: grid; place-content: center; justify-items: center; gap: 1rem; padding: 2rem; min-height: 100% }
|
|
20
|
+
.bionet .card { background: var(--bionet-surface); border: 1px solid var(--bionet-rule); border-radius: 10px; padding: 1.1rem 1.25rem; margin: 0 0 1rem }
|
|
21
|
+
.bionet .card.narrow { max-width: 34rem } .bionet .pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; max-width: 60rem; width: 100% }
|
|
22
|
+
.bionet .empty { color: var(--bionet-dim); padding: 1.5rem 0; text-align: center }
|
|
23
|
+
.bionet fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: contents }
|
|
24
|
+
.bionet form.stack { display: grid; gap: .7rem; margin-top: .6rem }
|
|
25
|
+
.bionet form.row, .bionet .row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .6rem }
|
|
26
|
+
.bionet .row.tight { margin-top: 0; gap: .35rem; flex-wrap: nowrap }
|
|
27
|
+
.bionet label { display: grid; gap: .25rem; font-size: .86rem; color: var(--bionet-dim) }
|
|
28
|
+
.bionet label.check { display: flex; align-items: center; gap: .4rem; color: var(--bionet-ink) }
|
|
29
|
+
.bionet input, .bionet textarea, .bionet select { font: inherit; color: var(--bionet-ink); background: var(--bionet-field); border: 1px solid var(--bionet-rule); border-radius: 6px; padding: .4rem .55rem; min-width: 0 }
|
|
30
|
+
.bionet form.row input:not(.num):not([type=checkbox]) { flex: 1 }
|
|
31
|
+
.bionet textarea { font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; resize: vertical }
|
|
32
|
+
.bionet input.num { width: 5.2rem } .bionet input[type=checkbox] { width: auto; accent-color: var(--bionet-yours) }
|
|
33
|
+
.bionet input:focus-visible, .bionet textarea:focus-visible, .bionet select:focus-visible, .bionet button:focus-visible { outline: 2px solid var(--bionet-yours); outline-offset: 1px }
|
|
34
|
+
.bionet button { font: inherit; border-radius: 6px; padding: .42rem .8rem; border: 1px solid var(--bionet-action); background: var(--bionet-action); color: var(--bionet-on-action); cursor: pointer; white-space: nowrap }
|
|
35
|
+
.bionet button.quiet { background: transparent; color: var(--bionet-ink); border-color: var(--bionet-rule) }
|
|
36
|
+
.bionet button.quiet:hover { border-color: var(--bionet-dim) }
|
|
37
|
+
.bionet button.plain { background: none; border: 0; color: var(--bionet-dim); text-decoration: underline; padding: 0 .3rem }
|
|
38
|
+
.bionet button:disabled, .bionet fieldset:disabled button { opacity: .55; cursor: default }
|
|
39
|
+
.bionet table { width: 100%; border-collapse: collapse; margin: .5rem 0 .2rem }
|
|
40
|
+
.bionet th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--bionet-dim); font-weight: 600; padding: .3rem .5rem .3rem 0; border-bottom: 1px solid var(--bionet-rule) }
|
|
41
|
+
.bionet td { padding: .45rem .5rem .45rem 0; border-bottom: 1px solid var(--bionet-rule); vertical-align: middle }
|
|
42
|
+
.bionet tr:last-child td { border-bottom: 0 } .bionet tr.gone td { color: var(--bionet-dim) }
|
|
43
|
+
.bionet tr.flagged td { background: color-mix(in srgb, var(--bionet-attention) 9%, transparent) }
|
|
44
|
+
.bionet .parthead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem } .bionet .parthead p { margin: 0 }
|
|
45
|
+
.bionet .badge { display: inline-block; margin-left: .5rem; padding: .05rem .45rem; border-radius: 999px; font-size: .74rem; border: 1px solid var(--bionet-attention); color: var(--bionet-attention) }
|
|
46
|
+
.bionet .badge.calm { border-color: var(--bionet-rule); color: var(--bionet-dim) }
|
|
47
|
+
.bionet .keybox { border: 1px dashed var(--bionet-rule); border-radius: 8px; padding: .7rem .8rem; margin: .8rem 0 }
|
|
48
|
+
.bionet .keybox > div { display: flex; justify-content: space-between; align-items: center; margin-bottom: .35rem } .bionet .keybox p { margin: .4rem 0 0 }
|
|
49
|
+
.bionet .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--bionet-dim); font-weight: 600 }
|
|
50
|
+
.bionet .sync { display: flex; align-items: center; gap: .5rem; font-size: .86rem; color: var(--bionet-dim); white-space: nowrap }
|
|
51
|
+
.bionet .dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--bionet-dim) }
|
|
52
|
+
.bionet .dot.synced { background: var(--bionet-good) } .bionet .dot.syncing, .bionet .dot.connecting { background: var(--bionet-yours) }
|
|
53
|
+
.bionet .dot.waiting { background: var(--bionet-held) }
|
|
54
|
+
.bionet .trouble { background: color-mix(in srgb, var(--bionet-attention) 12%, transparent); border: 1px solid var(--bionet-attention); border-radius: 8px; padding: .55rem .8rem; display: flex; justify-content: space-between; gap: 1rem }
|
|
55
|
+
.bionet .note { border-left: 3px solid var(--bionet-held); padding: .1rem 0 .1rem .7rem; font-size: .9rem }
|
|
56
|
+
.bionet h3 { font-size: .92rem; margin: 1.2rem 0 .3rem }
|
|
57
|
+
.bionet a { color: inherit; text-decoration-color: var(--bionet-dim); text-underline-offset: 2px }
|
|
58
|
+
.bionet .good { color: var(--bionet-good) } .bionet .bad { color: var(--bionet-attention) }
|
|
59
|
+
.bionet main.page { max-width: 46rem; margin: 0 auto; padding: 3rem 1.25rem 6rem; overflow: visible; font-size: 15px; line-height: 1.65 }
|
|
60
|
+
.bionet main.page .title { margin-bottom: .6rem } .bionet main.page h1 { font-size: 1.6rem }
|
|
61
|
+
.bionet main.page h2 { font-size: 1.1rem; margin: 2.4rem 0 .6rem; padding-bottom: .3rem; border-bottom: 1px solid var(--bionet-rule) }
|
package/src/freezer.tsx
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/** The freezer: every part, its tubes, and what can be done to them. */
|
|
4
|
+
import type { ItemState, PartState } from "@biolibs/bionet";
|
|
5
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
6
|
+
import { Ask } from "./parts.js";
|
|
7
|
+
|
|
8
|
+
const whole = (data: FormData, name: string): number => Number(String(data.get(name) ?? "").trim());
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* How much of an item there is, with its unit.
|
|
12
|
+
*
|
|
13
|
+
* @param item - The item.
|
|
14
|
+
* @returns Something like `7 µL`.
|
|
15
|
+
*/
|
|
16
|
+
export const amountOf = (item: Pick<ItemState, "amount" | "unit">): string => `${item.amount}${item.unit === null ? "" : ` ${item.unit}`}`;
|
|
17
|
+
|
|
18
|
+
/** Every part with its tubes, and a form to add a part. Draws nothing until the lab has arrived. */
|
|
19
|
+
export function Freezer() {
|
|
20
|
+
const lab = useLab()?.lab;
|
|
21
|
+
const act = useAct();
|
|
22
|
+
if (lab === null || lab === undefined) return null;
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
{lab.parts.length === 0 && <p className="empty">Nothing in the freezer yet. Add the first part below.</p>}
|
|
26
|
+
{lab.parts.map((part) => <PartCard key={part.checksum} part={part} items={lab.items.filter((item) => item.part === part.checksum)} />)}
|
|
27
|
+
<section className="card">
|
|
28
|
+
<h2>Add a part</h2>
|
|
29
|
+
<p className="dim small">A part is a molecule, known by the checksum of its sequence. Two people adding the same sequence get the same part, whatever each calls it.</p>
|
|
30
|
+
<Ask onAsk={(data) => act("addPart", { name: String(data.get("name") ?? ""), sequence: String(data.get("sequence") ?? ""), circular: data.get("circular") === "on" })} className="stack">
|
|
31
|
+
<label>Name<input name="name" placeholder="pUC19" required maxLength={200} /></label>
|
|
32
|
+
<label>Sequence<textarea name="sequence" placeholder="GGATCACAGTCTACACTGCTCACTCC…" required rows={3} spellCheck={false} /></label>
|
|
33
|
+
<label className="check"><input type="checkbox" name="circular" /> It is a circle</label>
|
|
34
|
+
<button type="submit">Add part</button>
|
|
35
|
+
</Ask>
|
|
36
|
+
</section>
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One part and its tubes. */
|
|
42
|
+
export function PartCard({ part, items }: { part: PartState; items: ItemState[] }) {
|
|
43
|
+
const act = useAct();
|
|
44
|
+
const live = items.filter((item) => !item.retired);
|
|
45
|
+
return (
|
|
46
|
+
<section className="card part">
|
|
47
|
+
<div className="parthead">
|
|
48
|
+
<div>
|
|
49
|
+
<h2>{part.name}</h2>
|
|
50
|
+
<p className="dim small">{part.length} bp{part.circular ? " · circular" : ""} · <code>{part.checksum.slice(0, 26)}…</code></p>
|
|
51
|
+
</div>
|
|
52
|
+
<label className="check" title="Whether other labs are told this part can be asked for">
|
|
53
|
+
<input type="checkbox" checked={part.offered} onChange={(event) => void act("offer", { part: part.checksum, available: event.target.checked })} />
|
|
54
|
+
On offer to other labs
|
|
55
|
+
</label>
|
|
56
|
+
</div>
|
|
57
|
+
{live.length === 0 ? <p className="dim small">No tubes of this.</p> : (
|
|
58
|
+
<table>
|
|
59
|
+
<thead><tr><th>Tube</th><th>Amount</th><th>Use or add</th><th>Count</th><th /></tr></thead>
|
|
60
|
+
<tbody>{live.map((item) => <ItemRow key={item.item} item={item} />)}</tbody>
|
|
61
|
+
</table>
|
|
62
|
+
)}
|
|
63
|
+
<Ask onAsk={(data) => act("addItem", { part: part.checksum, amount: whole(data, "amount"), unit: String(data.get("unit") ?? "") })} className="row tight">
|
|
64
|
+
<input name="amount" type="number" min={0} step={1} placeholder="Amount" required />
|
|
65
|
+
<input name="unit" placeholder="Unit, e.g. µL" maxLength={20} />
|
|
66
|
+
<button type="submit" className="quiet">Add a tube</button>
|
|
67
|
+
</Ask>
|
|
68
|
+
</section>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One tube: how much there is, and the ways to change that. */
|
|
73
|
+
export function ItemRow({ item }: { item: ItemState }) {
|
|
74
|
+
const act = useAct();
|
|
75
|
+
return (
|
|
76
|
+
<tr className={item.needsRecount ? "flagged" : undefined}>
|
|
77
|
+
<td><code>{item.item.slice(0, 10)}…</code></td>
|
|
78
|
+
<td>
|
|
79
|
+
<strong>{amountOf(item)}</strong>
|
|
80
|
+
{item.needsRecount && <span className="badge" title="The log has lost track of this tube: it went below zero, or two people counted it at once.">needs a count</span>}
|
|
81
|
+
</td>
|
|
82
|
+
<td>
|
|
83
|
+
<div className="row tight">
|
|
84
|
+
<button type="button" className="quiet" onClick={() => void act("adjust", { item: item.item, by: -1 })}>−1</button>
|
|
85
|
+
<button type="button" className="quiet" onClick={() => void act("adjust", { item: item.item, by: 1 })}>+1</button>
|
|
86
|
+
<Ask onAsk={(data) => act("adjust", { item: item.item, by: whole(data, "by") })} className="row tight">
|
|
87
|
+
<input name="by" type="number" step={1} placeholder="±" required className="num" aria-label="Change by" />
|
|
88
|
+
<button type="submit" className="quiet">Apply</button>
|
|
89
|
+
</Ask>
|
|
90
|
+
</div>
|
|
91
|
+
</td>
|
|
92
|
+
<td>
|
|
93
|
+
<Ask onAsk={(data) => act("recount", { item: item.item, amount: whole(data, "amount") })} className="row tight">
|
|
94
|
+
<input name="amount" type="number" min={0} step={1} placeholder="There is" required className="num" aria-label="Amount there is" />
|
|
95
|
+
<button type="submit" className="quiet">Set</button>
|
|
96
|
+
</Ask>
|
|
97
|
+
</td>
|
|
98
|
+
<td><button type="button" className="plain" onClick={() => void act("retire", { item: item.item })}>retire</button></td>
|
|
99
|
+
</tr>
|
|
100
|
+
);
|
|
101
|
+
}
|
package/src/history.tsx
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/** The history: every signed change, and what became of it. */
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import type { EntryView, LabView } from "@biolibs/bionet-client";
|
|
6
|
+
import { useLab } from "@biolibs/bionet-react";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What one change was, in words.
|
|
10
|
+
*
|
|
11
|
+
* @param entry - The change.
|
|
12
|
+
* @param lab - The lab, to name the parts, tubes and people it refers to.
|
|
13
|
+
* @returns A phrase that follows the name of whoever made it, like `used 2 µL of a tube of f1`.
|
|
14
|
+
*/
|
|
15
|
+
export function describeEntry(entry: Pick<EntryView, "op">, lab: Pick<LabView, "parts" | "items" | "roster">): string {
|
|
16
|
+
const op = entry.op;
|
|
17
|
+
const part = (checksum: unknown): string => lab.parts.find((one) => one.checksum === checksum)?.name ?? "a part";
|
|
18
|
+
const tube = (id: unknown): string => {
|
|
19
|
+
const item = lab.items.find((one) => one.item === id);
|
|
20
|
+
return item === undefined ? "a tube" : `a tube of ${part(item.part)}`;
|
|
21
|
+
};
|
|
22
|
+
const unit = (id: unknown): string => lab.items.find((one) => one.item === id)?.unit ?? "";
|
|
23
|
+
const who = (key: unknown): string => lab.roster.find((one) => one.key === key)?.person ?? "a device";
|
|
24
|
+
const tidy = (words: string): string => words.replace(/\s+/g, " ").trim();
|
|
25
|
+
switch (op.type) {
|
|
26
|
+
case "roster.found": return `founded ${String(op["name"])}`;
|
|
27
|
+
case "roster.add": return `added ${String(op["person"])} as a ${String(op["role"])}`;
|
|
28
|
+
case "roster.remove": return `removed ${who(op["key"])}`;
|
|
29
|
+
case "roster.role": return `made ${who(op["key"])} a ${String(op["role"])}`;
|
|
30
|
+
case "part.add": return `added the part ${String(op["name"])}`;
|
|
31
|
+
case "part.offer": return op["available"] === true ? `put ${part(op["part"])} on offer` : `took ${part(op["part"])} off offer`;
|
|
32
|
+
case "item.add": return tidy(`added ${tube(op["item"])}, ${String(op["amount"])} ${String(op["unit"] ?? "")}`);
|
|
33
|
+
case "item.adjust": return tidy(`${Number(op["by"]) < 0 ? "used" : "added"} ${Math.abs(Number(op["by"]))} ${unit(op["item"])} ${Number(op["by"]) < 0 ? "of" : "to"} ${tube(op["item"])}`);
|
|
34
|
+
case "item.recount": return tidy(`counted ${String(op["amount"])} ${unit(op["item"])} in ${tube(op["item"])}`);
|
|
35
|
+
case "item.retire": return `retired ${tube(op["item"])}`;
|
|
36
|
+
case "field.set": return `set ${String(op["field"])} to ${String(op["value"])}`;
|
|
37
|
+
default: return `did something this version does not know (${op.type})`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Every change, newest first, with what became of each. Draws nothing until the lab has arrived. */
|
|
42
|
+
export function History({ first = 40 }: { first?: number }) {
|
|
43
|
+
const lab = useLab()?.lab;
|
|
44
|
+
const [all, setAll] = useState(false);
|
|
45
|
+
if (lab === null || lab === undefined) return null;
|
|
46
|
+
const newest = [...lab.entries].reverse();
|
|
47
|
+
const shown = all ? newest : newest.slice(0, first);
|
|
48
|
+
return (
|
|
49
|
+
<section className="card">
|
|
50
|
+
<h2>Everything that has happened</h2>
|
|
51
|
+
<p className="dim small">Each line is one signed change. The time is what the signer's computer said, which is a claim; the order is worked out from what each person had seen.</p>
|
|
52
|
+
{lab.overlaps.length > 0 && <p className="note">{lab.overlaps.length} {lab.overlaps.length === 1 ? "pair of changes was" : "pairs of changes were"} made without knowledge of each other. One of each stood; both are below.</p>}
|
|
53
|
+
{lab.waiting > 0 && <p className="note">{lab.waiting} {lab.waiting === 1 ? "change is" : "changes are"} waiting on others that have not arrived yet.</p>}
|
|
54
|
+
<table>
|
|
55
|
+
<thead><tr><th>When</th><th>Who</th><th>What</th><th /></tr></thead>
|
|
56
|
+
<tbody>
|
|
57
|
+
{shown.map((entry) => (
|
|
58
|
+
<tr key={entry.id} className={entry.status === "applied" ? undefined : "gone"}>
|
|
59
|
+
<td className="dim nowrap">{new Date(entry.signedAt).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" })}</td>
|
|
60
|
+
<td>{entry.signer ?? lab.roster.find((one) => one.key === entry.author)?.person ?? "unknown"}</td>
|
|
61
|
+
<td>{describeEntry(entry, lab)}</td>
|
|
62
|
+
<td>{entry.status !== "applied" && <span className="badge" title={entry.reason ?? ""}>{entry.status}</span>}</td>
|
|
63
|
+
</tr>
|
|
64
|
+
))}
|
|
65
|
+
</tbody>
|
|
66
|
+
</table>
|
|
67
|
+
{!all && newest.length > shown.length && <button type="button" className="quiet" onClick={() => setAll(true)}>Show all {newest.length}</button>}
|
|
68
|
+
</section>
|
|
69
|
+
);
|
|
70
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* `@biolibs/bionet-panels`: the parts of a Bionet lab application, ready to place.
|
|
4
|
+
*
|
|
5
|
+
* Each panel reads the lab through `@biolibs/bionet-react`, so it goes anywhere inside a
|
|
6
|
+
* `LabProvider`, and takes its colours from `@biolibs/bionet-theme`, so it follows a light or dark
|
|
7
|
+
* theme. `LabWindow` is all of them put together: a whole application in one component.
|
|
8
|
+
*
|
|
9
|
+
* Import `@biolibs/bionet-theme/theme.css` and `@biolibs/bionet-panels/panels.css` once. The panels'
|
|
10
|
+
* styles apply only inside an element with the class `bionet`, which `LabWindow` supplies; put a
|
|
11
|
+
* panel used on its own inside one.
|
|
12
|
+
*
|
|
13
|
+
* - `window.tsx` — `LabWindow`, and the screens before there is a lab
|
|
14
|
+
* - `freezer.tsx` — parts, tubes, amounts
|
|
15
|
+
* - `people.tsx` — the roster, and letting somebody in
|
|
16
|
+
* - `history.tsx` — every signed change, and what became of it
|
|
17
|
+
* - `sharing.tsx` — what other labs are shown, and the lab's web peer
|
|
18
|
+
* - `parts.tsx` — the small pieces they are made of
|
|
19
|
+
* - `public.tsx` — a lab's public page: what it holds, and what it can see of another lab
|
|
20
|
+
*
|
|
21
|
+
* Everything but `public.tsx` uses hooks and is marked `"use client"`, for frameworks that draw on a
|
|
22
|
+
* server first. The public page's pieces take plain values and can be drawn there.
|
|
23
|
+
*/
|
|
24
|
+
export * from "./window.js";
|
|
25
|
+
export * from "./freezer.js";
|
|
26
|
+
export * from "./people.js";
|
|
27
|
+
export * from "./history.js";
|
|
28
|
+
export * from "./sharing.js";
|
|
29
|
+
export * from "./parts.js";
|
|
30
|
+
export * from "./public.js";
|