diff --git a/docs/development/PERFORMANCE_BASELINE.md b/docs/development/PERFORMANCE_BASELINE.md index 1dff90e4..12760a22 100644 --- a/docs/development/PERFORMANCE_BASELINE.md +++ b/docs/development/PERFORMANCE_BASELINE.md @@ -165,6 +165,12 @@ transaction. Master ID matches take priority over product descriptions. Concurre clients receive the same item ID. Older Hosts require an update for this Dashboard shortcut. Manual purchase entry uses the ordinary create operation. Overlapping clicks share a request only for the same product and target. A completed purchase opens Purchases directly for that library. +The Stock tab reads only the total purchase count locally. A paired Client sends +its saved Stock page revision to the Host. On the first read or a revision +change, the Host includes up to 50 recent orders in the same snapshot so the +Client can renew its offline copy. Only the count crosses the desktop bridge +on a successful compact read. Older Hosts use the existing purchase reader. + 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 diff --git a/scripts/run-loan-dialog-regressions.mjs b/scripts/run-loan-dialog-regressions.mjs index 29cdbd80..daab0b92 100644 --- a/scripts/run-loan-dialog-regressions.mjs +++ b/scripts/run-loan-dialog-regressions.mjs @@ -181,6 +181,7 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks const reads = []; let mode = "live"; let revision = 1; + let purchaseCount = 1; state.invoke = (command,payload) => { switch (command) { case "get_library_sync_page_status": return status; @@ -196,6 +197,9 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks case "fetch_cached_library_sync_spools": assert.deepEqual(payload.input,target); return {rows:[hidden],captured_at:"2026-01-01"}; + case "get_stock_purchase_count": + assert.deepEqual(payload.target,target); + return purchaseCount; case "get_stock_card_page": { assert.deepEqual(payload.target,target); if (mode === "legacy") return null; @@ -217,6 +221,7 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks await page.locator("#inventory-stock-tab").click(); const panel=page.locator("#inventory-stock-panel"); await panel.getByText(/8 spools/).waitFor(); + await expectBadges(page, {purchases: 1}); assert.equal(await panel.locator(".inventory-roll-row").count(),3); await panel.getByRole("button",{name:/Show all/}).click(); await panel.locator(".inventory-roll-row").nth(7).waitFor(); @@ -239,6 +244,11 @@ async function checkStockCards({page, state, fixture, calls, fallback, openWorks assert.equal(await panel.locator(".inventory-product-card").count(), mode === "legacy" ? 3 : 1); } assert.ok(calls.some(c=>c.command==="fetch_cached_library_sync_spools")); + mode = "live"; + purchaseCount++; + await page.getByRole("button", {name: "Refresh", exact: true}).click(); + await expectBadges(page, {purchases: 2}); + assert.ok(!calls.some(c => c.command === "get_purchase_queue_page")); } async function checkLegacyLocation({ page, state, fixture, calls, fallback, openWorkspace }) { diff --git a/scripts/ui-browser-performance-probe.mjs b/scripts/ui-browser-performance-probe.mjs index 2d8258c4..ddbc7118 100644 --- a/scripts/ui-browser-performance-probe.mjs +++ b/scripts/ui-browser-performance-probe.mjs @@ -772,6 +772,7 @@ export function resolveUiBrowserPerformanceInvoke( return []; case "set_window_title": case "set_dock_icon_theme": + case "get_stock_purchase_count": case "get_purchase_queue_page": // This fixture models a Host with the legacy purchase queue. case "set_native_window_theme": case "set_desktop_tray_menu_labels": diff --git a/src-tauri/src/companion_http.rs b/src-tauri/src/companion_http.rs index ba0a2c09..73c73d69 100644 --- a/src-tauri/src/companion_http.rs +++ b/src-tauri/src/companion_http.rs @@ -319,6 +319,7 @@ pub(crate) fn is_companion_data_read(request: &Request) -> bool { "/api/v1/library/printer-spool-picker" | "/api/v1/library/loan-spool-picker" | "/api/v1/library/purchase-queue" + | "/api/v1/library/stock-purchase-count" | "/api/v1/library/location-spools" ) } @@ -522,6 +523,7 @@ mod tests { "/api/v1/library/printer-spool-picker", "/api/v1/library/loan-spool-picker", "/api/v1/library/purchase-queue", + "/api/v1/library/stock-purchase-count", "/api/v1/library/location-spools", ] { let query = Request::post(path).body(()).unwrap(); diff --git a/src-tauri/src/companion_library_api.rs b/src-tauri/src/companion_library_api.rs index 9ec87629..7bb68fbc 100644 --- a/src-tauri/src/companion_library_api.rs +++ b/src-tauri/src/companion_library_api.rs @@ -67,6 +67,7 @@ pub(super) async fn handle_health( PRINTER_PICKER_CAPABILITY, LOAN_PICKER_CAPABILITY, crate::companion_models::STOCK_CARDS_CAPABILITY, + crate::companion_models::STOCK_PURCHASE_COUNT_CAPABILITY, crate::companion_models::PURCHASE_QUEUE_CAPABILITY, crate::companion_models::DASHBOARD_PURCHASE_CAPABILITY, LOCATION_SPOOLS_CAPABILITY, @@ -248,6 +249,22 @@ pub(super) async fn handle_loan_picker_page( .await } +pub(super) async fn handle_stock_purchase_count( + State(state): State, + headers: HeaderMap, + Json(query): Json, +) -> Result, CompanionApiError> +{ + require_allowed_host(&headers, &state.runtime)?; + state + .run_blocking("stock purchase count", move |state| { + Ok(Json( + FilamentDatabase::open(&state.db_path)?.stock_purchase_snapshot(&query)?, + )) + }) + .await +} + pub(super) async fn handle_purchase_queue_page( State(state): State, headers: HeaderMap, diff --git a/src-tauri/src/companion_models.rs b/src-tauri/src/companion_models.rs index 013a8d83..e72a5cfb 100644 --- a/src-tauri/src/companion_models.rs +++ b/src-tauri/src/companion_models.rs @@ -279,6 +279,7 @@ pub(crate) const WISHLIST_RECEIPT_LOCATION_CAPABILITY: &str = "wishlist-receipt- pub(crate) const WISHLIST_RECEIPT_IDEMPOTENCY_CAPABILITY: &str = "wishlist-receipt-idempotency-v1"; pub(crate) const CATALOG_SPOOL_BATCH_CAPABILITY: &str = "catalog-spool-batch-v1"; pub(crate) const LOAN_WORKSPACE_COUNTS: &str = "loan-workspace-counts-v1"; +pub(crate) const STOCK_PURCHASE_COUNT_CAPABILITY: &str = "stock-purchase-count-v1"; pub(crate) const PURCHASE_QUEUE_CAPABILITY: &str = "purchase-queue-page-v1"; pub(crate) const STOCK_CARDS_CAPABILITY: &str = "stock-cards-v1"; pub(crate) const DASHBOARD_PURCHASE_CAPABILITY: &str = "dashboard-purchase-v1"; diff --git a/src-tauri/src/companion_routes.rs b/src-tauri/src/companion_routes.rs index 6c34d9ef..f6707537 100644 --- a/src-tauri/src/companion_routes.rs +++ b/src-tauri/src/companion_routes.rs @@ -56,6 +56,7 @@ fn build_router_with_security_config( .route("/library/snapshot", get(handle_library_snapshot)) .route("/library/printer-spool-picker", post(handle_printer_picker_page)) .route("/library/loan-workspace-counts", get(handle_loan_workspace_counts)) + .route("/library/stock-purchase-count", post(handle_stock_purchase_count)) .route("/library/purchase-queue", post(handle_purchase_queue_page)) .route("/library/stock-cards", post(handle_stock_cards)) .route("/library/location-spools", post(handle_location_spools)) diff --git a/src-tauri/src/library_sync_resilience_tests.rs b/src-tauri/src/library_sync_resilience_tests.rs index f256a827..2a1c7259 100644 --- a/src-tauri/src/library_sync_resilience_tests.rs +++ b/src-tauri/src/library_sync_resilience_tests.rs @@ -1436,3 +1436,65 @@ async fn real_tcp_client_completes_the_five_fixed_workflows_on_the_host() { assert_eq!(client_local_snapshot(&client_db_path), client_local_before); host.stop().await; } + +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn stock_purchase_count_refreshes_the_offline_copy_after_an_order() { + use crate::spool_picker_commands::{stock_purchase_count_blocking, PickerTarget}; + let _guard = RESILIENCE_PROCESS_TEST_LOCK.lock().await; + let host_path = temp_db_path("purchase-host"); + let client_path = temp_db_path("purchase-client"); + let _files = TestDatabases::new(vec![host_path.clone(), client_path.clone()]); + seed_host(&host_path); + let host = HostProcess::start(&host_path, 0, 1).await; + let url = format!("http://127.0.0.1:{}", host.port()); + configure_client(&client_path, &url); + let client = app_state( + &client_path, + TrustedLanCompanionRuntime::new(host.port()).with_qa_mode(true), + ); + let generation = pair_client_with_host(&client, &client_path, &url).await; + let read = || { + let state = client.clone(); + let target = PickerTarget { + base_url: Some(url.clone()), + expected_library_id: HOST_LIBRARY_ID.into(), + target_generation: generation, + }; + run_blocking(move || stock_purchase_count_blocking(&state, target)) + }; + assert_eq!(read().await, Some(0)); + let db = FilamentDatabase::open(&host_path).unwrap(); + let host_inventory = InventoryEngine::new(db); + host_inventory + .create_wishlist_item(CreateWishlistItemInput { + id: "new-order".into(), + master_id: None, + material: "PLA".into(), + filament_name: "Silk".into(), + color_name: "Blue".into(), + vendor: None, + quantity: Some(1), + note: None, + }) + .unwrap(); + host_inventory + .update_wishlist_item_status(UpdateWishlistStatusInput { + item_id: "new-order".into(), + status: "ON_ORDER".into(), + }) + .unwrap(); + assert_eq!(read().await, Some(1)); + assert_eq!(read().await, Some(1)); + host.stop().await; + let saved = FilamentDatabase::open(&client_path) + .unwrap() + .get_library_sync_settings() + .unwrap() + .cached_wishlist + .unwrap(); + assert_eq!(saved.rows.len(), 1); + assert!(saved + .rows + .iter() + .any(|row| row.id == "new-order" && row.status == "ON_ORDER")); +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 667172f2..90c9d15b 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -130,7 +130,6 @@ mod trusted_lan_network_watcher; mod trusted_lan_pairing_commands; mod trusted_lan_runtime_commands; mod trusted_lan_status_commands; - pub(crate) use app_storage::{with_db, with_inventory, with_stats}; use filament_manager_core::backend; #[cfg(target_os = "macos")] @@ -378,6 +377,7 @@ fn main() { printer_read_commands::list_printer_overview, spool_picker_commands::get_printer_picker_page, spool_picker_commands::get_loan_picker_page, + spool_picker_commands::get_stock_purchase_count, spool_picker_commands::get_purchase_queue_page, spool_picker_commands::get_stock_card_page, spool_picker_commands::get_location_spool_page, diff --git a/src-tauri/src/spool_picker_commands.rs b/src-tauri/src/spool_picker_commands.rs index d1f50ea8..b8eb5b32 100644 --- a/src-tauri/src/spool_picker_commands.rs +++ b/src-tauri/src/spool_picker_commands.rs @@ -6,7 +6,7 @@ use crate::{ backend::database_printer_picker::{PrinterPickerPage, PrinterPickerQuery}, backend::database_result::InventoryResult, backend::database_stock_cards::{StockCardPage, StockCardQuery}, - backend::database_wishlist_queue::{PurchaseQueuePage, PurchaseQueueQuery}, + backend::database_wishlist_queue::{PurchaseQueuePage, PurchaseQueueQuery, StockPurchaseQuery}, backend::filament_database::FilamentDatabase, companion_models::{ LOAN_PICKER_CAPABILITY, LOCATION_SPOOLS_CAPABILITY, PRINTER_PICKER_CAPABILITY, @@ -78,6 +78,45 @@ pub(crate) fn loan_picker_page_blocking( ) } +#[tauri::command] +pub(crate) async fn get_stock_purchase_count( + state: tauri::State<'_, AppState>, + target: PickerTarget, +) -> Result, String> { + let state = state.inner().clone(); + run_library_sync_blocking(move || stock_purchase_count_blocking(&state, target)).await +} + +pub(crate) fn stock_purchase_count_blocking( + state: &AppState, + target: PickerTarget, +) -> Result, String> { + if target.base_url.is_none() { + return target + .with_database(state, FilamentDatabase::stock_purchase_count) + .map(Some); + } + let cached_revision = + target.with_database(state, FilamentDatabase::cached_stock_purchase_revision)?; + let Some(snapshot) = read_picker_page( + state, + &StockPurchaseQuery { cached_revision }, + target.clone(), + crate::companion_models::STOCK_PURCHASE_COUNT_CAPABILITY, + "/api/v1/library/stock-purchase-count", + FilamentDatabase::stock_purchase_snapshot, + )? + else { + return Ok(None); + }; + target.with_database(state, |db| { + if let Some(rows) = snapshot.rows { + let _ = db.cache_purchase_rows(&rows, snapshot.total, snapshot.revision, true); + } + Ok(Some(snapshot.total)) + }) +} + #[tauri::command] pub(crate) async fn get_purchase_queue_page( state: tauri::State<'_, AppState>, diff --git a/src/backend/database_wishlist.rs b/src/backend/database_wishlist.rs index 79fb1118..487b1994 100644 --- a/src/backend/database_wishlist.rs +++ b/src/backend/database_wishlist.rs @@ -37,7 +37,7 @@ pub(crate) fn list_wishlist_items( "SELECT id, master_id, material, filament_name, color_name, vendor, status, quantity, note, created_at, updated_at FROM wishlist_items - ORDER BY updated_at DESC, created_at DESC + ORDER BY updated_at DESC, created_at DESC, id LIMIT ?1", )?; let rows = stmt.query_map(params![limit], map_wishlist_item)?; diff --git a/src/backend/database_wishlist_queue.rs b/src/backend/database_wishlist_queue.rs index ca432c69..9bef796a 100644 --- a/src/backend/database_wishlist_queue.rs +++ b/src/backend/database_wishlist_queue.rs @@ -1,4 +1,4 @@ -use rusqlite::{functions::FunctionFlags, params}; +use rusqlite::{functions::FunctionFlags, params, OptionalExtension}; use serde::{Deserialize, Serialize}; use super::{ @@ -34,7 +34,52 @@ pub struct PurchaseQueuePage { pub rows: Vec, } +#[derive(Debug, Deserialize, Serialize)] +pub struct StockPurchaseQuery { + pub cached_revision: Option, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct StockPurchaseSnapshot { + pub total: i64, + pub revision: i64, + #[serde(skip_serializing_if = "Option::is_none")] + pub rows: Option>, +} + impl FilamentDatabase { + pub fn stock_purchase_count(&self) -> InventoryResult { + Ok(self + .connection() + .query_row("SELECT count(*) FROM wishlist_items", [], |row| row.get(0))?) + } + + pub fn stock_purchase_snapshot( + &self, + query: &StockPurchaseQuery, + ) -> InventoryResult { + self.with_read_transaction(|db| { + let revision = db.library_domain_revisions()?.wishlist; + Ok(StockPurchaseSnapshot { + revision, + total: db.stock_purchase_count()?, + rows: if query.cached_revision == Some(revision) { + None + } else { + Some(db.list_wishlist_items(PAGE_SIZE)?) + }, + }) + }) + } + + pub fn cached_stock_purchase_revision(&self) -> InventoryResult> { + Ok(self.connection().query_row( + "SELECT CASE WHEN json_valid(value) THEN CASE WHEN json_extract(value,'$.stock_page')=1 + AND json_type(value,'$.rows')='array' THEN json_extract(value,'$.revision') END END + FROM settings WHERE key='library_sync_cached_wishlist_json'", [], |row| row.get(0), + ).optional()?.flatten()) + } + pub fn purchase_queue_page( &self, query: &PurchaseQueueQuery, @@ -84,6 +129,8 @@ impl FilamentDatabase { // omit the optional revision. Pages from different Host revisions must not mix. #[derive(Deserialize, Serialize)] struct CachedQueue { + #[serde(default)] + stock_page: bool, revision: Option, captured_at: String, rows: Vec, @@ -91,9 +138,19 @@ struct CachedQueue { impl FilamentDatabase { pub fn cache_purchase_queue_page(&self, page: &PurchaseQueuePage) -> InventoryResult<()> { + self.cache_purchase_rows(&page.rows, page.summary.all, page.revision, false) + } + + pub fn cache_purchase_rows( + &self, + page_rows: &[WishlistItemRow], + total: i64, + revision: i64, + stock_page: bool, + ) -> InventoryResult<()> { const KEY: &str = "library_sync_cached_wishlist_json"; // An empty filter is not an empty library. Keep the last offline capture. - if page.rows.is_empty() && page.summary.all > 0 { + if page_rows.is_empty() && total > 0 { return Ok(()); } self.with_write_transaction(|db| { @@ -103,14 +160,14 @@ impl FilamentDatabase { if previous .as_ref() .and_then(|cache| cache.revision) - .is_some_and(|rev| rev > page.revision) + .is_some_and(|rev| rev > revision) { return Ok(()); } - let mut rows = page.rows.clone(); - if let Some(cache) = previous.filter(|cache| cache.revision == Some(page.revision)) { + let mut rows = page_rows.to_vec(); + if let Some(cache) = previous.filter(|cache| cache.revision == Some(revision)) { let seen: std::collections::HashSet<_> = - page.rows.iter().map(|row| &row.id).collect(); + page_rows.iter().map(|row| &row.id).collect(); rows.extend( cache .rows @@ -120,7 +177,8 @@ impl FilamentDatabase { ); } let cached = CachedQueue { - revision: Some(page.revision), + stock_page, + revision: Some(revision), captured_at: db.sqlite_now()?, rows, }; @@ -135,6 +193,36 @@ impl FilamentDatabase { mod tests { use super::*; + #[test] + fn stock_count_distinguishes_a_saved_empty_page_from_a_missing_capture() { + let db = FilamentDatabase::open(":memory:").unwrap(); + db.apply_schema().unwrap(); + let read = || { + db.stock_purchase_snapshot(&StockPurchaseQuery { + cached_revision: db.cached_stock_purchase_revision().unwrap(), + }) + .unwrap() + }; + let empty = read(); + assert_eq!(empty.total, 0); + let rows = empty.rows.unwrap(); + assert!(rows.is_empty()); + db.cache_purchase_rows(&rows, 0, empty.revision, true) + .unwrap(); + assert!(read().rows.is_none()); + + db.connection() + .execute_batch( + "WITH RECURSIVE n(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM n WHERE i<51) + INSERT INTO wishlist_items(id,material,filament_name,color_name,status) + SELECT printf('order-%02d',i),'PLA','Silk','Blue','ON_ORDER' FROM n", + ) + .unwrap(); + let changed = read(); + assert_eq!(changed.total, 51); + assert_eq!(changed.rows.unwrap().len(), 50); + } + #[test] fn searches_and_counts_the_entire_queue_and_caches_only_visited_rows() { let db = FilamentDatabase::open(":memory:").unwrap(); diff --git a/ui/src/lib/purchase_queue_page.ts b/ui/src/lib/purchase_queue_page.ts index b35ff435..f8e0f88f 100644 --- a/ui/src/lib/purchase_queue_page.ts +++ b/ui/src/lib/purchase_queue_page.ts @@ -1,8 +1,8 @@ -import { getPurchaseQueuePage, type WishlistItemRow } from "./tauri_wishlist_client"; +import { getPurchaseQueuePage, getStockPurchaseCount, type WishlistItemRow } from "./tauri_wishlist_client"; import { fetchCachedLibrarySyncWishlist, type LibraryReadTarget } from "./tauri_library_sync_client"; import { filterWishlistQueueItems, loadWishlistItemsSnapshot, summarizeWishlistQueue, - type WishlistDataSourceOptions, type WishlistQueueSummary, type WishlistStatusFilter, + type WishlistDataSourceOptions, type WishlistItemsLoadResult, type WishlistQueueSummary, type WishlistStatusFilter, } from "./wishlist_data_source"; export const PURCHASE_PAGE_SIZE = 50; @@ -20,8 +20,17 @@ function pageOfSavedRows(rows: WishlistItemRow[], query: PurchaseQueueQuery, pin return { rows: ordered.slice(offset, offset + PURCHASE_PAGE_SIZE), matched: ordered.length, offset, summary: summarizeWishlistQueue(rows) }; } -export async function loadPurchaseQueuePage(target: LibraryReadTarget, query: PurchaseQueueQuery, options: WishlistDataSourceOptions) { +export async function loadPurchaseQueuePage( + target: LibraryReadTarget, + query: PurchaseQueueQuery, + options: WishlistDataSourceOptions, + stockCountOnly = false, +): Promise { try { + if (stockCountOnly) { + const total = await getStockPurchaseCount(target); + if (total != null) return { total, rows: [], page: null, source: "LIVE" as const }; + } const page = await getPurchaseQueuePage(target, query, options.reviewedItemId); if (page) return { rows: page.rows, page, source: "LIVE" as const }; } catch (error) { diff --git a/ui/src/lib/tauri_wishlist_client.ts b/ui/src/lib/tauri_wishlist_client.ts index 1a304a49..884ab5e1 100644 --- a/ui/src/lib/tauri_wishlist_client.ts +++ b/ui/src/lib/tauri_wishlist_client.ts @@ -196,6 +196,10 @@ export async function fetchLibrarySyncWishlistItems( }); } +export function getStockPurchaseCount(target: LibraryReadTarget) { + return invoke("get_stock_purchase_count", { target }); +} + export function getPurchaseQueuePage(target: LibraryReadTarget, query: PurchaseQueueQuery, reviewedItemId?: string) { return invoke("get_purchase_queue_page", { target, query: { ...query, reviewed_item_id: reviewedItemId }, diff --git a/ui/src/lib/use_inventory_page_data.ts b/ui/src/lib/use_inventory_page_data.ts index 6338a073..aacbd58e 100644 --- a/ui/src/lib/use_inventory_page_data.ts +++ b/ui/src/lib/use_inventory_page_data.ts @@ -180,8 +180,8 @@ export function useInventoryPageData({ const [usageLoading, setUsageLoading] = useState(false); const [usagePoints, setUsagePoints] = useState([]); const [wishlistLoading, setWishlistLoading] = useState(false); - const [queueResult, setQueueResult] = useState<{query: PurchaseQueueQuery; page: PurchaseQueuePage} | null>(null); - const queuePage = queueResult?.query === queueQuery ? queueResult?.page : undefined; + const [queueResult, setQueueResult] = useState<{query: PurchaseQueueQuery; page: PurchaseQueuePage | null; total: number} | null>(null); + const queuePage = queueResult?.query === queueQuery ? queueResult?.page ?? undefined : undefined; const [wishlistItems, setWishlistItems] = useState([]); const [activeLoans, setActiveLoans] = useState([]); const [printerOverview, setPrinterOverview] = useState([]); @@ -546,8 +546,8 @@ export function useInventoryPageData({ ? { base_url: clientReadOnly ? clientHostBaseUrl : null, expected_library_id: clientLibraryId, target_generation: clientTargetGeneration } : null; const result = target - ? await loadPurchaseQueuePage(target, queueQuery, options) - : { ...await loadWishlistItemsSnapshot(options), page: null }; + ? await loadPurchaseQueuePage(target, queueQuery, options, queueQuery === stockQueueQuery) + : { ...await loadWishlistItemsSnapshot(options), page: null, total: undefined }; const pairingRejected = checkPairing && result.source !== "LIVE" && clientHostWritePaired && clientHostBaseUrl && clientLibraryId && dataRequestIsCurrent("wishlist", requestId) && await inventoryFallbackPairingRejected(clientHostBaseUrl, clientLibraryId); @@ -568,7 +568,11 @@ export function useInventoryPageData({ recordClientInventoryDomainSource("wishlist", "OFFLINE"); return; } - setQueueResult(result.page ? {query: queueQuery, page: result.page} : null); + setQueueResult({ + query: queueQuery, + page: result.page, + total: result.total ?? result.page?.summary.all ?? result.rows.length, + }); setWishlistItems(result.rows); recordClientInventoryDomainSource("wishlist", result.source); reportResult?.("wishlist", result.source); @@ -962,8 +966,9 @@ export function useInventoryPageData({ refreshing, usageLoading, usagePoints, + purchaseCount: queueResult?.query === queueQuery ? queueResult.total : undefined, queuePage, - wishlistItems: queueResult && !queuePage ? [] : wishlistItems, + wishlistItems: queueResult && queueResult.query !== queueQuery ? [] : wishlistItems, wishlistLoading, }; } diff --git a/ui/src/pages/inventory.tsx b/ui/src/pages/inventory.tsx index 37c16b5d..764e4c80 100644 --- a/ui/src/pages/inventory.tsx +++ b/ui/src/pages/inventory.tsx @@ -212,6 +212,7 @@ export default function InventoryPage({ spools, usageLoading, usagePoints, + purchaseCount, queuePage, wishlistItems, wishlistLoading, @@ -1686,7 +1687,7 @@ export default function InventoryPage({ showRollModal={showRollModal} totalInventoryCount={compactBadges ? compactCounts?.stock ?? null : hasCount(domainSources.spools) || detailVisualFixture ? (cardPage?.total ?? spools.length) : null} totalLocationCount={loansOnly ? loanCounts?.locations ?? null : hasCount(domainSources.locations) ? selectableInventoryLocations(locations).length : null} - totalPurchaseCount={compactBadges ? compactCounts?.purchases ?? null : hasCount(domainSources.wishlist) ? queuePage?.summary.all ?? wishlistItems.length : null} + totalPurchaseCount={compactBadges ? compactCounts?.purchases ?? null : hasCount(domainSources.wishlist) ? purchaseCount ?? wishlistItems.length : null} /> );