fix(panel): projects table fits narrow widths, keeps loaded versions on refresh, skips settings
The projects table sits in a min-width-0 host so fitColumns can drop columns. A live refresh re-reads only the changed, expanded projects and keeps as many versions as were shown (Load more included). Version pages ask for the summary form, so the panel no longer downloads settings it never shows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
26bab759fe
commit
353024fc71
4 files changed
+54
-10
No files matched your search
@@ -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. */
|
||||
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). */
|
||||
const MAX_NAME = 60;
|
||||
/** 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();
|
||||
let timer = 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 = `
|
||||
<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 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 {
|
||||
projects = await api.get(base);
|
||||
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) {
|
||||
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) {
|
||||
projects = [];
|
||||
failed = errorText(err);
|
||||
@@ -58,14 +67,23 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
||||
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 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 });
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
expanded.delete(id);
|
||||
versions.delete(id);
|
||||
@@ -222,9 +240,13 @@ export function projectsSection(host, meta, { api, sequenceId }) {
|
||||
return {
|
||||
onEvent(e) {
|
||||
if ((e.type === "projectChanged" && e.sequenceId === sequenceId) || e.type === "reconnected") {
|
||||
if (e.type === "reconnected") changed = null;
|
||||
else changed?.add(e.projectId);
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
if (host.isConnected) load();
|
||||
const stale = changed;
|
||||
changed = new Set();
|
||||
if (host.isConnected) load(stale);
|
||||
}, AFTER_CHANGE_MS);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user