txn filtering based on tags

This commit is contained in:
2026-05-18 07:44:04 +05:30
parent 000c0063e5
commit 58271584ce
2 changed files with 21 additions and 17 deletions

View File

@@ -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 ────────────────────────────────────────────