From d3e6bc33b8144e1fc9111781f6cdfc0ba4a37df4 Mon Sep 17 00:00:00 2001 From: zachtt Date: Tue, 5 May 2026 19:48:22 -0700 Subject: [PATCH] fixed checkout trend gaps and merge inventory items with the same uuid --- .../kiosks/admin/statistics/CheckoutTrend.tsx | 26 ++++++++++++++++--- .../admin/statistics/TopCheckedOutItems.tsx | 11 +++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/website/components/kiosks/admin/statistics/CheckoutTrend.tsx b/website/components/kiosks/admin/statistics/CheckoutTrend.tsx index 298abf7b..3ebed979 100644 --- a/website/components/kiosks/admin/statistics/CheckoutTrend.tsx +++ b/website/components/kiosks/admin/statistics/CheckoutTrend.tsx @@ -51,9 +51,29 @@ export default function CheckoutTrend({ dayCounts[dayKey].count += 1; }); - return Object.entries(dayCounts) - .sort(([a], [b]) => a.localeCompare(b)) - .map(([, value]) => value); + const sortedKeys = Object.keys(dayCounts).sort(); + if (sortedKeys.length === 0) return []; + + const filled: { date: string; count: number }[] = []; + const cursor = new Date(sortedKeys[0]); + const end = new Date(sortedKeys[sortedKeys.length - 1]); + + while (cursor <= end) { + const dayKey = cursor.toISOString().slice(0, 10); // "YYYY-MM-DD" + + if (dayCounts[dayKey]) { + filled.push(dayCounts[dayKey]); + } else { + // Format the label the same way, but from a plain JS Date + const label = dateFormatter + ? dateFormatter.format(new Date(cursor)) + : `${cursor.getMonth() + 1}/${cursor.getDate()}/${cursor.getFullYear()}`; + filled.push({ date: label, count: 0 }); + } + + cursor.setDate(cursor.getDate() + 1); + } + return filled; }, [checkouts, config?.schedule.locale, config?.schedule.timezone]); //just in case there is no data at all, display this diff --git a/website/components/kiosks/admin/statistics/TopCheckedOutItems.tsx b/website/components/kiosks/admin/statistics/TopCheckedOutItems.tsx index 643b7ec6..078a5e84 100644 --- a/website/components/kiosks/admin/statistics/TopCheckedOutItems.tsx +++ b/website/components/kiosks/admin/statistics/TopCheckedOutItems.tsx @@ -31,17 +31,14 @@ export default function TopCheckedOutItems({ checkouts.forEach((checkout) => { checkout.items.forEach((checkoutItem) => { - itemCounts[checkoutItem.item_uuid] = - (itemCounts[checkoutItem.item_uuid] || 0) + - checkoutItem.quantity; + const name = + inventoryMap.get(checkoutItem.item_uuid)?.name || "Unknown Item"; + itemCounts[name] = (itemCounts[name] || 0) + checkoutItem.quantity; }); }); return Object.entries(itemCounts) - .map(([uuid, count]) => ({ - name: inventoryMap.get(uuid)?.name || "Unknown Item", - count, - })) + .map(([name, count]) => ({name, count})) .sort((a, b) => b.count - a.count); }, [checkouts, inventoryMap]);