feat: owner review 2 phase 5b: the server as a project home #17
No files matched your search
@@ -387,7 +387,9 @@ textarea.input.notes { height: auto; min-height: 64px; padding: 6px 10px; resize
|
|||||||
.frame-badge.hero { color: var(--sun); }
|
.frame-badge.hero { color: var(--sun); }
|
||||||
.frame-badge.warn { top: auto; bottom: 4px; inset-inline: 4px auto; color: var(--warning); }
|
.frame-badge.warn { top: auto; bottom: 4px; inset-inline: 4px auto; color: var(--warning); }
|
||||||
.table.renders { grid-template-columns: minmax(100px, 1.4fr) max-content max-content max-content max-content max-content; }
|
.table.renders { grid-template-columns: minmax(100px, 1.4fr) max-content max-content max-content max-content max-content; }
|
||||||
/* A sequence's projects (owner review 2, R8) and, under one opened, its versions. */
|
/* A sequence's projects (owner review 2, R8) and, under one opened, its versions. Their table sits in a wrapper, a grid item
|
||||||
|
of the panel: it may be narrower than the table, so the table's columns fit (fitColumns) instead of the panel scrolling. */
|
||||||
|
.panel > .table-host { min-width: 0; }
|
||||||
.table.projects { grid-template-columns: minmax(120px, 1.4fr) max-content minmax(120px, 1.2fr) max-content; }
|
.table.projects { grid-template-columns: minmax(120px, 1.4fr) max-content minmax(120px, 1.2fr) max-content; }
|
||||||
.table.projects.fit-1 { grid-template-columns: minmax(120px, 1fr) max-content max-content; }
|
.table.projects.fit-1 { grid-template-columns: minmax(120px, 1fr) max-content max-content; }
|
||||||
.table.projects.fit-1 .col-changed { display: none; }
|
.table.projects.fit-1 .col-changed { display: none; }
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { escapeHtml, attr, formatNumber, formatDateTime, toast, errorText, confi
|
|||||||
|
|
||||||
/** Versions read at a time when a project is opened, and with each Load more. */
|
/** Versions read at a time when a project is opened, and with each Load more. */
|
||||||
const VERSION_PAGE = 20;
|
const VERSION_PAGE = 20;
|
||||||
|
/** The most versions one read of them gives (ProjectEndpoints.MaxPage): a refresh reads again as many as are shown, up to this. */
|
||||||
|
const MAX_PAGE = 200;
|
||||||
/** A project name, as the server takes it (ProjectService.MaxNameLength). */
|
/** A project name, as the server takes it (ProjectService.MaxNameLength). */
|
||||||
const MAX_NAME = 60;
|
const MAX_NAME = 60;
|
||||||
/** The name every sequence's Main project is made with; shown in the panel's language. */
|
/** The name every sequence's Main project is made with; shown in the panel's language. */
|
||||||
@@ -27,6 +29,8 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
|||||||
const expanded = new Set();
|
const expanded = new Set();
|
||||||
let timer = null;
|
let timer = null;
|
||||||
let failed = null;
|
let failed = null;
|
||||||
|
/** The projects a projectChanged named since the last read; null after a reconnection, when any may have changed. */
|
||||||
|
let changed = new Set();
|
||||||
|
|
||||||
host.innerHTML = `
|
host.innerHTML = `
|
||||||
<div class="table projects" data-levels="1" role="table" aria-labelledby="projects-title">
|
<div class="table projects" data-levels="1" role="table" aria-labelledby="projects-title">
|
||||||
@@ -40,15 +44,20 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
|||||||
const table = host.querySelector(".table");
|
const table = host.querySelector(".table");
|
||||||
const rows = host.querySelector("#project-rows");
|
const rows = host.querySelector("#project-rows");
|
||||||
|
|
||||||
async function load() {
|
/**
|
||||||
|
* Reads the projects again, and the versions of those opened that may have changed (every one when stale is null): as
|
||||||
|
* many as are shown, so the pages Load more read stay.
|
||||||
|
*/
|
||||||
|
async function load(stale = null) {
|
||||||
try {
|
try {
|
||||||
projects = await api.get(base);
|
projects = await api.get(base);
|
||||||
failed = null;
|
failed = null;
|
||||||
// A project deleted meanwhile (here or elsewhere) closes; the others' versions are read again.
|
// A project deleted meanwhile (here or elsewhere) closes; the versions of the others that changed are read again.
|
||||||
for (const id of expanded) {
|
for (const id of expanded) {
|
||||||
if (!projects.some((p) => p.id === id)) forget(id);
|
if (!projects.some((p) => p.id === id)) forget(id);
|
||||||
}
|
}
|
||||||
await Promise.all([...expanded].map((id) => loadVersions(id).catch(() => forget(id))));
|
const again = [...expanded].filter((id) => stale === null || stale.has(id));
|
||||||
|
await Promise.all(again.map((id) => reloadVersions(id).catch(() => forget(id))));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
projects = [];
|
projects = [];
|
||||||
failed = errorText(err);
|
failed = errorText(err);
|
||||||
@@ -58,14 +67,23 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
|||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The newest versions of a project, or with more the next page after those shown. */
|
/**
|
||||||
async function loadVersions(id, more = false) {
|
* The newest versions of a project, or with more the next page after those shown. Read without their settings
|
||||||
|
* (summary): the panel shows none, and a large sequence's versions are megabytes each.
|
||||||
|
*/
|
||||||
|
async function loadVersions(id, more = false, limit = VERSION_PAGE) {
|
||||||
const known = versions.get(id);
|
const known = versions.get(id);
|
||||||
const before = more && known?.items.length ? `&before=${known.items[known.items.length - 1].number}` : "";
|
const before = more && known?.items.length ? `&before=${known.items[known.items.length - 1].number}` : "";
|
||||||
const page = await api.get(`${base}/${encodeURIComponent(id)}/versions?limit=${VERSION_PAGE}${before}`);
|
const page = await api.get(`${base}/${encodeURIComponent(id)}/versions?limit=${limit}${before}&summary=true`);
|
||||||
versions.set(id, { items: more && known ? known.items.concat(page.items) : page.items, more: page.more });
|
versions.set(id, { items: more && known ? known.items.concat(page.items) : page.items, more: page.more });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The newest versions of a project read again, as many as are shown (at least a page, at most MAX_PAGE). */
|
||||||
|
function reloadVersions(id) {
|
||||||
|
const shown = versions.get(id)?.items.length ?? 0;
|
||||||
|
return loadVersions(id, false, Math.min(MAX_PAGE, Math.max(VERSION_PAGE, shown)));
|
||||||
|
}
|
||||||
|
|
||||||
function forget(id) {
|
function forget(id) {
|
||||||
expanded.delete(id);
|
expanded.delete(id);
|
||||||
versions.delete(id);
|
versions.delete(id);
|
||||||
@@ -222,9 +240,13 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
|||||||
return {
|
return {
|
||||||
onEvent(e) {
|
onEvent(e) {
|
||||||
if ((e.type === "projectChanged" && e.sequenceId === sequenceId) || e.type === "reconnected") {
|
if ((e.type === "projectChanged" && e.sequenceId === sequenceId) || e.type === "reconnected") {
|
||||||
|
if (e.type === "reconnected") changed = null;
|
||||||
|
else changed?.add(e.projectId);
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = setTimeout(() => {
|
timer = setTimeout(() => {
|
||||||
if (host.isConnected) load();
|
const stale = changed;
|
||||||
|
changed = new Set();
|
||||||
|
if (host.isConnected) load(stale);
|
||||||
}, AFTER_CHANGE_MS);
|
}, AFTER_CHANGE_MS);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export async function renderSequence(root, { api, setMeta, actions, onEvent }, i
|
|||||||
</section>
|
</section>
|
||||||
<section class="panel flush" aria-labelledby="projects-title">
|
<section class="panel flush" aria-labelledby="projects-title">
|
||||||
<div class="panel-head padded"><h2 id="projects-title" data-i18n="Admin.Projects.Title"></h2><span class="muted ellipsis" id="projects-meta"></span></div>
|
<div class="panel-head padded"><h2 id="projects-title" data-i18n="Admin.Projects.Title"></h2><span class="muted ellipsis" id="projects-meta"></span></div>
|
||||||
<div id="projects"></div>
|
<div id="projects" class="table-host"></div>
|
||||||
</section>
|
</section>
|
||||||
<section class="panel flush" aria-labelledby="renders-title">
|
<section class="panel flush" aria-labelledby="renders-title">
|
||||||
<div class="panel-head padded"><h2 id="renders-title" data-i18n="Admin.Sequence.Renders"></h2></div>
|
<div class="panel-head padded"><h2 id="renders-title" data-i18n="Admin.Sequence.Renders"></h2></div>
|
||||||
|
|||||||
@@ -43,7 +43,16 @@ public sealed partial class AdminProjectsTests(TestContext context)
|
|||||||
Assert.True(!Regex.IsMatch(projects, @"\son[a-z]+="""), "inline handler");
|
Assert.True(!Regex.IsMatch(projects, @"\son[a-z]+="""), "inline handler");
|
||||||
// It lists, opens versions, renames and deletes: no push, no restore, no settings (R6: the panel manages, never edits).
|
// It lists, opens versions, renames and deletes: no push, no restore, no settings (R6: the panel manages, never edits).
|
||||||
Assert.Contains("projects = await api.get(base);", projects);
|
Assert.Contains("projects = await api.get(base);", projects);
|
||||||
Assert.Contains("api.get(`${base}/${encodeURIComponent(id)}/versions?limit=${VERSION_PAGE}${before}`)", projects);
|
// Versions are read without their settings, which the panel never shows (a large sequence's are megabytes each).
|
||||||
|
Assert.Contains("api.get(`${base}/${encodeURIComponent(id)}/versions?limit=${limit}${before}&summary=true`)", projects);
|
||||||
|
// A live refresh reads again only the opened projects an event named (every one after a reconnection), as many
|
||||||
|
// versions as are shown: the pages Load more read stay.
|
||||||
|
Assert.Contains("const again = [...expanded].filter((id) => stale === null || stale.has(id));", projects);
|
||||||
|
Assert.Contains("return loadVersions(id, false, Math.min(MAX_PAGE, Math.max(VERSION_PAGE, shown)));", projects);
|
||||||
|
Assert.Contains("else changed?.add(e.projectId);", projects);
|
||||||
|
// The table's wrapper may be narrower than the table (a grid item of the panel), so its columns fit on a phone.
|
||||||
|
Assert.Contains(@"<div id=""projects"" class=""table-host""></div>", page);
|
||||||
|
Assert.Contains(".panel > .table-host { min-width: 0; }", await server.Client.GetStringAsync("/admin/admin.css"));
|
||||||
Assert.Contains("await api.patch(`${base}/${encodeURIComponent(project.id)}`, { name });", projects);
|
Assert.Contains("await api.patch(`${base}/${encodeURIComponent(project.id)}`, { name });", projects);
|
||||||
Assert.Contains("await api.del(`${base}/${encodeURIComponent(project.id)}`);", projects);
|
Assert.Contains("await api.del(`${base}/${encodeURIComponent(project.id)}`);", projects);
|
||||||
Assert.False(projects.Contains("api.post(", StringComparison.Ordinal), "the panel pushes or makes nothing");
|
Assert.False(projects.Contains("api.post(", StringComparison.Ordinal), "the panel pushes or makes nothing");
|
||||||
@@ -110,6 +119,17 @@ public sealed partial class AdminProjectsTests(TestContext context)
|
|||||||
Assert.Equal((1, "imported"), (first.GetProperty("number").GetInt32(), first.GetProperty("kind").GetString()));
|
Assert.Equal((1, "imported"), (first.GetProperty("number").GetInt32(), first.GetProperty("kind").GetString()));
|
||||||
Assert.True(first.TryGetProperty("storedAt", out _) && first.TryGetProperty("createdAt", out _) && first.TryGetProperty("clientName", out _));
|
Assert.True(first.TryGetProperty("storedAt", out _) && first.TryGetProperty("createdAt", out _) && first.TryGetProperty("clientName", out _));
|
||||||
Assert.False(json.RootElement.GetProperty("more").GetBoolean());
|
Assert.False(json.RootElement.GetProperty("more").GetBoolean());
|
||||||
|
Assert.NotEqual(string.Empty, first.GetProperty("settingsJson").GetString());
|
||||||
|
}
|
||||||
|
// The page's own form: the same versions, without their settings.
|
||||||
|
using (var versions = await browser.SendAsync(HttpMethod.Get, $"{url}/{vertical}/versions?limit=20&summary=true"))
|
||||||
|
{
|
||||||
|
await versions.ExpectAsync(HttpStatusCode.OK);
|
||||||
|
using var json = JsonDocument.Parse(await versions.Content.ReadAsStringAsync());
|
||||||
|
var first = json.RootElement.GetProperty("items").EnumerateArray().Single();
|
||||||
|
Assert.Equal((1, "imported", string.Empty), (first.GetProperty("number").GetInt32(), first.GetProperty("kind").GetString(),
|
||||||
|
first.GetProperty("settingsJson").GetString()));
|
||||||
|
Assert.Equal(64, first.GetProperty("contentHash").GetString()!.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var renamed = await browser.SendAsync(HttpMethod.Patch, $"{url}/{vertical}", Json("""{"name":"Vertical"}""")))
|
using (var renamed = await browser.SendAsync(HttpMethod.Patch, $"{url}/{vertical}", Json("""{"name":"Vertical"}""")))
|
||||||
|
|||||||
Reference in new issue
Block a user