@mx-cartographer/experiences 9.7.54 → 9.7.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/core/types/Insights.d.ts +13 -5
- package/dist/core/types/Insights.es.js.map +1 -1
- package/dist/core/types/localization/InsightsFeedCopy.d.ts +7 -0
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/TransactionHistoryBlock.es.js +100 -100
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/TransactionHistoryBlock.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/layout.es.js +63 -43
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/layout.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/utils.d.ts +2 -3
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/utils.es.js +25 -20
- package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/utils.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/TransactionListBlock/TransactionListBlock.es.js +45 -29
- package/dist/insights-v2/actionBlocks/TransactionListBlock/TransactionListBlock.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/TransactionListBlock/TransactionListSummaryCard.d.ts +18 -0
- package/dist/insights-v2/actionBlocks/TransactionListBlock/TransactionListSummaryCard.es.js +81 -0
- package/dist/insights-v2/actionBlocks/TransactionListBlock/TransactionListSummaryCard.es.js.map +1 -0
- package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.d.ts +33 -0
- package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.es.js +37 -0
- package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.es.js.map +1 -0
- package/dist/insights-v2/actionBlocks/util.es.js +14 -6
- package/dist/insights-v2/actionBlocks/util.es.js.map +1 -1
- package/dist/insights-v2/mappings/blocks.es.js +83 -82
- package/dist/insights-v2/mappings/blocks.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { buildDynamicCopy as C } from "../../../core/utils/Localization.es.js";
|
|
2
|
-
import { DATE_FORMATS_INTL as A, formatDate as
|
|
3
|
-
import { fromUnixUTC as
|
|
4
|
-
import { getCategoryColor as
|
|
2
|
+
import { DATE_FORMATS_INTL as A, formatDate as h } from "../../../core/constants/DateFormats.es.js";
|
|
3
|
+
import { fromUnixUTC as O } from "../../../core/utils/DateUtil.es.js";
|
|
4
|
+
import { getCategoryColor as I } from "../../../core/utils/CategoryUtil.es.js";
|
|
5
5
|
import { getLayoutConfig as L } from "../../blocks/ChartBlocks/DoubleBarChartBlock/layout.es.js";
|
|
6
|
-
import { MerchantLogo as
|
|
7
|
-
import { Icon as
|
|
8
|
-
import { jsx as
|
|
9
|
-
import { endOfMonth as
|
|
6
|
+
import { MerchantLogo as E } from "@mxenabled/mxui";
|
|
7
|
+
import { Icon as M } from "@mxenabled/mx-icons";
|
|
8
|
+
import { jsx as g } from "react/jsx-runtime";
|
|
9
|
+
import { endOfMonth as f, fromUnixTime as b, isValid as S, parseISO as d, startOfMonth as N } from "date-fns";
|
|
10
10
|
var i = {
|
|
11
11
|
TRANSACTION: "not_standard_amount",
|
|
12
12
|
CATEGORY_SPEND: "category_spend",
|
|
@@ -20,10 +20,10 @@ var i = {
|
|
|
20
20
|
NON_ESSENTIAL_CATEGORY: "non_essential_category_summary",
|
|
21
21
|
DEPOSIT_SUMMARY: "monthly_deposit_summary",
|
|
22
22
|
LOW_BALANCE: "low_balance"
|
|
23
|
-
}, c = (t, e) => e &&
|
|
24
|
-
start:
|
|
25
|
-
end:
|
|
26
|
-
}),
|
|
23
|
+
}, c = (t, e) => e && I(e, t) || t.palette.primary.main, p = (t) => typeof t == "string" ? d(t) : new Date(t ?? NaN), _ = (t) => ({
|
|
24
|
+
start: N(p(t)),
|
|
25
|
+
end: f(p(t))
|
|
26
|
+
}), u = (t) => t?.length ? { accounts: t } : {}, v = ({ beat: t }) => {
|
|
27
27
|
const { account_guid: e, from_date: o, to_date: r } = t.insights_payload?.drilldown_data ?? {};
|
|
28
28
|
return typeof e != "string" || typeof o != "number" || typeof r != "number" || !Number.isFinite(o) || !Number.isFinite(r) || r <= o ? {
|
|
29
29
|
accounts: [],
|
|
@@ -31,65 +31,78 @@ var i = {
|
|
|
31
31
|
} : {
|
|
32
32
|
accounts: [e],
|
|
33
33
|
dateRange: {
|
|
34
|
-
start:
|
|
35
|
-
end:
|
|
34
|
+
start: O(o),
|
|
35
|
+
end: O(r - 1)
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
},
|
|
38
|
+
}, y = ({ beatTransactions: t, dataSeries: e, selectedIndex: o }) => {
|
|
39
39
|
const r = e[o], a = r?.guid, s = t.find((n) => n.guid === a)?.has_been_split;
|
|
40
40
|
return {
|
|
41
41
|
custom: (n) => n.guid === a,
|
|
42
|
-
dateRange:
|
|
42
|
+
dateRange: _(r?.date),
|
|
43
43
|
showSplits: !s
|
|
44
44
|
};
|
|
45
45
|
}, D = ({ dataSeries: t, selectedIndex: e, instanceSlotData: o }) => {
|
|
46
46
|
const r = t[e], a = o.category_guid ?? r?.guid;
|
|
47
47
|
return {
|
|
48
48
|
custom: (s) => s.category_guid === a || s.top_level_category_guid === a,
|
|
49
|
-
dateRange:
|
|
49
|
+
dateRange: _(r?.date)
|
|
50
50
|
};
|
|
51
|
-
},
|
|
51
|
+
}, R = ({ dataSeries: t, selectedIndex: e, spendCategoryGuids: o, instanceSlotData: r }) => {
|
|
52
52
|
const a = t[e];
|
|
53
53
|
return {
|
|
54
54
|
custom: (s) => !!s.top_level_category_guid && o.includes(s.top_level_category_guid),
|
|
55
|
-
dateRange:
|
|
56
|
-
...
|
|
55
|
+
dateRange: _(a?.date),
|
|
56
|
+
...u(r.account_guids)
|
|
57
57
|
};
|
|
58
|
-
},
|
|
59
|
-
const s = e[o], { start: n, end: l } =
|
|
58
|
+
}, B = (t) => typeof t == "number" ? b(t) : d(t ?? ""), G = ({ beat: t, dataSeries: e, selectedIndex: o, isLastTab: r, instanceSlotData: a }) => {
|
|
59
|
+
const s = e[o], { start: n, end: l } = _(s?.date), m = B(t.created_at);
|
|
60
60
|
return {
|
|
61
61
|
dateRange: {
|
|
62
62
|
start: n,
|
|
63
|
-
end: r &&
|
|
63
|
+
end: r && S(m) && m < l ? m : l
|
|
64
64
|
},
|
|
65
|
-
...
|
|
65
|
+
...u(t.account_guids?.length ? t.account_guids : a.account_guids)
|
|
66
66
|
};
|
|
67
|
-
},
|
|
68
|
-
const a = e[o], s = new Set(r === 1 ? a?.comparisonGuids : a?.mainGuids), n =
|
|
69
|
-
return !s.size || !
|
|
67
|
+
}, T = ({ beat: t, comparisonBars: e, selectedIndex: o, subIndex: r }) => {
|
|
68
|
+
const a = e[o], s = new Set(r === 1 ? a?.comparisonGuids : a?.mainGuids), n = d(a?.date ?? "");
|
|
69
|
+
return !s.size || !S(n) ? {
|
|
70
70
|
accounts: [],
|
|
71
71
|
custom: () => !1
|
|
72
72
|
} : {
|
|
73
73
|
custom: (l) => s.has(l.guid),
|
|
74
74
|
dateRange: {
|
|
75
|
-
start:
|
|
76
|
-
end:
|
|
75
|
+
start: N(n),
|
|
76
|
+
end: f(n)
|
|
77
77
|
},
|
|
78
|
-
...
|
|
78
|
+
...u(t.account_guids)
|
|
79
79
|
};
|
|
80
|
-
},
|
|
80
|
+
}, P = ({ beat: t, dataSeries: e, subIndex: o }) => {
|
|
81
|
+
const r = e[o], a = new Set(r?.aggregated_guids), s = d(r?.date ?? "");
|
|
82
|
+
return !a.size || !S(s) ? {
|
|
83
|
+
accounts: [],
|
|
84
|
+
custom: () => !1
|
|
85
|
+
} : {
|
|
86
|
+
custom: (n) => a.has(n.guid),
|
|
87
|
+
dateRange: {
|
|
88
|
+
start: N(s),
|
|
89
|
+
end: f(s)
|
|
90
|
+
},
|
|
91
|
+
...u(t.account_guids)
|
|
92
|
+
};
|
|
93
|
+
}, j = {
|
|
81
94
|
[i.TRANSACTION]: {
|
|
82
95
|
top: "singleBar",
|
|
83
96
|
scope: "store",
|
|
84
97
|
filterMode: "store",
|
|
85
|
-
filterStrategy:
|
|
98
|
+
filterStrategy: y,
|
|
86
99
|
colors: (t, e) => [c(t, e)],
|
|
87
100
|
header: (t) => {
|
|
88
101
|
const { title: e, subHeader: o } = t;
|
|
89
102
|
return {
|
|
90
103
|
heading: e,
|
|
91
104
|
subHeadingText: o?.text || void 0,
|
|
92
|
-
icon: /* @__PURE__ */
|
|
105
|
+
icon: /* @__PURE__ */ g(E, {
|
|
93
106
|
alt: o?.text,
|
|
94
107
|
categoryGuid: o?.logo?.category_guid || "",
|
|
95
108
|
merchantGuid: o?.logo?.merchant_guid || "",
|
|
@@ -98,7 +111,7 @@ var i = {
|
|
|
98
111
|
};
|
|
99
112
|
},
|
|
100
113
|
tipSection: (t, e, o = "") => ({
|
|
101
|
-
message: C(e.general.tip_section_message, /* @__PURE__ */
|
|
114
|
+
message: C(e.general.tip_section_message, /* @__PURE__ */ g("strong", { children: e.general.tip_section_title }), /* @__PURE__ */ g("strong", { children: o })),
|
|
102
115
|
onDismiss: () => t(!0)
|
|
103
116
|
})
|
|
104
117
|
},
|
|
@@ -110,8 +123,8 @@ var i = {
|
|
|
110
123
|
colors: (t, e) => [c(t, e)],
|
|
111
124
|
header: (t) => ({
|
|
112
125
|
heading: t.categoryName,
|
|
113
|
-
subHeadingText: t.selectedDate &&
|
|
114
|
-
icon: /* @__PURE__ */
|
|
126
|
+
subHeadingText: t.selectedDate && h(p(t.selectedDate), A.MONTH_LONG) || "",
|
|
127
|
+
icon: /* @__PURE__ */ g(M, {
|
|
115
128
|
name: "calendar_month",
|
|
116
129
|
size: 16
|
|
117
130
|
})
|
|
@@ -119,7 +132,7 @@ var i = {
|
|
|
119
132
|
},
|
|
120
133
|
[i.MONTHLY_SPEND]: {
|
|
121
134
|
top: "singleBar",
|
|
122
|
-
filterStrategy:
|
|
135
|
+
filterStrategy: R,
|
|
123
136
|
scope: "store",
|
|
124
137
|
filterMode: "store",
|
|
125
138
|
colors: (t) => [t.palette.chart.chart2 ?? t.palette.primary.main]
|
|
@@ -133,7 +146,7 @@ var i = {
|
|
|
133
146
|
},
|
|
134
147
|
[i.UPCOMING_BILL]: {
|
|
135
148
|
top: "upcomingBill",
|
|
136
|
-
filterStrategy:
|
|
149
|
+
filterStrategy: y,
|
|
137
150
|
scope: "beat",
|
|
138
151
|
filterMode: "local",
|
|
139
152
|
colors: (t, e) => [c(t, e)]
|
|
@@ -147,7 +160,7 @@ var i = {
|
|
|
147
160
|
},
|
|
148
161
|
[i.SPEND_TO_INCOME]: {
|
|
149
162
|
top: "doubleBar",
|
|
150
|
-
filterStrategy:
|
|
163
|
+
filterStrategy: T,
|
|
151
164
|
scope: "store",
|
|
152
165
|
filterMode: "store",
|
|
153
166
|
colors: (t) => L(t, "spend_to_income")?.color ?? [],
|
|
@@ -155,23 +168,30 @@ var i = {
|
|
|
155
168
|
},
|
|
156
169
|
[i.COST_OF_LIVING]: {
|
|
157
170
|
top: "doubleBar",
|
|
158
|
-
filterStrategy:
|
|
171
|
+
filterStrategy: T,
|
|
159
172
|
scope: "store",
|
|
160
173
|
filterMode: "store",
|
|
161
174
|
colors: (t, e) => [c(t, e), t.palette.chart.chart4 ?? t.palette.primary.main],
|
|
162
175
|
subTabAriaLabels: (t) => [void 0, t.general.income_transactions]
|
|
176
|
+
},
|
|
177
|
+
[i.NON_ESSENTIAL_CATEGORY]: {
|
|
178
|
+
top: "tabsOnly",
|
|
179
|
+
filterStrategy: P,
|
|
180
|
+
scope: "store",
|
|
181
|
+
filterMode: "store",
|
|
182
|
+
colors: (t) => [t.palette.primary.main]
|
|
163
183
|
}
|
|
164
|
-
},
|
|
184
|
+
}, K = {
|
|
165
185
|
top: "singleBar",
|
|
166
|
-
filterStrategy:
|
|
186
|
+
filterStrategy: y,
|
|
167
187
|
scope: "store",
|
|
168
188
|
filterMode: "store",
|
|
169
189
|
colors: (t, e) => [c(t, e)]
|
|
170
190
|
};
|
|
171
191
|
export {
|
|
172
192
|
i as DRILLDOWN_VARIANTS,
|
|
173
|
-
|
|
174
|
-
|
|
193
|
+
K as FALLBACK,
|
|
194
|
+
j as layout
|
|
175
195
|
};
|
|
176
196
|
|
|
177
197
|
//# sourceMappingURL=layout.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionHistoryBlock/layout.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport type { Theme } from '@mui/material/styles'\nimport { endOfMonth, fromUnixTime, isValid, parseISO, startOfMonth } from 'date-fns'\nimport { getCategoryColor } from '../../../core/utils/CategoryUtil'\nimport {\n type Beat,\n type InsightsFeedCopy,\n type Subtitle,\n type Transaction,\n buildDynamicCopy,\n} from '../../../core'\nimport type { TransactionFilter } from '../../../core/stores/TransactionStore'\nimport type {\n DataSet,\n InsightsInstanceSlotData,\n} from '../../../core/types/InsightsInstanceSlotData'\nimport { MerchantLogo } from '@mxenabled/mxui'\nimport { DATE_FORMATS_INTL, formatDate } from '../../../core/constants'\nimport { fromUnixUTC } from '../../../core/utils/DateUtil'\nimport { Icon } from '@mxenabled/mx-icons'\nimport type { ChartDataSeriesItem } from '../../blocks/ChartBlocks/BarchartBlock/utils'\nimport { getLayoutConfig as getDoubleBarLayoutConfig } from '../../blocks/ChartBlocks/DoubleBarChartBlock/layout'\nimport type { TipSectionProps } from '../../../insights/components/shared/ChartDrawerTemplate/TipSection'\n\nexport interface DrillDownHeader {\n heading?: string\n subHeadingText?: string\n icon?: ReactNode\n}\n\nexport interface DrillDownHeaderContext {\n title?: string\n subHeader?: Subtitle\n categoryName: string\n selectedDate?: string | Date\n}\n\nexport const DRILLDOWN_VARIANTS = {\n TRANSACTION: 'not_standard_amount',\n CATEGORY_SPEND: 'category_spend',\n MONTHLY_SPEND: 'monthly_spend_comparison',\n ACCOUNT_BALANCE: 'account_balance',\n UPCOMING_BILL: 'upcoming_bill',\n SPEND_TO_INCOME: 'monthly_spend_to_income',\n SAVINGS_TO_INCOME: 'monthly_savings_to_income',\n DEBT_TO_INCOME: 'monthly_debt_to_income',\n COST_OF_LIVING: 'cost_living_to_income',\n NON_ESSENTIAL_CATEGORY: 'non_essential_category_summary',\n DEPOSIT_SUMMARY: 'monthly_deposit_summary',\n LOW_BALANCE: 'low_balance',\n} as const\n\nexport type DrillDownVariant = (typeof DRILLDOWN_VARIANTS)[keyof typeof DRILLDOWN_VARIANTS]\n\n/**\n * One row of the flattened data_series a filterStrategy indexes into: a single-bar monthly total or a\n * synthesized upcoming-bill bar. Fields are optional because the backend keys each row dynamically\n * from data_series.names and not every variant carries a guid/category. Double-bar comparison rows\n * will extend this in the next MR.\n */\n\n// Resolves the top-chart palette from the theme (and the beat's category, when relevant).\nexport type ColorKind = (theme: Theme, categoryGuid?: string) => string[]\n\n// Resolves the dynamic drawer header (heading/sub-heading/icon JSX) from the selection context.\nexport type HeaderKind = (ctx: DrillDownHeaderContext) => DrillDownHeader\n\n/**\n * Everything a filterStrategy needs to turn the currently-selected bar/sub-tab into a\n * TransactionFilter. Data-only so strategies stay pure and testable.\n */\nexport interface FilterContext {\n beat: Beat\n beatTransactions: Transaction[]\n dataSeries: ChartDataSeriesItem[]\n // The double-bar drawer's month columns (main / comparison per month, with their guids); empty\n // for every other top kind.\n comparisonBars: DataSet[]\n selectedIndex: number\n subIndex: number\n isLastTab: boolean\n instanceSlotData: InsightsInstanceSlotData\n spendCategoryGuids: string[]\n displayedDateRange: { start: Date; end: Date }\n}\n\n// Resolves the current selection into a TransactionFilter. Carried on each config row so behavior\n// lives next to the variant it belongs to (no separate strategy registry to chase).\nexport type FilterStrategy = (ctx: FilterContext) => TransactionFilter\n\nexport interface DrillDownVariantConfig {\n // `list`: no chart or tabs above the transaction list (an account's transactions for a window).\n top: 'singleBar' | 'upcomingBill' | 'doubleBar' | 'tabsOnly' | 'list'\n filterStrategy: FilterStrategy\n colors: ColorKind\n header?: HeaderKind\n tipSection?: (\n setCloseTipSection: (flag: boolean) => void,\n copy: InsightsFeedCopy,\n merchantName?: string,\n ) => TipSectionProps\n scope: 'store' | 'beat'\n filterMode: 'store' | 'local'\n // Double bar: accessible names for the series tabs ([0] main, [1] comparison), as legacy pulse.\n subTabAriaLabels?: (copy: InsightsFeedCopy) => (string | undefined)[]\n}\nconst categoryColor = (theme: Theme, categoryGuid?: string): string =>\n (categoryGuid && getCategoryColor(categoryGuid, theme)) || theme.palette.primary.main\n\nconst toLocalDate = (date: string | number | Date | undefined) =>\n typeof date === 'string' ? parseISO(date) : new Date(date ?? NaN)\n\nconst monthRange = (date: string | number | Date | undefined) => ({\n start: startOfMonth(toLocalDate(date)),\n end: endOfMonth(toLocalDate(date)),\n})\n\n// Scopes a filter to the beat's accounts when the beat carries account_guids; otherwise leaves\n// accounts unset so the store default (all accounts) applies.\nconst accountScope = (accountGuids?: string[]): Pick<TransactionFilter, 'accounts'> =>\n accountGuids?.length ? { accounts: accountGuids } : {}\n\n// Low Account Balance — `drilldown_data` names one account and a window (epoch seconds at UTC\n// midnight, to_date exclusive). Fails closed: a drawer that cannot name its rows shows none.\nconst accountWindowStrategy: FilterStrategy = ({ beat }) => {\n const { account_guid, from_date, to_date } = beat.insights_payload?.drilldown_data ?? {}\n if (\n typeof account_guid !== 'string' ||\n typeof from_date !== 'number' ||\n typeof to_date !== 'number' ||\n !Number.isFinite(from_date) ||\n !Number.isFinite(to_date) ||\n to_date <= from_date\n ) {\n return { accounts: [], custom: () => false }\n }\n\n return {\n accounts: [account_guid],\n dateRange: { start: fromUnixUTC(from_date), end: fromUnixUTC(to_date - 1) },\n }\n}\n\n// ── Single-bar filter strategies (this MR) ────────────────────────────────────────────────────\n\n// BillAmountNotStandard / UpcomingBill — the series carries a transaction (TRN) guid; match a single\n// transaction by guid within its month.\nconst transactionGuidStrategy: FilterStrategy = ({\n beatTransactions,\n dataSeries,\n selectedIndex,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n const seriesGuid = seriesItem?.guid\n const hasBeenSplit = beatTransactions.find((trn) => trn.guid === seriesGuid)?.has_been_split\n\n return {\n custom: (trn) => trn.guid === seriesGuid,\n dateRange: monthRange(seriesItem?.date),\n showSplits: !hasBeenSplit,\n }\n}\n\n// CategorySpendingV2 — match transactions in the beat's category (or whose top-level category is that\n// guid) within the month.\nconst categoryStrategy: FilterStrategy = ({ dataSeries, selectedIndex, instanceSlotData }) => {\n const seriesItem = dataSeries[selectedIndex]\n const categoryGuid = instanceSlotData.category_guid ?? seriesItem?.guid\n\n return {\n custom: (trn) =>\n trn.category_guid === categoryGuid || trn.top_level_category_guid === categoryGuid,\n dateRange: monthRange(seriesItem?.date),\n }\n}\n\n// MonthlySpendComparisonV2 — no per-bar guid; show all spending-category transactions\n// (income/transfers/investments excluded via spendCategoryGuids) within the month.\nconst spendCategoriesStrategy: FilterStrategy = ({\n dataSeries,\n selectedIndex,\n spendCategoryGuids,\n instanceSlotData,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n\n return {\n custom: (trn) =>\n !!trn.top_level_category_guid && spendCategoryGuids.includes(trn.top_level_category_guid),\n dateRange: monthRange(seriesItem?.date),\n ...accountScope(instanceSlotData.account_guids),\n }\n}\n\n// The beat's creation: tupac sends epoch seconds on the envelope and an ISO string on the wrapper.\nconst toCreatedAt = (createdAt: Beat['created_at']) =>\n typeof createdAt === 'number' ? fromUnixTime(createdAt) : parseISO(createdAt ?? '')\n\n// SavingsAccountBalancesSummary — balances, not categorized spend: the beat's account within the\n// month. Bars are snapshots, so the most recent month ends at the beat's creation (the partial month\n// its balance was taken in); an older month, or a beat created after its last month ended, keeps the\n// whole month.\nconst accountDateStrategy: FilterStrategy = ({\n beat,\n dataSeries,\n selectedIndex,\n isLastTab,\n instanceSlotData,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n const { start, end } = monthRange(seriesItem?.date)\n const createdAt = toCreatedAt(beat.created_at)\n\n return {\n dateRange: {\n start,\n end: isLastTab && isValid(createdAt) && createdAt < end ? createdAt : end,\n },\n ...accountScope(\n beat.account_guids?.length ? beat.account_guids : instanceSlotData.account_guids,\n ),\n }\n}\n\n// ── Double-bar strategies ──────────────────────────────────────────────────────────────────────\n\n// Monthly Spend to Income Comparison — the selected month's main (Spend, sub-tab 0) or comparison\n// (Income, sub-tab 1) transactions: membership in that bar's stored guids (data_series\n// aggregated_guids), within the month. Fails closed: a bar that names no guids for the tab shows none.\nconst comparisonGuidsStrategy: FilterStrategy = ({\n beat,\n comparisonBars,\n selectedIndex,\n subIndex,\n}) => {\n const bar = comparisonBars[selectedIndex]\n const guids = new Set(subIndex === 1 ? bar?.comparisonGuids : bar?.mainGuids)\n // parseISO reads the 'yyyy-MM-dd' bar date as a local calendar day, so the month never shifts with\n // the viewer's time zone; a missing bar, guid list or date fails closed.\n const month = parseISO(bar?.date ?? '')\n if (!guids.size || !isValid(month)) return { accounts: [], custom: () => false }\n\n return {\n custom: (trn) => guids.has(trn.guid),\n dateRange: { start: startOfMonth(month), end: endOfMonth(month) },\n // The V2 payload carries no account_guids (neither instance_slot.data nor insights_payload).\n ...accountScope(beat.account_guids),\n }\n}\n\n// TODO(next MR — tabsOnly): aggregatedGuids / depositSummary strategies for the donut-drawer beats.\n\nexport const layout: Partial<Record<DrillDownVariant, DrillDownVariantConfig>> = {\n [DRILLDOWN_VARIANTS.TRANSACTION]: {\n top: 'singleBar',\n scope: 'store',\n filterMode: 'store',\n filterStrategy: transactionGuidStrategy,\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n header: (ctx: DrillDownHeaderContext) => {\n const { title, subHeader } = ctx\n return {\n heading: title,\n subHeadingText: subHeader?.text || undefined,\n icon: (\n <MerchantLogo\n alt={subHeader?.text}\n categoryGuid={subHeader?.logo?.category_guid || ''}\n merchantGuid={subHeader?.logo?.merchant_guid || ''}\n size={16}\n />\n ),\n }\n },\n tipSection: (setCloseTipSection, copy, merchantName = '') => {\n return {\n message: buildDynamicCopy(\n copy.general.tip_section_message,\n <strong>{copy.general.tip_section_title}</strong>,\n <strong>{merchantName}</strong>,\n ),\n onDismiss: () => setCloseTipSection(true),\n } as TipSectionProps\n },\n },\n [DRILLDOWN_VARIANTS.CATEGORY_SPEND]: {\n top: 'singleBar',\n filterStrategy: categoryStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n header: (ctx: DrillDownHeaderContext) => {\n return {\n heading: ctx.categoryName,\n subHeadingText: ctx.selectedDate\n ? formatDate(toLocalDate(ctx.selectedDate), DATE_FORMATS_INTL.MONTH_LONG) || ''\n : '',\n icon: <Icon name=\"calendar_month\" size={16} />,\n }\n },\n },\n [DRILLDOWN_VARIANTS.MONTHLY_SPEND]: {\n top: 'singleBar',\n filterStrategy: spendCategoriesStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.chart.chart2 ?? theme.palette.primary.main],\n },\n [DRILLDOWN_VARIANTS.ACCOUNT_BALANCE]: {\n top: 'singleBar',\n filterStrategy: accountDateStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.success.main],\n },\n [DRILLDOWN_VARIANTS.UPCOMING_BILL]: {\n top: 'upcomingBill',\n filterStrategy: transactionGuidStrategy,\n scope: 'beat',\n filterMode: 'local',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n },\n\n // Low Account Balance's \"Transactions\" link: the account's transactions for the alert's window.\n [DRILLDOWN_VARIANTS.LOW_BALANCE]: {\n top: 'list',\n filterStrategy: accountWindowStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.primary.main],\n },\n\n // ── Double-bar comparison beats (month tabs + main / comparison sub-tabs) ────────────────────\n // Monthly Spend to Income Comparison: Spend vs Income per month, in the card block's palette.\n [DRILLDOWN_VARIANTS.SPEND_TO_INCOME]: {\n top: 'doubleBar',\n filterStrategy: comparisonGuidsStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => getDoubleBarLayoutConfig(theme, 'spend_to_income')?.color ?? [],\n subTabAriaLabels: (copy) => [copy.general.spend_transactions, copy.general.income_transactions],\n },\n // Cost of Living to Income: one living-cost category (Housing, Groceries, ...) vs Income per month.\n // The cost bar takes the beat category's colour and Income the legacy chart4, as the pulse drawer.\n [DRILLDOWN_VARIANTS.COST_OF_LIVING]: {\n top: 'doubleBar',\n filterStrategy: comparisonGuidsStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [\n categoryColor(theme, categoryGuid),\n theme.palette.chart.chart4 ?? theme.palette.primary.main,\n ],\n subTabAriaLabels: (copy) => [undefined, copy.general.income_transactions],\n },\n // NEXT MR — the other double-bar beats reuse comparisonGuidsStrategy with their own palettes:\n // [DRILLDOWN_VARIANTS.SAVINGS_TO_INCOME]: comparison('savingsVsIncome'),\n // [DRILLDOWN_VARIANTS.DEBT_TO_INCOME]: comparison('debtVsIncome'),\n //\n // ── NEXT MR: tabsOnly donut-drawer beats (no top chart) ───────────────────────────────────\n // [DRILLDOWN_VARIANTS.NON_ESSENTIAL_CATEGORY]: { top: 'tabsOnly', ... },\n // [DRILLDOWN_VARIANTS.DEPOSIT_SUMMARY]: { top: 'tabsOnly', ... },\n}\n\n// Fallback for a missing/typo'd backend variant: a single-bar, store-scoped drawer filtered by the\n// beat's transaction guid and colored by category, so the drawer still renders instead of crashing.\nexport const FALLBACK: DrillDownVariantConfig = {\n top: 'singleBar',\n filterStrategy: transactionGuidStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n}\n"],"mappings":";;;;;;;;;AAqCA,IAAa,IAAqB;AAAA,EAChC,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACn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ACP,YAAY;AAAA,IACZ,QAAA,CAAS,MAAiB,EAAyB,GAAO,iBAAiB,GAAG,SAAS,CAAC;AAAA,IACxF,kBAAA,CAAmB,MAAS,CAAC,EAAK,QAAQ,oBAAoB,EAAK,QAAQ,mBAAmB;AAAA,EAChG;AAAA,EAGC,CAAA,EAAmB,cAAA,GAAiB;AAAA,IACnC,KAAK;AAAA,IACL,gBAAgB;AAAA,IAChB,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,QAAA,CAAS,GAAc,MAA0B,CAC/C,EAAc,GAAO,CAAY,GACjC,EAAM,QAAQ,MAAM,UAAU,EAAM,QAAQ,QAAQ,IACtD;AAAA,IACA,kBAAA,CAAmB,MAAS,CAAC,QAAW,EAAK,QAAQ,mBAAmB;AAAA,EAC1E;AAQF,GAIa,IAAmC;AAAA,EAC9C,KAAK;AAAA,EACL,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,QAAA,CAAS,GAAc,MAA0B,CAAC,EAAc,GAAO,CAAY,CAAC;AACtF"}
|
|
1
|
+
{"version":3,"file":"layout.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionHistoryBlock/layout.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport type { Theme } from '@mui/material/styles'\nimport { endOfMonth, fromUnixTime, isValid, parseISO, startOfMonth } from 'date-fns'\nimport { getCategoryColor } from '../../../core/utils/CategoryUtil'\nimport {\n type Beat,\n type InsightsFeedCopy,\n type Subtitle,\n type Transaction,\n buildDynamicCopy,\n} from '../../../core'\nimport type { TransactionFilter } from '../../../core/stores/TransactionStore'\nimport type {\n DataSet,\n InsightsInstanceSlotData,\n} from '../../../core/types/InsightsInstanceSlotData'\nimport { MerchantLogo } from '@mxenabled/mxui'\nimport { DATE_FORMATS_INTL, formatDate } from '../../../core/constants'\nimport { fromUnixUTC } from '../../../core/utils/DateUtil'\nimport { Icon } from '@mxenabled/mx-icons'\nimport type { ChartDataSeriesItem } from '../../blocks/ChartBlocks/BarchartBlock/utils'\nimport { getLayoutConfig as getDoubleBarLayoutConfig } from '../../blocks/ChartBlocks/DoubleBarChartBlock/layout'\nimport type { TipSectionProps } from '../../../insights/components/shared/ChartDrawerTemplate/TipSection'\n\nexport interface DrillDownHeader {\n heading?: string\n subHeadingText?: string\n icon?: ReactNode\n}\n\nexport interface DrillDownHeaderContext {\n title?: string\n subHeader?: Subtitle\n categoryName: string\n selectedDate?: string | Date\n}\n\nexport const DRILLDOWN_VARIANTS = {\n TRANSACTION: 'not_standard_amount',\n CATEGORY_SPEND: 'category_spend',\n MONTHLY_SPEND: 'monthly_spend_comparison',\n ACCOUNT_BALANCE: 'account_balance',\n UPCOMING_BILL: 'upcoming_bill',\n SPEND_TO_INCOME: 'monthly_spend_to_income',\n SAVINGS_TO_INCOME: 'monthly_savings_to_income',\n DEBT_TO_INCOME: 'monthly_debt_to_income',\n COST_OF_LIVING: 'cost_living_to_income',\n NON_ESSENTIAL_CATEGORY: 'non_essential_category_summary',\n DEPOSIT_SUMMARY: 'monthly_deposit_summary',\n LOW_BALANCE: 'low_balance',\n} as const\n\nexport type DrillDownVariant = (typeof DRILLDOWN_VARIANTS)[keyof typeof DRILLDOWN_VARIANTS]\n\n/**\n * One row of the flattened data_series a filterStrategy indexes into: a single-bar monthly total or a\n * synthesized upcoming-bill bar. Fields are optional because the backend keys each row dynamically\n * from data_series.names and not every variant carries a guid/category. Double-bar comparison rows\n * will extend this in the next MR.\n */\n\n// Resolves the top-chart palette from the theme (and the beat's category, when relevant).\nexport type ColorKind = (theme: Theme, categoryGuid?: string) => string[]\n\n// Resolves the dynamic drawer header (heading/sub-heading/icon JSX) from the selection context.\nexport type HeaderKind = (ctx: DrillDownHeaderContext) => DrillDownHeader\n\n/**\n * Everything a filterStrategy needs to turn the currently-selected bar/sub-tab into a\n * TransactionFilter. Data-only so strategies stay pure and testable.\n */\nexport interface FilterContext {\n beat: Beat\n beatTransactions: Transaction[]\n dataSeries: ChartDataSeriesItem[]\n // The double-bar drawer's month columns (main / comparison per month, with their guids); empty\n // for every other top kind.\n comparisonBars: DataSet[]\n selectedIndex: number\n subIndex: number\n isLastTab: boolean\n instanceSlotData: InsightsInstanceSlotData\n spendCategoryGuids: string[]\n displayedDateRange: { start: Date; end: Date }\n}\n\n// Resolves the current selection into a TransactionFilter. Carried on each config row so behavior\n// lives next to the variant it belongs to (no separate strategy registry to chase).\nexport type FilterStrategy = (ctx: FilterContext) => TransactionFilter\n\nexport interface DrillDownVariantConfig {\n // `list`: no chart or tabs above the transaction list (an account's transactions for a window).\n top: 'singleBar' | 'upcomingBill' | 'doubleBar' | 'tabsOnly' | 'list'\n filterStrategy: FilterStrategy\n colors: ColorKind\n header?: HeaderKind\n tipSection?: (\n setCloseTipSection: (flag: boolean) => void,\n copy: InsightsFeedCopy,\n merchantName?: string,\n ) => TipSectionProps\n scope: 'store' | 'beat'\n filterMode: 'store' | 'local'\n // Double bar: accessible names for the series tabs ([0] main, [1] comparison), as legacy pulse.\n subTabAriaLabels?: (copy: InsightsFeedCopy) => (string | undefined)[]\n}\nconst categoryColor = (theme: Theme, categoryGuid?: string): string =>\n (categoryGuid && getCategoryColor(categoryGuid, theme)) || theme.palette.primary.main\n\nconst toLocalDate = (date: string | number | Date | undefined) =>\n typeof date === 'string' ? parseISO(date) : new Date(date ?? NaN)\n\nconst monthRange = (date: string | number | Date | undefined) => ({\n start: startOfMonth(toLocalDate(date)),\n end: endOfMonth(toLocalDate(date)),\n})\n\n// Scopes a filter to the beat's accounts when the beat carries account_guids; otherwise leaves\n// accounts unset so the store default (all accounts) applies.\nconst accountScope = (accountGuids?: string[]): Pick<TransactionFilter, 'accounts'> =>\n accountGuids?.length ? { accounts: accountGuids } : {}\n\n// Low Account Balance — `drilldown_data` names one account and a window (epoch seconds at UTC\n// midnight, to_date exclusive). Fails closed: a drawer that cannot name its rows shows none.\nconst accountWindowStrategy: FilterStrategy = ({ beat }) => {\n const { account_guid, from_date, to_date } = beat.insights_payload?.drilldown_data ?? {}\n if (\n typeof account_guid !== 'string' ||\n typeof from_date !== 'number' ||\n typeof to_date !== 'number' ||\n !Number.isFinite(from_date) ||\n !Number.isFinite(to_date) ||\n to_date <= from_date\n ) {\n return { accounts: [], custom: () => false }\n }\n\n return {\n accounts: [account_guid],\n dateRange: { start: fromUnixUTC(from_date), end: fromUnixUTC(to_date - 1) },\n }\n}\n\n// ── Single-bar filter strategies (this MR) ────────────────────────────────────────────────────\n\n// BillAmountNotStandard / UpcomingBill — the series carries a transaction (TRN) guid; match a single\n// transaction by guid within its month.\nconst transactionGuidStrategy: FilterStrategy = ({\n beatTransactions,\n dataSeries,\n selectedIndex,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n const seriesGuid = seriesItem?.guid\n const hasBeenSplit = beatTransactions.find((trn) => trn.guid === seriesGuid)?.has_been_split\n\n return {\n custom: (trn) => trn.guid === seriesGuid,\n dateRange: monthRange(seriesItem?.date),\n showSplits: !hasBeenSplit,\n }\n}\n\n// CategorySpendingV2 — match transactions in the beat's category (or whose top-level category is that\n// guid) within the month.\nconst categoryStrategy: FilterStrategy = ({ dataSeries, selectedIndex, instanceSlotData }) => {\n const seriesItem = dataSeries[selectedIndex]\n const categoryGuid = instanceSlotData.category_guid ?? seriesItem?.guid\n\n return {\n custom: (trn) =>\n trn.category_guid === categoryGuid || trn.top_level_category_guid === categoryGuid,\n dateRange: monthRange(seriesItem?.date),\n }\n}\n\n// MonthlySpendComparisonV2 — no per-bar guid; show all spending-category transactions\n// (income/transfers/investments excluded via spendCategoryGuids) within the month.\nconst spendCategoriesStrategy: FilterStrategy = ({\n dataSeries,\n selectedIndex,\n spendCategoryGuids,\n instanceSlotData,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n\n return {\n custom: (trn) =>\n !!trn.top_level_category_guid && spendCategoryGuids.includes(trn.top_level_category_guid),\n dateRange: monthRange(seriesItem?.date),\n ...accountScope(instanceSlotData.account_guids),\n }\n}\n\n// The beat's creation: tupac sends epoch seconds on the envelope and an ISO string on the wrapper.\nconst toCreatedAt = (createdAt: Beat['created_at']) =>\n typeof createdAt === 'number' ? fromUnixTime(createdAt) : parseISO(createdAt ?? '')\n\n// SavingsAccountBalancesSummary — balances, not categorized spend: the beat's account within the\n// month. Bars are snapshots, so the most recent month ends at the beat's creation (the partial month\n// its balance was taken in); an older month, or a beat created after its last month ended, keeps the\n// whole month.\nconst accountDateStrategy: FilterStrategy = ({\n beat,\n dataSeries,\n selectedIndex,\n isLastTab,\n instanceSlotData,\n}) => {\n const seriesItem = dataSeries[selectedIndex]\n const { start, end } = monthRange(seriesItem?.date)\n const createdAt = toCreatedAt(beat.created_at)\n\n return {\n dateRange: {\n start,\n end: isLastTab && isValid(createdAt) && createdAt < end ? createdAt : end,\n },\n ...accountScope(\n beat.account_guids?.length ? beat.account_guids : instanceSlotData.account_guids,\n ),\n }\n}\n\n// ── Double-bar strategies ──────────────────────────────────────────────────────────────────────\n\n// Monthly Spend to Income Comparison — the selected month's main (Spend, sub-tab 0) or comparison\n// (Income, sub-tab 1) transactions: membership in that bar's stored guids (data_series\n// aggregated_guids), within the month. Fails closed: a bar that names no guids for the tab shows none.\nconst comparisonGuidsStrategy: FilterStrategy = ({\n beat,\n comparisonBars,\n selectedIndex,\n subIndex,\n}) => {\n const bar = comparisonBars[selectedIndex]\n const guids = new Set(subIndex === 1 ? bar?.comparisonGuids : bar?.mainGuids)\n // parseISO reads the 'yyyy-MM-dd' bar date as a local calendar day, so the month never shifts with\n // the viewer's time zone; a missing bar, guid list or date fails closed.\n const month = parseISO(bar?.date ?? '')\n if (!guids.size || !isValid(month)) return { accounts: [], custom: () => false }\n\n return {\n custom: (trn) => guids.has(trn.guid),\n dateRange: { start: startOfMonth(month), end: endOfMonth(month) },\n // The V2 payload carries no account_guids (neither instance_slot.data nor insights_payload).\n ...accountScope(beat.account_guids),\n }\n}\n\n// ── Tabs-only strategies ───────────────────────────────────────────────────────────────────────\n\n// Monthly Non-Essential Category Summary — the series is the two sides of one month (non-essential /\n// essential), not a time series; each row names its own aggregated_guids. The selected sub-tab picks\n// the row, within the row's month. Fails closed, as comparisonGuidsStrategy does: a side that names\n// no guids or no readable date shows none, never the store's displayed range.\nconst aggregatedGuidsStrategy: FilterStrategy = ({ beat, dataSeries, subIndex }) => {\n const row = dataSeries[subIndex]\n const guids = new Set(row?.aggregated_guids)\n const month = parseISO(row?.date ?? '')\n if (!guids.size || !isValid(month)) return { accounts: [], custom: () => false }\n\n return {\n custom: (trn) => guids.has(trn.guid),\n dateRange: { start: startOfMonth(month), end: endOfMonth(month) },\n ...accountScope(beat.account_guids),\n }\n}\n\nexport const layout: Partial<Record<DrillDownVariant, DrillDownVariantConfig>> = {\n [DRILLDOWN_VARIANTS.TRANSACTION]: {\n top: 'singleBar',\n scope: 'store',\n filterMode: 'store',\n filterStrategy: transactionGuidStrategy,\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n header: (ctx: DrillDownHeaderContext) => {\n const { title, subHeader } = ctx\n return {\n heading: title,\n subHeadingText: subHeader?.text || undefined,\n icon: (\n <MerchantLogo\n alt={subHeader?.text}\n categoryGuid={subHeader?.logo?.category_guid || ''}\n merchantGuid={subHeader?.logo?.merchant_guid || ''}\n size={16}\n />\n ),\n }\n },\n tipSection: (setCloseTipSection, copy, merchantName = '') => {\n return {\n message: buildDynamicCopy(\n copy.general.tip_section_message,\n <strong>{copy.general.tip_section_title}</strong>,\n <strong>{merchantName}</strong>,\n ),\n onDismiss: () => setCloseTipSection(true),\n } as TipSectionProps\n },\n },\n [DRILLDOWN_VARIANTS.CATEGORY_SPEND]: {\n top: 'singleBar',\n filterStrategy: categoryStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n header: (ctx: DrillDownHeaderContext) => {\n return {\n heading: ctx.categoryName,\n subHeadingText: ctx.selectedDate\n ? formatDate(toLocalDate(ctx.selectedDate), DATE_FORMATS_INTL.MONTH_LONG) || ''\n : '',\n icon: <Icon name=\"calendar_month\" size={16} />,\n }\n },\n },\n [DRILLDOWN_VARIANTS.MONTHLY_SPEND]: {\n top: 'singleBar',\n filterStrategy: spendCategoriesStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.chart.chart2 ?? theme.palette.primary.main],\n },\n [DRILLDOWN_VARIANTS.ACCOUNT_BALANCE]: {\n top: 'singleBar',\n filterStrategy: accountDateStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.success.main],\n },\n [DRILLDOWN_VARIANTS.UPCOMING_BILL]: {\n top: 'upcomingBill',\n filterStrategy: transactionGuidStrategy,\n scope: 'beat',\n filterMode: 'local',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n },\n\n // Low Account Balance's \"Transactions\" link: the account's transactions for the alert's window.\n [DRILLDOWN_VARIANTS.LOW_BALANCE]: {\n top: 'list',\n filterStrategy: accountWindowStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.primary.main],\n },\n\n // ── Double-bar comparison beats (month tabs + main / comparison sub-tabs) ────────────────────\n // Monthly Spend to Income Comparison: Spend vs Income per month, in the card block's palette.\n [DRILLDOWN_VARIANTS.SPEND_TO_INCOME]: {\n top: 'doubleBar',\n filterStrategy: comparisonGuidsStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => getDoubleBarLayoutConfig(theme, 'spend_to_income')?.color ?? [],\n subTabAriaLabels: (copy) => [copy.general.spend_transactions, copy.general.income_transactions],\n },\n // Cost of Living to Income: one living-cost category (Housing, Groceries, ...) vs Income per month.\n // The cost bar takes the beat category's colour and Income the legacy chart4, as the pulse drawer.\n [DRILLDOWN_VARIANTS.COST_OF_LIVING]: {\n top: 'doubleBar',\n filterStrategy: comparisonGuidsStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [\n categoryColor(theme, categoryGuid),\n theme.palette.chart.chart4 ?? theme.palette.primary.main,\n ],\n subTabAriaLabels: (copy) => [undefined, copy.general.income_transactions],\n },\n // NEXT MR — the other double-bar beats reuse comparisonGuidsStrategy with their own palettes:\n // [DRILLDOWN_VARIANTS.SAVINGS_TO_INCOME]: comparison('savingsVsIncome'),\n // [DRILLDOWN_VARIANTS.DEBT_TO_INCOME]: comparison('debtVsIncome'),\n\n // ── Tabs-only beats (no chart; one side tab per series row) ─────────────────────────────────\n // Monthly Non-Essential Category Summary: the donut card's \"View more\" lists one month's spend by\n // side, Non-essential / Essential, each side its own aggregated_guids. The tabs are labelled by\n // the rows' pre-localized labels, in wire order; a row without one gets no tab.\n [DRILLDOWN_VARIANTS.NON_ESSENTIAL_CATEGORY]: {\n top: 'tabsOnly',\n filterStrategy: aggregatedGuidsStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme) => [theme.palette.primary.main],\n },\n // NEXT MR — [DRILLDOWN_VARIANTS.DEPOSIT_SUMMARY] (WEC-2097, MR !1756).\n}\n\n// Fallback for a missing/typo'd backend variant: a single-bar, store-scoped drawer filtered by the\n// beat's transaction guid and colored by category, so the drawer still renders instead of crashing.\nexport const FALLBACK: DrillDownVariantConfig = {\n top: 'singleBar',\n filterStrategy: transactionGuidStrategy,\n scope: 'store',\n filterMode: 'store',\n colors: (theme: Theme, categoryGuid?: string) => [categoryColor(theme, categoryGuid)],\n}\n"],"mappings":";;;;;;;;;AAqCA,IAAa,IAAqB;AAAA,EAChC,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,EACnB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,wBAAwB;AAAA,EACxB,iBAAiB;AAAA,EACjB,aAAa;AACf,GAwDM,IAAA,CAAiB,GAAc,MAClC,KAAgB,EAAiB,GAAc,CAAK,KAAM,EAAM,QAAQ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Set[];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Shapes the beat's raw data_series into the chart inputs for the variant's top kind
|
|
20
|
-
*
|
|
21
|
-
* for the next MR so the call site is already wired.
|
|
19
|
+
* Shapes the beat's raw data_series into the chart inputs for the variant's top kind: the single-bar
|
|
20
|
+
* family (singleBar / upcomingBill), the double bar's month columns, or a tabs-only drawer's sides.
|
|
22
21
|
*/
|
|
23
22
|
interface FlattenedDataSeriesInput {
|
|
24
23
|
data: DataSeries | undefined;
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { DATE_FORMATS_INTL as l } from "../../../core/constants/DateFormats.es.js";
|
|
2
|
-
import { buildChartData as
|
|
2
|
+
import { buildChartData as u, buildDataSeries as d } from "../../blocks/ChartBlocks/BarchartBlock/utils.es.js";
|
|
3
3
|
import { buildComparisonSeries as g } from "../../blocks/ChartBlocks/DoubleBarChartBlock/comparisonUtils.es.js";
|
|
4
4
|
import { DRILLDOWN_VARIANTS as m, FALLBACK as _, layout as h } from "./layout.es.js";
|
|
5
5
|
import { format as D, fromUnixTime as f } from "date-fns";
|
|
6
|
-
var
|
|
6
|
+
var I = (t) => h[t] ?? _, A = ({ data: t, ariaLabel: e, top: r, beatTransactions: s, payload: o }) => {
|
|
7
7
|
if (r === "upcomingBill") {
|
|
8
|
-
const
|
|
8
|
+
const i = S(s, o);
|
|
9
9
|
return {
|
|
10
|
-
dataSeries:
|
|
11
|
-
chartData:
|
|
10
|
+
dataSeries: i,
|
|
11
|
+
chartData: u(i, e, l.MONTH_DAY),
|
|
12
12
|
comparisonBars: []
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
if (r === "tabsOnly") return {
|
|
16
|
+
dataSeries: d(t).filter((i) => i.localized_label),
|
|
17
|
+
chartData: [],
|
|
18
|
+
comparisonBars: []
|
|
19
|
+
};
|
|
20
|
+
const a = [...d(t)].sort((i, n) => !i.date || !n.date ? 0 : new Date(i.date).getTime() - new Date(n.date).getTime());
|
|
16
21
|
return r === "doubleBar" ? {
|
|
17
22
|
dataSeries: a,
|
|
18
23
|
chartData: [],
|
|
19
24
|
comparisonBars: g(t, e)
|
|
20
25
|
} : {
|
|
21
26
|
dataSeries: a,
|
|
22
|
-
chartData:
|
|
27
|
+
chartData: u(a, e),
|
|
23
28
|
comparisonBars: []
|
|
24
29
|
};
|
|
25
30
|
}, p = "TRN-projected-bill", B = (t) => ({
|
|
@@ -29,42 +34,42 @@ var b = (t) => h[t] ?? _, A = ({ data: t, ariaLabel: e, top: r, beatTransactions
|
|
|
29
34
|
category_guid: t.top_level_category_guid ?? t.category_guid
|
|
30
35
|
}), S = (t = [], e) => {
|
|
31
36
|
if (!t.length || e?.date == null || e?.amount == null) return [];
|
|
32
|
-
const r = [...t].sort((n, c) => n.date - c.date),
|
|
37
|
+
const r = [...t].sort((n, c) => n.date - c.date), s = /* @__PURE__ */ new Set(), o = [];
|
|
33
38
|
for (const n of r)
|
|
34
|
-
|
|
35
|
-
const a = r[r.length - 1],
|
|
39
|
+
s.has(n.date) || (s.add(n.date), o.push(B(n)));
|
|
40
|
+
const a = r[r.length - 1], i = {
|
|
36
41
|
date: e.date,
|
|
37
42
|
amount: e.amount,
|
|
38
43
|
guid: p,
|
|
39
44
|
category_guid: a.top_level_category_guid ?? a.category_guid
|
|
40
45
|
};
|
|
41
|
-
return [...o,
|
|
46
|
+
return [...o, i];
|
|
42
47
|
}, w = (t, e) => {
|
|
43
|
-
const r = e.insights_feed?.general?.transaction_history_title ?? "",
|
|
48
|
+
const r = e.insights_feed?.general?.transaction_history_title ?? "", s = e.insights_feed?.transaction_history_block;
|
|
44
49
|
if (t === m.TRANSACTION) return r;
|
|
45
50
|
const o = `${t}_drawer_title`;
|
|
46
|
-
return
|
|
51
|
+
return s?.[o] ?? r;
|
|
47
52
|
}, C = (t, e) => ({
|
|
48
53
|
accounts: t.accounts ?? e.allAccountGuids,
|
|
49
54
|
dateRange: t.dateRange ?? e.displayedDateRange,
|
|
50
55
|
custom: t.custom ?? (() => !0),
|
|
51
56
|
showSplits: t.showSplits ?? !1
|
|
52
|
-
}), R = ({ chartTabCount: t, comparisonTabCount: e, actionDrawer: r, beatGuid:
|
|
53
|
-
const o = e || t, a = r.guid ===
|
|
57
|
+
}), R = ({ chartTabCount: t, comparisonTabCount: e, actionDrawer: r, beatGuid: s }) => {
|
|
58
|
+
const o = e || t, a = r.guid === s && r.trigger === "chartBar", i = r.context, n = a ? i?.tabIndex ?? 0 : 0;
|
|
54
59
|
return a ? {
|
|
55
|
-
chartBarIndex: Math.min(Math.max(
|
|
60
|
+
chartBarIndex: Math.min(Math.max(i?.chartBarIndex ?? 0, 0), Math.max(0, o - 1)),
|
|
56
61
|
subTabIndex: n
|
|
57
62
|
} : {
|
|
58
63
|
chartBarIndex: Math.max(0, o - 1),
|
|
59
64
|
subTabIndex: n
|
|
60
65
|
};
|
|
61
|
-
}, M = ({ series: t, category_guid: e, average_amount: r, additional_data:
|
|
62
|
-
const o =
|
|
66
|
+
}, M = ({ series: t, category_guid: e, average_amount: r, additional_data: s }) => {
|
|
67
|
+
const o = d(t).map(({ guid: a }) => a).filter((a) => !!a);
|
|
63
68
|
return {
|
|
64
69
|
data_series: t,
|
|
65
70
|
category_guid: e,
|
|
66
71
|
average_amount: r,
|
|
67
|
-
legends:
|
|
72
|
+
legends: s,
|
|
68
73
|
transaction_guids: o.length ? o : void 0
|
|
69
74
|
};
|
|
70
75
|
}, N = (t) => {
|
|
@@ -82,7 +87,7 @@ export {
|
|
|
82
87
|
S as buildUpcomingBillSeries,
|
|
83
88
|
R as getDefaultSelection,
|
|
84
89
|
w as getDrawerHeaderTitle,
|
|
85
|
-
|
|
90
|
+
I as getDrillDownConfig,
|
|
86
91
|
A as getFlattenedDataSeries,
|
|
87
92
|
N as resolveDrillDownSubHeader,
|
|
88
93
|
M as toDrillDownSlotData,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionHistoryBlock/utils.ts"],"sourcesContent":["import { format, fromUnixTime } from 'date-fns'\n\nimport type {\n ActionDrawerState,\n DataSeries,\n DrilldownPayload,\n GlobalCopy,\n InsightsPayload,\n Subtitle,\n Transaction,\n} from '../../../core'\nimport { DATE_FORMATS_INTL } from '../../../core/constants'\nimport type {\n BarChartBlockData,\n DataSet,\n InsightsInstanceSlotData,\n} from '../../../core/types/InsightsInstanceSlotData'\nimport type { TransactionFilter } from '../../../core/stores/TransactionStore'\nimport {\n buildChartData,\n buildDataSeries,\n type ChartDataSeriesItem,\n} from '../../blocks/ChartBlocks/BarchartBlock/utils'\nimport { buildComparisonSeries } from '../../blocks/ChartBlocks/DoubleBarChartBlock/comparisonUtils'\nimport {\n layout,\n FALLBACK,\n DRILLDOWN_VARIANTS,\n DrillDownVariant,\n DrillDownVariantConfig,\n} from './layout'\nimport { TransactionHistoryBlock } from '../../../core/types/localization/InsightsFeedCopy'\n\ninterface DefaultSelectionProp {\n chartTabCount: number\n comparisonTabCount: number\n actionDrawer: ActionDrawerState\n beatGuid: string\n}\nexport const getDrillDownConfig = (variant?: string): DrillDownVariantConfig =>\n layout[variant as DrillDownVariant] ?? FALLBACK\n\n// The shaped chart inputs a drill-down needs, derived once from the beat's data_series. `dataSeries`\n// is the flat per-bar source (indexes the filterStrategy); `chartData` feeds the single-bar chart;\n// `comparisonBars` feeds the double-bar chart and its month tabs (empty for every other top kind).\nexport interface FlattenedDataSeries {\n dataSeries: ChartDataSeriesItem[]\n chartData: ReturnType<typeof buildChartData>\n comparisonBars: DataSet[]\n}\n\n/**\n * Shapes the beat's raw data_series into the chart inputs for the variant's top kind. This MR handles\n * the single-bar family (singleBar / upcomingBill); the double-bar and tabsOnly branches are stubbed\n * for the next MR so the call site is already wired.\n */\ninterface FlattenedDataSeriesInput {\n data: DataSeries | undefined\n ariaLabel: string\n top: DrillDownVariantConfig['top']\n // UpcomingBill has no data_series; it builds its bars from these instead.\n beatTransactions: Transaction[]\n payload: { date?: string; amount?: number } | undefined\n}\n\nexport const getFlattenedDataSeries = ({\n data,\n ariaLabel,\n top,\n beatTransactions,\n payload,\n}: FlattenedDataSeriesInput): FlattenedDataSeries => {\n // UpcomingBill has no backend data_series: synthesize the bars from the beat's recurring-bill\n // transactions + the projected bill, and label each bar by day (MONTH_DAY) since a bar is one bill.\n if (top === 'upcomingBill') {\n const dataSeries = buildUpcomingBillSeries(beatTransactions, payload)\n return {\n dataSeries,\n chartData: buildChartData(dataSeries, ariaLabel, DATE_FORMATS_INTL.MONTH_DAY),\n comparisonBars: [],\n }\n }\n\n // Single-bar family (THIS MR): the backend sends data_series newest-first, so normalize it\n // date-ascending here. chartData/tabs and the filter's dataSeries[selectedIndex] indexing both read\n // this one array, so they stay aligned and the last tab is the most recent month.\n const dataSeries = [...buildDataSeries(data)].sort((a, b) => {\n if (!a.date || !b.date) return 0\n\n return new Date(a.date).getTime() - new Date(b.date).getTime()\n })\n\n // Double bar: comparison beats build paired month columns (with their guids) instead of chartData.\n if (top === 'doubleBar') {\n return { dataSeries, chartData: [], comparisonBars: buildComparisonSeries(data, ariaLabel) }\n }\n\n // NEXT MR — tabsOnly: donut-drawer beats render no top chart.\n // if (top === \"tabsOnly\") {\n // return { dataSeries, chartData: [], comparisonBars: [] };\n // }\n\n return { dataSeries, chartData: buildChartData(dataSeries, ariaLabel), comparisonBars: [] }\n}\n\n// Sentinel guid for the synthesized projected bill. It intentionally matches no real store\n// transaction, so the projected tab's guid filter yields an empty list (projected-bar-only scope).\nexport const PROJECTED_BILL_GUID = 'TRN-projected-bill'\n\n// One bar in the UpcomingBill chart. `date` is 'yyyy-MM-dd' so buildChartData/parseISO can read both\n// historical unix timestamps and the ISO payload date after normalization here.\nexport interface UpcomingBillBar {\n date: string\n amount: number\n guid: string\n category_guid?: string\n}\n\nconst toUpcomingBillBar = (transaction: Transaction): UpcomingBillBar => ({\n date: format(fromUnixTime(transaction.date), 'yyyy-MM-dd'),\n amount: transaction.amount,\n guid: transaction.guid,\n category_guid: transaction.top_level_category_guid ?? transaction.category_guid,\n})\n\n/**\n * UpcomingBill has no data_series: build the bar series straight from the beat's recurring-bill\n * transactions plus the synthesized projected bill from payload (mirrors pulse's magicTransactions).\n * Historical bills are de-duped by date and each keeps its real transaction guid so the guid filter\n * finds it in the store; the projected bar (cloned category from the latest bill) carries the\n * PROJECTED_BILL_GUID sentinel. The result is sorted date-ascending so the projected bill lands last.\n */\nexport const buildUpcomingBillSeries = (\n transactions: Transaction[] = [],\n payload: { date?: string; amount?: number } | undefined,\n): UpcomingBillBar[] => {\n if (!transactions.length || payload?.date == null || payload?.amount == null) {\n return []\n }\n\n const sorted = [...transactions].sort((a, b) => a.date - b.date)\n\n const seenDates = new Set<number>()\n const history: UpcomingBillBar[] = []\n for (const transaction of sorted) {\n if (seenDates.has(transaction.date)) continue\n seenDates.add(transaction.date)\n history.push(toUpcomingBillBar(transaction))\n }\n\n const latestBill = sorted[sorted.length - 1]\n const projected: UpcomingBillBar = {\n date: payload.date,\n amount: payload.amount,\n guid: PROJECTED_BILL_GUID,\n category_guid: latestBill.top_level_category_guid ?? latestBill.category_guid,\n }\n\n return [...history, projected]\n}\n\nexport const getDrawerHeaderTitle = (\n variant: string | null | undefined,\n copy: GlobalCopy,\n): string => {\n const transactionHistoryTitle = copy.insights_feed?.general?.transaction_history_title ?? ''\n const drawerTitleCopy = copy.insights_feed?.transaction_history_block as TransactionHistoryBlock\n\n if (variant === DRILLDOWN_VARIANTS.TRANSACTION) return transactionHistoryTitle\n\n // Safely access the drawer title from transaction_history_block\n const key = `${variant}_drawer_title` as keyof TransactionHistoryBlock\n return (drawerTitleCopy?.[key] as string) ?? transactionHistoryTitle\n}\n\nexport const toStoreFilter = (\n filter: TransactionFilter,\n defaults: { allAccountGuids: string[]; displayedDateRange: { start: Date; end: Date } },\n): TransactionFilter => ({\n accounts: filter.accounts ?? defaults.allAccountGuids,\n dateRange: filter.dateRange ?? defaults.displayedDateRange,\n custom: filter.custom ?? (() => true),\n showSplits: filter.showSplits ?? false,\n})\n\nexport const getDefaultSelection = ({\n chartTabCount,\n comparisonTabCount,\n actionDrawer,\n beatGuid,\n}: DefaultSelectionProp): { chartBarIndex: number; subTabIndex: number } => {\n // A double-bar drawer's tabs are its comparison columns; every other drawer's are its chart bars.\n const tabCount = comparisonTabCount || chartTabCount\n const openedViaChartBar = actionDrawer.guid === beatGuid && actionDrawer.trigger === 'chartBar'\n\n // actionDrawer.context is an opaque `unknown` bag; narrow it to the shape the chart blocks write.\n const context = actionDrawer.context as DrilldownPayload | undefined\n const subTabIndex = openedViaChartBar ? (context?.tabIndex ?? 0) : 0\n\n if (openedViaChartBar) {\n const clamped = Math.min(Math.max(context?.chartBarIndex ?? 0, 0), Math.max(0, tabCount - 1))\n return { chartBarIndex: clamped, subTabIndex }\n }\n\n return { chartBarIndex: Math.max(0, tabCount - 1), subTabIndex }\n}\n\n/** The drawer's facts: the generic slot facts plus the bar chart's average. */\nexport type DrillDownSlotData = InsightsInstanceSlotData & Pick<BarChartBlockData, 'average_amount'>\n\n/** The drawer's facts from a bar chart's `instance_slot.data`. */\nexport const toDrillDownSlotData = ({\n series,\n category_guid,\n average_amount,\n additional_data,\n}: BarChartBlockData): DrillDownSlotData => {\n const transactionGuids = buildDataSeries(series)\n .map(({ guid }) => guid)\n .filter((guid): guid is string => !!guid)\n\n return {\n data_series: series,\n category_guid,\n average_amount,\n legends: additional_data,\n transaction_guids: transactionGuids.length ? transactionGuids : undefined,\n }\n}\n\n/** The drawer's sub-heading: the merchant name and logo. */\nexport const resolveDrillDownSubHeader = (\n payload: Partial<InsightsPayload> | undefined,\n): Subtitle | undefined => {\n if (!payload) return undefined\n\n return {\n text: payload.subtitle ?? '',\n logo: { merchant_guid: payload.logo?.guid, category_guid: '' },\n }\n}\n"],"mappings":";;;;;AAuCA,IAAa,IAAA,CAAsB,MACjC,EAAO,CAAA,KAAgC,GAyB5B,IAAA,CAA0B,EACrC,MAAA,GACA,WAAA,GACA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ACtB,OAAA,CAAQ,MAAyB,CAAC,CAAC,CAAI;AAE1C,SAAO;AAAA,IACL,aAAa;AAAA,IACb,eAAA;AAAA,IACA,gBAAA;AAAA,IACA,SAAS;AAAA,IACT,mBAAmB,EAAiB,SAAS,IAAmB;AAAA,EAClE;AACF,GAGa,IAAA,CACX,MACyB;AACzB,MAAK;AAEL,WAAO;AAAA,MACL,MAAM,EAAQ,YAAY;AAAA,MAC1B,MAAM;AAAA,QAAE,eAAe,EAAQ,MAAM;AAAA,QAAM,eAAe;AAAA,MAAG;AAAA,IAC/D;AACF"}
|
|
1
|
+
{"version":3,"file":"utils.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionHistoryBlock/utils.ts"],"sourcesContent":["import { format, fromUnixTime } from 'date-fns'\n\nimport type {\n ActionDrawerState,\n DataSeries,\n DrilldownPayload,\n GlobalCopy,\n InsightsPayload,\n Subtitle,\n Transaction,\n} from '../../../core'\nimport { DATE_FORMATS_INTL } from '../../../core/constants'\nimport type {\n BarChartBlockData,\n DataSet,\n InsightsInstanceSlotData,\n} from '../../../core/types/InsightsInstanceSlotData'\nimport type { TransactionFilter } from '../../../core/stores/TransactionStore'\nimport {\n buildChartData,\n buildDataSeries,\n type ChartDataSeriesItem,\n} from '../../blocks/ChartBlocks/BarchartBlock/utils'\nimport { buildComparisonSeries } from '../../blocks/ChartBlocks/DoubleBarChartBlock/comparisonUtils'\nimport {\n layout,\n FALLBACK,\n DRILLDOWN_VARIANTS,\n DrillDownVariant,\n DrillDownVariantConfig,\n} from './layout'\nimport { TransactionHistoryBlock } from '../../../core/types/localization/InsightsFeedCopy'\n\ninterface DefaultSelectionProp {\n chartTabCount: number\n comparisonTabCount: number\n actionDrawer: ActionDrawerState\n beatGuid: string\n}\nexport const getDrillDownConfig = (variant?: string): DrillDownVariantConfig =>\n layout[variant as DrillDownVariant] ?? FALLBACK\n\n// The shaped chart inputs a drill-down needs, derived once from the beat's data_series. `dataSeries`\n// is the flat per-bar source (indexes the filterStrategy); `chartData` feeds the single-bar chart;\n// `comparisonBars` feeds the double-bar chart and its month tabs (empty for every other top kind).\nexport interface FlattenedDataSeries {\n dataSeries: ChartDataSeriesItem[]\n chartData: ReturnType<typeof buildChartData>\n comparisonBars: DataSet[]\n}\n\n/**\n * Shapes the beat's raw data_series into the chart inputs for the variant's top kind: the single-bar\n * family (singleBar / upcomingBill), the double bar's month columns, or a tabs-only drawer's sides.\n */\ninterface FlattenedDataSeriesInput {\n data: DataSeries | undefined\n ariaLabel: string\n top: DrillDownVariantConfig['top']\n // UpcomingBill has no data_series; it builds its bars from these instead.\n beatTransactions: Transaction[]\n payload: { date?: string; amount?: number } | undefined\n}\n\nexport const getFlattenedDataSeries = ({\n data,\n ariaLabel,\n top,\n beatTransactions,\n payload,\n}: FlattenedDataSeriesInput): FlattenedDataSeries => {\n // UpcomingBill has no backend data_series: synthesize the bars from the beat's recurring-bill\n // transactions + the projected bill, and label each bar by day (MONTH_DAY) since a bar is one bill.\n if (top === 'upcomingBill') {\n const dataSeries = buildUpcomingBillSeries(beatTransactions, payload)\n return {\n dataSeries,\n chartData: buildChartData(dataSeries, ariaLabel, DATE_FORMATS_INTL.MONTH_DAY),\n comparisonBars: [],\n }\n }\n\n // Tabs only: the rows are the sides of one month, not bars. They keep their wire order, which the\n // side tabs and the filter's dataSeries[subIndex] both index; there is no chart and no month tab.\n if (top === 'tabsOnly') {\n return {\n dataSeries: buildDataSeries(data).filter((row) => row.localized_label),\n chartData: [],\n comparisonBars: [],\n }\n }\n\n // Single-bar family (THIS MR): the backend sends data_series newest-first, so normalize it\n // date-ascending here. chartData/tabs and the filter's dataSeries[selectedIndex] indexing both read\n // this one array, so they stay aligned and the last tab is the most recent month.\n const dataSeries = [...buildDataSeries(data)].sort((a, b) => {\n if (!a.date || !b.date) return 0\n\n return new Date(a.date).getTime() - new Date(b.date).getTime()\n })\n\n // Double bar: comparison beats build paired month columns (with their guids) instead of chartData.\n if (top === 'doubleBar') {\n return { dataSeries, chartData: [], comparisonBars: buildComparisonSeries(data, ariaLabel) }\n }\n\n return { dataSeries, chartData: buildChartData(dataSeries, ariaLabel), comparisonBars: [] }\n}\n\n// Sentinel guid for the synthesized projected bill. It intentionally matches no real store\n// transaction, so the projected tab's guid filter yields an empty list (projected-bar-only scope).\nexport const PROJECTED_BILL_GUID = 'TRN-projected-bill'\n\n// One bar in the UpcomingBill chart. `date` is 'yyyy-MM-dd' so buildChartData/parseISO can read both\n// historical unix timestamps and the ISO payload date after normalization here.\nexport interface UpcomingBillBar {\n date: string\n amount: number\n guid: string\n category_guid?: string\n}\n\nconst toUpcomingBillBar = (transaction: Transaction): UpcomingBillBar => ({\n date: format(fromUnixTime(transaction.date), 'yyyy-MM-dd'),\n amount: transaction.amount,\n guid: transaction.guid,\n category_guid: transaction.top_level_category_guid ?? transaction.category_guid,\n})\n\n/**\n * UpcomingBill has no data_series: build the bar series straight from the beat's recurring-bill\n * transactions plus the synthesized projected bill from payload (mirrors pulse's magicTransactions).\n * Historical bills are de-duped by date and each keeps its real transaction guid so the guid filter\n * finds it in the store; the projected bar (cloned category from the latest bill) carries the\n * PROJECTED_BILL_GUID sentinel. The result is sorted date-ascending so the projected bill lands last.\n */\nexport const buildUpcomingBillSeries = (\n transactions: Transaction[] = [],\n payload: { date?: string; amount?: number } | undefined,\n): UpcomingBillBar[] => {\n if (!transactions.length || payload?.date == null || payload?.amount == null) {\n return []\n }\n\n const sorted = [...transactions].sort((a, b) => a.date - b.date)\n\n const seenDates = new Set<number>()\n const history: UpcomingBillBar[] = []\n for (const transaction of sorted) {\n if (seenDates.has(transaction.date)) continue\n seenDates.add(transaction.date)\n history.push(toUpcomingBillBar(transaction))\n }\n\n const latestBill = sorted[sorted.length - 1]\n const projected: UpcomingBillBar = {\n date: payload.date,\n amount: payload.amount,\n guid: PROJECTED_BILL_GUID,\n category_guid: latestBill.top_level_category_guid ?? latestBill.category_guid,\n }\n\n return [...history, projected]\n}\n\nexport const getDrawerHeaderTitle = (\n variant: string | null | undefined,\n copy: GlobalCopy,\n): string => {\n const transactionHistoryTitle = copy.insights_feed?.general?.transaction_history_title ?? ''\n const drawerTitleCopy = copy.insights_feed?.transaction_history_block as TransactionHistoryBlock\n\n if (variant === DRILLDOWN_VARIANTS.TRANSACTION) return transactionHistoryTitle\n\n // Safely access the drawer title from transaction_history_block\n const key = `${variant}_drawer_title` as keyof TransactionHistoryBlock\n return (drawerTitleCopy?.[key] as string) ?? transactionHistoryTitle\n}\n\nexport const toStoreFilter = (\n filter: TransactionFilter,\n defaults: { allAccountGuids: string[]; displayedDateRange: { start: Date; end: Date } },\n): TransactionFilter => ({\n accounts: filter.accounts ?? defaults.allAccountGuids,\n dateRange: filter.dateRange ?? defaults.displayedDateRange,\n custom: filter.custom ?? (() => true),\n showSplits: filter.showSplits ?? false,\n})\n\nexport const getDefaultSelection = ({\n chartTabCount,\n comparisonTabCount,\n actionDrawer,\n beatGuid,\n}: DefaultSelectionProp): { chartBarIndex: number; subTabIndex: number } => {\n // A double-bar drawer's tabs are its comparison columns; every other drawer's are its chart bars.\n const tabCount = comparisonTabCount || chartTabCount\n const openedViaChartBar = actionDrawer.guid === beatGuid && actionDrawer.trigger === 'chartBar'\n\n // actionDrawer.context is an opaque `unknown` bag; narrow it to the shape the chart blocks write.\n const context = actionDrawer.context as DrilldownPayload | undefined\n const subTabIndex = openedViaChartBar ? (context?.tabIndex ?? 0) : 0\n\n if (openedViaChartBar) {\n const clamped = Math.min(Math.max(context?.chartBarIndex ?? 0, 0), Math.max(0, tabCount - 1))\n return { chartBarIndex: clamped, subTabIndex }\n }\n\n return { chartBarIndex: Math.max(0, tabCount - 1), subTabIndex }\n}\n\n/** The drawer's facts: the generic slot facts plus the bar chart's average. */\nexport type DrillDownSlotData = InsightsInstanceSlotData & Pick<BarChartBlockData, 'average_amount'>\n\n/** The drawer's facts from a bar chart's `instance_slot.data`. */\nexport const toDrillDownSlotData = ({\n series,\n category_guid,\n average_amount,\n additional_data,\n}: BarChartBlockData): DrillDownSlotData => {\n const transactionGuids = buildDataSeries(series)\n .map(({ guid }) => guid)\n .filter((guid): guid is string => !!guid)\n\n return {\n data_series: series,\n category_guid,\n average_amount,\n legends: additional_data,\n transaction_guids: transactionGuids.length ? transactionGuids : undefined,\n }\n}\n\n/** The drawer's sub-heading: the merchant name and logo. */\nexport const resolveDrillDownSubHeader = (\n payload: Partial<InsightsPayload> | undefined,\n): Subtitle | undefined => {\n if (!payload) return undefined\n\n return {\n text: payload.subtitle ?? '',\n logo: { merchant_guid: payload.logo?.guid, category_guid: '' },\n }\n}\n"],"mappings":";;;;;AAuCA,IAAa,IAAA,CAAsB,MACjC,EAAO,CAAA,KAAgC,GAwB5B,IAAA,CAA0B,EACrC,MAAA,GACA,WAAA,GACA,KAAA,GACA,kBAAA,GACA,SAAA,EAAA,MACmD;AAGnD,MAAI,MAAQ,gBAAgB;AAC1B,UAAM,IAAa,EAAwB,GAAkB,CAAO;AACpE,WAAO;AAAA,MACL,YAAA;AAAA,MACA,WAAW,EAAe,GAAY,GAAW,EAAkB,SAAS;AAAA,MAC5E,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAIA,MAAI,MAAQ,WACV,QAAO;AAAA,IACL,YAAY,EAAgB,CAAI,EAAE,OAAA,CAAQ,MAAQ,EAAI,eAAe;AAAA,IACrE,WAAW,CAAC;AAAA,IACZ,gBAAgB,CAAC;AAAA,EACnB;AAMF,QAAM,IAAa,CAAC,GAAG,EAAgB,CAAI,CAAC,EAAE,KAAA,CAAM,GAAG,MACjD,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAa,IAExB,IAAI,KAAK,EAAE,IAAI,EAAE,QAAQ,IAAI,IAAI,KAAK,EAAE,IAAI,EAAE,QAAQ,CAC9D;AAGD,SAAI,MAAQ,cACH;AAAA,IAAE,YAAA;AAAA,IAAY,WAAW,CAAC;AAAA,IAAG,gBAAgB,EAAsB,GAAM,CAAS;AAAA,EAAE,IAGtF;AAAA,IAAE,YAAA;AAAA,IAA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cAAc;AACnC,IAEa,IAAA,CAAuB,EAClC,eAAA,GACA,oBAAA,GACA,cAAA,GACA,UAAA,EAAA,MAC0E;AAE1E,QAAM,IAAW,KAAsB,GACjC,IAAoB,EAAa,SAAS,KAAY,EAAa,YAAY,YAG/E,IAAU,EAAa,SACvB,IAAc,IAAqB,GAAS,YAAY,IAAK;AAEnE,SAAI,IAEK;AAAA,IAAE,eADO,KAAK,IAAI,KAAK,IAAI,GAAS,iBAAiB,GAAG,CAAC,GAAG,KAAK,IAAI,GAAG,IAAW,CAAC,CACnE;AAAA,IAAS,aAAA;AAAA,EAAY,IAGxC;AAAA,IAAE,eAAe,KAAK,IAAI,GAAG,IAAW,CAAC;AAAA,IAAG,aAAA;AAAA,EAAY;AACjE,GAMa,IAAA,CAAuB,EAClC,QAAA,GACA,eAAA,GACA,gBAAA,GACA,iBAAA,EAAA,MAC0C;AAC1C,QAAM,IAAmB,EAAgB,CAAM,EAC5C,IAAA,CAAK,EAAE,MAAA,EAAA,MAAW,CAAI,EACtB,OAAA,CAAQ,MAAyB,CAAC,CAAC,CAAI;AAE1C,SAAO;AAAA,IACL,aAAa;AAAA,IACb,eAAA;AAAA,IACA,gBAAA;AAAA,IACA,SAAS;AAAA,IACT,mBAAmB,EAAiB,SAAS,IAAmB;AAAA,EAClE;AACF,GAGa,IAAA,CACX,MACyB;AACzB,MAAK;AAEL,WAAO;AAAA,MACL,MAAM,EAAQ,YAAY;AAAA,MAC1B,MAAM;AAAA,QAAE,eAAe,EAAQ,MAAM;AAAA,QAAM,eAAe;AAAA,MAAG;AAAA,IAC/D;AACF"}
|
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
import { useGlobalCopyStore as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { selectTransactionsByGuids as
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { useGlobalCopyStore as w, useInsightsV2Store as S, useTransactionStore as D } from "../../../common/context/hooks.es.js";
|
|
2
|
+
import k from "../../../common/components/drawer/Drawer.es.js";
|
|
3
|
+
import B from "../../../transactions/components/shared/TransactionList.es.js";
|
|
4
|
+
import { selectTransactionsByGuids as L } from "../../CommonUtils.es.js";
|
|
5
|
+
import { getDynamicCtaBasedOnTriggers as O } from "../util.es.js";
|
|
6
|
+
import { TransactionDetailsBlock as x } from "../TransactionDetailsBlock/TransactionDetailsBlock.es.js";
|
|
7
|
+
import { readSummary as A } from "./layout.es.js";
|
|
8
|
+
import { TransactionListSummaryCard as j } from "./TransactionListSummaryCard.es.js";
|
|
9
|
+
import g from "react";
|
|
10
|
+
import { observer as G } from "mobx-react-lite";
|
|
11
|
+
import { Fragment as F, jsx as a, jsxs as I } from "react/jsx-runtime";
|
|
12
|
+
var R = (o) => Array.isArray(o) && o.every((t) => typeof t == "string"), $ = (o) => {
|
|
13
|
+
const t = o.insights_payload?.drilldown_data, i = o.insights_payload?.instance_slot_data ?? {}, [n, s] = t && Object.hasOwn(t, "transaction_guids") ? ["drilldown_data", t.transaction_guids] : ["instance_slot_data", i.transaction_guids];
|
|
14
|
+
if (s != null) {
|
|
15
|
+
if (R(s)) return s;
|
|
16
|
+
console.warn(`[TransactionListBlock] ${n}.transaction_guids is not a list of guids — listing no transactions.`);
|
|
14
17
|
}
|
|
15
|
-
},
|
|
16
|
-
const { common:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
}, Q = G(function({ beat: t }) {
|
|
19
|
+
const { common: i, insights_feed: n } = w(), { actionDrawer: s, setActionContext: c } = S(), _ = D(), [p, l] = g.useState(!1), r = $(t), f = L(_.detailedTransactions, r), { primary_cta: d, secondary_cta: m, in_description_cta: u, is_zero_state: y } = t.insights_payload ?? {}, e = g.useMemo(() => A(O(s, d, m, u)), [
|
|
20
|
+
s,
|
|
21
|
+
d,
|
|
22
|
+
m,
|
|
23
|
+
u
|
|
24
|
+
]), h = e !== void 0 && !y && (r?.length ?? 0) > 0, C = (v) => {
|
|
25
|
+
c({ transaction_guid: v }), l(!0);
|
|
26
|
+
}, T = () => {
|
|
27
|
+
l(!1), c({ transaction_guid: void 0 });
|
|
20
28
|
};
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
return /* @__PURE__ */ I(F, { children: [
|
|
30
|
+
h && /* @__PURE__ */ a(j, {
|
|
31
|
+
copy: n.general,
|
|
32
|
+
count: e.count ?? r?.length ?? 0,
|
|
33
|
+
summary: e
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ a(B, {
|
|
36
|
+
onClick: C,
|
|
37
|
+
transaction: f
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ a(k, {
|
|
40
|
+
ariaLabelClose: i.close_aria,
|
|
41
|
+
isOpen: p,
|
|
42
|
+
onClose: T,
|
|
43
|
+
title: n.general.transaction_details_title,
|
|
44
|
+
children: /* @__PURE__ */ a(x, { beat: t })
|
|
45
|
+
})
|
|
46
|
+
] });
|
|
31
47
|
});
|
|
32
48
|
export {
|
|
33
|
-
|
|
49
|
+
Q as TransactionListBlock
|
|
34
50
|
};
|
|
35
51
|
|
|
36
52
|
//# sourceMappingURL=TransactionListBlock.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionListBlock.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionListBlock/TransactionListBlock.tsx"],"sourcesContent":["import React from 'react'\n\nimport { observer } from 'mobx-react-lite'\n\nimport {\n Drawer,\n useGlobalCopyStore,\n useInsightsV2Store,\n useTransactionStore,\n} from '../../../common'\nimport type { Beat } from '../../../core'\nimport type { InsightsInstanceSlotData } from '../../../core/types/InsightsInstanceSlotData'\nimport { TransactionDetailsBlock } from '../TransactionDetailsBlock'\nimport { TransactionList } from '../../../transactions'\nimport { selectTransactionsByGuids } from '../../CommonUtils'\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((item) => typeof item === 'string')\n\n/**\n * The guids the drawer lists. V2 envelopes send them on `drilldown_data`, V1 on\n * `instance_slot_data`, which is read only when the V2 key is absent. The payload is untrusted, so\n * a present but malformed list fails closed (no rows, and a warning) rather than showing the other\n * source's rows; a non-array would otherwise reach new Set() inside selectTransactionsByGuids and\n * match per-character.\n */\nconst resolveTransactionGuids = (beat: Beat): string[] | undefined => {\n const drilldown = beat.insights_payload?.drilldown_data\n const slotData = (beat.insights_payload?.instance_slot_data ?? {}) as InsightsInstanceSlotData\n const [source, value]: [string, unknown] =\n drilldown && Object.hasOwn(drilldown, 'transaction_guids')\n ? ['drilldown_data', drilldown.transaction_guids]\n : ['instance_slot_data', slotData.transaction_guids]\n\n if (value == null) return undefined\n if (isStringArray(value)) return value\n\n console.warn(\n `[TransactionListBlock] ${source}.transaction_guids is not a list of guids — listing no transactions.`,\n )\n return undefined\n}\n\nexport interface TransactionListBlockProps {\n beat: Beat\n}\n\n/**\n * Opens a date-grouped list of the transactions a beat points at. Tapping a row stacks\n * the Transaction Details drawer over the list.\n *\n * ActionBlockLayer owns the outer Drawer (title, close button, copy-loaded gate).\n */\nexport const TransactionListBlock = observer(function TransactionListBlock({\n beat,\n}: TransactionListBlockProps) {\n const { common: commonCopy, insights_feed: insightsCopy } = useGlobalCopyStore()\n const { setActionContext } = useInsightsV2Store()\n const transactionStore = useTransactionStore()\n\n const [isDetailsOpen, setIsDetailsOpen] = React.useState(false)\n\n const guids = resolveTransactionGuids(beat)\n const transactions = selectTransactionsByGuids(transactionStore.detailedTransactions, guids)\n\n const handleRowClick = (guid: string) => {\n setActionContext({ transaction_guid: guid })\n setIsDetailsOpen(true)\n }\n\n const handleDetailsClose = () => {\n setIsDetailsOpen(false)\n // Clear only the key this nested drawer owns — same convention as TransactionHistoryBlock.\n // `setActionContext` merges, so an explicit `{}` would be a no-op; naming the key keeps the\n // outer drawer's own context intact.\n setActionContext({ transaction_guid: undefined })\n }\n\n return (\n <>\n <TransactionList onClick={handleRowClick} transaction={transactions} />\n <Drawer\n ariaLabelClose={commonCopy.close_aria}\n isOpen={isDetailsOpen}\n onClose={handleDetailsClose}\n title={insightsCopy.general.transaction_details_title}\n >\n <TransactionDetailsBlock beat={beat} />\n </Drawer>\n </>\n )\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"TransactionListBlock.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/TransactionListBlock/TransactionListBlock.tsx"],"sourcesContent":["import React from 'react'\n\nimport { observer } from 'mobx-react-lite'\n\nimport {\n Drawer,\n useGlobalCopyStore,\n useInsightsV2Store,\n useTransactionStore,\n} from '../../../common'\nimport type { Beat } from '../../../core'\nimport type { InsightsInstanceSlotData } from '../../../core/types/InsightsInstanceSlotData'\nimport { TransactionDetailsBlock } from '../TransactionDetailsBlock'\nimport { TransactionList } from '../../../transactions'\nimport { selectTransactionsByGuids } from '../../CommonUtils'\nimport { getDynamicCtaBasedOnTriggers } from '../util'\nimport { readSummary } from './layout'\nimport { TransactionListSummaryCard } from './TransactionListSummaryCard'\n\nconst isStringArray = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((item) => typeof item === 'string')\n\n/**\n * The guids the drawer lists. V2 envelopes send them on `drilldown_data`, V1 on\n * `instance_slot_data`, which is read only when the V2 key is absent. The payload is untrusted, so\n * a present but malformed list fails closed (no rows, and a warning) rather than showing the other\n * source's rows; a non-array would otherwise reach new Set() inside selectTransactionsByGuids and\n * match per-character.\n */\nconst resolveTransactionGuids = (beat: Beat): string[] | undefined => {\n const drilldown = beat.insights_payload?.drilldown_data\n const slotData = (beat.insights_payload?.instance_slot_data ?? {}) as InsightsInstanceSlotData\n const [source, value]: [string, unknown] =\n drilldown && Object.hasOwn(drilldown, 'transaction_guids')\n ? ['drilldown_data', drilldown.transaction_guids]\n : ['instance_slot_data', slotData.transaction_guids]\n\n if (value == null) return undefined\n if (isStringArray(value)) return value\n\n console.warn(\n `[TransactionListBlock] ${source}.transaction_guids is not a list of guids — listing no transactions.`,\n )\n return undefined\n}\n\nexport interface TransactionListBlockProps {\n beat: Beat\n}\n\n/**\n * Opens a date-grouped list of the transactions a beat points at. Tapping a row stacks\n * the Transaction Details drawer over the list.\n *\n * ActionBlockLayer owns the outer Drawer (title, close button, copy-loaded gate).\n */\nexport const TransactionListBlock = observer(function TransactionListBlock({\n beat,\n}: TransactionListBlockProps) {\n const { common: commonCopy, insights_feed: insightsCopy } = useGlobalCopyStore()\n const { actionDrawer, setActionContext } = useInsightsV2Store()\n const transactionStore = useTransactionStore()\n\n const [isDetailsOpen, setIsDetailsOpen] = React.useState(false)\n\n const guids = resolveTransactionGuids(beat)\n const transactions = selectTransactionsByGuids(transactionStore.detailedTransactions, guids)\n\n // Summary figures live on the clicked CTA's `drilldown_data`, so resolve which CTA opened this\n // drawer. `readSummary` fails closed (no finite `amount` -> undefined), so a plain list renders no\n // card; it is memoized so a bad payload warns once per opening, not per render. A zero-state\n // envelope, or one naming no transactions, has no figures to head.\n const { primary_cta, secondary_cta, in_description_cta, is_zero_state } =\n beat.insights_payload ?? {}\n const summary = React.useMemo(\n () =>\n readSummary(\n getDynamicCtaBasedOnTriggers(actionDrawer, primary_cta, secondary_cta, in_description_cta),\n ),\n [actionDrawer, primary_cta, secondary_cta, in_description_cta],\n )\n const showSummary = summary !== undefined && !is_zero_state && (guids?.length ?? 0) > 0\n\n const handleRowClick = (guid: string) => {\n setActionContext({ transaction_guid: guid })\n setIsDetailsOpen(true)\n }\n\n const handleDetailsClose = () => {\n setIsDetailsOpen(false)\n // Clear only the key this nested drawer owns — same convention as TransactionHistoryBlock.\n // `setActionContext` merges, so an explicit `{}` would be a no-op; naming the key keeps the\n // outer drawer's own context intact.\n setActionContext({ transaction_guid: undefined })\n }\n\n return (\n <>\n {showSummary && (\n <TransactionListSummaryCard\n copy={insightsCopy.general}\n // Prefer the payload count, else the beat's guid list length (stable), avoiding a\n // \"0 transactions\" flash before the store resolves the rows.\n count={summary.count ?? guids?.length ?? 0}\n summary={summary}\n />\n )}\n <TransactionList onClick={handleRowClick} transaction={transactions} />\n <Drawer\n ariaLabelClose={commonCopy.close_aria}\n isOpen={isDetailsOpen}\n onClose={handleDetailsClose}\n title={insightsCopy.general.transaction_details_title}\n >\n <TransactionDetailsBlock beat={beat} />\n </Drawer>\n </>\n )\n})\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,IAAA,CAAiB,MACrB,MAAM,QAAQ,CAAK,KAAK,EAAM,MAAA,CAAO,MAAS,OAAO,KAAS,QAAQ,GASlE,IAAA,CAA2B,MAAqC;AACpE,QAAM,IAAY,EAAK,kBAAkB,gBACnC,IAAY,EAAK,kBAAkB,sBAAsB,CAAC,GAC1D,CAAC,GAAQ,CAAA,IACb,KAAa,OAAO,OAAO,GAAW,mBAAmB,IACrD,CAAC,kBAAkB,EAAU,iBAAiB,IAC9C,CAAC,sBAAsB,EAAS,iBAAiB;AAEvD,MAAI,KAAS,MACb;AAAA,QAAI,EAAc,CAAK,EAAG,QAAO;AAEjC,YAAQ,KACN,0BAA0B,CAAA,sEAC5B;AAAA;AAEF,GAYa,IAAuB,EAAS,SAA8B,EACzE,MAAA,EAAA,GAC4B;AAC5B,QAAM,EAAE,QAAQ,GAAY,eAAe,EAAA,IAAiB,EAAmB,GACzE,EAAE,cAAA,GAAc,kBAAA,EAAA,IAAqB,EAAmB,GACxD,IAAmB,EAAoB,GAEvC,CAAC,GAAe,CAAA,IAAoB,EAAM,SAAS,EAAK,GAExD,IAAQ,EAAwB,CAAI,GACpC,IAAe,EAA0B,EAAiB,sBAAsB,CAAK,GAMrF,EAAE,aAAA,GAAa,eAAA,GAAe,oBAAA,GAAoB,eAAA,EAAA,IACtD,EAAK,oBAAoB,CAAC,GACtB,IAAU,EAAM,QAAA,MAElB,EACE,EAA6B,GAAc,GAAa,GAAe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