From a2063c8e43ca430699d67bd4b91c550b9dd5836a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 14:47:06 +0000 Subject: [PATCH] Fix a JSON import's transaction edits not showing until a reload (v1.16.18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings -> Data & reset -> Import JSON saved the file's transaction edits (txOverrides) but left the loaded transactions as they were: every screen kept the old descriptions, categories, types, flags and notes, and a transaction the file had no edit for kept its old edit. A reload didn't always fix it: the autosave wrote the transactions as shown, and a boot from finlens-state.json keeps a saved category and type where the edit has none. master has the same gap in importJsonFile(), but no button calls it there (Import JSON came in v1.16.0). - applyImportedEdits() (ui.js): with new edits, every loaded transaction is rebuilt from its CSV values (DataCleanup._unedited(), as Clear transaction edits does) with its imported edit on top (reconstituteTx()), then detectTransfers() runs: what an import of the CSVs makes with these edits. Flags an edit doesn't set follow the rules now in State (txFlags()). - _applyImportedSettings() is async and runs it when txOverrides changed; that rebuild also covers new flag rules and transfer keywords, so their own steps run only without new edits. Edits moved by adoptOverrides() count. - Plan links already showed at once (read from txOverrides); unchanged. - An export without edits (1.0, 1.1) changes no transaction. - Version bumped to v1.16.18 (CHANGELOG, footer, README, Settings, CLAUDE.md); CLAUDE.md §9 and §20 updated. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft --- CHANGELOG.md | 16 ++++++++++++++ CLAUDE.md | 8 ++++--- README.md | 4 ++-- index.html | 2 +- js/ui.js | 50 ++++++++++++++++++++++++++++++++++++-------- js/views-settings.js | 2 +- 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40dd30f..87a392b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.18] — 2026-11-02 + +### Fixed +- **Importing a JSON backup didn't show its transaction edits until a reload.** + - **When:** Settings → Data & reset → Import JSON with a file that has transaction edits (`txOverrides`). The edits were saved, but every screen kept the old descriptions, categories, types, flags and notes. A transaction the file had no edit for kept the edit it had before. + - **A reload didn't always fix it.** The autosave wrote the transactions as they were shown. A boot from `finlens-state.json` then kept an old edit's category and type wherever the file had no edit for that transaction; only a boot from IndexedDB rebuilt them from the CSV rows. + - **Cause:** `importJsonFile()` replaced `State.txOverrides` but rebuilt nothing. `_applyImportedSettings()` re-applied flag rules and transfer keywords only when those keys changed, and left edits for "after a reload". On `master` the function has the same gap, but no button calls it there: the Import JSON button came in v1.16.0. + - **Fix:** with new edits, `applyImportedEdits()` rebuilds every loaded transaction from its CSV values (`DataCleanup._unedited()`, as Clear transaction edits does), puts its imported edit on top (`reconstituteTx()`), then detects transfers again. The result is what importing the CSVs with those edits makes: edited fields from the edit, flags the edit doesn't set from the transaction rules (`txFlags()`), and everything else back to the CSV values. The render that follows shows it all. + - **Unchanged:** an export without edits (versions 1.0 and 1.1 may have none) changes no transaction. Plan links already showed at once, since they're read from the edits; they still do. + - **Older files:** a transaction from a `finlens-state.json` written by v1.16.0 or earlier doesn't record its CSV category and type. Its IndexedDB row gives them; without one they're worked out again where they were edited, exactly as Clear transaction edits does (exact for checking and savings). + +### Docs +- **CLAUDE.md:** §1 version; §9 `applyImportedEdits()`; §20 what takes effect without a reload. + +--- + ## [1.16.17] — 2026-11-02 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index 9a39450..96feb5f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,7 +59,7 @@ Until then, this section is the rule. FinLens is a **single-origin, zero-build, vanilla JavaScript personal finance dashboard** that runs entirely in the browser. There is no server, no npm, no bundler, no framework, and no TypeScript. The entry point is `index.html`; everything else is a plain `.js` file in the `js/` folder. -**Current version:** v1.16.17 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.18 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). **What it does:** Imports CSV exports from a bank (checking + savings) and credit cards, parses and normalizes them into a unified transaction model, and renders a multi-tab financial dashboard with budgeting, debt tracking, savings forecasting, investment planning, and Claude-powered AI analysis. @@ -698,6 +698,7 @@ confirmRecurring(r), dismissRecurring(key), undoDismissRecurring(key) // r: a addCatRule(), delCatRule(i), recategorizeAll() exportAllData(), importJsonFile(ev) // Settings → Data & reset → Export / Import JSON (v1.16.0; before, no button called them) // JSON_EXPORT_KEYS: what's in the file, version 1.2 (v1.16.6, §20) +applyImportedEdits(before) // (v1.16.18) after a JSON import with edits: each loaded transaction = its CSV values + its edit, then detectTransfers() clearAllData() // = DataCleanup.startOver('archive') — full reset + reload (§20) ``` @@ -1069,7 +1070,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.17 — 2026-11-02 (a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* +*Last updated: v1.16.18 — 2026-11-02 (a JSON import's transaction edits show at once: §9 `applyImportedEdits()`; §20 what takes effect without a reload; v1.16.17: a file read into another account takes its rows with it: §4.3 the account's `files`, `accountFiles()`; §4.5 the exception to an import never dropping rows; §8 `accountFiles()`, `earlierCopies()`, `moveEarlierCopies()`; §10 Read as changes the ids; §19 `DB.removeTransactions()`, `DB.patchAccount()`; §22 `_rekey()` is also used by imports; v1.16.16: the transaction and transfer drawers store only the fields you change: §4.1 TxOverride, §11 transfer keywords, §12 state mutations; v1.16.15: §1 desktop only; §3 `views-database.js` removed, the Changelog view reads CHANGELOG.md; §6, §18, §19 point to the current screens; v1.16.14: §9 the drawer is a modal dialog: inert page, Tab wraps, first field focused, focus returns after a re-render; v1.16.13: account order: §4.1 `accountOrder` keeps ids not loaded; §8 `orderedAccounts()`; §18 display order; v1.16.12: account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* --- @@ -1149,7 +1150,8 @@ CSV files on disk are **never** modified. - **The JSON export holds everything you entered or chose (v1.16.6).** `JSON_EXPORT_KEYS` (`ui.js`) lists the State keys and the kind of value each holds (`list`, `map`, `theme`); `exportAllData()` writes them with `version: '1.2'` and `importJsonFile()` reads the same list. - **Left out:** transactions and accounts (the CSVs bring them back), the API key (§15), this browser's own state (`sampleData`, `csvAutoImportPaused`, `lastFolderName`), the session (date range, accounts filter, current view) and `customSchemas` (nothing creates one, §19). - **Import:** accepts any version (1.0, 1.1, 1.2). A key that's missing, null or of the wrong kind keeps its current value. Each key is saved through `storageKey()` (§4.5). A file that isn't a JSON object is refused. - - **Takes effect without a reload** (`_applyImportedSettings()`, for keys whose value changed): account names and order, flag rules (`applyTxRulesToAll()`), transfer keywords (`reapplyTransferKeywords()`) and the theme (`applyTheme()`). Category rules apply to the next import, "Read as" choices to the next CSV read, and transaction edits after a reload. + - **Takes effect without a reload** (`_applyImportedSettings()`, for keys whose value changed): account names and order, flag rules (`applyTxRulesToAll()`), transfer keywords (`reapplyTransferKeywords()`), the theme (`applyTheme()`) and transaction edits (v1.16.18). Category rules apply to the next import, "Read as" choices to the next CSV read. + - **Transaction edits** (`applyImportedEdits()`, v1.16.18): every loaded transaction is rebuilt from its CSV values (`DataCleanup._unedited()`, as Clear transaction edits does) with its imported edit on top (`reconstituteTx()`), then `detectTransfers()` runs. That's what importing the CSVs with these edits makes. A transaction the file has no edit for goes back to its CSV values, and flags an edit doesn't set follow the rules now in State. This rebuild covers new flag rules and transfer keywords too, so with new edits those two steps don't run on their own. Plan links need nothing: they're read from `State.txOverrides`. Up to v1.16.17 the edits were only saved: every screen kept the old values until a reload, and a reload from `finlens-state.json` kept an old edit's category and type where the file had no edit. - **A new persisted field the user enters or chooses** goes in `JSON_EXPORT_KEYS` too. --- diff --git a/README.md b/README.md index da1e986..9445559 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money. -**Version:** v1.16.17  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.18  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -263,4 +263,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.17 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.18 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index 57c5b7c..199723b 100644 --- a/index.html +++ b/index.html @@ -1202,7 +1202,7 @@
-
v1.16.17 · FinLens
+
v1.16.18 · FinLens
diff --git a/js/ui.js b/js/ui.js index 5584ac1..2a72d4f 100644 --- a/js/ui.js +++ b/js/ui.js @@ -935,36 +935,68 @@ function exportAllData() { function importJsonFile(ev) { const file=ev.target.files[0]; if (!file) return; const reader=new FileReader(); - reader.onload=e=>{ + reader.onload=async e=>{ try { const d=JSON.parse(e.target.result); if (!_JSON_KIND.map(d)) throw new Error('this file is not a FinLens export.'); // Exports from before v1.12.0 use the old account codes (migrate.js) IdMigration.migrateState(d); + const before={ ...(State.txOverrides||{}) }; // the edits the loaded transactions show now const changed=new Set(); for (const [k,kind] of Object.entries(JSON_EXPORT_KEYS)) { if (!_JSON_KIND[kind](d[k])) continue; if (JSON.stringify(d[k])!==JSON.stringify(State[k])) changed.add(k); State[k]=d[k]; lsSet(storageKey(k),d[k]); } - if (IdMigration.adoptOverrides(State.transactions).size) lsSet('txOverrides',State.txOverrides); - _applyImportedSettings(changed); + if (IdMigration.adoptOverrides(State.transactions).size) { lsSet('txOverrides',State.txOverrides); changed.add('txOverrides'); } + await _applyImportedSettings(changed, before); alert('Imported successfully.'); renderActive(); } catch(err){ alert('Import failed: '+err.message); } }; reader.readAsText(file); } // Imported settings take effect now, without a reload. Most keys only need the render -// that follows. Category rules apply to the next import (or Re-categorize all), "Read as" -// choices to the next CSV read, and transaction edits once the page reloads, as before. +// that follows. Category rules apply to the next import (or Re-categorize all) and "Read +// as" choices to the next CSV read. Transaction edits rebuild the loaded transactions +// (applyImportedEdits(), v1.16.18): that also applies the flag rules and transfer keywords +// now in State, so those two steps are only needed on their own without new edits. // Imported account names need no copying: acctName() reads State.accountLabels, and an -// account's own name stays its default (v1.16.12). -function _applyImportedSettings(changed) { +// account's own name stays its default (v1.16.12). `before`: txOverrides before the import. +async function _applyImportedSettings(changed, before) { if (changed.has('accountLabels')||changed.has('accountOrder')) buildAccountFilter(); - if (changed.has('txRules')) applyTxRulesToAll(); - if (changed.has('transferKeywords')) reapplyTransferKeywords(); // views-main.js; re-runs transfer detection + if (changed.has('txOverrides')) await applyImportedEdits(before||{}); + else { + if (changed.has('txRules')) applyTxRulesToAll(); + if (changed.has('transferKeywords')) reapplyTransferKeywords(); // views-main.js; re-runs transfer detection + } if (changed.has('theme')) applyTheme(); } +// The loaded transactions with the edits a JSON import brought (v1.16.18). Each one is rebuilt +// from its CSV values (DataCleanup._unedited(), as Clear transaction edits does), with its edit +// now in State.txOverrides on top (reconstituteTx()); then transfers are detected again. That +// is what an import of the CSVs makes with these edits (mkTx(), detectTransfers()): +// description, categories, type, notes and flags from the edit, the flags it doesn't set from +// the transaction rules (txFlags()), and a transaction the file has no edit for back to its +// CSV values. Plan links need nothing: they're read from State.txOverrides. +// `before` is txOverrides as it was: _unedited() reads it for a transaction from a ≤v1.16.0 +// state file, which doesn't record its CSV category and type (its IndexedDB row gives them, +// when this browser has one). +// Up to v1.16.17 the import only saved the edits: every screen kept the old descriptions, +// categories, types, flags and notes until a reload, and a reload from finlens-state.json +// kept an old edit's category and type where the file had no edit. +async function applyImportedEdits(before) { + const known=(t)=>t._originalType&&Array.isArray(t._originalCategories)&&t._originalCategories.length; + let rows=new Map(); + if (State.transactions.some(t=>!known(t))&&typeof DB!=='undefined'&&DB._db) { + rows=new Map((await DB._getAllTransactions()).map(r=>[r.id,r])); + } + State.transactions=State.transactions.map(t=>{ + const base=DataCleanup._unedited(t,before[t.id],rows.get(t.id)); + const ov=State.txOverrides[t.id]; + return ov?reconstituteTx({ ...base, description:base._originalDesc },ov):base; + }); + detectTransfers(); +} // Erase everything and reload. Clearing only localStorage (as ≤v1.8.1 did) was undone on // reload by IndexedDB and finlens-state.json, so this delegates to the full reset in // views-cleanup.js. Call it from a click handler (it may need folder write access). diff --git a/js/views-settings.js b/js/views-settings.js index 81d2c40..fbd7a40 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -67,7 +67,7 @@ function _renderGeneralSettings(root) { ``).join('')} -
VersionFinLens v1.16.17
+
VersionFinLens v1.16.18
`); const opts=$$('[data-theme-opt]',root); opts.forEach((b,i)=>{