Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/development/PERFORMANCE_BASELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ bundle sizes.
| Dashboard revisit | The fixture exercises 250 cached-snapshot clones. A revisit paints the saved view before starting background reads. |

The default Inventory card view reads up to 96 product groups with three spool
previews per card. Counts and weights cover the whole group. More groups and
previews per card. Closed roll menus render only their summary. Opening a menu
shows up to 100 loaded rolls, with further choices available on demand. Counts and weights cover the whole group. More groups and
up to 100 more members of one group can be requested separately. A changed
inventory or catalog revision restarts paging. Free-text card search matches
all terms on each spool before grouping and paging. Typing refreshes the card
Expand Down
47 changes: 45 additions & 2 deletions scripts/run-loan-dialog-regressions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ async function checkWorkspaceOffline({ page, state, fixture, calls, fallback, op
}

async function checkStockCards({page, state, fixture, calls, fallback, openWorkspace}) {
const target = {base_url: "https://cards.invalid", expected_library_id: "cards", target_generation: 3};
const target = {base_url: "http://cards.local:4278", expected_library_id: "cards", target_generation: 3};
const status = {mode:"CLIENT", host_base_url:target.base_url, library_id:"cards", target_generation:3,
client_auth_paired:true};
const first = fixture.spoolRows[0], later = fixture.spoolRows[1];
const hidden = {...later, master: {...later.master, filament_name: "Hidden search match"}, spool: {...later.spool, id: "hidden-roll"}};
const members = Array.from({length: 8}, (_, i) => ({...first, spool:{...first.spool,id:"card-member-" + i}}));
const cachedMembers = Array.from({length: 105}, (_, index) => ({
...hidden, spool: {...hidden.spool, id: `cached-${index.toString().padStart(6, "0")}`},
}));
const reads = [];
let mode = "live";
let revision = 1;
Expand Down Expand Up @@ -211,9 +214,10 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
case "fetch_library_sync_spool_snapshot":
if (mode === "offline") throw Error("[loan-regression] Host disconnected");
return {rows:[...members,later,hidden],captured_at:"2026-01-01"};
case "fetch_library_sync_spool_detail": throw Error("[loan-regression] Host disconnected");
case "fetch_cached_library_sync_spools":
assert.deepEqual(payload.input,target);
return {rows:[hidden],captured_at:"2026-01-01"};
return {rows:cachedMembers,captured_at:"2026-01-01"};
case "get_stock_purchase_count":
assert.deepEqual(payload.target,target);
return purchaseCount;
Expand Down Expand Up @@ -268,6 +272,17 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await panel.getByRole("heading", {name: /Dialog b/}).waitFor();
assert.equal(reads.length, readsBeforeRegistration, "Closing registration must retain the loaded card pages");
assert.ok(!calls.some(c=>c.command==="fetch_library_sync_spool_snapshot"));
const menu = panel.locator(".inventory-product-menu").first();
const summary = menu.locator("summary");
assert.equal(await menu.locator("button").count(), 0);
await summary.press("Enter");
const moreMenuRolls = menu.getByRole("button", {name: "Show more", exact: true});
await moreMenuRolls.press("Enter");
const fourth = menu.getByRole("button", {name: /Open roll/}).nth(3);
await fourth.waitFor();
assert.equal(await fourth.evaluate(button => document.activeElement === button), true);
await summary.press("Enter");
await fourth.waitFor({state: "detached"});
const searchBox = page.getByPlaceholder(/Search by material/i);
calls.length = 0;
await searchBox.fill("slow");
Expand Down Expand Up @@ -346,6 +361,34 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks
await panel.getByRole("button",{name:"Reset filters",exact:true}).click();
await panel.getByRole("heading",{name:/Hidden search match/}).waitFor();
assert.equal(calls.filter(c => c.command === "fetch_library_sync_spool_snapshot").length, spoolReads);
if (mode === "offline") {
const cachedMenu = panel.locator(".inventory-product-menu");
const summary = cachedMenu.locator("summary");
const rollButtons = cachedMenu.getByRole("button", {name: /Open roll/});
const readsBeforeMenu = calls.length;
await summary.press("Enter");
await rollButtons.nth(99).waitFor();
assert.equal(await rollButtons.count(), 100);
await cachedMenu.getByRole("button", {name: "Show more", exact: true}).press("Enter");
await rollButtons.nth(104).waitFor();
assert.equal(await rollButtons.nth(100).evaluate(button => document.activeElement === button), true);
await summary.press("Enter");
await cachedMenu.locator("button").first().waitFor({state:"detached"});
await summary.press("Enter");
await rollButtons.nth(99).waitFor();
assert.equal(await rollButtons.count(), 100);
assert.ok(!calls.slice(readsBeforeMenu).some(c => ["get_stock_card_page", "fetch_cached_library_sync_spools",
"fetch_library_sync_spool_snapshot"].includes(c.command)));
await cachedMenu.getByRole("button", {name: "Show more", exact: true}).press("Enter");
const chosen = cachedMenu.getByRole("button", {name: /Open roll/}).nth(100);
const reference = (await chosen.innerText()).split("#").at(-1);
await chosen.press("Enter");
const dialog = page.getByRole("dialog", {name: /Selected roll:.*Hidden search match/});
await dialog.waitFor();
await dialog.getByRole("button", {name:"Close", exact:true}).first().click();
assert.ok(calls.some(c => c.command === "fetch_library_sync_spool_detail" &&
c.payload.input.spool_id === `cached-${reference}`));
}
}
assert.ok(calls.some(c=>c.command==="fetch_cached_library_sync_spools"));
mode = "live";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test("balanced inventory preserves per-roll weights, filtering, selection and co
await page.getByRole("button",{name:"List view",exact:true}).click();assert.equal(await page.locator(".inventory-list-row").count(),12);
await page.screenshot({path:resolve(out,"en-1440-dark-liste.png"),fullPage:true});
await page.getByRole("button",{name:"Card view",exact:true}).click();
const menu=black.locator(".inventory-product-menu");await menu.locator("summary").click();await menu.getByRole("button").first().click();await page.waitForFunction(()=>document.querySelector("output")?.getAttribute("data-selected-roll")==="spool_a44954");
const menu=black.locator(".inventory-product-menu");assert.equal(await menu.locator("button").count(),0);await menu.locator("summary").press("Enter");await menu.getByRole("button").first().press("Enter");await page.waitForFunction(()=>document.querySelector("output")?.getAttribute("data-selected-roll")==="spool_a44954");
}
await page.locator("#inventory-loans-tab").click();await page.locator(".inventory-loan-table").waitFor();
assert.equal(await page.locator(".inventory-loan-table tbody tr").count(),5);
Expand Down
55 changes: 41 additions & 14 deletions ui/src/components/inventory_spool_collection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useId, useMemo, useState } from "react";
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { PageHeaderButton } from "./page_header_button";
import { inlineStatusSignalClass } from "../lib/chip_styles";
import { formatPlacementLabel } from "../lib/display_format";
Expand Down Expand Up @@ -80,6 +80,45 @@ function OwnershipChip({
);
}

