Dashboard Refactor: Flow-based Metrics + Unified Data Model #4
@@ -14,24 +14,31 @@ function extractTransactions(
|
||||
selectedPeriodId: string | null,
|
||||
selectedGroupKey: GroupKey | null,
|
||||
): Transaction[] {
|
||||
const buckets = filterBuckets(reportData.buckets, selectedGroupKey);
|
||||
// 1. Get raw transactions
|
||||
let rawTxns: Transaction[] = [];
|
||||
|
||||
if (selectedPeriodId) {
|
||||
const key = periodIdToKey(selectedPeriodId);
|
||||
const periods = mergeBucketPeriods(buckets, key);
|
||||
const periods = mergeBucketPeriods(reportData.buckets, key);
|
||||
const selected = periods.find((p) => p.id === selectedPeriodId);
|
||||
|
||||
if (!selected) return [];
|
||||
|
||||
return selected.metric.transactions || [];
|
||||
rawTxns = selected?.metric.transactions || [];
|
||||
} else {
|
||||
const periods = mergeBucketPeriods(reportData.buckets, "all");
|
||||
if (periods.length > 0) {
|
||||
rawTxns = periods[0].metric.transactions || [];
|
||||
}
|
||||
}
|
||||
|
||||
const periods = mergeBucketPeriods(buckets, "all");
|
||||
// 2. Filter by group key
|
||||
if (selectedGroupKey?.tags && selectedGroupKey.tags.length > 0) {
|
||||
return rawTxns.filter(txn => {
|
||||
if (!txn.tags) return false;
|
||||
const txnTags = txn.tags.map(t => typeof t === "string" ? t : t.name);
|
||||
return selectedGroupKey.tags!.every(selectedTag => txnTags.includes(selectedTag));
|
||||
});
|
||||
}
|
||||
|
||||
if (!periods.length) return [];
|
||||
|
||||
const full = periods[0];
|
||||
|
||||
return full.metric.transactions || [];
|
||||
return rawTxns;
|
||||
}
|
||||
|
||||
// ─── Main adapter ────────────────────────────────────────────
|
||||
|
||||
@@ -26,14 +26,11 @@ export default function LatestItems({
|
||||
return buildLatestItems(reportData, selectedPeriodId, selectedGroupKey, mode);
|
||||
}, [reportData, selectedPeriodId, selectedGroupKey, mode]);
|
||||
|
||||
const hasSelection = Boolean(selectedPeriodId) || Boolean(selectedGroupKey);
|
||||
|
||||
const visibleItems = React.useMemo(() => {
|
||||
if (!hasSelection) return allItems.slice(0, 5);
|
||||
return allItems.slice(0, visibleCount);
|
||||
}, [allItems, hasSelection, visibleCount]);
|
||||
}, [allItems, visibleCount]);
|
||||
|
||||
const canExpand = hasSelection && visibleCount < allItems.length;
|
||||
const canExpand = visibleCount < allItems.length;
|
||||
|
||||
return (
|
||||
<LatestItemsView
|
||||
|
||||
Reference in New Issue
Block a user