@mx-cartographer/experiences 9.7.182 → 9.7.183
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 +4 -0
- package/dist/core/types/localization/CommonCopy.d.ts +1 -0
- package/dist/core/utils/TransactionUtils.d.ts +1 -0
- package/dist/core/utils/TransactionUtils.es.js +96 -95
- package/dist/core/utils/TransactionUtils.es.js.map +1 -1
- package/dist/finstrong/components/onboarding/OnboardingAddMonthlyIncome.es.js +20 -20
- package/dist/finstrong/components/onboarding/OnboardingAddMonthlyIncome.es.js.map +1 -1
- package/dist/transactions/components/shared/TransactionList.d.ts +1 -0
- package/dist/transactions/components/shared/TransactionList.es.js +58 -57
- package/dist/transactions/components/shared/TransactionList.es.js.map +1 -1
- package/dist/transactions/components/shared/TransactionTable.es.js +57 -49
- package/dist/transactions/components/shared/TransactionTable.es.js.map +1 -1
- package/dist/transactions/components/shared/transactiontable/cells/DateCell.d.ts +4 -2
- package/dist/transactions/components/shared/transactiontable/cells/DateCell.es.js +14 -9
- package/dist/transactions/components/shared/transactiontable/cells/DateCell.es.js.map +1 -1
- package/dist/transactions/utils/Transactions.d.ts +1 -1
- package/dist/transactions/utils/Transactions.es.js +15 -23
- package/dist/transactions/utils/Transactions.es.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -62,6 +62,7 @@ export declare const buildDetailedTransactions: (transactions: Transaction[], ac
|
|
|
62
62
|
is_duplicate: boolean;
|
|
63
63
|
feed_transacted_at: number | null;
|
|
64
64
|
}[];
|
|
65
|
+
export declare const sortPendingFirst: (transactions: Transaction[]) => Transaction[];
|
|
65
66
|
export declare const sortAndFilterTransactions: (filter: TransactionFilter, expandedSplits: string[], sortColumn: string, sortDirection: string, tags: Tag[], transactions: Transaction[]) => Transaction[];
|
|
66
67
|
/**
|
|
67
68
|
* Produces a list of transactions based on the given sorted transactions,
|
|
@@ -1,116 +1,117 @@
|
|
|
1
1
|
import { CategoryGuidToName as y, CategoryGuids as T } from "../constants/Category.es.js";
|
|
2
|
-
import { DATE_FORMATS_INTL as
|
|
3
|
-
import { TransactionStatus as
|
|
4
|
-
import { endOfUtcDay as
|
|
2
|
+
import { DATE_FORMATS_INTL as l, formatDate as m } from "../constants/DateFormats.es.js";
|
|
3
|
+
import { TransactionStatus as C, TransactionType as A } from "../types/Transaction.es.js";
|
|
4
|
+
import { endOfUtcDay as O, fromUnixUTC as h, startOfUtcDay as S } from "./DateUtil.es.js";
|
|
5
5
|
import { formatCurrency as b } from "./NumberFormatting.es.js";
|
|
6
6
|
import { getLocalizedCategoryName as D } from "./CategoryUtil.es.js";
|
|
7
7
|
import { TABLE_CONST as E } from "../constants/Table.es.js";
|
|
8
8
|
import { COLUMN_NAMES as _ } from "../constants/Transaction.es.js";
|
|
9
|
-
import { format as
|
|
10
|
-
import { startOfMonth as
|
|
11
|
-
import { startOfToday as
|
|
12
|
-
import { endOfToday as
|
|
13
|
-
var
|
|
14
|
-
const c =
|
|
15
|
-
...
|
|
16
|
-
[
|
|
17
|
-
}), {}),
|
|
18
|
-
...
|
|
19
|
-
[
|
|
20
|
-
}), {}),
|
|
21
|
-
const { transaction_guid:
|
|
22
|
-
if (!
|
|
23
|
-
...
|
|
24
|
-
[
|
|
9
|
+
import { format as N } from "date-fns/format";
|
|
10
|
+
import { startOfMonth as M } from "date-fns/startOfMonth";
|
|
11
|
+
import { startOfToday as U } from "date-fns/startOfToday";
|
|
12
|
+
import { endOfToday as L } from "date-fns/endOfToday";
|
|
13
|
+
var ee = (e) => e.top_level_category_guid === T.TRANSFER, te = (e) => !e.has_been_viewed && !e.parent_guid, re = (e, t, r, u = [], s) => {
|
|
14
|
+
const c = t.reduce((o, a) => ({
|
|
15
|
+
...o,
|
|
16
|
+
[a.guid]: a
|
|
17
|
+
}), {}), i = r.reduce((o, a) => ({
|
|
18
|
+
...o,
|
|
19
|
+
[a.guid]: a
|
|
20
|
+
}), {}), d = u.reduce((o, a) => {
|
|
21
|
+
const { transaction_guid: g, tag_guid: f } = a;
|
|
22
|
+
if (!o[g]) return {
|
|
23
|
+
...o,
|
|
24
|
+
[g]: [f]
|
|
25
25
|
};
|
|
26
|
-
const
|
|
26
|
+
const v = [...o[g], f];
|
|
27
27
|
return {
|
|
28
|
-
...
|
|
29
|
-
[
|
|
28
|
+
...o,
|
|
29
|
+
[g]: v
|
|
30
30
|
};
|
|
31
|
-
}, {});
|
|
32
|
-
return
|
|
33
|
-
const
|
|
31
|
+
}, {}), n = new Set(e.filter((o) => o.feed_status === C.PENDING).map((o) => o.guid));
|
|
32
|
+
return e.map((o) => {
|
|
33
|
+
const a = c[o.account_guid], g = o.category_guid ? i[o.category_guid] : null, f = d[o.guid] ?? [];
|
|
34
34
|
return {
|
|
35
|
-
...
|
|
36
|
-
account:
|
|
37
|
-
accountIsClosed:
|
|
38
|
-
accountIsHidden:
|
|
39
|
-
category:
|
|
40
|
-
institutionName:
|
|
41
|
-
isIncome:
|
|
42
|
-
isPending:
|
|
43
|
-
number:
|
|
44
|
-
payee:
|
|
45
|
-
tags:
|
|
35
|
+
...o,
|
|
36
|
+
account: a?.user_name || "Unknown",
|
|
37
|
+
accountIsClosed: a?.is_closed,
|
|
38
|
+
accountIsHidden: a?.is_hidden,
|
|
39
|
+
category: g ? D(g, s) : "Uncategorized",
|
|
40
|
+
institutionName: a?.institution?.name || a?.institutionName || void 0,
|
|
41
|
+
isIncome: o.top_level_category_guid === T.INCOME,
|
|
42
|
+
isPending: n.has(o.guid) || o.parent_guid != null && n.has(o.parent_guid),
|
|
43
|
+
number: a?.account_number || "",
|
|
44
|
+
payee: o.description,
|
|
45
|
+
tags: f
|
|
46
46
|
};
|
|
47
47
|
});
|
|
48
|
-
},
|
|
49
|
-
const
|
|
50
|
-
return
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
}),
|
|
54
|
-
},
|
|
55
|
-
const { accounts:
|
|
56
|
-
start:
|
|
57
|
-
end:
|
|
58
|
-
}, custom: c = () => !0, searchTerm:
|
|
59
|
-
return
|
|
60
|
-
if (
|
|
61
|
-
if (/^spl/i.test(
|
|
62
|
-
const
|
|
63
|
-
return p(
|
|
48
|
+
}, ne = (e) => [...e.filter((t) => t.isPending), ...e.filter((t) => !t.isPending)], R = "uncategorized", ie = (e, t, r, u, s, c) => {
|
|
49
|
+
const i = w(e, s, c), d = I(i, r, u);
|
|
50
|
+
return t.forEach((n) => {
|
|
51
|
+
const o = d.findIndex((g) => g.guid === n), a = c.filter((g) => g.parent_guid === n);
|
|
52
|
+
d.splice(o + 1, 0, ...a);
|
|
53
|
+
}), d;
|
|
54
|
+
}, w = (e, t, r) => {
|
|
55
|
+
const { accounts: u = [], dateRange: s = {
|
|
56
|
+
start: M(U()),
|
|
57
|
+
end: L()
|
|
58
|
+
}, custom: c = () => !0, searchTerm: i = "", showSplits: d = !1 } = e;
|
|
59
|
+
return r.filter((n) => d ? !n.has_been_split : !n.parent_guid).filter((n) => !!u.find((o) => o === n.account_guid)).filter((n) => n.date >= S(s.start) && n.date <= O(s.end)).filter(c).filter((n) => {
|
|
60
|
+
if (i === R && n.has_been_split) return !1;
|
|
61
|
+
if (/^spl/i.test(i) && (n.has_been_split || n.parent_guid)) return !0;
|
|
62
|
+
const o = n.tags.some((g) => p(i, t.find((f) => f.guid === g)?.name)), a = h(n.date);
|
|
63
|
+
return p(i, n.payee) || p(i, n.feed_description) || p(i, n.category) || p(i, m(a, l.MONTH)) || p(i, m(a, l.DAY)) || p(i, m(a, l.FULL_MONTH_DAY)) || p(i, m(a, l.MONTH_DAY_YEAR)) || p(i, N(a, "do")) || p(i, n.account) || p(i, b(n.amount, "0,0.00")) || p(i, n.memo) || o;
|
|
64
64
|
});
|
|
65
|
-
}, I = (t, r
|
|
66
|
-
const c =
|
|
67
|
-
let
|
|
68
|
-
return (
|
|
69
|
-
}), p = (
|
|
70
|
-
const
|
|
71
|
-
return
|
|
65
|
+
}, I = (e, t, r) => [...e].sort((u, s) => {
|
|
66
|
+
const c = t, i = (u[c] || "") > (s[c] || "");
|
|
67
|
+
let d = i ? -1 : 1, n = i ? 1 : -1;
|
|
68
|
+
return (t === _.DATE || t === _.AMOUNT) && (d = i ? 1 : -1, n = i ? -1 : 1), r === E.ASC ? d : n;
|
|
69
|
+
}), p = (e, t) => {
|
|
70
|
+
const r = e.toLowerCase().split(" "), u = t?.toString().toLowerCase() ?? "";
|
|
71
|
+
return r.every((s) => u.indexOf(s) > -1);
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
return new Set(
|
|
73
|
+
function P(e) {
|
|
74
|
+
return new Set(e.filter((t) => t.parent_guid !== void 0).map((t) => t.parent_guid));
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
return
|
|
76
|
+
function G(e) {
|
|
77
|
+
return e.reduce((t, r) => (r.parent_guid && (t[r.parent_guid] || (t[r.parent_guid] = []), t[r.parent_guid].push(r)), t), {});
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
for (const
|
|
82
|
-
|
|
83
|
-
}) :
|
|
79
|
+
function oe(e, t) {
|
|
80
|
+
const r = P(t), u = G(t), s = /* @__PURE__ */ new Set(), c = [];
|
|
81
|
+
for (const i of e) r.has(i.guid) ? (u[i.guid] ?? []).slice().sort((d, n) => Math.abs(n.amount) - Math.abs(d.amount)).forEach((d) => {
|
|
82
|
+
s.has(d.guid) || (c.push(d), s.add(d.guid));
|
|
83
|
+
}) : s.has(i.guid) || (c.push(i), s.add(i.guid));
|
|
84
84
|
return c;
|
|
85
85
|
}
|
|
86
|
-
var
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
Date:
|
|
91
|
-
Description:
|
|
92
|
-
"Original Description":
|
|
93
|
-
Amount: `${
|
|
94
|
-
Type:
|
|
95
|
-
"Parent Category": y[
|
|
96
|
-
Category:
|
|
97
|
-
Account:
|
|
98
|
-
Tags:
|
|
99
|
-
Memo:
|
|
100
|
-
Pending:
|
|
101
|
-
})),
|
|
102
|
-
`) +
|
|
103
|
-
`),
|
|
104
|
-
let
|
|
105
|
-
return
|
|
106
|
-
},
|
|
86
|
+
var se = (e, t) => {
|
|
87
|
+
const r = B(j(e, t)), u = new Blob([r], { type: "text/csv;charset=utf-8;" }), s = document.createElement("a");
|
|
88
|
+
s.href = URL.createObjectURL(u), s.setAttribute("download", "transactions.csv"), document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(s.href);
|
|
89
|
+
}, j = (e, t) => e.map((r) => ({
|
|
90
|
+
Date: m(h(r.date), l.YEAR_MONTH_DAY),
|
|
91
|
+
Description: Y(r),
|
|
92
|
+
"Original Description": r.feed_description,
|
|
93
|
+
Amount: `${r.amount}`,
|
|
94
|
+
Type: r.transaction_type === A.CREDIT ? "Credit" : "Debit",
|
|
95
|
+
"Parent Category": y[r.top_level_category_guid || ""],
|
|
96
|
+
Category: r.category,
|
|
97
|
+
Account: r.account,
|
|
98
|
+
Tags: k(r, t),
|
|
99
|
+
Memo: r.memo,
|
|
100
|
+
Pending: r.isPending ? "TRUE" : "FALSE"
|
|
101
|
+
})), F = (e) => e ? /[,"\n\r]/.test(e) ? `"${e.replace(/"/g, '""')}"` : e : "", B = (e) => e.length === 0 ? "" : Object.keys(e[0]).join(",").concat(`\r
|
|
102
|
+
`) + e.map((t) => Object.values(t).map(F).join(",")).join(`\r
|
|
103
|
+
`), Y = (e) => {
|
|
104
|
+
let t = e.parent_guid ? "Split: " : "";
|
|
105
|
+
return t += e.is_hidden ? "(Excluded) " : "", t += e.description, t;
|
|
106
|
+
}, k = (e, t) => e.tags.map((r) => t.filter((u) => u.guid === r)[0]?.name ?? "").join(" ");
|
|
107
107
|
export {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
re as buildDetailedTransactions,
|
|
109
|
+
se as exportTransactionsToCSV,
|
|
110
|
+
oe as flattenTransactionsWithSplits,
|
|
111
|
+
ee as isTransferTransaction,
|
|
112
|
+
te as isUnviewedTransaction,
|
|
113
|
+
ie as sortAndFilterTransactions,
|
|
114
|
+
ne as sortPendingFirst
|
|
114
115
|
};
|
|
115
116
|
|
|
116
117
|
//# sourceMappingURL=TransactionUtils.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionUtils.es.js","names":[],"sources":["../../../src/core/utils/TransactionUtils.ts"],"sourcesContent":["import { endOfToday } from 'date-fns/endOfToday'\nimport { format } from 'date-fns/format'\nimport { startOfMonth } from 'date-fns/startOfMonth'\nimport { startOfToday } from 'date-fns/startOfToday'\n\nimport { TABLE_CONST } from '../constants/Table'\nimport {\n CategoryGuids,\n CategoryGuidToName,\n DATE_FORMATS_INTL,\n formatDate,\n ORDINAL_DATE_FORMAT,\n} from '../constants'\nimport { COLUMN_NAMES } from '../constants/Transaction'\nimport { TransactionStatus, TransactionType } from '../types'\nimport type { Category, CategoryCopy, DetailedAccount, Tag, Tagging, Transaction } from '../types'\n\nimport { type TransactionFilter } from '../stores/TransactionStore'\n\nimport { getLocalizedCategoryName } from './CategoryUtil'\nimport { endOfUtcDay, fromUnixUTC, startOfUtcDay } from './DateUtil'\nimport { formatCurrency } from './NumberFormatting'\n\ninterface AccountsMap {\n [key: string]: DetailedAccount\n}\n\n// True for account-to-account transfers (top-level Transfer category). Used to\n// swap the payee/description for the institution name in the transaction detail\n// header, the table Payee column, and the mobile list.\nexport const isTransferTransaction = (\n transaction: Pick<Transaction, 'top_level_category_guid'>,\n): boolean => transaction.top_level_category_guid === CategoryGuids.TRANSFER\n\nexport const isUnviewedTransaction = (\n transaction: Pick<Transaction, 'has_been_viewed' | 'parent_guid'>,\n): boolean => !transaction.has_been_viewed && !transaction.parent_guid\n\ninterface CategoriesMap {\n [key: string]: Category\n}\n\ninterface TaggingsMap {\n [key: string]: string[]\n}\n\nexport const buildDetailedTransactions = (\n transactions: Transaction[],\n accounts: DetailedAccount[],\n categories: Category[],\n taggings: Tagging[] = [],\n categoryCopy: CategoryCopy,\n) => {\n const accountsMap = accounts.reduce((acc: AccountsMap, account: DetailedAccount) => {\n return { ...acc, [account.guid]: account }\n }, {})\n\n const categoriesMap = categories.reduce((acc: CategoriesMap, category: Category) => {\n return { ...acc, [category.guid]: category }\n }, {})\n\n const taggingsMap = taggings.reduce((acc: TaggingsMap, tagging: Tagging) => {\n const { transaction_guid, tag_guid } = tagging\n\n if (!acc[transaction_guid]) {\n return {\n ...acc,\n [transaction_guid]: [tag_guid],\n }\n }\n const tags = [...acc[transaction_guid], tag_guid] as string[]\n\n return {\n ...acc,\n [transaction_guid]: tags,\n }\n }, {})\n\n return transactions.map((transaction: Transaction) => {\n const account = accountsMap[transaction.account_guid]\n const category = transaction.category_guid ? categoriesMap[transaction.category_guid] : null\n const tags = taggingsMap[transaction.guid] ?? []\n\n return {\n ...transaction,\n account: account?.user_name || 'Unknown',\n accountIsClosed: account?.is_closed,\n accountIsHidden: account?.is_hidden,\n category: category ? getLocalizedCategoryName(category, categoryCopy) : 'Uncategorized',\n institutionName: account?.institution?.name || account?.institutionName || undefined,\n isIncome: transaction.top_level_category_guid === CategoryGuids.INCOME,\n isPending: transaction.feed_status === TransactionStatus.PENDING,\n number: account?.account_number || '',\n payee: transaction.description,\n tags,\n }\n })\n}\n\nconst UNCATEGORIZED_TERM = 'uncategorized'\n\nexport const sortAndFilterTransactions = (\n filter: TransactionFilter,\n expandedSplits: string[],\n sortColumn: string,\n sortDirection: string,\n tags: Tag[],\n transactions: Transaction[],\n) => {\n const filteredTransactions = filterTransactions(filter, tags, transactions)\n\n const sortedTransactions = sortTransactions(filteredTransactions, sortColumn, sortDirection)\n\n expandedSplits.forEach((guid) => {\n const index = sortedTransactions.findIndex((t) => t.guid === guid)\n const children = transactions.filter((t) => t.parent_guid === guid)\n sortedTransactions.splice(index + 1, 0, ...children)\n })\n return sortedTransactions\n}\n\nconst filterTransactions = (\n filter: TransactionFilter,\n tags: Tag[],\n transactions: Transaction[],\n) => {\n const {\n accounts = [],\n dateRange = { start: startOfMonth(startOfToday()), end: endOfToday() },\n custom = () => true,\n searchTerm: searchFilter = '',\n showSplits = false,\n } = filter\n\n return (\n transactions\n // Filters out parent of split transactions when showSplits is true and filters out split\n // transaction children when showSplits is false\n .filter((t) => (showSplits ? !t.has_been_split : !t.parent_guid))\n // Filter for selected accounts\n .filter((t) => Boolean(accounts.find((guid) => guid === t.account_guid)))\n // Date range on the UTC calendar day, the same day the Date cell, CSV export\n // and category totals use. Local-midnight bounds put a midnight-UTC row near\n // a month boundary in a different month than the chart. (MEW-4191)\n .filter(\n (t) => t.date >= startOfUtcDay(dateRange.start) && t.date <= endOfUtcDay(dateRange.end),\n )\n // Custom filter\n .filter(custom)\n // Search filter\n .filter((transaction) => {\n // Don't return uncategorized split transactions\n if (searchFilter === UNCATEGORIZED_TERM && transaction.has_been_split) {\n return false\n }\n\n // Split check - When searching for \"Splits\" and transaction is a split or is a parent of a split(s)\n const splitPattern = /^spl/i\n if (\n splitPattern.test(searchFilter) &&\n (transaction.has_been_split || Boolean(transaction.parent_guid))\n ) {\n return true\n }\n\n // Check transactions tags\n const isTagIncludedInSearch = transaction.tags.some((guid) =>\n isIncludedInSearch(searchFilter, tags.find((tag) => tag.guid === guid)?.name),\n )\n const date = fromUnixUTC(transaction.date)\n return (\n isIncludedInSearch(searchFilter, transaction.payee) ||\n isIncludedInSearch(searchFilter, transaction.feed_description) ||\n isIncludedInSearch(searchFilter, transaction.category) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.MONTH)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.DAY)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.FULL_MONTH_DAY)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.MONTH_DAY_YEAR)) ||\n isIncludedInSearch(searchFilter, format(date, ORDINAL_DATE_FORMAT)) ||\n isIncludedInSearch(searchFilter, transaction.account) ||\n isIncludedInSearch(searchFilter, formatCurrency(transaction.amount, '0,0.00')) ||\n isIncludedInSearch(searchFilter, transaction.memo) ||\n isTagIncludedInSearch\n )\n })\n )\n}\n\nconst sortTransactions = (\n transactions: Transaction[],\n sortColumn: string,\n sortDirection: string,\n) => {\n return [...transactions].sort((a: Transaction, b: Transaction) => {\n const column = sortColumn as keyof Transaction\n const sortCompare = (a[column] || '') > (b[column] || '')\n\n let sortASC = sortCompare ? -1 : 1\n let sortDESC = sortCompare ? 1 : -1\n\n if (sortColumn === COLUMN_NAMES.DATE || sortColumn === COLUMN_NAMES.AMOUNT) {\n sortASC = sortCompare ? 1 : -1\n sortDESC = sortCompare ? -1 : 1\n }\n\n return sortDirection === TABLE_CONST.ASC ? sortASC : sortDESC\n })\n}\n\n/**\n * Determines if a value is included within the terms set in the search bar\n */\nconst isIncludedInSearch = (searchFilter: string, value: string | null | undefined) => {\n const lowerCasedTerms = searchFilter.toLowerCase().split(' ')\n const lowerCasedValue = value?.toString().toLowerCase() ?? ''\n\n return lowerCasedTerms.every((filter) => lowerCasedValue.indexOf(filter) > -1)\n}\n\n// TODO: Change the way formatting data is exported in order to handle localization\ntype FormattedTransaction = {\n Date: string\n Description: string\n 'Original Description': string\n Amount: string\n Type: string\n 'Parent Category': string\n Category: string\n Account: string\n Tags: string\n Memo: string\n Pending: string\n}\n\n/**\n * Collects the GUIDs of all transactions that act as parents\n * to one or more split (child) transactions.\n */\nfunction extractParentTransactionGuids(transactions: Transaction[]): Set<string> {\n return new Set(\n transactions.filter((tx) => tx.parent_guid !== undefined).map((tx) => tx.parent_guid!),\n )\n}\n\n/**\n * Organizes child transactions by their parent transaction GUID.\n * Returns a map from parent GUID to an array of its child transactions.\n */\nfunction mapChildTransactionsByParent(transactions: Transaction[]): Record<string, Transaction[]> {\n return transactions.reduce<Record<string, Transaction[]>>((accumulator, tx) => {\n if (tx.parent_guid) {\n if (!accumulator[tx.parent_guid]) accumulator[tx.parent_guid] = []\n accumulator[tx.parent_guid].push(tx)\n }\n return accumulator\n }, {})\n}\n\n/**\n * Produces a list of transactions based on the given sorted transactions,\n * where parent transactions that have split children are replaced by those\n * children sorted by descending absolute amount. All other transactions\n * are included as-is, with duplicates removed.\n */\nexport function flattenTransactionsWithSplits(\n sortedTransactions: Transaction[],\n allTransactions: Transaction[],\n): Transaction[] {\n // Set of parent transaction GUIDs that have split child transactions\n const parentTransactionGuidsWithSplits = extractParentTransactionGuids(allTransactions)\n\n // Map from parent GUID to array of its child split transactions\n const childTransactionsGroupedByParent = mapChildTransactionsByParent(allTransactions)\n\n // Track GUIDs of transactions already included in the result to avoid duplicates\n const processedTransactionGuids = new Set<string>()\n\n // Resulting list of transactions with parents replaced by their split children\n const flattenedTransactionList: Transaction[] = []\n\n for (const transaction of sortedTransactions) {\n if (parentTransactionGuidsWithSplits.has(transaction.guid)) {\n // This transaction is a parent with splits, so replace it with its children\n const splitChildTransactions = childTransactionsGroupedByParent[transaction.guid] ?? []\n\n splitChildTransactions\n .slice()\n .sort((a, b) => Math.abs(b.amount) - Math.abs(a.amount))\n .forEach((childTransaction) => {\n if (!processedTransactionGuids.has(childTransaction.guid)) {\n flattenedTransactionList.push(childTransaction)\n processedTransactionGuids.add(childTransaction.guid)\n }\n })\n } else if (!processedTransactionGuids.has(transaction.guid)) {\n // Normal transaction (no splits), add as-is if not already added\n flattenedTransactionList.push(transaction)\n processedTransactionGuids.add(transaction.guid)\n }\n }\n\n return flattenedTransactionList\n}\n\nexport const exportTransactionsToCSV = (transactions: Transaction[], tags: Tag[]) => {\n const csvContent = structureCSVData(formatTransactions(transactions, tags))\n\n const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })\n const link = document.createElement('a')\n link.href = URL.createObjectURL(blob)\n link.setAttribute('download', 'transactions.csv')\n\n document.body.appendChild(link)\n link.click()\n document.body.removeChild(link)\n\n URL.revokeObjectURL(link.href)\n}\n\n/**\n * Formats a list of transactions into a list that will be used when\n * downloaded to a CSV file.\n */\nconst formatTransactions = (transactions: Transaction[], tags: Tag[]) => {\n return transactions.map((transaction) => ({\n // Post dates are calendar days; format on the UTC day so the export can't\n // shift to the prior day in a Western-offset browser.\n Date: formatDate(fromUnixUTC(transaction.date), DATE_FORMATS_INTL.YEAR_MONTH_DAY),\n Description: getDescription(transaction),\n 'Original Description': transaction.feed_description,\n Amount: `${transaction.amount}`,\n Type: transaction.transaction_type === TransactionType.CREDIT ? 'Credit' : 'Debit',\n 'Parent Category': CategoryGuidToName[transaction.top_level_category_guid || ''],\n Category: transaction.category,\n Account: transaction.account,\n Tags: getTags(transaction, tags),\n Memo: transaction.memo,\n Pending: transaction.isPending ? 'TRUE' : 'FALSE',\n })) as FormattedTransaction[]\n}\n\n/**\n * Escapes a value for safe CSV output\n */\nconst escapeCsvField = (field?: string | null): string => {\n if (!field) return ''\n return /[,\"\\n\\r]/.test(field) ? `\"${field.replace(/\"/g, '\"\"')}\"` : field\n}\n\n/**\n * Structures the CSV file data using the formatted transactions\n */\nconst structureCSVData = (formattedTransactions: FormattedTransaction[]) => {\n // Guard the empty export: Object.keys(undefined) would throw for a zero-row\n // list (e.g. an over-filtered range), so emit an empty file instead.\n if (formattedTransactions.length === 0) return ''\n\n const csvHeader = Object.keys(formattedTransactions[0]).join(',').concat('\\r\\n')\n const csvRows = formattedTransactions\n .map((transaction) => Object.values(transaction).map(escapeCsvField).join(','))\n .join('\\r\\n')\n\n return csvHeader + csvRows\n}\n\n/**\n * Get the description for a transaction that will be used within the CSV copy.\n * We want to highlight that split transactions are a split as well as\n * hidden transactions are hidden.\n */\nconst getDescription = (transaction: Transaction) => {\n let description = transaction.parent_guid ? 'Split: ' : ''\n description += transaction.is_hidden ? '(Excluded) ' : ''\n description += transaction.description\n\n return description\n}\n\nconst getTags = (transaction: Transaction, tags: Tag[]) => {\n return transaction.tags\n .map((tagGuid) => {\n const tag = tags.filter((t) => t.guid === tagGuid)[0]\n\n return tag?.name ?? ''\n })\n .join(' ')\n}\n"],"mappings":";;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from 'date-fns/endOfToday'\nimport { format } from 'date-fns/format'\nimport { startOfMonth } from 'date-fns/startOfMonth'\nimport { startOfToday } from 'date-fns/startOfToday'\n\nimport { TABLE_CONST } from '../constants/Table'\nimport {\n CategoryGuids,\n CategoryGuidToName,\n DATE_FORMATS_INTL,\n formatDate,\n ORDINAL_DATE_FORMAT,\n} from '../constants'\nimport { COLUMN_NAMES } from '../constants/Transaction'\nimport { TransactionStatus, TransactionType } from '../types'\nimport type { Category, CategoryCopy, DetailedAccount, Tag, Tagging, Transaction } from '../types'\n\nimport { type TransactionFilter } from '../stores/TransactionStore'\n\nimport { getLocalizedCategoryName } from './CategoryUtil'\nimport { endOfUtcDay, fromUnixUTC, startOfUtcDay } from './DateUtil'\nimport { formatCurrency } from './NumberFormatting'\n\ninterface AccountsMap {\n [key: string]: DetailedAccount\n}\n\n// True for account-to-account transfers (top-level Transfer category). Used to\n// swap the payee/description for the institution name in the transaction detail\n// header, the table Payee column, and the mobile list.\nexport const isTransferTransaction = (\n transaction: Pick<Transaction, 'top_level_category_guid'>,\n): boolean => transaction.top_level_category_guid === CategoryGuids.TRANSFER\n\nexport const isUnviewedTransaction = (\n transaction: Pick<Transaction, 'has_been_viewed' | 'parent_guid'>,\n): boolean => !transaction.has_been_viewed && !transaction.parent_guid\n\ninterface CategoriesMap {\n [key: string]: Category\n}\n\ninterface TaggingsMap {\n [key: string]: string[]\n}\n\nexport const buildDetailedTransactions = (\n transactions: Transaction[],\n accounts: DetailedAccount[],\n categories: Category[],\n taggings: Tagging[] = [],\n categoryCopy: CategoryCopy,\n) => {\n const accountsMap = accounts.reduce((acc: AccountsMap, account: DetailedAccount) => {\n return { ...acc, [account.guid]: account }\n }, {})\n\n const categoriesMap = categories.reduce((acc: CategoriesMap, category: Category) => {\n return { ...acc, [category.guid]: category }\n }, {})\n\n const taggingsMap = taggings.reduce((acc: TaggingsMap, tagging: Tagging) => {\n const { transaction_guid, tag_guid } = tagging\n\n if (!acc[transaction_guid]) {\n return {\n ...acc,\n [transaction_guid]: [tag_guid],\n }\n }\n const tags = [...acc[transaction_guid], tag_guid] as string[]\n\n return {\n ...acc,\n [transaction_guid]: tags,\n }\n }, {})\n\n const pendingTransactionGuids = new Set(\n transactions.filter((t) => t.feed_status === TransactionStatus.PENDING).map((t) => t.guid),\n )\n\n return transactions.map((transaction: Transaction) => {\n const account = accountsMap[transaction.account_guid]\n const category = transaction.category_guid ? categoriesMap[transaction.category_guid] : null\n const tags = taggingsMap[transaction.guid] ?? []\n\n return {\n ...transaction,\n account: account?.user_name || 'Unknown',\n accountIsClosed: account?.is_closed,\n accountIsHidden: account?.is_hidden,\n category: category ? getLocalizedCategoryName(category, categoryCopy) : 'Uncategorized',\n institutionName: account?.institution?.name || account?.institutionName || undefined,\n isIncome: transaction.top_level_category_guid === CategoryGuids.INCOME,\n // Without this, pending-first lists would move a split child away from its parent.\n isPending:\n pendingTransactionGuids.has(transaction.guid) ||\n (transaction.parent_guid != null && pendingTransactionGuids.has(transaction.parent_guid)),\n number: account?.account_number || '',\n payee: transaction.description,\n tags,\n }\n })\n}\n\nexport const sortPendingFirst = (transactions: Transaction[]) => [\n ...transactions.filter((t) => t.isPending),\n ...transactions.filter((t) => !t.isPending),\n]\n\nconst UNCATEGORIZED_TERM = 'uncategorized'\n\nexport const sortAndFilterTransactions = (\n filter: TransactionFilter,\n expandedSplits: string[],\n sortColumn: string,\n sortDirection: string,\n tags: Tag[],\n transactions: Transaction[],\n) => {\n const filteredTransactions = filterTransactions(filter, tags, transactions)\n\n const sortedTransactions = sortTransactions(filteredTransactions, sortColumn, sortDirection)\n\n expandedSplits.forEach((guid) => {\n const index = sortedTransactions.findIndex((t) => t.guid === guid)\n const children = transactions.filter((t) => t.parent_guid === guid)\n sortedTransactions.splice(index + 1, 0, ...children)\n })\n return sortedTransactions\n}\n\nconst filterTransactions = (\n filter: TransactionFilter,\n tags: Tag[],\n transactions: Transaction[],\n) => {\n const {\n accounts = [],\n dateRange = { start: startOfMonth(startOfToday()), end: endOfToday() },\n custom = () => true,\n searchTerm: searchFilter = '',\n showSplits = false,\n } = filter\n\n return (\n transactions\n // Filters out parent of split transactions when showSplits is true and filters out split\n // transaction children when showSplits is false\n .filter((t) => (showSplits ? !t.has_been_split : !t.parent_guid))\n // Filter for selected accounts\n .filter((t) => Boolean(accounts.find((guid) => guid === t.account_guid)))\n // Date range on the UTC calendar day, the same day the Date cell, CSV export\n // and category totals use. Local-midnight bounds put a midnight-UTC row near\n // a month boundary in a different month than the chart. (MEW-4191)\n .filter(\n (t) => t.date >= startOfUtcDay(dateRange.start) && t.date <= endOfUtcDay(dateRange.end),\n )\n // Custom filter\n .filter(custom)\n // Search filter\n .filter((transaction) => {\n // Don't return uncategorized split transactions\n if (searchFilter === UNCATEGORIZED_TERM && transaction.has_been_split) {\n return false\n }\n\n // Split check - When searching for \"Splits\" and transaction is a split or is a parent of a split(s)\n const splitPattern = /^spl/i\n if (\n splitPattern.test(searchFilter) &&\n (transaction.has_been_split || Boolean(transaction.parent_guid))\n ) {\n return true\n }\n\n // Check transactions tags\n const isTagIncludedInSearch = transaction.tags.some((guid) =>\n isIncludedInSearch(searchFilter, tags.find((tag) => tag.guid === guid)?.name),\n )\n const date = fromUnixUTC(transaction.date)\n return (\n isIncludedInSearch(searchFilter, transaction.payee) ||\n isIncludedInSearch(searchFilter, transaction.feed_description) ||\n isIncludedInSearch(searchFilter, transaction.category) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.MONTH)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.DAY)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.FULL_MONTH_DAY)) ||\n isIncludedInSearch(searchFilter, formatDate(date, DATE_FORMATS_INTL.MONTH_DAY_YEAR)) ||\n isIncludedInSearch(searchFilter, format(date, ORDINAL_DATE_FORMAT)) ||\n isIncludedInSearch(searchFilter, transaction.account) ||\n isIncludedInSearch(searchFilter, formatCurrency(transaction.amount, '0,0.00')) ||\n isIncludedInSearch(searchFilter, transaction.memo) ||\n isTagIncludedInSearch\n )\n })\n )\n}\n\nconst sortTransactions = (\n transactions: Transaction[],\n sortColumn: string,\n sortDirection: string,\n) => {\n return [...transactions].sort((a: Transaction, b: Transaction) => {\n const column = sortColumn as keyof Transaction\n const sortCompare = (a[column] || '') > (b[column] || '')\n\n let sortASC = sortCompare ? -1 : 1\n let sortDESC = sortCompare ? 1 : -1\n\n if (sortColumn === COLUMN_NAMES.DATE || sortColumn === COLUMN_NAMES.AMOUNT) {\n sortASC = sortCompare ? 1 : -1\n sortDESC = sortCompare ? -1 : 1\n }\n\n return sortDirection === TABLE_CONST.ASC ? sortASC : sortDESC\n })\n}\n\n/**\n * Determines if a value is included within the terms set in the search bar\n */\nconst isIncludedInSearch = (searchFilter: string, value: string | null | undefined) => {\n const lowerCasedTerms = searchFilter.toLowerCase().split(' ')\n const lowerCasedValue = value?.toString().toLowerCase() ?? ''\n\n return lowerCasedTerms.every((filter) => lowerCasedValue.indexOf(filter) > -1)\n}\n\n// TODO: Change the way formatting data is exported in order to handle localization\ntype FormattedTransaction = {\n Date: string\n Description: string\n 'Original Description': string\n Amount: string\n Type: string\n 'Parent Category': string\n Category: string\n Account: string\n Tags: string\n Memo: string\n Pending: string\n}\n\n/**\n * Collects the GUIDs of all transactions that act as parents\n * to one or more split (child) transactions.\n */\nfunction extractParentTransactionGuids(transactions: Transaction[]): Set<string> {\n return new Set(\n transactions.filter((tx) => tx.parent_guid !== undefined).map((tx) => tx.parent_guid!),\n )\n}\n\n/**\n * Organizes child transactions by their parent transaction GUID.\n * Returns a map from parent GUID to an array of its child transactions.\n */\nfunction mapChildTransactionsByParent(transactions: Transaction[]): Record<string, Transaction[]> {\n return transactions.reduce<Record<string, Transaction[]>>((accumulator, tx) => {\n if (tx.parent_guid) {\n if (!accumulator[tx.parent_guid]) accumulator[tx.parent_guid] = []\n accumulator[tx.parent_guid].push(tx)\n }\n return accumulator\n }, {})\n}\n\n/**\n * Produces a list of transactions based on the given sorted transactions,\n * where parent transactions that have split children are replaced by those\n * children sorted by descending absolute amount. All other transactions\n * are included as-is, with duplicates removed.\n */\nexport function flattenTransactionsWithSplits(\n sortedTransactions: Transaction[],\n allTransactions: Transaction[],\n): Transaction[] {\n // Set of parent transaction GUIDs that have split child transactions\n const parentTransactionGuidsWithSplits = extractParentTransactionGuids(allTransactions)\n\n // Map from parent GUID to array of its child split transactions\n const childTransactionsGroupedByParent = mapChildTransactionsByParent(allTransactions)\n\n // Track GUIDs of transactions already included in the result to avoid duplicates\n const processedTransactionGuids = new Set<string>()\n\n // Resulting list of transactions with parents replaced by their split children\n const flattenedTransactionList: Transaction[] = []\n\n for (const transaction of sortedTransactions) {\n if (parentTransactionGuidsWithSplits.has(transaction.guid)) {\n // This transaction is a parent with splits, so replace it with its children\n const splitChildTransactions = childTransactionsGroupedByParent[transaction.guid] ?? []\n\n splitChildTransactions\n .slice()\n .sort((a, b) => Math.abs(b.amount) - Math.abs(a.amount))\n .forEach((childTransaction) => {\n if (!processedTransactionGuids.has(childTransaction.guid)) {\n flattenedTransactionList.push(childTransaction)\n processedTransactionGuids.add(childTransaction.guid)\n }\n })\n } else if (!processedTransactionGuids.has(transaction.guid)) {\n // Normal transaction (no splits), add as-is if not already added\n flattenedTransactionList.push(transaction)\n processedTransactionGuids.add(transaction.guid)\n }\n }\n\n return flattenedTransactionList\n}\n\nexport const exportTransactionsToCSV = (transactions: Transaction[], tags: Tag[]) => {\n const csvContent = structureCSVData(formatTransactions(transactions, tags))\n\n const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })\n const link = document.createElement('a')\n link.href = URL.createObjectURL(blob)\n link.setAttribute('download', 'transactions.csv')\n\n document.body.appendChild(link)\n link.click()\n document.body.removeChild(link)\n\n URL.revokeObjectURL(link.href)\n}\n\n/**\n * Formats a list of transactions into a list that will be used when\n * downloaded to a CSV file.\n */\nconst formatTransactions = (transactions: Transaction[], tags: Tag[]) => {\n return transactions.map((transaction) => ({\n // Post dates are calendar days; format on the UTC day so the export can't\n // shift to the prior day in a Western-offset browser.\n Date: formatDate(fromUnixUTC(transaction.date), DATE_FORMATS_INTL.YEAR_MONTH_DAY),\n Description: getDescription(transaction),\n 'Original Description': transaction.feed_description,\n Amount: `${transaction.amount}`,\n Type: transaction.transaction_type === TransactionType.CREDIT ? 'Credit' : 'Debit',\n 'Parent Category': CategoryGuidToName[transaction.top_level_category_guid || ''],\n Category: transaction.category,\n Account: transaction.account,\n Tags: getTags(transaction, tags),\n Memo: transaction.memo,\n Pending: transaction.isPending ? 'TRUE' : 'FALSE',\n })) as FormattedTransaction[]\n}\n\n/**\n * Escapes a value for safe CSV output\n */\nconst escapeCsvField = (field?: string | null): string => {\n if (!field) return ''\n return /[,\"\\n\\r]/.test(field) ? `\"${field.replace(/\"/g, '\"\"')}\"` : field\n}\n\n/**\n * Structures the CSV file data using the formatted transactions\n */\nconst structureCSVData = (formattedTransactions: FormattedTransaction[]) => {\n // Guard the empty export: Object.keys(undefined) would throw for a zero-row\n // list (e.g. an over-filtered range), so emit an empty file instead.\n if (formattedTransactions.length === 0) return ''\n\n const csvHeader = Object.keys(formattedTransactions[0]).join(',').concat('\\r\\n')\n const csvRows = formattedTransactions\n .map((transaction) => Object.values(transaction).map(escapeCsvField).join(','))\n .join('\\r\\n')\n\n return csvHeader + csvRows\n}\n\n/**\n * Get the description for a transaction that will be used within the CSV copy.\n * We want to highlight that split transactions are a split as well as\n * hidden transactions are hidden.\n */\nconst getDescription = (transaction: Transaction) => {\n let description = transaction.parent_guid ? 'Split: ' : ''\n description += transaction.is_hidden ? '(Excluded) ' : ''\n description += transaction.description\n\n return description\n}\n\nconst getTags = (transaction: Transaction, tags: Tag[]) => {\n return transaction.tags\n .map((tagGuid) => {\n const tag = tags.filter((t) => t.guid === tagGuid)[0]\n\n return tag?.name ?? ''\n })\n .join(' ')\n}\n"],"mappings":";;;;;;;;;;;;AA8BA,IAAa,KAAA,CACX,MACY,EAAY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EAAY,aAEpB;AACT,GAEM,IAAA,CAAW,GAA0B,MAClC,EAAY,KAChB,IAAA,CAAK,MACQ,EAAK,OAAA,CAAQ,MAAM,EAAE,SAAS,CAAO,EAAE,CAAA,GAEvC,QAAQ,EACrB,EACA,KAAK,GAAG"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useGlobalCopyStore as
|
|
1
|
+
import { useGlobalCopyStore as S } from "../../../common/context/hooks.es.js";
|
|
2
2
|
import { fromUnixToDayOfWeekAndDate as x } from "../../../core/utils/DateUtil.es.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { hasInsetBorder as v,
|
|
3
|
+
import D from "../../../transactions/components/shared/transactionlist/TransactionRow.es.js";
|
|
4
|
+
import I from "../../../common/components/SubheaderRow.es.js";
|
|
5
|
+
import { hasInsetBorder as v, shouldShowSubheader as A } from "../../../transactions/utils/Transactions.es.js";
|
|
6
6
|
import { AddRecurringTransactionDetails as C } from "../../../recurringtransactions/components/shared/recurringsettings/AddRecurringTransactionDetails.es.js";
|
|
7
7
|
import { OnboardingSteps as _ } from "../../../core/types/Finstrong.es.js";
|
|
8
8
|
import m from "react";
|
|
@@ -13,35 +13,35 @@ import { Add as R } from "@mxenabled/mx-icons";
|
|
|
13
13
|
import { jsx as r, jsxs as n } from "react/jsx-runtime";
|
|
14
14
|
import a from "@mui/material/Box";
|
|
15
15
|
import k from "@mui/material/Divider";
|
|
16
|
-
var B = ({ firstDay: p, frequency: f, secondDay: h, incomeTransactions: o, setCurrentStep:
|
|
17
|
-
const { finstrong: g } =
|
|
16
|
+
var B = ({ firstDay: p, frequency: f, secondDay: h, incomeTransactions: o, setCurrentStep: u, setFirstDay: c, setFrequency: l, setSecondDay: s, transaction: d }) => {
|
|
17
|
+
const { finstrong: g } = S();
|
|
18
18
|
return /* @__PURE__ */ n(m.Fragment, { children: [/* @__PURE__ */ n(F, { children: [!!o.length && /* @__PURE__ */ r(a, {
|
|
19
19
|
sx: { pb: 24 },
|
|
20
|
-
children: o.reduce((
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
/* @__PURE__ */ r(
|
|
20
|
+
children: o.reduce((t, e, i) => {
|
|
21
|
+
if (e.guid === d.guid) return t;
|
|
22
|
+
const b = A(i, o), y = v(i, o);
|
|
23
|
+
return t.push(/* @__PURE__ */ n(m.Fragment, { children: [
|
|
24
|
+
b && /* @__PURE__ */ r(I, { children: x(e.date) }),
|
|
25
|
+
/* @__PURE__ */ r(D, {
|
|
26
26
|
component: "div",
|
|
27
|
-
transaction:
|
|
27
|
+
transaction: e
|
|
28
28
|
}),
|
|
29
|
-
/* @__PURE__ */ r(k, { sx: { ml:
|
|
30
|
-
] },
|
|
29
|
+
/* @__PURE__ */ r(k, { sx: { ml: y ? 44 : 0 } })
|
|
30
|
+
] }, e.guid)), t;
|
|
31
31
|
}, [])
|
|
32
32
|
}), /* @__PURE__ */ r(C, {
|
|
33
33
|
firstDay: p,
|
|
34
34
|
frequency: f,
|
|
35
|
-
onFirstDayChange:
|
|
36
|
-
onFrequencyChange:
|
|
37
|
-
onSecondDayChange:
|
|
35
|
+
onFirstDayChange: c,
|
|
36
|
+
onFrequencyChange: l,
|
|
37
|
+
onSecondDayChange: s,
|
|
38
38
|
secondDay: h,
|
|
39
|
-
transaction:
|
|
39
|
+
transaction: d
|
|
40
40
|
})] }), /* @__PURE__ */ r(a, {
|
|
41
41
|
sx: { px: 24 },
|
|
42
42
|
children: /* @__PURE__ */ r(O, {
|
|
43
43
|
fullWidth: !0,
|
|
44
|
-
onClick: () =>
|
|
44
|
+
onClick: () => u({
|
|
45
45
|
step: _.MonthlyIncome,
|
|
46
46
|
type: "main"
|
|
47
47
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnboardingAddMonthlyIncome.es.js","names":[],"sources":["../../../../src/finstrong/components/onboarding/OnboardingAddMonthlyIncome.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Divider from '@mui/material/Divider'\nimport Stack from '@mui/material/Stack'\n\nimport { Add } from '@mxenabled/mx-icons'\n\nimport { useGlobalCopyStore } from '../../../common'\nimport { Frequency, type Transaction } from '../../../core'\nimport SubheaderRow from '../../../common/components/SubheaderRow'\nimport { OnboardingSteps } from '../../../core/types/Finstrong'\nimport { fromUnixToDayOfWeekAndDate } from '../../../core/utils/DateUtil'\nimport { AddRecurringTransactionDetails } from '../../../recurringtransactions'\nimport { TransactionRow } from '../../../transactions'\nimport { hasInsetBorder,
|
|
1
|
+
{"version":3,"file":"OnboardingAddMonthlyIncome.es.js","names":[],"sources":["../../../../src/finstrong/components/onboarding/OnboardingAddMonthlyIncome.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Divider from '@mui/material/Divider'\nimport Stack from '@mui/material/Stack'\n\nimport { Add } from '@mxenabled/mx-icons'\n\nimport { useGlobalCopyStore } from '../../../common'\nimport { Frequency, type Transaction } from '../../../core'\nimport SubheaderRow from '../../../common/components/SubheaderRow'\nimport { OnboardingSteps } from '../../../core/types/Finstrong'\nimport { fromUnixToDayOfWeekAndDate } from '../../../core/utils/DateUtil'\nimport { AddRecurringTransactionDetails } from '../../../recurringtransactions'\nimport { TransactionRow } from '../../../transactions'\nimport { hasInsetBorder, shouldShowSubheader } from '../../../transactions/utils/Transactions'\n\nimport type { StepState } from './OnboardingStepsDrawer'\n\ninterface OnboardingAddMonthlyIncomeProps {\n firstDay: number\n frequency: Frequency\n secondDay: number\n incomeTransactions: Transaction[]\n setCurrentStep: (step: StepState) => void\n setFirstDay: (day: number) => void\n setFrequency: (frequency: Frequency) => void\n setSecondDay: (day: number) => void\n transaction: Transaction\n}\n\nconst OnboardingAddMonthlyIncome = ({\n firstDay,\n frequency,\n secondDay,\n incomeTransactions,\n setCurrentStep,\n setFirstDay,\n setFrequency,\n setSecondDay,\n transaction,\n}: OnboardingAddMonthlyIncomeProps) => {\n const { finstrong: copy } = useGlobalCopyStore()\n\n return (\n <React.Fragment>\n <Stack>\n {!!incomeTransactions.length && (\n <Box sx={{ pb: 24 }}>\n {incomeTransactions.reduce<React.JSX.Element[]>((elements, txn, i) => {\n if (txn.guid === transaction.guid) return elements\n\n const showSubheader = shouldShowSubheader(i, incomeTransactions)\n const isInset = hasInsetBorder(i, incomeTransactions)\n\n elements.push(\n <React.Fragment key={txn.guid}>\n {showSubheader && <SubheaderRow>{fromUnixToDayOfWeekAndDate(txn.date)}</SubheaderRow>}\n <TransactionRow component=\"div\" transaction={txn} />\n <Divider sx={{ ml: isInset ? 44 : 0 }} />\n </React.Fragment>,\n )\n\n return elements\n }, [])}\n </Box>\n )}\n <AddRecurringTransactionDetails\n firstDay={firstDay}\n frequency={frequency}\n onFirstDayChange={setFirstDay}\n onFrequencyChange={setFrequency}\n onSecondDayChange={setSecondDay}\n secondDay={secondDay}\n transaction={transaction}\n />\n </Stack>\n\n <Box sx={{ px: 24 }}>\n <Button\n fullWidth={true}\n onClick={() => setCurrentStep({ step: OnboardingSteps.MonthlyIncome, type: 'main' })}\n startIcon={<Add />}\n >\n {copy.onboarding_add_more_income}\n </Button>\n </Box>\n </React.Fragment>\n )\n}\n\nexport default observer(OnboardingAddMonthlyIncome)\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,IAAM,IAAA,CAA8B,EAClC,UAAA,GACA,WAAA,GACA,WAAA,GACA,oBAAA,GACA,gBAAA,GACA,aAAA,GACA,cAAA,GACA,cAAA,GACA,aAAA,EAAA,MACqC;AACrC,QAAM,EAAE,WAAW,EAAA,IAAS,EAAmB;AAE/C,SACE,gBAAA,EAAC,EAAM,UAAP,EAAA,UAAA,CACE,gBAAA,EAAC,GAAD,EAAA,UAAA,CACG,CAAC,CAAC,EAAmB,UACpB,gBAAA,EAAC,GAAD;AAAA,IAAK,IAAI,E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?: boolean;
|
|
24
24
|
showUnviewedIndicator?: boolean;
|
|
25
|
+
/** Replaces the store transactions. Pending transactions still go first. */
|
|
25
26
|
transaction?: Transaction[];
|
|
26
27
|
width?: number | string;
|
|
27
28
|
zeroState?: React.JSX.Element;
|
|
@@ -2,63 +2,64 @@ import { useEvent as oe, useGlobalCopyStore as ne, useTransactionStore as re } f
|
|
|
2
2
|
import { fromUnixUTCToDayOfWeekAndDate as se } from "../../../core/utils/DateUtil.es.js";
|
|
3
3
|
import { VISUALLY_HIDDEN_SX as ie } from "../../../common/constants/Styles.es.js";
|
|
4
4
|
import { ANALYTICS_EVENTS as ae } from "../../../common/constants/Analytics.es.js";
|
|
5
|
-
import ce from "../../../
|
|
6
|
-
import le from "../../../common/components/
|
|
5
|
+
import { sortPendingFirst as ce } from "../../../core/utils/TransactionUtils.es.js";
|
|
6
|
+
import le from "../../../common/components/Loader.es.js";
|
|
7
|
+
import de from "../../../common/components/ZeroState.es.js";
|
|
7
8
|
import { useTransactionsUiStore as ue } from "../../context/hooks.es.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { hasInsetBorder as
|
|
9
|
+
import fe from "./transactionlist/TransactionRow.es.js";
|
|
10
|
+
import me from "../../../common/components/SubheaderRow.es.js";
|
|
11
|
+
import { hasInsetBorder as pe, shouldShowSubheader as y } from "../../utils/Transactions.es.js";
|
|
11
12
|
import o from "react";
|
|
12
|
-
import { observer as
|
|
13
|
-
import { Fragment as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
13
|
+
import { observer as ge } from "mobx-react-lite";
|
|
14
|
+
import { Fragment as he, jsx as s, jsxs as b } from "react/jsx-runtime";
|
|
15
|
+
import d from "@mui/material/Box";
|
|
16
|
+
import Se from "@mui/material/Divider";
|
|
16
17
|
import xe from "@mui/material/List";
|
|
17
|
-
import { useVirtualizer as
|
|
18
|
-
var
|
|
18
|
+
import { useVirtualizer as ve } from "@tanstack/react-virtual";
|
|
19
|
+
var B = 65, D = 32, Te = (g) => {
|
|
19
20
|
for (let r = g?.parentElement; r; r = r.parentElement) if (/(auto|scroll)/.test(getComputedStyle(r).overflowY)) return r;
|
|
20
21
|
return null;
|
|
21
|
-
},
|
|
22
|
+
}, be = ({ bgcolor: g, filter: r, height: N = "calc(100dvh - 36px)", isRowDisabled: O, loader: U = /* @__PURE__ */ s(le, {
|
|
22
23
|
label: "Loading",
|
|
23
24
|
size: 40
|
|
24
|
-
}), onClick: E, renderAmountCaption: k, renderSecondaryText:
|
|
25
|
-
const { isLoading:
|
|
26
|
-
const e = r ?
|
|
27
|
-
return _ ?? e;
|
|
25
|
+
}), onClick: E, renderAmountCaption: k, renderSecondaryText: F, scrollsWithParent: a = !1, showInsights: I = !1, showLoader: V = !1, showUnviewedIndicator: $ = !1, stickyHeader: h, transaction: _, width: S = "100%", zeroState: M = /* @__PURE__ */ s(de, {}) }) => {
|
|
26
|
+
const { isLoading: Y, sortedTransactions: x } = re(), n = o.useMemo(() => {
|
|
27
|
+
const e = r ? x.filter(r) : x;
|
|
28
|
+
return ce(_ ?? e);
|
|
28
29
|
}, [
|
|
29
|
-
|
|
30
|
+
x,
|
|
30
31
|
r,
|
|
31
32
|
_
|
|
32
|
-
]), { clearExpandedSplits:
|
|
33
|
+
]), { clearExpandedSplits: G, setShowInsights: j, toggleSplit: P } = ue(), { onEvent: q } = oe(), { common: R } = ne(), [u, C] = o.useState(null), K = (e) => {
|
|
33
34
|
const t = n.find((i) => i.guid === e);
|
|
34
35
|
if (t?.has_been_split) {
|
|
35
|
-
|
|
36
|
+
P(t.guid);
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
39
|
q(ae.ACCOUNT_DETAILS_CLICK_TRANSACTION, {
|
|
39
40
|
account_guid: t?.account_guid,
|
|
40
41
|
transaction_guid: e
|
|
41
42
|
}), E?.(e);
|
|
42
|
-
}, f = o.useRef(null),
|
|
43
|
+
}, f = o.useRef(null), X = !!h, [L, Z] = o.useState(null), [w, J] = o.useState(0), m = o.useRef(null), [H, Q] = o.useState(0);
|
|
43
44
|
o.useLayoutEffect(() => {
|
|
44
45
|
if (!a) return;
|
|
45
46
|
const e = f.current;
|
|
46
47
|
if (!e) return;
|
|
47
|
-
const t =
|
|
48
|
-
|
|
48
|
+
const t = Te(e) ?? e, i = () => {
|
|
49
|
+
J(e.getBoundingClientRect().top - t.getBoundingClientRect().top + t.scrollTop), Q(m.current?.offsetHeight ?? 0);
|
|
49
50
|
};
|
|
50
|
-
|
|
51
|
+
Z(t), i();
|
|
51
52
|
const l = new ResizeObserver(i);
|
|
52
53
|
return l.observe(t.firstElementChild ?? t), m.current && l.observe(m.current), () => l.disconnect();
|
|
53
|
-
}, [a,
|
|
54
|
-
const p =
|
|
54
|
+
}, [a, X]);
|
|
55
|
+
const p = ve({
|
|
55
56
|
count: n.length,
|
|
56
|
-
getScrollElement: () => a ?
|
|
57
|
-
estimateSize: (e) =>
|
|
57
|
+
getScrollElement: () => a ? L : f.current,
|
|
58
|
+
estimateSize: (e) => B + (y(e, n) ? D : 0),
|
|
58
59
|
overscan: 5,
|
|
59
|
-
scrollMargin:
|
|
60
|
-
scrollPaddingStart:
|
|
61
|
-
}), v = p.getVirtualItems(), c = v.at(-1)?.index ?? -1,
|
|
60
|
+
scrollMargin: w,
|
|
61
|
+
scrollPaddingStart: H
|
|
62
|
+
}), v = p.getVirtualItems(), c = v.at(-1)?.index ?? -1, A = n.length - (c + 1), T = !Y && !V, z = T && v.length > 0, W = p.getTotalSize() || "auto", ee = () => {
|
|
62
63
|
const e = c + 1;
|
|
63
64
|
p.scrollToIndex(e, { align: "start" }), C({
|
|
64
65
|
index: e,
|
|
@@ -66,17 +67,17 @@ var z = 65, y = 32, ve = (g) => {
|
|
|
66
67
|
});
|
|
67
68
|
};
|
|
68
69
|
return o.useEffect(() => {
|
|
69
|
-
if (!
|
|
70
|
-
const e = f.current?.querySelector(`[data-index="${
|
|
71
|
-
e?.focus(), (e || c !==
|
|
72
|
-
}, [
|
|
73
|
-
h && /* @__PURE__ */ s(
|
|
70
|
+
if (!u) return;
|
|
71
|
+
const e = f.current?.querySelector(`[data-index="${u.index}"]`);
|
|
72
|
+
e?.focus(), (e || c !== u.from) && C(null);
|
|
73
|
+
}, [u, c]), o.useEffect(() => p.measure(), [n, L]), o.useEffect(() => j(I), [I]), o.useEffect(() => () => G(), []), /* @__PURE__ */ b(he, { children: [
|
|
74
|
+
h && /* @__PURE__ */ s(d, {
|
|
74
75
|
ref: m,
|
|
75
76
|
sx: {
|
|
76
77
|
bgcolor: "background.paper",
|
|
77
78
|
position: a ? "sticky" : void 0,
|
|
78
79
|
top: 0,
|
|
79
|
-
width:
|
|
80
|
+
width: S,
|
|
80
81
|
zIndex: 1
|
|
81
82
|
},
|
|
82
83
|
children: h
|
|
@@ -84,24 +85,24 @@ var z = 65, y = 32, ve = (g) => {
|
|
|
84
85
|
/* @__PURE__ */ s(xe, {
|
|
85
86
|
component: "div",
|
|
86
87
|
role: "list",
|
|
87
|
-
sx: { width:
|
|
88
|
-
children: /* @__PURE__ */ s(
|
|
88
|
+
sx: { width: S },
|
|
89
|
+
children: /* @__PURE__ */ s(d, {
|
|
89
90
|
height: a ? void 0 : N,
|
|
90
91
|
overflow: a ? void 0 : "auto",
|
|
91
92
|
ref: f,
|
|
92
93
|
role: "presentation",
|
|
93
|
-
width:
|
|
94
|
-
children: /* @__PURE__ */ b(
|
|
94
|
+
width: S,
|
|
95
|
+
children: /* @__PURE__ */ b(d, {
|
|
95
96
|
height: W,
|
|
96
97
|
position: "relative",
|
|
97
98
|
role: "presentation",
|
|
98
99
|
width: "100%",
|
|
99
100
|
children: [
|
|
100
|
-
!T &&
|
|
101
|
-
T && n.length === 0 &&
|
|
102
|
-
|
|
103
|
-
const t = n[e.index], i =
|
|
104
|
-
return /* @__PURE__ */ b(
|
|
101
|
+
!T && U,
|
|
102
|
+
T && n.length === 0 && M,
|
|
103
|
+
z && v.map((e) => {
|
|
104
|
+
const t = n[e.index], i = y(e.index, n), l = pe(e.index, n), te = B + (i ? D : 0);
|
|
105
|
+
return /* @__PURE__ */ b(d, {
|
|
105
106
|
"aria-posinset": e.index + 1,
|
|
106
107
|
"aria-setsize": n.length,
|
|
107
108
|
"data-index": e.index,
|
|
@@ -110,26 +111,26 @@ var z = 65, y = 32, ve = (g) => {
|
|
|
110
111
|
sx: {
|
|
111
112
|
height: te,
|
|
112
113
|
position: "absolute",
|
|
113
|
-
scrollMarginTop:
|
|
114
|
-
transform: `translateY(${e.start -
|
|
114
|
+
scrollMarginTop: H,
|
|
115
|
+
transform: `translateY(${e.start - w}px)`,
|
|
115
116
|
width: "100%",
|
|
116
117
|
bgcolor: "background.paper"
|
|
117
118
|
},
|
|
118
119
|
children: [
|
|
119
|
-
i && /* @__PURE__ */ s(
|
|
120
|
+
i && /* @__PURE__ */ s(me, {
|
|
120
121
|
bgcolor: g,
|
|
121
|
-
children: se(t.date)
|
|
122
|
+
children: t.isPending ? R.pending : se(t.date)
|
|
122
123
|
}),
|
|
123
|
-
/* @__PURE__ */ s(
|
|
124
|
+
/* @__PURE__ */ s(fe, {
|
|
124
125
|
component: "div",
|
|
125
126
|
disabled: O?.(t),
|
|
126
|
-
...E && { onClick:
|
|
127
|
+
...E && { onClick: K },
|
|
127
128
|
renderAmountCaption: k,
|
|
128
|
-
renderSecondaryText:
|
|
129
|
+
renderSecondaryText: F,
|
|
129
130
|
showUnviewedIndicator: $,
|
|
130
131
|
transaction: t
|
|
131
132
|
}),
|
|
132
|
-
/* @__PURE__ */ s(
|
|
133
|
+
/* @__PURE__ */ s(Se, { sx: { ml: l ? 68 : 0 } })
|
|
133
134
|
]
|
|
134
135
|
}, t.guid);
|
|
135
136
|
})
|
|
@@ -137,18 +138,18 @@ var z = 65, y = 32, ve = (g) => {
|
|
|
137
138
|
})
|
|
138
139
|
})
|
|
139
140
|
}),
|
|
140
|
-
|
|
141
|
+
z && A > 0 && /* @__PURE__ */ s(d, {
|
|
141
142
|
component: "button",
|
|
142
143
|
onClick: ee,
|
|
143
144
|
sx: ie,
|
|
144
145
|
tabIndex: -1,
|
|
145
146
|
type: "button",
|
|
146
|
-
children: `${
|
|
147
|
+
children: `${R.view_more} (${A})`
|
|
147
148
|
})
|
|
148
149
|
] });
|
|
149
|
-
},
|
|
150
|
+
}, Ve = ge(be);
|
|
150
151
|
export {
|
|
151
|
-
|
|
152
|
+
Ve as default
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
//# sourceMappingURL=TransactionList.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionList.es.js","names":[],"sources":["../../../../src/transactions/components/shared/TransactionList.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { useVirtualizer } from '@tanstack/react-virtual'\n\nimport Box from '@mui/material/Box'\nimport Divider from '@mui/material/Divider'\nimport List from '@mui/material/List'\n\nimport {\n ANALYTICS_EVENTS,\n Loader,\n useEvent,\n useGlobalCopyStore,\n VISUALLY_HIDDEN_SX,\n ZeroState,\n} from '../../../common'\nimport { type Transaction } from '../../../core'\n\nimport { useTransactionsUiStore } from '../../context/hooks'\nimport { useTransactionStore } from '../../../common'\n\nimport SubheaderRow from '../../../common/components/SubheaderRow'\nimport TransactionRow from './transactionlist/TransactionRow'\n\nimport { hasInsetBorder, shouldShowDate } from '../../utils/Transactions'\nimport { fromUnixUTCToDayOfWeekAndDate } from '../../../core/utils/DateUtil'\n\nconst ROW_HEIGHT = 65\nconst DATE_ROW_HEIGHT = 32\n\nconst findScrollParent = (node: HTMLElement | null): HTMLElement | null => {\n for (let el = node?.parentElement; el; el = el.parentElement) {\n if (/(auto|scroll)/.test(getComputedStyle(el).overflowY)) return el\n }\n return null\n}\n\nexport interface TransactionListProps {\n bgcolor?: string\n filter?: (t: Transaction) => boolean\n height?: number | string\n /**\n * Marks rows that stay in the list but cannot be acted on. Disabled rows are rendered greyed\n * out and inert instead of being removed, so list membership and ordering are unaffected.\n */\n isRowDisabled?: (t: Transaction) => boolean\n loader?: React.JSX.Element\n onClick?: (guid: string) => void\n /** An opt-in trailing caption on each row's subline (see TransactionRow). */\n renderAmountCaption?: (transaction: Transaction) => React.ReactNode\n /** Replaces each row's category subline (see TransactionRow); omitted, rows show the category. */\n renderSecondaryText?: (transaction: Transaction) => React.ReactNode\n /** Virtualize against the nearest scrolling ancestor instead of an own fixed-height scroll box. */\n scrollsWithParent?: boolean\n /** Rendered above the rows; stays at the top of the scroll area when used with scrollsWithParent. */\n stickyHeader?: React.ReactNode\n showInsights?: boolean\n showLoader?: boolean\n showUnviewedIndicator?: boolean\n transaction?: Transaction[]\n width?: number | string\n zeroState?: React.JSX.Element\n}\n\nconst TransactionList: React.FC<TransactionListProps> = ({\n bgcolor,\n filter,\n height = 'calc(100dvh - 36px)',\n isRowDisabled,\n loader = <Loader label=\"Loading\" size={40} />,\n onClick,\n renderAmountCaption,\n renderSecondaryText,\n scrollsWithParent = false,\n showInsights = false,\n showLoader = false,\n showUnviewedIndicator = false,\n stickyHeader,\n transaction,\n width = '100%',\n zeroState = <ZeroState />,\n}) => {\n const { isLoading, sortedTransactions: allTransactions } = useTransactionStore()\n const transactions = React.useMemo(() => {\n const updatedTransactions = filter ? allTransactions.filter(filter) : allTransactions\n return transaction ?? updatedTransactions\n }, [allTransactions, filter, transaction])\n\n const { clearExpandedSplits, setShowInsights, toggleSplit } = useTransactionsUiStore()\n const { onEvent } = useEvent()\n const { common: commonCopy } = useGlobalCopyStore()\n const [pendingFocus, setPendingFocus] = React.useState<{ index: number; from: number } | null>(\n null,\n )\n\n const handleClick = (guid: string) => {\n const transaction = transactions.find((t) => t.guid === guid)\n\n if (transaction?.has_been_split) {\n toggleSplit(transaction.guid)\n return\n }\n\n onEvent(ANALYTICS_EVENTS.ACCOUNT_DETAILS_CLICK_TRANSACTION, {\n account_guid: transaction?.account_guid,\n transaction_guid: guid,\n })\n onClick?.(guid)\n }\n\n const parentRef = React.useRef<HTMLDivElement>(null)\n const hasStickyHeader = Boolean(stickyHeader)\n const [scrollParent, setScrollParent] = React.useState<HTMLElement | null>(null)\n const [scrollMargin, setScrollMargin] = React.useState(0)\n const headerRef = React.useRef<HTMLDivElement>(null)\n const [headerHeight, setHeaderHeight] = React.useState(0)\n\n React.useLayoutEffect(() => {\n if (!scrollsWithParent) return\n const list = parentRef.current\n if (!list) return\n // With no scrolling ancestor the list itself is the viewport, so every row renders.\n const scroller = findScrollParent(list) ?? list\n\n const measureOffset = () => {\n setScrollMargin(\n list.getBoundingClientRect().top -\n scroller.getBoundingClientRect().top +\n scroller.scrollTop,\n )\n setHeaderHeight(headerRef.current?.offsetHeight ?? 0)\n }\n\n setScrollParent(scroller)\n measureOffset()\n const observer = new ResizeObserver(measureOffset)\n observer.observe(scroller.firstElementChild ?? scroller)\n if (headerRef.current) observer.observe(headerRef.current)\n return () => observer.disconnect()\n }, [scrollsWithParent, hasStickyHeader])\n\n const rowVirtualizer = useVirtualizer({\n count: transactions.length,\n getScrollElement: () => (scrollsWithParent ? scrollParent : parentRef.current),\n estimateSize: (i) => ROW_HEIGHT + (shouldShowDate(i, transactions) ? DATE_ROW_HEIGHT : 0),\n overscan: 5,\n scrollMargin,\n scrollPaddingStart: headerHeight,\n })\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n const lastRenderedIndex = virtualItems.at(-1)?.index ?? -1\n const unrenderedCount = transactions.length - (lastRenderedIndex + 1)\n const isSettled = !isLoading && !showLoader\n const showRows = isSettled && virtualItems.length > 0\n // The total size comes from the row count, so a content-sized list has height before any row\n // is drawn. It is 0 only with no transactions, where the zero state needs 'auto'.\n const rowBoxHeight = rowVirtualizer.getTotalSize() || 'auto'\n\n // Screen reader reading modes do not scroll the list, so rows past the rendered window\n // are unreachable without this control.\n const showNextRows = () => {\n const nextIndex = lastRenderedIndex + 1\n rowVirtualizer.scrollToIndex(nextIndex, { align: 'start' })\n setPendingFocus({ index: nextIndex, from: lastRenderedIndex })\n }\n\n React.useEffect(() => {\n if (!pendingFocus) return\n const row = parentRef.current?.querySelector<HTMLElement>(\n `[data-index=\"${pendingFocus.index}\"]`,\n )\n row?.focus()\n // Give up once the window moves, so a missed row cannot take focus later.\n if (row || lastRenderedIndex !== pendingFocus.from) setPendingFocus(null)\n }, [pendingFocus, lastRenderedIndex])\n\n React.useEffect(() => rowVirtualizer.measure(), [transactions, scrollParent])\n React.useEffect(() => setShowInsights(showInsights), [showInsights])\n\n React.useEffect(() => {\n return () => clearExpandedSplits()\n }, [])\n\n return (\n <>\n {stickyHeader && (\n <Box\n ref={headerRef}\n sx={{\n bgcolor: 'background.paper',\n position: scrollsWithParent ? 'sticky' : undefined,\n top: 0,\n width,\n zIndex: 1,\n }}\n >\n {stickyHeader}\n </Box>\n )}\n <List component=\"div\" role=\"list\" sx={{ width: width }}>\n <Box\n height={scrollsWithParent ? undefined : height}\n overflow={scrollsWithParent ? undefined : 'auto'}\n ref={parentRef}\n role=\"presentation\"\n width={width}\n >\n <Box height={rowBoxHeight} position=\"relative\" role=\"presentation\" width=\"100%\">\n {!isSettled && loader}\n {isSettled && transactions.length === 0 && zeroState}\n {showRows &&\n virtualItems.map((row) => {\n const transaction = transactions[row.index]\n const showDate = shouldShowDate(row.index, transactions)\n const isInset = hasInsetBorder(row.index, transactions)\n const rowHeight = ROW_HEIGHT + (showDate ? DATE_ROW_HEIGHT : 0)\n\n return (\n <Box\n aria-posinset={row.index + 1}\n aria-setsize={transactions.length}\n data-index={row.index}\n key={transaction.guid}\n role=\"listitem\"\n tabIndex={-1}\n sx={{\n height: rowHeight,\n position: 'absolute',\n // Keeps a focused row from scrolling under the sticky header.\n scrollMarginTop: headerHeight,\n transform: `translateY(${row.start - scrollMargin}px)`,\n width: '100%',\n bgcolor: 'background.paper',\n }}\n >\n {showDate && (\n <SubheaderRow bgcolor={bgcolor}>\n {fromUnixUTCToDayOfWeekAndDate(transaction.date)}\n </SubheaderRow>\n )}\n <TransactionRow\n component=\"div\"\n disabled={isRowDisabled?.(transaction)}\n {...(onClick && { onClick: handleClick })}\n renderAmountCaption={renderAmountCaption}\n renderSecondaryText={renderSecondaryText}\n showUnviewedIndicator={showUnviewedIndicator}\n transaction={transaction}\n />\n <Divider sx={{ ml: isInset ? 68 : 0 }} />\n </Box>\n )\n })}\n </Box>\n </Box>\n </List>\n {showRows && unrenderedCount > 0 && (\n <Box\n component=\"button\"\n onClick={showNextRows}\n sx={VISUALLY_HIDDEN_SX}\n tabIndex={-1}\n type=\"button\"\n >\n {`${commonCopy.view_more} (${unrenderedCount})`}\n </Box>\n )}\n </>\n )\n}\n\nexport default observer(TransactionList)\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,IAAM,IAAa,IACb,IAAkB,IAElB,KAAA,CAAoB,MAAiD;AACzE,WAAS,IAAK,GAAM,eAAe,GAAI,IAAK,EAAG,cAC7C,KAAI,gBAAgB,KAAK,iBAAiB,CAAE,EAAE,SAAS,EAAG,QAAO;AAEnE,SAAO;AACT,GA6BM,KAAA,CAAmD,EACvD,SAAA,GACA,QAAA,GACA,QAAA,IAAS,uBACT,eAAA,GACA,QAAA,IAAS,gBAAA,EAAC,IAAD;AAAA,EAAQ,OAAM;AAAA,EAAU,MAAM;AAAK,CAAA,GAC5C,SAAA,GACA,qBAAA,GACA,qBAAA,GACA,mBAAA,IAAoB,IACpB,cAAA,IAAe,IACf,YAAA,IAAa,IACb,uBAAA,IAAwB,IACxB,cAAA,GACA,aAAA,GACA,OAAA,IAAQ,QACR,WAAA,IAAY,gBAAA,EAAC,IAAD,CAAY,CAAA,EAAA,MACpB;AACJ,QAAM,EAAE,WAAA,GAAW,oBAAoB,EAAA,IAAoB,GAAoB,GACzE,IAAe,EAAM,QAAA,MAAc;AACvC,UAAM,IAAsB,IAAS,EAAgB,OAAO,CAAM,IAAI;AACtE,WAAO,KAAe;AAAA,EACxB,GAAG;AAAA,IAAC;AAAA,IAAiB;AAAA,IAAQ;AAAA,EAAW,CAAC,GAEnC,EAAE,qBAAA,GAAqB,iBAAA,GAAiB,aAAA,EAAA,IAAgB,GAAuB,GAC/E,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B,qBAAA;AAAA,oBACA,qBAAA;AAAA,oBACE,uBAAA;AAAA,oBACV,aAAA;AAAA,kBACd,CAAA;AAAA,kBACD,gBAAA,EAAC,IAAD,EAAS,IAAI,EAAE,IAAI,IAAU,KAAK,EAAE,EAAI,CAAA;AAAA,gBACrC;AAAA,cA5BE,GAAA,EAAY,IA4Bd;AAAA,YAET,CAAC;AAAA,UACA;AAAA;MACF,CAAA;AAAA,IACD,CAAA;AAAA,IACL,KAAY,IAAkB,KAC7B,gBAAA,EAAC,GAAD;AAAA,MACE,WAAU;AAAA,MACV,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,UAAU;AAAA,MACV,MAAK;AAAA,MAEJ,UAAA,GAAG,EAAW,SAAA,KAAc,CAAA;AAAA,IAC1B,CAAA;AAAA,EAEP,EAAA,CAAA;AAEN,GAEA,KAAe,GAAS,EAAe"}
|
|
1
|
+
{"version":3,"file":"TransactionList.es.js","names":[],"sources":["../../../../src/transactions/components/shared/TransactionList.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { useVirtualizer } from '@tanstack/react-virtual'\n\nimport Box from '@mui/material/Box'\nimport Divider from '@mui/material/Divider'\nimport List from '@mui/material/List'\n\nimport {\n ANALYTICS_EVENTS,\n Loader,\n useEvent,\n useGlobalCopyStore,\n VISUALLY_HIDDEN_SX,\n ZeroState,\n} from '../../../common'\nimport { type Transaction } from '../../../core'\n\nimport { useTransactionsUiStore } from '../../context/hooks'\nimport { useTransactionStore } from '../../../common'\n\nimport SubheaderRow from '../../../common/components/SubheaderRow'\nimport TransactionRow from './transactionlist/TransactionRow'\n\nimport { hasInsetBorder, shouldShowSubheader } from '../../utils/Transactions'\nimport { fromUnixUTCToDayOfWeekAndDate } from '../../../core/utils/DateUtil'\nimport { sortPendingFirst } from '../../../core/utils/TransactionUtils'\n\nconst ROW_HEIGHT = 65\nconst SUBHEADER_ROW_HEIGHT = 32\n\nconst findScrollParent = (node: HTMLElement | null): HTMLElement | null => {\n for (let el = node?.parentElement; el; el = el.parentElement) {\n if (/(auto|scroll)/.test(getComputedStyle(el).overflowY)) return el\n }\n return null\n}\n\nexport interface TransactionListProps {\n bgcolor?: string\n filter?: (t: Transaction) => boolean\n height?: number | string\n /**\n * Marks rows that stay in the list but cannot be acted on. Disabled rows are rendered greyed\n * out and inert instead of being removed, so list membership and ordering are unaffected.\n */\n isRowDisabled?: (t: Transaction) => boolean\n loader?: React.JSX.Element\n onClick?: (guid: string) => void\n /** An opt-in trailing caption on each row's subline (see TransactionRow). */\n renderAmountCaption?: (transaction: Transaction) => React.ReactNode\n /** Replaces each row's category subline (see TransactionRow); omitted, rows show the category. */\n renderSecondaryText?: (transaction: Transaction) => React.ReactNode\n /** Virtualize against the nearest scrolling ancestor instead of an own fixed-height scroll box. */\n scrollsWithParent?: boolean\n /** Rendered above the rows; stays at the top of the scroll area when used with scrollsWithParent. */\n stickyHeader?: React.ReactNode\n showInsights?: boolean\n showLoader?: boolean\n showUnviewedIndicator?: boolean\n /** Replaces the store transactions. Pending transactions still go first. */\n transaction?: Transaction[]\n width?: number | string\n zeroState?: React.JSX.Element\n}\n\nconst TransactionList: React.FC<TransactionListProps> = ({\n bgcolor,\n filter,\n height = 'calc(100dvh - 36px)',\n isRowDisabled,\n loader = <Loader label=\"Loading\" size={40} />,\n onClick,\n renderAmountCaption,\n renderSecondaryText,\n scrollsWithParent = false,\n showInsights = false,\n showLoader = false,\n showUnviewedIndicator = false,\n stickyHeader,\n transaction,\n width = '100%',\n zeroState = <ZeroState />,\n}) => {\n const { isLoading, sortedTransactions: allTransactions } = useTransactionStore()\n const transactions = React.useMemo(() => {\n const updatedTransactions = filter ? allTransactions.filter(filter) : allTransactions\n return sortPendingFirst(transaction ?? updatedTransactions)\n }, [allTransactions, filter, transaction])\n\n const { clearExpandedSplits, setShowInsights, toggleSplit } = useTransactionsUiStore()\n const { onEvent } = useEvent()\n const { common: commonCopy } = useGlobalCopyStore()\n const [pendingFocus, setPendingFocus] = React.useState<{ index: number; from: number } | null>(\n null,\n )\n\n const handleClick = (guid: string) => {\n const transaction = transactions.find((t) => t.guid === guid)\n\n if (transaction?.has_been_split) {\n toggleSplit(transaction.guid)\n return\n }\n\n onEvent(ANALYTICS_EVENTS.ACCOUNT_DETAILS_CLICK_TRANSACTION, {\n account_guid: transaction?.account_guid,\n transaction_guid: guid,\n })\n onClick?.(guid)\n }\n\n const parentRef = React.useRef<HTMLDivElement>(null)\n const hasStickyHeader = Boolean(stickyHeader)\n const [scrollParent, setScrollParent] = React.useState<HTMLElement | null>(null)\n const [scrollMargin, setScrollMargin] = React.useState(0)\n const headerRef = React.useRef<HTMLDivElement>(null)\n const [headerHeight, setHeaderHeight] = React.useState(0)\n\n React.useLayoutEffect(() => {\n if (!scrollsWithParent) return\n const list = parentRef.current\n if (!list) return\n // With no scrolling ancestor the list itself is the viewport, so every row renders.\n const scroller = findScrollParent(list) ?? list\n\n const measureOffset = () => {\n setScrollMargin(\n list.getBoundingClientRect().top -\n scroller.getBoundingClientRect().top +\n scroller.scrollTop,\n )\n setHeaderHeight(headerRef.current?.offsetHeight ?? 0)\n }\n\n setScrollParent(scroller)\n measureOffset()\n const observer = new ResizeObserver(measureOffset)\n observer.observe(scroller.firstElementChild ?? scroller)\n if (headerRef.current) observer.observe(headerRef.current)\n return () => observer.disconnect()\n }, [scrollsWithParent, hasStickyHeader])\n\n const rowVirtualizer = useVirtualizer({\n count: transactions.length,\n getScrollElement: () => (scrollsWithParent ? scrollParent : parentRef.current),\n estimateSize: (i) =>\n ROW_HEIGHT + (shouldShowSubheader(i, transactions) ? SUBHEADER_ROW_HEIGHT : 0),\n overscan: 5,\n scrollMargin,\n scrollPaddingStart: headerHeight,\n })\n\n const virtualItems = rowVirtualizer.getVirtualItems()\n const lastRenderedIndex = virtualItems.at(-1)?.index ?? -1\n const unrenderedCount = transactions.length - (lastRenderedIndex + 1)\n const isSettled = !isLoading && !showLoader\n const showRows = isSettled && virtualItems.length > 0\n // The total size comes from the row count, so a content-sized list has height before any row\n // is drawn. It is 0 only with no transactions, where the zero state needs 'auto'.\n const rowBoxHeight = rowVirtualizer.getTotalSize() || 'auto'\n\n // Screen reader reading modes do not scroll the list, so rows past the rendered window\n // are unreachable without this control.\n const showNextRows = () => {\n const nextIndex = lastRenderedIndex + 1\n rowVirtualizer.scrollToIndex(nextIndex, { align: 'start' })\n setPendingFocus({ index: nextIndex, from: lastRenderedIndex })\n }\n\n React.useEffect(() => {\n if (!pendingFocus) return\n const row = parentRef.current?.querySelector<HTMLElement>(\n `[data-index=\"${pendingFocus.index}\"]`,\n )\n row?.focus()\n // Give up once the window moves, so a missed row cannot take focus later.\n if (row || lastRenderedIndex !== pendingFocus.from) setPendingFocus(null)\n }, [pendingFocus, lastRenderedIndex])\n\n React.useEffect(() => rowVirtualizer.measure(), [transactions, scrollParent])\n React.useEffect(() => setShowInsights(showInsights), [showInsights])\n\n React.useEffect(() => {\n return () => clearExpandedSplits()\n }, [])\n\n return (\n <>\n {stickyHeader && (\n <Box\n ref={headerRef}\n sx={{\n bgcolor: 'background.paper',\n position: scrollsWithParent ? 'sticky' : undefined,\n top: 0,\n width,\n zIndex: 1,\n }}\n >\n {stickyHeader}\n </Box>\n )}\n <List component=\"div\" role=\"list\" sx={{ width: width }}>\n <Box\n height={scrollsWithParent ? undefined : height}\n overflow={scrollsWithParent ? undefined : 'auto'}\n ref={parentRef}\n role=\"presentation\"\n width={width}\n >\n <Box height={rowBoxHeight} position=\"relative\" role=\"presentation\" width=\"100%\">\n {!isSettled && loader}\n {isSettled && transactions.length === 0 && zeroState}\n {showRows &&\n virtualItems.map((row) => {\n const transaction = transactions[row.index]\n const showSubheader = shouldShowSubheader(row.index, transactions)\n const isInset = hasInsetBorder(row.index, transactions)\n const rowHeight = ROW_HEIGHT + (showSubheader ? SUBHEADER_ROW_HEIGHT : 0)\n\n return (\n <Box\n aria-posinset={row.index + 1}\n aria-setsize={transactions.length}\n data-index={row.index}\n key={transaction.guid}\n role=\"listitem\"\n tabIndex={-1}\n sx={{\n height: rowHeight,\n position: 'absolute',\n // Keeps a focused row from scrolling under the sticky header.\n scrollMarginTop: headerHeight,\n transform: `translateY(${row.start - scrollMargin}px)`,\n width: '100%',\n bgcolor: 'background.paper',\n }}\n >\n {showSubheader && (\n <SubheaderRow bgcolor={bgcolor}>\n {transaction.isPending\n ? commonCopy.pending\n : fromUnixUTCToDayOfWeekAndDate(transaction.date)}\n </SubheaderRow>\n )}\n <TransactionRow\n component=\"div\"\n disabled={isRowDisabled?.(transaction)}\n {...(onClick && { onClick: handleClick })}\n renderAmountCaption={renderAmountCaption}\n renderSecondaryText={renderSecondaryText}\n showUnviewedIndicator={showUnviewedIndicator}\n transaction={transaction}\n />\n <Divider sx={{ ml: isInset ? 68 : 0 }} />\n </Box>\n )\n })}\n </Box>\n </Box>\n </List>\n {showRows && unrenderedCount > 0 && (\n <Box\n component=\"button\"\n onClick={showNextRows}\n sx={VISUALLY_HIDDEN_SX}\n tabIndex={-1}\n type=\"button\"\n >\n {`${commonCopy.view_more} (${unrenderedCount})`}\n </Box>\n )}\n </>\n )\n}\n\nexport default observer(TransactionList)\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,IAAM,IAAa,IACb,IAAuB,IAEvB,KAAA,CAAoB,MAAiD;AACzE,WAAS,IAAK,GAAM,eAAe,GAAI,IAAK,EAAG,cAC7C,KAAI,gBAAgB,KAAK,iBAAiB,CAAE,EAAE,SAAS,EAAG,QAAO;AAEnE,SAAO;AACT,GA8BM,KAAA,CAAmD,EACvD,SAAA,GACA,QAAA,GACA,QAAA,IAAS,uBACT,eAAA,GACA,QAAA,IAAS,gBAAA,EAAC,IAAD;AAAA,EAAQ,OAAM;AAAA,EAAU,MAAM;AAAK,CAAA,GAC5C,SAAA,GACA,qBAAA,GACA,qBAAA,GACA,mBAAA,IAAoB,IACpB,cAAA,IAAe,IACf,YAAA,IAAa,IACb,uBAAA,IAAwB,IACxB,cAAA,GACA,aAAA,GACA,OAAA,IA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UAAU;AAAA,kBAEV,iBAAiB;AAAA,kBACjB,WAAW,cAAc,EAAI,QAAQ,CAAA;AAAA,kBACrC,OAAO;AAAA,kBACP,SAAS;AAAA,gBACX;AAAA,gBAfF,UAAA;AAAA,kBAiBG,KACC,gBAAA,EAAC,IAAD;AAAA,oBAAuB,SAAA;AAAA,oBACpB,UAAA,EAAY,YACT,EAAW,UACX,GAA8B,EAAY,IAAI;AAAA,kBACtC,CAAA;AAAA,kBAEhB,gBAAA,EAAC,IAAD;AAAA,oBACE,WAAU;AAAA,oBACV,UAAU,IAAgB,CAAW;AAAA,oBACrC,GAAK,KAAW,EAAE,SAAS,EAAY;AAAA,oBAClB,qBAAA;AAAA,oBACA,qBAAA;AAAA,oBACE,uBAAA;AAAA,oBACV,aAAA;AAAA,kBACd,CAAA;AAAA,kBACD,gBAAA,EAAC,IAAD,EAAS,IAAI,EAAE,IAAI,IAAU,KAAK,EAAE,EAAI,CAAA;AAAA,gBACrC;AAAA,cA9BE,GAAA,EAAY,IA8Bd;AAAA,YAET,CAAC;AAAA,UACA;AAAA;MACF,CAAA;AAAA,IACD,CAAA;AAAA,IACL,KAAY,IAAkB,KAC7B,gBAAA,EAAC,GAAD;AAAA,MACE,WAAU;AAAA,MACV,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,UAAU;AAAA,MACV,MAAK;AAAA,MAEJ,UAAA,GAAG,EAAW,SAAA,KAAc,CAAA;AAAA,IAC1B,CAAA;AAAA,EAEP,EAAA,CAAA;AAEN,GAEA,KAAe,GAAS,EAAe"}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { useEvent as
|
|
2
|
-
import { ANALYTICS_EVENTS as
|
|
3
|
-
import
|
|
4
|
-
import { useTransactionsUiStore as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
1
|
+
import { useEvent as y, useGlobalCopyStore as N, useGlobalUiStore as T, useTransactionStore as v } from "../../../common/context/hooks.es.js";
|
|
2
|
+
import { ANALYTICS_EVENTS as A } from "../../../common/constants/Analytics.es.js";
|
|
3
|
+
import E from "../../../common/components/Loader.es.js";
|
|
4
|
+
import { useTransactionsUiStore as H } from "../../context/hooks.es.js";
|
|
5
|
+
import O from "./transactiontable/cells/AccountCell.es.js";
|
|
6
|
+
import L from "./transactiontable/cells/AmountCell.es.js";
|
|
7
|
+
import P from "./transactiontable/cells/CategoryCell.es.js";
|
|
8
|
+
import k from "./transactiontable/cells/DateCell.es.js";
|
|
9
|
+
import R from "./transactiontable/cells/FlagCell.es.js";
|
|
10
|
+
import n from "./transactiontable/cells/HeaderCell.es.js";
|
|
11
11
|
import D from "./transactiontable/cells/PayeeCell.es.js";
|
|
12
|
-
import
|
|
13
|
-
import { observer as
|
|
14
|
-
import
|
|
15
|
-
import { jsx as
|
|
16
|
-
import { DataGridPro as
|
|
17
|
-
var
|
|
18
|
-
const
|
|
19
|
-
d
|
|
20
|
-
|
|
12
|
+
import f from "react";
|
|
13
|
+
import { observer as F } from "mobx-react-lite";
|
|
14
|
+
import G from "@mui/material/Paper";
|
|
15
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
16
|
+
import { DataGridPro as I, gridStringOrNumberComparator as B } from "@mui/x-data-grid-pro";
|
|
17
|
+
var g = ({ api: a, id: l }) => !!a.getRow(l)?.isPending, i = (a) => {
|
|
18
|
+
const l = a === "desc" ? -1 : 1;
|
|
19
|
+
return (s, c, r, d) => Number(g(d)) - Number(g(r)) || l * B(s, c, r, d);
|
|
20
|
+
}, K = ({ height: a = "100dvh", onCategoryClick: l, onRowClick: s }) => {
|
|
21
|
+
const { onEvent: c } = y(), { transactions: r } = N(), { isCopyLoaded: d } = T(), { isLoading: C, sortedTransactions: m } = v(), { clearExpandedSplits: p, toggleSplit: h } = H();
|
|
22
|
+
f.useEffect(() => () => p(), []);
|
|
23
|
+
const _ = f.useMemo(() => m.map((e) => ({
|
|
21
24
|
id: e.guid,
|
|
22
25
|
isHovering: !1,
|
|
23
26
|
...e
|
|
24
|
-
})), [
|
|
25
|
-
t.key !== "Enter" && t.key !== " " ||
|
|
27
|
+
})), [m]), u = ({ row: { id: e, guid: t, has_been_split: S }, field: b }) => S ? h(e) : b === "category" ? (c(A.TRANSACTIONS_TABLE_CLICK_CATEGORY, { guid: t }), l?.(t)) : s?.(t), w = (e, t) => {
|
|
28
|
+
t.key !== "Enter" && t.key !== " " || u(e);
|
|
26
29
|
};
|
|
27
|
-
if (!
|
|
30
|
+
if (!d) return /* @__PURE__ */ o(E, {});
|
|
28
31
|
const x = [
|
|
29
32
|
{
|
|
30
33
|
field: "flag",
|
|
@@ -32,64 +35,69 @@ var F = ({ height: i = "100dvh", onCategoryClick: s, onRowClick: c }) => {
|
|
|
32
35
|
minWidth: 32,
|
|
33
36
|
width: 32,
|
|
34
37
|
sortable: !1,
|
|
35
|
-
renderCell: (e) => /* @__PURE__ */
|
|
36
|
-
renderHeader: () => /* @__PURE__ */
|
|
38
|
+
renderCell: (e) => /* @__PURE__ */ o(R, { ...e }),
|
|
39
|
+
renderHeader: () => /* @__PURE__ */ o("span", { "aria-label": r.transaction_status })
|
|
37
40
|
},
|
|
38
41
|
{
|
|
39
42
|
field: "date",
|
|
40
|
-
|
|
43
|
+
getSortComparator: i,
|
|
44
|
+
headerName: r.date_title,
|
|
41
45
|
width: 103,
|
|
42
|
-
renderHeader:
|
|
43
|
-
renderCell: (e) => e.row.parent_guid ? null : /* @__PURE__ */
|
|
46
|
+
renderHeader: n,
|
|
47
|
+
renderCell: (e) => e.row.parent_guid ? null : /* @__PURE__ */ o(k, { ...e }),
|
|
44
48
|
sortingOrder: ["desc", "asc"]
|
|
45
49
|
},
|
|
46
50
|
{
|
|
47
51
|
cellClassName: "vertical-align-center",
|
|
48
52
|
field: "payee",
|
|
49
|
-
|
|
53
|
+
getSortComparator: i,
|
|
54
|
+
headerName: r.payee_title,
|
|
50
55
|
flex: 0.33,
|
|
51
|
-
renderHeader:
|
|
52
|
-
renderCell: (e) => /* @__PURE__ */
|
|
56
|
+
renderHeader: n,
|
|
57
|
+
renderCell: (e) => /* @__PURE__ */ o(D, {
|
|
53
58
|
...e,
|
|
54
|
-
excludedText:
|
|
59
|
+
excludedText: r.is_excluded
|
|
55
60
|
}),
|
|
56
61
|
sortingOrder: ["asc", "desc"]
|
|
57
62
|
},
|
|
58
63
|
{
|
|
59
64
|
field: "category",
|
|
60
|
-
|
|
65
|
+
getSortComparator: i,
|
|
66
|
+
headerName: r.category_title,
|
|
61
67
|
flex: 0.25,
|
|
62
|
-
renderHeader:
|
|
63
|
-
renderCell: (e) => /* @__PURE__ */
|
|
68
|
+
renderHeader: n,
|
|
69
|
+
renderCell: (e) => /* @__PURE__ */ o(P, { ...e }),
|
|
64
70
|
sortingOrder: ["asc", "desc"]
|
|
65
71
|
},
|
|
66
72
|
{
|
|
67
73
|
field: "account",
|
|
68
|
-
|
|
74
|
+
getSortComparator: i,
|
|
75
|
+
headerName: r.account_title,
|
|
69
76
|
flex: 0.33,
|
|
70
|
-
renderHeader:
|
|
71
|
-
renderCell: (e) => e.row.parent_guid ? null : /* @__PURE__ */
|
|
77
|
+
renderHeader: n,
|
|
78
|
+
renderCell: (e) => e.row.parent_guid ? null : /* @__PURE__ */ o(O, { ...e }),
|
|
72
79
|
sortingOrder: ["asc", "desc"]
|
|
73
80
|
},
|
|
74
81
|
{
|
|
75
82
|
field: "amount",
|
|
76
|
-
|
|
83
|
+
getSortComparator: i,
|
|
84
|
+
headerName: r.amount_title,
|
|
77
85
|
flex: 0.25,
|
|
78
|
-
renderHeader:
|
|
79
|
-
renderCell:
|
|
86
|
+
renderHeader: n,
|
|
87
|
+
renderCell: L,
|
|
80
88
|
align: "right",
|
|
81
89
|
headerAlign: "right",
|
|
82
90
|
sortingOrder: ["asc", "desc"]
|
|
83
91
|
}
|
|
84
92
|
];
|
|
85
|
-
return /* @__PURE__ */
|
|
93
|
+
return /* @__PURE__ */ o(G, {
|
|
86
94
|
sx: {
|
|
87
|
-
height:
|
|
95
|
+
height: a,
|
|
88
96
|
px: 24,
|
|
89
97
|
width: "100%",
|
|
90
98
|
boxShadow: "none"
|
|
91
99
|
},
|
|
92
|
-
children: /* @__PURE__ */
|
|
100
|
+
children: /* @__PURE__ */ o(I, {
|
|
93
101
|
columns: x,
|
|
94
102
|
disableColumnFilter: !0,
|
|
95
103
|
disableColumnMenu: !0,
|
|
@@ -99,10 +107,10 @@ var F = ({ height: i = "100dvh", onCategoryClick: s, onRowClick: c }) => {
|
|
|
99
107
|
field: "date",
|
|
100
108
|
sort: "desc"
|
|
101
109
|
}] } },
|
|
102
|
-
loading:
|
|
103
|
-
onCellClick:
|
|
104
|
-
onCellKeyDown:
|
|
105
|
-
rows:
|
|
110
|
+
loading: C,
|
|
111
|
+
onCellClick: u,
|
|
112
|
+
onCellKeyDown: w,
|
|
113
|
+
rows: _,
|
|
106
114
|
slotProps: { baseIconButton: { material: {
|
|
107
115
|
color: "secondary",
|
|
108
116
|
sx: { ml: 8 }
|
|
@@ -116,9 +124,9 @@ var F = ({ height: i = "100dvh", onCategoryClick: s, onRowClick: c }) => {
|
|
|
116
124
|
}
|
|
117
125
|
})
|
|
118
126
|
});
|
|
119
|
-
},
|
|
127
|
+
}, te = F(K);
|
|
120
128
|
export {
|
|
121
|
-
|
|
129
|
+
te as default
|
|
122
130
|
};
|
|
123
131
|
|
|
124
132
|
//# sourceMappingURL=TransactionTable.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionTable.es.js","names":[],"sources":["../../../../src/transactions/components/shared/TransactionTable.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Paper from '@mui/material/Paper'\nimport {
|
|
1
|
+
{"version":3,"file":"TransactionTable.es.js","names":[],"sources":["../../../../src/transactions/components/shared/TransactionTable.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\n\nimport Paper from '@mui/material/Paper'\nimport {\n DataGridPro,\n GridCellParams,\n GridColDef,\n GridSortCellParams,\n GridSortDirection,\n gridStringOrNumberComparator,\n} from '@mui/x-data-grid-pro'\n\nimport {\n ANALYTICS_EVENTS,\n Loader,\n useEvent,\n useGlobalCopyStore,\n useGlobalUiStore,\n useTransactionStore,\n} from '../../../common'\n\nimport { useTransactionsUiStore } from '../../context/hooks'\n\nimport {\n AccountCell,\n AmountCell,\n CategoryCell,\n DateCell,\n FlagCell,\n HeaderCell,\n PayeeCell,\n} from './transactiontable/cells'\n\nconst isPendingRow = ({ api, id }: GridSortCellParams) => Boolean(api.getRow(id)?.isPending)\n\n// The grid reverses a plain sortComparator for desc, which would drop pending rows to the bottom.\nconst pendingFirst = (sortDirection: GridSortDirection) => {\n const direction = sortDirection === 'desc' ? -1 : 1\n\n return (v1: unknown, v2: unknown, p1: GridSortCellParams, p2: GridSortCellParams) =>\n Number(isPendingRow(p2)) - Number(isPendingRow(p1)) ||\n direction * gridStringOrNumberComparator(v1, v2, p1, p2)\n}\n\ninterface TransactionTableProps {\n height?: number | string\n onCategoryClick?: (guid: string) => void\n onRowClick?: (guid: string) => void\n}\n\nconst TransactionTable: React.FC<TransactionTableProps> = ({\n height = '100dvh',\n onCategoryClick,\n onRowClick,\n}) => {\n const { onEvent } = useEvent()\n const { transactions: copy } = useGlobalCopyStore()\n const { isCopyLoaded } = useGlobalUiStore()\n const { isLoading, sortedTransactions } = useTransactionStore()\n const { clearExpandedSplits, toggleSplit } = useTransactionsUiStore()\n\n React.useEffect(() => {\n return () => clearExpandedSplits()\n }, [])\n\n const rows = React.useMemo(\n () =>\n sortedTransactions.map((transaction) => ({\n id: transaction.guid,\n isHovering: false,\n ...transaction,\n })),\n [sortedTransactions],\n )\n\n const handleCellClick = ({ row: { id, guid, has_been_split }, field }: GridCellParams) => {\n if (has_been_split) return toggleSplit(id)\n\n if (field === 'category') {\n onEvent(ANALYTICS_EVENTS.TRANSACTIONS_TABLE_CLICK_CATEGORY, { guid })\n return onCategoryClick?.(guid)\n }\n\n return onRowClick?.(guid)\n }\n\n const handleCellKeyDown = (params: GridCellParams, event: React.KeyboardEvent) => {\n if (event.key !== 'Enter' && event.key !== ' ') return\n handleCellClick(params)\n }\n\n if (!isCopyLoaded) {\n return <Loader />\n }\n\n const columns: GridColDef[] = [\n {\n field: 'flag',\n headerName: '',\n minWidth: 32,\n width: 32,\n sortable: false,\n renderCell: (params) => <FlagCell {...params} />,\n renderHeader: () => <span aria-label={copy.transaction_status} />,\n },\n {\n field: 'date',\n getSortComparator: pendingFirst,\n headerName: copy.date_title,\n width: 103,\n renderHeader: HeaderCell,\n renderCell: (params) => (params.row.parent_guid ? null : <DateCell {...params} />),\n sortingOrder: ['desc', 'asc'],\n },\n {\n cellClassName: 'vertical-align-center',\n field: 'payee',\n getSortComparator: pendingFirst,\n headerName: copy.payee_title,\n flex: 0.33,\n renderHeader: HeaderCell,\n renderCell: (params) => <PayeeCell {...params} excludedText={copy.is_excluded} />,\n sortingOrder: ['asc', 'desc'],\n },\n {\n field: 'category',\n getSortComparator: pendingFirst,\n headerName: copy.category_title,\n flex: 0.25,\n renderHeader: HeaderCell,\n renderCell: (params) => <CategoryCell {...params} />,\n sortingOrder: ['asc', 'desc'],\n },\n {\n field: 'account',\n getSortComparator: pendingFirst,\n headerName: copy.account_title,\n flex: 0.33,\n renderHeader: HeaderCell,\n renderCell: (params) => (params.row.parent_guid ? null : <AccountCell {...params} />),\n sortingOrder: ['asc', 'desc'],\n },\n {\n field: 'amount',\n getSortComparator: pendingFirst,\n headerName: copy.amount_title,\n flex: 0.25,\n renderHeader: HeaderCell,\n renderCell: AmountCell,\n align: 'right',\n headerAlign: 'right',\n sortingOrder: ['asc', 'desc'],\n },\n ]\n\n return (\n <Paper sx={{ height: height, px: 24, width: '100%', boxShadow: 'none' }}>\n <DataGridPro\n columns={columns}\n disableColumnFilter={true}\n disableColumnMenu={true}\n getCellClassName={(params) => {\n if (params.row.parent_guid) return 'split-row'\n if (params.row.is_hidden) return 'excluded-row'\n return ''\n }}\n hideFooter={true}\n initialState={{ sorting: { sortModel: [{ field: 'date', sort: 'desc' }] } }}\n loading={isLoading}\n onCellClick={handleCellClick}\n onCellKeyDown={handleCellKeyDown}\n rows={rows}\n slotProps={{ baseIconButton: { material: { color: 'secondary', sx: { ml: 8 } } } }}\n sx={{\n '& .split-row': {\n bgcolor: 'background.default',\n },\n '& .excluded-row': {\n bgcolor: 'grey.50',\n color: 'text.secondary',\n },\n }}\n />\n </Paper>\n )\n}\n\nexport default observer(TransactionTable)\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,IAAM,IAAA,CAAgB,EAAE,KAAA,GAAK,IAAA,EAAA,MAA6B,EAAQ,EAAI,OAAO,CAAE,GAAG,WAG5E,IAAA,CAAgB,MAAqC;AACzD,QAAM,IAAY,MAAkB,SAAS,KAAK;AAElD,SAAA,CAAQ,GAAa,GAAa,GAAwB,MACxD,OAAO,EAAa,CAAE,CAAC,IAAI,OAAO,EAAa,CAAE,CAAC,KAClD,IAAY,EAA6B,GAAI,GAAI,GAAI,CAAE;AAC3D,GAQM,IAAA,CAAqD,EACzD,QAAA,IAAS,UACT,iBAAA,GACA,YAAA,EAAA,MACI;AACJ,QAAM,EAAE,SAAA,EAAA,IAAY,EAAS,GACvB,EAAE,cAAc,EAAA,IAAS,EAAmB,GAC5C,EAAE,cAAA,EAAA,IAAiB,EAAiB,GACpC,EAAE,WAAA,GAAW,oBAAA,EAAA,IAAuB,EAAoB,GACxD,EAAE,qBAAA,GAAqB,aAAA,EAAA,IAAgB,EAAuB;AAEpE,EAAA,EAAM,UAAA,MACJ,MAAa,EAAoB,GAChC,CAAC,CAAC;AAEL,QAAM,IAAO,EAAM,QAAA,MAEf,EAAmB,IAAA,CAAK,OAAiB;AAAA,IACvC,IAAI,EAAY;AAAA,IAChB,YAAY;AAAA,IACZ,GAAG;AAAA,EACL,EAAE,GACJ,CAAC,CAAkB,CACrB,GAEM,IAAA,CAAmB,EAAE,KAAK,EAAE,IAAA,GA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AAI,EAAE;AAAA,MAAE,EAAE,EAAE;AAAA,MACjF,IAAI;AAAA,QACF,gBAAgB,EACd,SAAS,qBACX;AAAA,QACA,mBAAmB;AAAA,UACjB,SAAS;AAAA,UACT,OAAO;AAAA,QACT;AAAA,MACF;AAAA,IACD,CAAA;AAAA,EACI,CAAA;AAEX,GAEA,KAAe,EAAS,CAAgB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { GridCellParams } from '@mui/x-data-grid';
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const _default: ((params: GridCellParams) => import("react/jsx-runtime").JSX.Element) & {
|
|
3
|
+
displayName: string;
|
|
4
|
+
};
|
|
5
|
+
export default _default;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import { DATE_FORMATS_INTL as t, formatDate as
|
|
2
|
-
import {
|
|
1
|
+
import { DATE_FORMATS_INTL as t, formatDate as e } from "../../../../../core/constants/DateFormats.es.js";
|
|
2
|
+
import { useGlobalCopyStore as m } from "../../../../../common/context/hooks.es.js";
|
|
3
|
+
import { fromUnixUTC as n } from "../../../../../core/utils/DateUtil.es.js";
|
|
4
|
+
import { observer as i } from "mobx-react-lite";
|
|
3
5
|
import { Text as a } from "@mxenabled/mxui";
|
|
4
|
-
import { jsx as
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
7
|
+
var d = (o) => {
|
|
8
|
+
const { common: r } = m();
|
|
9
|
+
return /* @__PURE__ */ f(a, {
|
|
10
|
+
tabIndex: o.tabIndex,
|
|
11
|
+
variant: "body2",
|
|
12
|
+
children: o.row.isPending ? r.pending : e(n(o.row.date), t.MONTH_DAY)
|
|
13
|
+
});
|
|
14
|
+
}, D = i(d);
|
|
10
15
|
export {
|
|
11
|
-
|
|
16
|
+
D as default
|
|
12
17
|
};
|
|
13
18
|
|
|
14
19
|
//# sourceMappingURL=DateCell.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateCell.es.js","names":[],"sources":["../../../../../../src/transactions/components/shared/transactiontable/cells/DateCell.tsx"],"sourcesContent":["import { GridCellParams } from '@mui/x-data-grid'\n\nimport { Text } from '@mxenabled/mxui'\n\nimport { DATE_FORMATS_INTL, formatDate } from '../../../../../core/constants'\nimport { fromUnixUTC } from '../../../../../core/utils/DateUtil'\n\nconst DateCell = (params: GridCellParams) => {\n return (\n <Text tabIndex={params.tabIndex} variant=\"body2\">\n {formatDate(fromUnixUTC(params.row.date), DATE_FORMATS_INTL.MONTH_DAY)}\n </Text>\n )\n}\n\nexport default DateCell\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"DateCell.es.js","names":[],"sources":["../../../../../../src/transactions/components/shared/transactiontable/cells/DateCell.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite'\nimport { GridCellParams } from '@mui/x-data-grid'\n\nimport { Text } from '@mxenabled/mxui'\n\nimport { useGlobalCopyStore } from '../../../../../common'\nimport { DATE_FORMATS_INTL, formatDate } from '../../../../../core/constants'\nimport { fromUnixUTC } from '../../../../../core/utils/DateUtil'\n\nconst DateCell = (params: GridCellParams) => {\n const { common: commonCopy } = useGlobalCopyStore()\n\n return (\n <Text tabIndex={params.tabIndex} variant=\"body2\">\n {params.row.isPending\n ? commonCopy.pending\n : formatDate(fromUnixUTC(params.row.date), DATE_FORMATS_INTL.MONTH_DAY)}\n </Text>\n )\n}\n\nexport default observer(DateCell)\n"],"mappings":";;;;;;AASA,IAAM,IAAA,CAAY,MAA2B;AAC3C,QAAM,EAAE,QAAQ,EAAA,IAAe,EAAmB;AAElD,SACE,gBAAA,EAAC,GAAD;AAAA,IAAM,UAAU,EAAO;AAAA,IAAU,SAAQ;AAAA,IACtC,UAAA,EAAO,IAAI,YACR,EAAW,UACX,EAAW,EAAY,EAAO,IAAI,IAAI,GAAG,EAAkB,SAAS;AAAA,EACpE,CAAA;AAEV,GAEA,IAAe,EAAS,CAAQ"}
|
|
@@ -7,7 +7,7 @@ export interface ChartDataProps {
|
|
|
7
7
|
date: string;
|
|
8
8
|
}
|
|
9
9
|
export declare const sortByDate: (a: Transaction, b: Transaction) => number;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const shouldShowSubheader: (index: number, transactions: Transaction[]) => boolean;
|
|
11
11
|
export declare const hasInsetBorder: (index: number, transactions: Transaction[]) => boolean;
|
|
12
12
|
export declare const buildDataSeries: (data?: DataSeries) => {
|
|
13
13
|
[k: string]: any;
|
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
import { DATE_FORMATS_INTL as
|
|
2
|
-
import { fromUnixUTC as
|
|
3
|
-
import { formatCurrency as
|
|
4
|
-
import { isSameDay as
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
const t = m(e[r].date), a = m(e[r - 1].date);
|
|
8
|
-
return !o(t, a);
|
|
9
|
-
}, d = (r, e) => {
|
|
10
|
-
if (r === e.length - 1) return !1;
|
|
11
|
-
const t = m(e[r].date), a = m(e[r + 1].date);
|
|
12
|
-
return o(t, a);
|
|
13
|
-
}, l = (r) => r?.data ? r.data.map((e) => Object.fromEntries((r.names || []).map((t, a) => [t, e[a]]))) : [], v = (r, e = "") => r.map((t) => {
|
|
14
|
-
const a = f(t.date, n.MONTH_SHORT);
|
|
1
|
+
import { DATE_FORMATS_INTL as u, formatDate as i } from "../../core/constants/DateFormats.es.js";
|
|
2
|
+
import { fromUnixUTC as o } from "../../core/utils/DateUtil.es.js";
|
|
3
|
+
import { formatCurrency as t } from "../../core/utils/NumberFormatting.es.js";
|
|
4
|
+
import { isSameDay as f } from "date-fns/isSameDay";
|
|
5
|
+
var n = (r, e) => r.isPending || e.isPending ? !!r.isPending == !!e.isPending : f(o(r.date), o(e.date)), l = (r, e) => r === 0 || !n(e[r], e[r - 1]), s = (r, e) => r < e.length - 1 && n(e[r], e[r + 1]), v = (r) => r?.data ? r.data.map((e) => Object.fromEntries((r.names || []).map((a, m) => [a, e[m]]))) : [], T = (r, e = "") => r.map((a) => {
|
|
6
|
+
const m = i(a.date, u.MONTH_SHORT);
|
|
15
7
|
return {
|
|
16
8
|
ariaLabel: `
|
|
17
|
-
${
|
|
18
|
-
${
|
|
9
|
+
${m},
|
|
10
|
+
${t(a.amount, "0.00")},
|
|
19
11
|
${e}`,
|
|
20
|
-
label:
|
|
21
|
-
value:
|
|
22
|
-
formattedAmount:
|
|
12
|
+
label: m,
|
|
13
|
+
value: a.amount,
|
|
14
|
+
formattedAmount: t(a.amount, "0,0")
|
|
23
15
|
};
|
|
24
16
|
});
|
|
25
17
|
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
T as buildChartData,
|
|
19
|
+
v as buildDataSeries,
|
|
20
|
+
s as hasInsetBorder,
|
|
21
|
+
l as shouldShowSubheader
|
|
30
22
|
};
|
|
31
23
|
|
|
32
24
|
//# sourceMappingURL=Transactions.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transactions.es.js","names":[],"sources":["../../../src/transactions/utils/Transactions.ts"],"sourcesContent":["import { isSameDay } from 'date-fns/isSameDay'\n\nimport { DATE_FORMATS_INTL, formatDate } from '../../core/constants'\nimport { fromUnixUTC } from '../../core/utils/DateUtil'\nimport { type DataSeries, type Transaction } from '../../core'\nimport { formatCurrency } from '../../core/utils/NumberFormatting'\n\nexport interface ChartDataProps {\n guid?: string\n label?: string\n localized_label?: string\n amount: number\n date: string\n}\n\nexport const sortByDate = (a: Transaction, b: Transaction) => {\n return b.date - a.date\n}\n\
|
|
1
|
+
{"version":3,"file":"Transactions.es.js","names":[],"sources":["../../../src/transactions/utils/Transactions.ts"],"sourcesContent":["import { isSameDay } from 'date-fns/isSameDay'\n\nimport { DATE_FORMATS_INTL, formatDate } from '../../core/constants'\nimport { fromUnixUTC } from '../../core/utils/DateUtil'\nimport { type DataSeries, type Transaction } from '../../core'\nimport { formatCurrency } from '../../core/utils/NumberFormatting'\n\nexport interface ChartDataProps {\n guid?: string\n label?: string\n localized_label?: string\n amount: number\n date: string\n}\n\nexport const sortByDate = (a: Transaction, b: Transaction) => {\n return b.date - a.date\n}\n\nconst isSameSubheader = (a: Transaction, b: Transaction) => {\n if (a.isPending || b.isPending) return Boolean(a.isPending) === Boolean(b.isPending)\n\n return isSameDay(fromUnixUTC(a.date), fromUnixUTC(b.date))\n}\n\nexport const shouldShowSubheader = (index: number, transactions: Transaction[]) =>\n index === 0 || !isSameSubheader(transactions[index], transactions[index - 1])\n\nexport const hasInsetBorder = (index: number, transactions: Transaction[]) =>\n index < transactions.length - 1 && isSameSubheader(transactions[index], transactions[index + 1])\n\nexport const buildDataSeries = (data?: DataSeries) => {\n if (!data?.data) return []\n\n return data.data.map((row) => {\n return Object.fromEntries((data.names || []).map((name, index) => [name, row[index]]))\n })\n}\n\nexport const buildChartData = (dataSeries: ChartDataProps[], merchantName = '') => {\n const data = dataSeries.map((total) => {\n const label = formatDate(total.date, DATE_FORMATS_INTL.MONTH_SHORT)\n\n return {\n ariaLabel: `\n ${label},\n ${formatCurrency(total.amount, '0.00')},\n ${merchantName}`,\n label,\n value: total.amount,\n formattedAmount: formatCurrency(total.amount, '0,0'),\n }\n })\n\n return data\n}\n"],"mappings":";;;;AAmBA,IAAM,IAAA,CAAmB,GAAgB,MACnC,EAAE,aAAa,EAAE,YAAkB,EAAQ,EAAE,aAAe,EAAQ,EAAE,YAEnE,EAAU,EAAY,EAAE,IAAI,GAAG,EAAY,EAAE,IAAI,CAAC,GAG9C,IAAA,CAAuB,GAAe,MACjD,MAAU,KAAK,CAAC,EAAgB,EAAa,CAAA,GAAQ,EAAa,IAAQ,CAAA,CAAE,GAEjE,IAAA,CAAkB,GAAe,MAC5C,IAAQ,EAAa,SAAS,KAAK,EAAgB,EAAa,CAAA,GAAQ,EAAa,IAAQ,CAAA,CAAE,GAEpF,IAAA,CAAmB,MACzB,GAAM,OAEJ,EAAK,KAAK,IAAA,CAAK,MACb,OAAO,aAAa,EAAK,SAAS,CAAC,GAAG,IAAA,CAAK,GAAM,MAAU,CAAC,GAAM,EAAI,CAAA,CAAM,CAAC,CAAC,CACtF,IAJuB,CAAC,GAOd,IAAA,CAAkB,GAA8B,IAAe,OAC7D,EAAW,IAAA,CAAK,MAAU;AACrC,QAAM,IAAQ,EAAW,EAAM,MAAM,EAAkB,WAAW;AAElE,SAAO;AAAA,IACL,WAAW;AAAA,UACP,CAAA;AAAA,UACA,EAAe,EAAM,QAAQ,MAAM,CAAA;AAAA,UACnC,CAAA;AAAA,IACJ,OAAA;AAAA,IACA,OAAO,EAAM;AAAA,IACb,iBAAiB,EAAe,EAAM,QAAQ,KAAK;AAAA,EACrD;AACF,CAEO"}
|