function StockRollMenu({ group, count, moreRolls, onSelectRoll }: {
group: SpoolGroup;
count: number;
moreRolls?: (id: string) => void;
onSelectRoll: (id: string) => void;
}) {
const { t } = useI18n();
const [limit, setLimit] = useState(0);
const details = useRef<HTMLDetailsElement>(null);
const focusIndex = useRef<number | null>(null);
const visible = Math.min(limit, group.rolls.length);
useLayoutEffect(() => {
const index = focusIndex.current;
if (index === null || index >= visible) return;
focusIndex.current = null;
if (details.current?.open && (details.current.contains(document.activeElement) || document.activeElement === document.body)) {
details.current.querySelectorAll<HTMLButtonElement>("div > button")[index]?.focus();
}
}, [visible]);

return <details className="inventory-product-menu" ref={details} onToggle={event => {
if (!event.currentTarget.open) focusIndex.current = null;
setLimit(event.currentTarget.open ? 100 : 0);
}}>
<summary aria-label={`${t("common.actions", "Actions")} · ${formatInventoryDisplayTitle(group.material, group.filamentName, group.colorName)}`}>⋮</summary>
{limit > 0 && <div>
{group.rolls.slice(0, visible).map(roll => <button key={roll.id} type="button" onClick={() => {
if (details.current) details.current.open = false;
onSelectRoll(roll.id);
}}>{t("inventory.openCreatedRoll", "Open roll")} · {formatRollReference(roll)}</button>)}
{visible < count && <button type="button" onClick={() => {
focusIndex.current = visible;
setLimit(visible + 100);
if (visible === group.rolls.length) moreRolls?.(group.rolls[0].id);
}}>{t("inventory.showMoreHistory", "Show more")}</button>}
</div>}
</details>;
}

function RemainingMeter({
className = "mt-2",
spool,
Expand Down Expand Up @@ -233,19 +272,7 @@ export function InventorySpoolCollection({
<OwnershipChip ownershipType={group.ownershipType} t={t} />
</div>
</div>
<details className="inventory-product-menu">
<summary aria-label={`${t("common.actions", "Actions")} · ${formatInventoryDisplayTitle(group.material, group.filamentName, group.colorName)}`}>⋮</summary>
<div>{group.rolls.map(roll => <button key={roll.id} type="button" onClick={event => {
event.currentTarget.closest("details")?.removeAttribute("open");
onSelectRoll(roll.id);
}}>{t("inventory.openCreatedRoll", "Open roll")} · {formatRollReference(roll)}</button>)}
{cardPage && group.rolls.length < rollCount ? (
<button type="button" onClick={() => cardPage.moreRolls(group.rolls[0].id)}>
{t("inventory.showMoreHistory", "Show more")}
</button>
) : null}
</div>
</details>
<StockRollMenu group={group} count={rollCount} moreRolls={cardPage?.moreRolls} onSelectRoll={onSelectRoll} />
</header>
{rollCount > 1 ? <div className="inventory-product-total">
{rollCount} {t("inventory.spoolResults", "spools")} · {formatGrams(stats?.remaining ?? group.totalRemaining, "dash", locale)}
Expand Down
Loading