From 48d07a643361e520c4dd89d9565a54febd6ad7ce Mon Sep 17 00:00:00 2001 From: bliatun-code <270035675+bliatun-code@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:54:30 +0100 Subject: [PATCH 1/2] Coalesce purchase queue searches while typing --- docs/development/PERFORMANCE_BASELINE.md | 4 +- ui/src/lib/use_inventory_add_workflow.ts | 2 +- ui/src/lib/use_inventory_page_data.ts | 5 +- ui/src/lib/use_wishlist_queue.ts | 33 ++++++++++--- ...hboard_purchase_navigation.browser.test.ts | 48 +++++++++++++++---- ui/src/pages/inventory.tsx | 3 +- 6 files changed, 76 insertions(+), 19 deletions(-) diff --git a/docs/development/PERFORMANCE_BASELINE.md b/docs/development/PERFORMANCE_BASELINE.md index 9e80b63a..224510f2 100644 --- a/docs/development/PERFORMANCE_BASELINE.md +++ b/docs/development/PERFORMANCE_BASELINE.md @@ -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 diff --git a/ui/src/lib/use_inventory_add_workflow.ts b/ui/src/lib/use_inventory_add_workflow.ts index 8d75a3db..c169d723 100644 --- a/ui/src/lib/use_inventory_add_workflow.ts +++ b/ui/src/lib/use_inventory_add_workflow.ts @@ -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}, diff --git a/ui/src/lib/use_inventory_page_data.ts b/ui/src/lib/use_inventory_page_data.ts index 7a20a589..cdfac9c0 100644 --- a/ui/src/lib/use_inventory_page_data.ts +++ b/ui/src/lib/use_inventory_page_data.ts @@ -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 | null; setRfidCaptureFieldsBySlotId: Dispatch>>; @@ -116,6 +117,7 @@ function createInventoryDomainSources(): Record< } export function useInventoryPageData({ + setPurchaseSearchText, queueQuery = stockQueueQuery, purchaseIntent, setRfidCaptureFieldsBySlotId, @@ -230,6 +232,7 @@ export function useInventoryPageData({ setLocationsLoading(false); setLocationMutationsSupported(false); setLocationSource("OFFLINE"); + setPurchaseSearchText(""); setQueueResult(null); setWishlistItems([]); setWishlistLoading(false); @@ -245,7 +248,7 @@ export function useInventoryPageData({ setDomainSources(createInventoryDomainSources()); setClientInventoryUpdatedAt(null); setRfidCaptureFieldsBySlotId({}); - }, [setRfidCaptureFieldsBySlotId]); + }, [setPurchaseSearchText, setRfidCaptureFieldsBySlotId]); const resolveLibrarySyncRole = useCallback(async () => { if (!tauriAvailable) { diff --git a/ui/src/lib/use_wishlist_queue.ts b/ui/src/lib/use_wishlist_queue.ts index f5b5eb03..92e93551 100644 --- a/ui/src/lib/use_wishlist_queue.ts +++ b/ui/src/lib/use_wishlist_queue.ts @@ -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({ status: "WISHLIST", search: "", offset: 0 }); const [confirmWishlistRemoveId, setConfirmWishlistRemoveId] = useState(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 }; } diff --git a/ui/src/pages/dashboard_purchase_navigation.browser.test.ts b/ui/src/pages/dashboard_purchase_navigation.browser.test.ts index 72c603a3..7628e3ad 100644 --- a/ui/src/pages/dashboard_purchase_navigation.browser.test.ts +++ b/ui/src/pages/dashboard_purchase_navigation.browser.test.ts @@ -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"; @@ -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]); @@ -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())); @@ -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(); diff --git a/ui/src/pages/inventory.tsx b/ui/src/pages/inventory.tsx index 27a0a878..37c16b5d 100644 --- a/ui/src/pages/inventory.tsx +++ b/ui/src/pages/inventory.tsx @@ -155,8 +155,8 @@ export default function InventoryPage({ const loansOnly = activeWorkspaceView === "LOANS"; const [loanCounts, setLoanCounts] = useState(null); const locationsOnly = activeWorkspaceView === "LOCATIONS"; - const purchaseQueue = useWishlistQueue(); const purchasesOnly = activeWorkspaceView === "PURCHASES"; + const purchaseQueue = useWishlistQueue(purchasesOnly); const [rfidCaptureFieldsBySlotId, setRfidCaptureFieldsBySlotId] = useState< Record >({}); @@ -216,6 +216,7 @@ export default function InventoryPage({ wishlistItems, wishlistLoading, } = useInventoryPageData({ + setPurchaseSearchText: purchaseQueue.setWishlistQueueQuery, queueQuery: purchasesOnly ? purchaseQueue.query : undefined, purchaseIntent: purchasesOnly ? reviewedPurchase : null, setRfidCaptureFieldsBySlotId, From ae0bca387a558dc0311ee467f159eb1229be97ba Mon Sep 17 00:00:00 2001 From: bliatun-code <270035675+bliatun-code@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:57:32 +0100 Subject: [PATCH 2/2] Support inventory consumers without a purchase search field --- ui/src/lib/use_inventory_page_data.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/lib/use_inventory_page_data.ts b/ui/src/lib/use_inventory_page_data.ts index cdfac9c0..6338a073 100644 --- a/ui/src/lib/use_inventory_page_data.ts +++ b/ui/src/lib/use_inventory_page_data.ts @@ -52,7 +52,7 @@ import { matchesWishlistPurchaseTarget } from "./tauri_wishlist_client"; const stockQueueQuery: PurchaseQueueQuery = { status: "ALL", search: "", offset: 0 }; type InventoryPageDataInput = { - setPurchaseSearchText: (text: string) => void; + setPurchaseSearchText?: (text: string) => void; queueQuery?: PurchaseQueueQuery; purchaseIntent?: Extract | null; setRfidCaptureFieldsBySlotId: Dispatch>>; @@ -232,7 +232,7 @@ export function useInventoryPageData({ setLocationsLoading(false); setLocationMutationsSupported(false); setLocationSource("OFFLINE"); - setPurchaseSearchText(""); + setPurchaseSearchText?.(""); setQueueResult(null); setWishlistItems([]); setWishlistLoading(false);