diff --git a/CHANGELOG.md b/CHANGELOG.md index 407c2252..09f51c89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ versions may change the store format and the API; the release notes say how to u ### Fixed +- The web UI's Import page no longer shows the word `null` under the file's card when the server runs without `--schema-tools`, nor after **Add to the graph** when no file is left to import (#801). - The Python package's README installs the `rdflib` extra from PyPI in its rdflib section too, `pip install "tripletrail[rdflib]"`, instead of from a checkout (#807). - A failing command prints its error as a sentence that names the file or address, such as `Error: missing.ttl does not exist` or `Error: cannot listen on 127.0.0.1:7878: address already in use` (#804). Before, `load`, `validate` and `serve` printed Rust's debug form, `Error: Os { code: 2, kind: NotFound, … }`, which did not say which file of several was missing, and other errors came out quoted (`Error: "1 of 1 queries failed"`). See [the server options](docs/server.md#main-options). - `geof:length(?g, uom:metre)` answers on a projected CRS (#786): GeoSPARQL 1.1's form with a unit was unbound for `geof:length`, `geof:perimeter`, `geof:area` and `geof:size` on every CRS, while `geof:metricLength` and `st:ST_Length` gave the length. They now give the `metric*` value in metres or kilometres (square metres or kilometres for an area); another unit is still unbound. `geof:distance` and `geof:buffer` took a unit already. See [docs/spatial.md](docs/spatial.md). diff --git a/crates/tripletrail-server/ui-tests/test/add-data.test.mjs b/crates/tripletrail-server/ui-tests/test/add-data.test.mjs index 4569905d..4b195526 100644 --- a/crates/tripletrail-server/ui-tests/test/add-data.test.mjs +++ b/crates/tripletrail-server/ui-tests/test/add-data.test.mjs @@ -28,6 +28,11 @@ const TTL = " 1 .\n"; let browser; +// No "null" written as text under `selector` (#801): `replaceChildren` writes a null child so. +async function noNull(page, selector) { + assert.doesNotMatch(await page.locator(selector).innerText(), /\bnull\b/, selector); +} + async function start(args, env = {}) { const child = spawn(bin, ["serve", "--bind", "127.0.0.1:0", "--dataset", "ds", ...args], { stdio: ["ignore", "pipe", "pipe"], @@ -115,6 +120,8 @@ test("files go from the drop to a named graph, and the lift into a workspace", a assert.equal(await page.locator("#imp-ns").inputValue(), "https://data.example.org/src/stations/"); assert.equal(await page.locator("#imp-kinds select").inputValue(), "id"); assert.deepEqual(await ask(base, "SELECT (COUNT(*) AS ?n) { ?s ?p ?o }"), ["n", "1"], "the Turtle file loaded"); + // Nothing where the server has no schema tools (#801). + await noNull(page, "#imp-work"); await page.click("#imp-run"); await page.locator("#imp-out", { hasText: "Added to urn:import:stations" }).waitFor(); @@ -157,6 +164,11 @@ test("files go from the drop to a named graph, and the lift into a workspace", a await page.waitForFunction(() => document.querySelector("#imp-query")?.value.includes("src:Tracks")); const kinds = await page.locator("#imp-kinds select").evaluateAll((s) => s.map((x) => x.dataset.kind)); assert.deepEqual(kinds, ["network", "stations", "tracks"]); + // The last file added: nothing where the next one would be (#801). + await page.click("#imp-run"); + await page.locator("#imp-out", { hasText: "Added to urn:import:network" }).waitFor(); + assert.equal(await page.locator("#imp-next").count(), 0); + await noNull(page, "#imp-work"); }); test("a file larger than the import keeps is drafted from its first lines", async (t) => { diff --git a/crates/tripletrail-server/ui/import.js b/crates/tripletrail-server/ui/import.js index a056ab24..e89fd0f8 100644 --- a/crates/tripletrail-server/ui/import.js +++ b/crates/tripletrail-server/ui/import.js @@ -25,6 +25,8 @@ window.TripleTrailImport = (function () { const page = () => document.getElementById("page-import"); const el = (...a) => ui.el(...a); const $ = (id) => document.getElementById(id); + // replaceChildren writes a null or false child as text (#801): left out here, as `el` does. + const fill = (node, ...children) => node.replaceChildren(...children.flat().filter((c) => c != null && c !== false)); const base = () => "/" + encodeURIComponent(ds) + "/import"; /** A request with the admin token, answered as text; errors as ApiError like ui.api. */ @@ -52,7 +54,7 @@ window.TripleTrailImport = (function () { } catch (e) { ui.fail(e); } let want = args[0] ? decodeURIComponent(args[0]) : null; if (!want || !datasets.includes(want)) want = ds && datasets.includes(ds) ? ds : ui.preferred(datasets); - if (!want) { root.replaceChildren(el("p", { class: "muted loading" }, "No dataset to import into yet.")); return; } + if (!want) { fill(root, el("p", { class: "muted loading" }, "No dataset to import into yet.")); return; } if (queue.length && queueFor && datasets.includes(queueFor)) want = queueFor; if (want !== ds) forget(); ds = want; @@ -72,7 +74,7 @@ window.TripleTrailImport = (function () { e.preventDefault(); drop.classList.remove("over"); if (e.dataTransfer.files[0]) read(e.dataTransfer.files[0]); }); - root.replaceChildren( + fill(root, el("div", { class: "query-bar" }, el("label", {}, "Dataset ", select), el("span", { class: "grow" }), el("span", { class: "muted small" }, "Turn a file into RDF with a query, and add it to a graph.")), drop, @@ -101,7 +103,7 @@ window.TripleTrailImport = (function () { async function read(f) { forget(); const work = $("imp-work"); - work.replaceChildren(el("p", { class: "muted loading" }, "Reading " + f.name + "…")); + fill(work, el("p", { class: "muted loading" }, "Reading " + f.name + "…")); // The server takes names of letters, digits, '.', '-' and '_'. const name = f.name.replace(/[^A-Za-z0-9._-]/g, "_").replace(/^\.+/, "") || "upload"; const max = await limit(); @@ -110,7 +112,7 @@ window.TripleTrailImport = (function () { // Too large to keep in memory: a file of lines is drafted from its first ones, to save // or download the query and lift the whole file with tripletrail lift or a pipeline. if (!/\.(csv|tsv|txt|jsonl|ndjson)$/i.test(f.name)) { - work.replaceChildren(el("div", { class: "card imp-card" }, + fill(work, el("div", { class: "card imp-card" }, el("p", { class: "error" }, `${f.name} is ${ui.fmtBytes(f.size)}, more than the ${ui.fmtBytes(max)} the import keeps in memory.`), el("p", {}, "Lift it with ", el("code", {}, "tripletrail lift"), " or a ", el("code", {}, "lift"), " step of a Workbench pipeline instead (see the guide, chapter 7), or start the server with a larger ", @@ -125,7 +127,7 @@ window.TripleTrailImport = (function () { try { upload = JSON.parse(await send("POST", base() + "?name=" + encodeURIComponent(name), body)); } catch (e) { - work.replaceChildren(el("p", { class: "error" }, e.message), next()); + fill(work, el("p", { class: "error" }, e.message), next()); return; } upload.file = f; @@ -175,12 +177,12 @@ window.TripleTrailImport = (function () { const [what, tool] = TOOLS[u.schemaTool] || ["a schema", "the schema tool"]; const out = el("div", { id: "imp-schema-made" }); const make = async (write) => { - out.replaceChildren(el("p", { class: "muted small" }, write ? "Adding…" : `Running ${tool}…`)); + fill(out, el("p", { class: "muted small" }, write ? "Adding…" : `Running ${tool}…`)); try { const m = JSON.parse(await send("POST", base() + "/" + encodeURIComponent(u.id) + "/schema", JSON.stringify({ kind: u.schemaTool, namespace: ($("imp-ns") || {}).value || u.namespace, write }))); const c = m.counts; - out.replaceChildren( + fill(out, el("p", {}, `${ui.fmtNum(c.ontology)} ontology, ${ui.fmtNum(c.shapes)} shape, ${ui.fmtNum(c.skos)} SKOS (${m.schemes.length} concept schemes) and ${ui.fmtNum(c.provenance)} provenance triples.`), m.warnings.length ? el("details", {}, el("summary", {}, `${m.warnings.length} warnings`), el("ul", {}, ...m.warnings.map((w) => el("li", {}, w)))) : null, m.graphs @@ -189,7 +191,7 @@ window.TripleTrailImport = (function () { el("button", { class: "btn primary", type: "button", id: "imp-schema-write", onclick: () => make(true) }, "Add to the dataset"), el("span", { class: "muted small" }, "Into the source's schema graphs, replacing what they held.")), el("details", {}, el("summary", {}, "The shapes"), el("pre", { class: "imp-tree" }, m.shapes))); - } catch (e) { out.replaceChildren(el("p", { class: "error" }, e.message || String(e))); } + } catch (e) { fill(out, el("p", { class: "error" }, e.message || String(e))); } }; return el("div", { class: "card imp-card", id: "imp-schema-card" }, el("div", { class: "toolbar" }, el("h2", {}, "Schema to RDF"), el("span", { class: "grow" }), @@ -206,12 +208,12 @@ window.TripleTrailImport = (function () { const u = upload; const graph = "urn:import:" + u.name.replace(/\.[^.]*$/, ""); const schemaNames = { xsd: "an XML Schema", "json-schema": "a JSON Schema", openapi: "an OpenAPI document" }; - $("imp-work").replaceChildren( + fill($("imp-work"), el("div", { class: "card imp-card" }, el("div", { class: "toolbar" }, el("h2", {}, u.name), el("span", { class: "muted small" }, ui.fmtBytes(u.bytes) + " · " + ui.fmtNum(u.triples) + (u.truncated ? "+" : "") + " triples as Facade-X" + (u.options ? " · " + u.options : "")), el("span", { class: "grow" }), - el("button", { class: "btn small", type: "button", onclick: () => { forget(); $("imp-work").replaceChildren(); } }, "Forget the file")), + el("button", { class: "btn small", type: "button", onclick: () => { forget(); fill($("imp-work")); } }, "Forget the file")), u.sample ? el("p", { class: "error", id: "imp-sample" }, `${u.file.name} is ${ui.fmtBytes(u.file.size)}, more than the import keeps in memory: the query is drafted from its first ${ui.fmtBytes(u.bytes)}. Save it as a lift query or download it, and lift the whole file with tripletrail lift or a pipeline.`) : null, u.schema ? el("p", { class: "muted small", id: "imp-schema" }, `The file names ${schemaNames[u.schema.kind] || "a schema"}` + (u.schema.location ? ": " + u.schema.location : "") + ". Generating an ontology and shapes from it is a step of its own (schema to RDF).") : null, el("details", { open: true }, el("summary", {}, "The file as triples" + (u.truncated ? " (the first ones)" : "")), @@ -254,7 +256,7 @@ window.TripleTrailImport = (function () { try { const nt = await send("POST", base() + "/" + upload.id + "/preview", query(), "application/n-triples"); const lines = nt.split("\n").filter(Boolean); - out.replaceChildren(el("h2", {}, "Preview: " + ui.fmtNum(lines.length) + " triples, nothing written"), + fill(out, el("h2", {}, "Preview: " + ui.fmtNum(lines.length) + " triples, nothing written"), el("pre", { class: "imp-tree" }, lines.slice(0, 500).join("\n") + (lines.length > 500 ? "\n…" : ""))); out.hidden = false; status(""); @@ -269,7 +271,7 @@ window.TripleTrailImport = (function () { const r = JSON.parse(await send("POST", base() + "/" + upload.id + "/run?graph=" + encodeURIComponent(graph), query())); status(""); const out = $("imp-out"); - out.replaceChildren(el("h2", {}, "Added to " + r.graph), + fill(out, el("h2", {}, "Added to " + r.graph), el("p", {}, "The graph had " + ui.fmtNum(r.before) + " triples and now has " + ui.fmtNum(r.after) + ". ", el("a", { href: UI + "query/" + encodeURIComponent(ds) + "?query=" + encodeURIComponent("SELECT * WHERE { GRAPH <" + r.graph + "> { ?s ?p ?o } } LIMIT 100") }, "Look at it")), next()); @@ -279,9 +281,9 @@ window.TripleTrailImport = (function () { } function fail(e) { - if (e.status === 404) { upload = null; $("imp-work").replaceChildren(el("p", { class: "error" }, e.message + ". Drop the file again.")); return; } + if (e.status === 404) { upload = null; fill($("imp-work"), el("p", { class: "error" }, e.message + ". Drop the file again.")); return; } const out = $("imp-out"); - out.replaceChildren(el("p", { class: "error" }, e.message)); + fill(out, el("p", { class: "error" }, e.message)); out.hidden = false; } @@ -303,7 +305,7 @@ window.TripleTrailImport = (function () { const c = AI && AI.connection(); const log = $("imp-ai-log"); if (!c) { - log.replaceChildren("Set up an AI service first: ", el("a", { href: UI + "workbench", "data-route": "" }, "Workbench, AI tab, “Key and model…”"), "."); + fill(log, "Set up an AI service first: ", el("a", { href: UI + "workbench", "data-route": "" }, "Workbench, AI tab, “Key and model…”"), "."); return; } if (aiAbort) { aiAbort.abort(); return; } @@ -405,7 +407,7 @@ window.TripleTrailImport = (function () { const pick = el("select", { id: "imp-ws", "aria-label": "Workspace" }, el("option", { value: "" }, "A new workspace: lift " + upload.name), list.map((w) => el("option", { value: w.id }, w.name || w.id))); - out.replaceChildren(el("h2", {}, "Save as lift query"), + fill(out, el("h2", {}, "Save as lift query"), el("p", { class: "muted small" }, `Writes lift/${stem}.rq, reading lift/${upload.name}` + (upload.sample ? "" : ", the file beside it") + `, and a lift step into graph ${$("imp-graph").value.trim()} in the workspace's pipeline.yaml.`), el("div", { class: "sb-actions" }, el("label", {}, "Workspace ", pick), el("button", { class: "btn primary", type: "button", id: "imp-ws-save", onclick: () => saveInto(pick.value, stem) }, "Save")), @@ -433,7 +435,7 @@ window.TripleTrailImport = (function () { const yaml = await wsSend("GET", files + "pipeline.yaml"); const step = ` - name: lift ${upload.name}\n lift: lift/${stem}.rq\n` + (/^[a-z][a-z0-9+.-]*:\S+$/i.test(graph) ? ` graph: ${graph}\n clear: true\n` : ""); if (!(yaml || "").includes(`lift: lift/${stem}.rq`)) await wsSend("PUT", files + "pipeline.yaml", withStep(yaml, step), "application/yaml"); - msg.replaceChildren("Saved. ", copied ? "" : `Put ${upload.name} into the workspace's lift/ folder, where the query reads it. `, + fill(msg, "Saved. ", copied ? "" : `Put ${upload.name} into the workspace's lift/ folder, where the query reads it. `, el("a", { href: UI + "workbench/" + encodeURIComponent(id), "data-route": "" }, "Open the workspace")); } catch (e) { msg.className = "error small";