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
4 changes: 3 additions & 1 deletion docs/development/PERFORMANCE_BASELINE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ product and target. A completed purchase opens Purchases directly for that libra
Opening and refreshing Purchases reads the queue independently of stock.
The current Host and local database count the full purchase queue and return
50 matching rows per page. Filtering and literal case-insensitive search run
before pagination. A Dashboard handoff sorts the acknowledged order first
before pagination. The search field updates immediately and requests a page after
200 ms without typing. Clearing the search or choosing a status takes effect
immediately. A Dashboard handoff sorts the acknowledged order first
within the selected filter. Each response reads totals and rows from one
SQLite snapshot. Older Hosts use their existing recent list. Offline search
and counts use only saved rows. The Client retains up to 500 visited rows from
Expand Down
2 changes: 1 addition & 1 deletion ui/src/lib/use_inventory_add_workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function useInventoryAddWorkflow({
onReconcileReceipt: reconcileWishlistReceipt,
onStatusChange: handleWishlistStatus,
onStockItem: handleStockFromWishlist,
query: wishlistQueueQuery,
query: purchaseQueue.searchText,
resolvedTheme,
summary: queuePage?.summary ?? summarizeWishlistQueue(wishlistItems),
page: queuePage && {offset: queuePage.offset, matched: queuePage.matched, size: PURCHASE_PAGE_SIZE, select: purchaseQueue.setOffset},
Expand Down
5 changes: 4 additions & 1 deletion ui/src/lib/use_inventory_page_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { matchesWishlistPurchaseTarget } from "./tauri_wishlist_client";
const stockQueueQuery: PurchaseQueueQuery = { status: "ALL", search: "", offset: 0 };

type InventoryPageDataInput = {
setPurchaseSearchText?: (text: string) => void;
queueQuery?: PurchaseQueueQuery;
purchaseIntent?: Extract<InventoryNavigationIntent, { kind: "PURCHASES" }> | null;
setRfidCaptureFieldsBySlotId: Dispatch<SetStateAction<Record<string, RfidCaptureField[]>>>;
Expand Down Expand Up @@ -116,6 +117,7 @@ function createInventoryDomainSources(): Record<
}

export function useInventoryPageData({
setPurchaseSearchText,
queueQuery = stockQueueQuery,
purchaseIntent,
setRfidCaptureFieldsBySlotId,
Expand Down Expand Up @@ -230,6 +232,7 @@ export function useInventoryPageData({
setLocationsLoading(false);
setLocationMutationsSupported(false);
setLocationSource("OFFLINE");
setPurchaseSearchText?.("");
setQueueResult(null);
setWishlistItems([]);
setWishlistLoading(false);
Expand All @@ -245,7 +248,7 @@ export function useInventoryPageData({
setDomainSources(createInventoryDomainSources());
setClientInventoryUpdatedAt(null);
setRfidCaptureFieldsBySlotId({});
}, [setRfidCaptureFieldsBySlotId]);
}, [setPurchaseSearchText, setRfidCaptureFieldsBySlotId]);

const resolveLibrarySyncRole = useCallback(async () => {
if (!tauriAvailable) {
Expand Down
33 changes: 26 additions & 7 deletions ui/src/lib/use_wishlist_queue.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import type { PurchaseQueueQuery } from "./purchase_queue_page";
import type { WishlistStatusFilter } from "./wishlist_data_source";

export function useWishlistQueue() {
export function useWishlistQueue(active = true) {
const [searchText, setSearchText] = useState("");
const [query, setQuery] = useState<PurchaseQueueQuery>({ status: "WISHLIST", search: "", offset: 0 });
const [confirmWishlistRemoveId, setConfirmWishlistRemoveId] = useState<string | null>(null);
useEffect(() => {
if (!active || searchText === query.search) return;
const timer = window.setTimeout(() => {
setQuery(current => ({ ...current, search: searchText, offset: 0 }));
}, 200);
return () => window.clearTimeout(timer);
}, [active, query.search, searchText]);

const setWishlistQueueQuery = useCallback((text: string) => {
setSearchText(text);
if (!text) {
setQuery(current => current.search || current.offset ? { ...current, search: "", offset: 0 } : current);
}
}, []);

const setWishlistQueueFilter = useCallback((status: WishlistStatusFilter) =>
setQuery(current => ({ ...current, status, offset: 0 })), []);
const setWishlistQueueQuery = useCallback((search: string) =>
setQuery(current => ({ ...current, search, offset: 0 })), []);
const setOffset = useCallback((offset: number) => setQuery(current => ({ ...current, offset })), []);
setQuery({ status, search: searchText, offset: 0 }), [searchText]);

const setOffset = useCallback((offset: number) => setQuery(current => ({
...current, search: searchText, offset: current.search === searchText ? offset : 0,
})), [searchText]);

const resetWishlistQueue = useCallback((status: WishlistStatusFilter = "WISHLIST") => {
setSearchText("");
setQuery({ status, search: "", offset: 0 });
setConfirmWishlistRemoveId(null);
}, []);
return { query, setOffset, confirmWishlistRemoveId, resetWishlistQueue, setConfirmWishlistRemoveId,
return { query, searchText, setOffset, confirmWishlistRemoveId, resetWishlistQueue, setConfirmWishlistRemoveId,
setWishlistQueueFilter, setWishlistQueueQuery };
}
48 changes: 40 additions & 8 deletions ui/src/pages/dashboard_purchase_navigation.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ test("Dashboard purchase handoff stays with the reviewed library", async (t) =>
const replacement = { ...origin, host_base_url: "http://host-b.test", library_id: "library-b", target_generation: 2 };
const backToA = { ...origin, target_generation: 3 };

for (const scenario of ["paged queue", "older ordered purchase", "switch after save", "A–B–A after save", "switch on arrival", "A–B–A on arrival", "offline return", "switch before offline return",
for (const scenario of ["paged queue", "A–B–A during search", "older ordered purchase", "switch after save", "A–B–A after save", "switch on arrival", "A–B–A on arrival", "offline return", "switch before offline return",
"refresh cached queue", "refresh without a saved queue", "switch during queue read", "A–B–A during cached read", "receive and open stock"] as const) {
await t.test(scenario, async () => {
const page = await browser.newPage();
try {
if (scenario === "paged queue") await page.clock.install();
let target = origin;
let offline = false;
let queueOffline = scenario === "refresh cached queue" || scenario === "refresh without a saved queue" || scenario === "A–B–A during cached read";
Expand All @@ -49,6 +50,7 @@ test("Dashboard purchase handoff stays with the reviewed library", async (t) =>
let arrivalRead = false;
let checkedAfterSave = false;
const calls: string[] = [];
const queueSearches: string[] = [];
const saved: WishlistItemRow[] = [];
const row = (name: string) => {
const sample = structuredClone(fixture.spoolRows[0]);
Expand Down Expand Up @@ -86,11 +88,19 @@ test("Dashboard purchase handoff stays with the reviewed library", async (t) =>
case "fetch_library_sync_spool_detail": return { spool: rows[0], history: [], usage: [] };
case "fetch_library_sync_spool_snapshot": return { rows, captured_at: snapshot.captured_at };
case "get_purchase_queue_page": {
if (scenario !== "paged queue") return null;
assert.deepEqual(args.target, { base_url: origin.host_base_url, expected_library_id: origin.library_id,
target_generation: origin.target_generation });
if (queueOffline) throw new Error("Host offline");
if (scenario !== "paged queue" && scenario !== "A–B–A during search") return null;
assert.deepEqual(args.target, { base_url: target.host_base_url, expected_library_id: target.library_id,
target_generation: target.target_generation });
const q = args.query!;
queueSearches.push(q.search);
if (scenario === "A–B–A during search") {
if (target === backToA) assert.equal(q.search, "");
const name = target === backToA ? "Current purchase" : q.search ? "Obsolete search result" : "Purchased roll";
if (q.search) target = backToA;
return { summary: {all:1, wishlist:1, onOrder:0, received:0}, matched:1, offset:0,
rows:[{...saved[0], filament_name:name}] };
}
if (queueOffline) throw new Error("Host offline");
const recent = Array.from({length: 501}, (_, i) => ({ ...saved[0], id: String(i), filament_name: "Receipt " + i, status: "RECEIVED" }));
const matching = [saved[0], ...recent].filter(r => (q.status === "ALL" || r.status === q.status) &&
r.filament_name.toLowerCase().includes(q.search.toLowerCase()));
Expand Down Expand Up @@ -188,18 +198,40 @@ test("Dashboard purchase handoff stays with the reviewed library", async (t) =>

const queue = page.locator("#inventory-purchases-panel:not([hidden])");
const notice = "Added to the wishlist. Opening Purchases.";
if (scenario === "paged queue") {
if (scenario === "A–B–A during search") {
await queue.getByText(/Purchased roll/).first().waitFor();
await queue.getByRole("searchbox").fill("original library search");
await queue.getByText(/Current purchase/).first().waitFor();
assert.equal(await queue.getByRole("searchbox").inputValue(), "");
assert.ok(!await page.evaluate("window.purchasePaints.some(text => text.includes('Obsolete search result'))"));
} else if (scenario === "paged queue") {
await queue.getByText(/Purchased roll/).first().waitFor();
assert.equal(await page.locator("#inventory-purchases-tab .inventory-workspace-count").innerText(), "502");
await queue.getByRole("button", {name:"Received 501", exact:true}).click();
await queue.getByText("1–50 / 501").waitFor();
await queue.getByRole("button", {name:"Continue"}).click();
await queue.getByText("51–100 / 501").waitFor();
await queue.getByRole("searchbox").fill("Receipt 500");
await page.clock.pauseAt(new Date(await page.evaluate(() => Date.now()) + 1000));
const search = queue.getByRole("searchbox");
queueSearches.length = 0;
await search.pressSequentially("Receipt 500");
assert.equal(await search.inputValue(), "Receipt 500");
assert.deepEqual(queueSearches, []);
await page.clock.runFor(200);
await queue.getByText(/Receipt 500/).first().waitFor();
assert.deepEqual(queueSearches, ["Receipt 500"]);
assert.ok(!calls.includes("fetch_library_sync_wishlist_items"));
await search.fill("Receipt 499");
await queue.getByRole("button", {name: "All 502", exact: true}).click({force: true});
await queue.getByText(/Receipt 499/).first().waitFor();
await page.clock.runFor(250);
assert.deepEqual(queueSearches, ["Receipt 500", "Receipt 499"]);
await search.fill("discarded draft");
queueOffline = true;
await queue.getByRole("searchbox").fill("");
await search.fill("");
await page.clock.runFor(250);
assert.ok(!queueSearches.includes("discarded draft"));
await page.clock.resume();
await page.waitForFunction(() => document.querySelector("#inventory-purchases-tab .inventory-workspace-count")?.textContent === "1");
await queue.getByRole("button", {name:"On order 1", exact:true}).click();
await queue.getByText(/Cached purchase/).first().waitFor();
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export default function InventoryPage({
const loansOnly = activeWorkspaceView === "LOANS";
const [loanCounts, setLoanCounts] = useState<LoanWorkspaceCounts | null>(null);
const locationsOnly = activeWorkspaceView === "LOCATIONS";
const purchaseQueue = useWishlistQueue();
const purchasesOnly = activeWorkspaceView === "PURCHASES";
const purchaseQueue = useWishlistQueue(purchasesOnly);
const [rfidCaptureFieldsBySlotId, setRfidCaptureFieldsBySlotId] = useState<
Record<string, RfidCaptureField[]>
>({});
Expand Down Expand Up @@ -216,6 +216,7 @@ export default function InventoryPage({
wishlistItems,
wishlistLoading,
} = useInventoryPageData({
setPurchaseSearchText: purchaseQueue.setWishlistQueueQuery,
queueQuery: purchasesOnly ? purchaseQueue.query : undefined,
purchaseIntent: purchasesOnly ? reviewedPurchase : null,
setRfidCaptureFieldsBySlotId,
Expand Down
Loading