diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d4565..0774474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,33 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.7] — 2026-11-02 + +### Transactions, Budget, Savings buckets, Debt tracker +- **Linked transactions no longer move to another budget, bucket or debt when one is deleted.** A transaction can be linked to one in its edit drawer ("Link to a budget, bucket or debt"). + - **What went wrong:** the link stored the item's position in its list (`txOverrides[id].link = { type, idx }`). Deleting an item moved the ones after it up a place, so their links pointed at the next item, or past the end of the list. With three budgets, deleting the first moved the second's link to the third, and the third's link showed the second (the drawer's first option). + - **Fix:** each budget, bucket and debt now has an `id`. It's given when the item is created and kept when it's edited. Links store it: `{ type, id }`. +- **Deleting a budget, bucket or debt removes the links to it.** Before, they stayed and pointed at whatever moved into its place. The transaction's other edits stay. +- **A link to an item that no longer exists shows as None** in the drawer; saving drops it. +- **The bucket drawer's Linked transactions** finds them by id (`linkedTransactions()`). + +### Settings → Data & reset +- **Clear budgets, Clear buckets and Clear debts also remove the transaction links to them** (saved as transaction edits). Other edits on those transactions are kept. + +### Technical +- **Ids:** `newPlanId()` and `PLAN_LINK_TYPES` in `core.js`. An id is `bud_`, `bkt_` or `dbt_` plus 10 random base-36 characters. `saveBudget()`, `seedBudgets()` (Use starter budget), `addBucket()`, `saveBucket()` and `saveDebt()` (including a debt started from a card) give one; every edit keeps it. +- **`ui.js`:** `planItem()`, `linkedTransactions()`, `unlinkPlanItems()` and `ensurePlanIds()`. `deleteBudget()`, `deleteBucket()` and `deleteDebt()` remove the links to the deleted item. **`views-main.js`:** `showTxDrawer()` lists items by id and saves `{ type, id }`. **`views-cleanup.js`:** `clearPlan()` removes the links. **`views-db.js`:** the schema note says `{type,id}`. +- **Migration** (`IdMigration.migratePlanLinks()` in `migrate.js`). Data saved before v1.16.7 is rewritten in the same places as the account codes: at boot, when `finlens-state.json` loads, and on JSON import (all through `migrateState()`). + - **Items without an id** get `_m`, n being their position. The same old data gets the same ids wherever it's migrated. + - **Each `{ type, idx }` link** becomes `{ type, id }` of the item it pointed at, so no link changes target. A link past the end of its list is dropped. + - **At boot,** `storePlanLinks()` writes State's budgets, buckets, debts and transaction edits back to localStorage and IndexedDB `app_state`, and the normal save rewrites the state file. Running it again changes nothing. +- **The AI summary is unchanged.** `buildFinancialSummary()` reads neither links nor ids. On `samples/`, with and without budgets, buckets, debts and links, its output is byte-identical to v1.16.0's, and so is the AI Eval's sample summary. `docs/EVAL.md` stays valid. + +### Docs +- **CLAUDE.md** §4.1 (the `id` fields, TxOverride and its `link`), §8, §9, §20 (clears remove links) and §22 (the migration). + +--- + ## [1.16.6] — 2026-11-02 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index e8e71fc..70ebb77 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.6 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.7 (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. @@ -112,7 +112,7 @@ FinLens/ ├── core.js ← State, helpers, CSV parsing, date range, account filter ├── aggregation.js ← Pure data aggregation: sums, groupings, recurring detection ├── db.js ← IndexedDB layer (finlens_db) - ├── migrate.js ← Rewrites data saved by older versions: account codes (§22) + ├── migrate.js ← Rewrites data saved by older versions: account codes, plan links (§22) ├── ui.js ← View registry, drawer, theme, chart helpers, CRUD helpers ├── views-main.js ← Overview, Transactions, Income, Bills, Spending, Transfers ├── views-plan.js ← Budget, Savings buckets, Debt tracker (Plan, v1.15.0); Trends (v1.16.0) @@ -155,7 +155,7 @@ const State = { debts: [], // Debt[] — persisted bills: [], // Bill[] — persisted (shape below) recurringConfirmed: {}, // { [recurringKey]: 'confirmed' | 'dismissed' } — Bills → Spotted recurring charges; Undo deletes the key - txOverrides: {}, // { [txId]: TxOverride } — user edits on transactions + txOverrides: {}, // { [txId]: TxOverride } — user edits on transactions (shape below) manualBalances: {}, // { [accountId]: number, [accountId+'_limit']: number, [accountId+'_initial']: number } categoryRules: [], // { contains: string, category: string }[] categories: [], // string[] — user-editable category list @@ -201,16 +201,18 @@ The optional fields live inside `bills`, so they're saved, loaded, exported and **Plan records (v1.15.0).** New fields live inside the existing arrays; only `debtPlan` is a new top-level key. +**Ids (v1.16.7).** Every budget, bucket and debt has a stable `id`: `'bud_'`, `'bkt_'` or `'dbt_'` plus 10 random base-36 characters (`newPlanId()`, core.js). It's given when the item is created (the drawers, + New bucket, Use starter budget, a debt started from a card) and kept when it's edited. Items saved before v1.16.7 get `'_m'` from the migration (§22). An id is a name, not a position: never derive one from the list order. + ```js // Budget (State.budgets) -{ name, limit: number /* a month */, categories: string[], color?: '#hex' /* before v1.15.0; kept, not shown */ } +{ id, name, limit: number /* a month */, categories: string[], color?: '#hex' /* before v1.15.0; kept, not shown */ } // Bucket (State.buckets) -{ name, goal, current, targetDate: 'YYYY-MM-DD' | '', +{ id, name, goal, current, targetDate: 'YYYY-MM-DD' | '', icon?: 'shield'|'plane'|'laptop'|'wrench'|'home'|'gift'|'heart'|'book'|'star', // BUCKET_ICONS hue?: 'accent'|'pink'|'sky'|'card'|'good'|'violet'|'teal'|'warn' } // BUCKET_HUES // older buckets have an emoji icon and a hex color: they show an icon guessed from the name and a hue by position // Debt (State.debts) -{ name, type: 'Credit Card'|'Personal Loan'|'Student Loan'|'Auto Loan'|'Mortgage'|'Other', +{ id, name, type: 'Credit Card'|'Personal Loan'|'Student Loan'|'Auto Loan'|'Mortgage'|'Other', balance, apr /* % */, minPayment, limit, dueDay, account?: string } // a credit card account: balance and limit then come from it (debtBalance(), debtLimit()); // `balance` keeps the value at the last save; the limit is State.manualBalances[account+'_limit'] @@ -219,6 +221,18 @@ The optional fields live inside `bills`, so they're saved, loaded, exported and // scenarios from before v1.15.0 have the old simulator's inputs; scenarioInputs() converts them for display ``` +**TxOverride** (an entry of `State.txOverrides`, keyed by transaction id). Every field is optional; only the ones the user changed are there. + +```js +{ description, categories: string[], type, notes, isBill, isRecurring, isSubscription, + accountOverride?: string, // an accountId + link?: { type: 'budget' | 'bucket' | 'debt', id: string } } // the transaction drawer's "Link to"; id = the item's id (v1.16.7) +``` + +- **Links point at an item's `id`, never its position.** Up to v1.16.6 a link was `{ type, idx }`, so deleting an item left the links of the items after it pointing at the wrong one. `PLAN_LINK_TYPES` (core.js) maps a link type to its State key and id prefix. +- **Read links through the helpers** (ui.js, §9): `planItem(type, id)` finds the item; `linkedTransactions(type, id)` lists its transactions. A link whose item is gone matches nothing, and the drawer shows it as None. +- **Deleting an item removes the links to it** (`unlinkPlanItems(type, id)`, saved as `txOverrides`). So does clearing its list in Data & reset (§20). An edit left with nothing else in it is removed. + ### 4.2 The Transaction Model Transactions are created by `mkTx()` in `core.js` and never mutated directly — edits go through `State.txOverrides[tx.id]` and are persisted via `lsSet('txOverrides', ...)`. @@ -550,6 +564,8 @@ growthByYear(start, monthly, yearlyPct, years) // [{ year, balance, putIn }], de // Utilities hash(str) // Deterministic 'tx' + base36 hash for transaction IDs +PLAN_LINK_TYPES // { budget: ['budgets','bud'], bucket: ['buckets','bkt'], debt: ['debts','dbt'] } — link type → State key, id prefix (v1.16.7) +newPlanId(type, list?) // a new budget/bucket/debt id: prefix + '_' + 10 random base-36 characters, not already in list (default: the State list) escapeHtml(str) // Escape HTML entities for safe innerHTML insertion escapeAttr(str) // Escape for use in HTML attribute strings renderMarkdown(md) // marked → DOMPurify (no images/styles/forms) → safe HTML string; escaped-text fallback; only ~~double~~ tildes strike through @@ -638,6 +654,11 @@ editDebt(i, account?), saveDebt(i), deleteDebt(i), debtCardChoices(current) // setPayoffStrategy(s), setPayoffExtra(v) // save State.debtPlan simulatePayoff(debts, extra) // older payoff model, kept unchanged and unused (extra to the first debt only, no rollover) // deleteBudget/Bucket/Debt no longer confirm(): the drawer's Delete asks for a second click +// Every create path gives the item an id (newPlanId) and every save keeps it; each delete removes the links to it (v1.16.7) +planItem(type, id) // the budget / bucket / debt a link points at, or null (v1.16.7) +linkedTransactions(type, id) // transactions linked to it, newest first (the bucket drawer's "Linked transactions") +unlinkPlanItems(type, ids) // remove links to those items (an id or a list; a missing id removes nothing), or ids 'all': every item of the type; saves txOverrides; returns the count +ensurePlanIds() // give an item without an id one (the transaction drawer calls it before listing items) confirmRecurring(r), dismissRecurring(key), undoDismissRecurring(key) // r: a detectRecurring() entry addCatRule(), delCatRule(i), recategorizeAll() exportAllData(), importJsonFile(ev) // Settings → Data & reset → Export / Import JSON (v1.16.0; before, no button called them) @@ -991,7 +1012,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.6 — 2026-11-02 (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.7 — 2026-11-02 (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)* --- @@ -1040,7 +1061,7 @@ CSV files on disk are **never** modified. | Clear transactions & accounts | Empties memory + `transactions`/`accounts` stores; turns `sampleData` off; with a folder connected, sets `csvAutoImportPaused` | Plans, edits, account labels/balances, `cardDetails`, settings | | Clear import log | Empties `import_log` | Everything else | | Clear transaction edits | `txOverrides` + `tx_overrides` store; rebuilds each loaded transaction without its edit, from memory (`_unedited()`), then `detectTransfers()` | Every loaded transaction; the `transactions` store as it is | -| Clear budgets / bills / buckets / debts / forecast scenarios / investment mix / AI history | `State[key] = []` (`{}` for `investAlloc`; the empty value is `PLAN_ITEMS[i][2]`) + `lsSet`. Bills also resets `recurringConfirmed` (confirmed/dismissed spotted charges); Debts also resets `debtPlan` (`PLAN_ALSO`) | — | +| Clear budgets / bills / buckets / debts / forecast scenarios / investment mix / AI history | `State[key] = []` (`{}` for `investAlloc`; the empty value is `PLAN_ITEMS[i][2]`) + `lsSet`. Bills also resets `recurringConfirmed` (confirmed/dismissed spotted charges); Debts also resets `debtPlan` (`PLAN_ALSO`). Budgets, buckets and debts also remove the transaction links to them (`unlinkPlanItems(type, 'all')`, saved as `txOverrides`, v1.16.7) | Other edits on those transactions | | Rebuild from folder | `reloadFromDirHandle()` reads every CSV first; only if they can all be read (`_rebuildBlockers()`) it clears transactions, accounts and import log (in `beforeImport`), then imports them | Plans, edits, settings; everything, when a CSV can't be read | | Disconnect folder | `forgetDataFolder()` — stops CSV auto-reload and state-file writes | Files on disk | | Use my own files (sample banner) | `clearSampleData()`: transactions, accounts and import log (memory + stores), `sampleData` off, state file rewritten, back to the Welcome | Plans made while trying it | @@ -1064,6 +1085,7 @@ CSV files on disk are **never** modified. - **After the clear, the import finishes.** `importParsedCsv()` logs a failing IndexedDB write and carries on, so `_finish()` still saves every transaction to the file. - **Start over must leave nothing behind.** It sets `State._resetInProgress` so a pending debounced save can't re-create the file, and `DB.open()` registers `onversionchange` so other tabs release the database. `idbGet`/`idbSet`/`idbDel` close their connections so `finlens_fs` can be deleted. - **Fields added in v1.16.0:** `cardDetails` and `sampleData` live in localStorage, IndexedDB `app_state` (`DB.loadAll()`) and `finlens-state.json`; Start over erases both with everything else. `cardDetails` is also in the JSON export. Importing your own files turns `sampleData` off after clearing the samples (`loadFiles()`). +- **No link outlives its item (v1.16.7).** Clearing budgets, buckets or debts removes the `txOverrides[…].link`s of that type, as deleting one item removes the links to it. Clear transaction edits and Start over remove every link with the rest of the edits. The ids live inside `budgets`, `buckets` and `debts`, so no new place stores data. - `clearAllData()` is kept as a wrapper for `DataCleanup.startOver('archive')`. Up to v1.8.1 it only cleared `localStorage`, which IndexedDB and the state file then restored on reload. - **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). @@ -1127,3 +1149,26 @@ Each step is idempotent: on new data nothing matches and nothing is written. - **Names the user typed are never changed.** Only the old default names are renamed. - **File names are user data.** An account id derived from a file name keeps whatever that name contains. To hide a name, relabel the account; renaming the CSV file creates a new account on the next import. - **No new storage.** It only rewrites places listed in §20. + +### v1.16.7: plan item ids and transaction links + +Up to v1.16.6 a transaction's link to a budget, bucket or debt (`txOverrides[txId].link`) was `{ type, idx }`, the item's position in its list. Deleting an item moved the ones after it up a place, so their links pointed at the wrong item. Items now have an `id` and links are `{ type, id }` (§4.1). `IdMigration.migratePlanLinks(s)` rewrites older data, in place: + +| What | Becomes | +|---|---| +| An item with no `id` (or one an earlier item in the list already has) | `'_m'`, n = its position when the migration runs (`bud_m0`, `bkt_m2` …); `_2`, `_3` … if that id is taken | +| A link `{ type, idx }` with idx inside the list | `{ type, id: list[idx].id }`: the item it already pointed at | +| A link whose idx is past the end of the list (or not a whole number) | dropped; an edit left with nothing else in it is removed | +| A link whose list isn't in the object (an export without it), a link of another type, a link that already has an id | left as is | + +**Where it runs:** inside `migrateState()`, so in the same three places as the account codes: +- **Boot** (`atBoot()`): on State, then `storePlanLinks()` writes State's `budgets`, `buckets`, `debts` and `txOverrides` back through `lsSet()` (localStorage, IndexedDB `app_state` and the debounced state-file save). It writes them when the migration changed State, or when a copy in browser storage still has old links or items without ids (State came from the state file, already migrated). The four keys are written together, so a copy's links always come with the lists they point into. +- **The state file** (`loadStateFromFile()`): it rewrites the loaded copy and schedules a save, as for account codes. `_restoreStateIfBrowserEmpty()` loads through it too. +- **JSON import** (`importJsonFile()` calls `migrateState()`): the export's lists and links are rewritten before they replace State's. + +One log line (`[FinLens] Plan links: …`) says what changed and where. + +**Rules** +- **The ids it gives depend only on position**, so the same old data gets the same ids wherever it's migrated (browser storage, the state file, an export), and a link never changes target. Running it again changes nothing. +- **It doesn't touch the `tx_overrides` IndexedDB store.** Nothing writes that store any more, and links are read only from `State.txOverrides`. +- **New items never get `_m` ids:** they get random ones from `newPlanId()`. diff --git a/README.md b/README.md index a8f17ee..376455b 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.6  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.7  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.6 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.7 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index 98fd848..1a5775a 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
-
v1.16.6 · FinLens
+
v1.16.7 · FinLens
diff --git a/js/core.js b/js/core.js index b811aec..e3c6049 100644 --- a/js/core.js +++ b/js/core.js @@ -23,6 +23,27 @@ const hash = (s) => { for (let i=0;i x && x.id)); + for (;;) { + let s = ''; + try { s = Array.from(crypto.getRandomValues(new Uint8Array(10)), b => (b % 36).toString(36)).join(''); } + catch (e) { while (s.length < 10) s += Math.random().toString(36).slice(2); s = s.slice(0, 10); } + const id = prefix + '_' + s; + if (!taken.has(id)) return id; + } +} const lsGet = (k, def) => { try { const v=localStorage.getItem('finlens_'+k); return v?JSON.parse(v):def; } catch(e){ return def; } @@ -155,9 +176,12 @@ async function loadStateFromFile() { .filter(t => !isNaN(t.date)) .sort((a, b) => b.date - a.date); } - // A file written before v1.12.0 (or an old backup) uses the old account codes: - // rewrite them (migrate.js) and save the file again once it's loaded. - if (IdMigration.migrateState(loaded).changed.length) _saveStateDebounced(State); + // A file written before v1.12.0 (or an old backup) uses the old account codes, and one + // written before v1.16.7 links transactions to plan items by position: rewrite them + // (migrate.js) and save the file again once it's loaded. + const migrated = IdMigration.migrateState(loaded); + if (migrated.changed.length) _saveStateDebounced(State); + IdMigration.logPlanLinks(migrated.plan, 'finlens-state.json'); console.log('[FinLens] State loaded from finlens-state.json'); return loaded; } catch(e) { @@ -368,7 +392,7 @@ const State = { debts: lsGet('debts', []), bills: lsGet('bills', []), recurringConfirmed: lsGet(storageKey('recurringConfirmed'), {}), // stored as 'recurring' - txOverrides: lsGet('txOverrides', {}), // id -> { description, categories, notes, isBill, isRecurring, isSubscription, type, accountOverride } + txOverrides: lsGet('txOverrides', {}), // id -> { description, categories, notes, isBill, isRecurring, isSubscription, type, accountOverride, link: { type, id } } manualBalances: lsGet('manualBalances', {}), // id -> amount; id+'_limit' -> limit; id+'_initial' -> initial balance categoryRules: lsGet(storageKey('categoryRules'), []), // stored as 'catRules' categories: lsGet('categories', null) || [ diff --git a/js/migrate.js b/js/migrate.js index a7c1690..a6b28cc 100644 --- a/js/migrate.js +++ b/js/migrate.js @@ -14,6 +14,9 @@ // change too. The stored transaction lacks two of the hash inputs (the bank's time or // the post date), but the hash is linear enough to swap the account part of an existing // id without them: see _rekey(). +// +// v1.16.7: budgets, buckets and debts get ids, and transaction links point at them by id +// instead of list position (migratePlanLinks(), further down). const IdMigration = { // Account kinds and BANK_SCHEMAS ids KINDS: { ally_checking: 'bank_checking', ally_savings: 'bank_savings', chase: 'credit_card' }, @@ -204,12 +207,14 @@ const IdMigration = { // Rewrites a state object in place: State, a parsed finlens-state.json (transactions // already rebuilt with reconstituteTx()), or a JSON export. Safe to run on data that's // already new: nothing matches, nothing changes. - // Returns { changed: [keys], idMap: Map(old tx id → new), kept: count of transactions - // whose id couldn't be traced and so kept their old id }. + // Returns { changed: [keys], codes: [keys the account codes changed], idMap: Map(old tx + // id → new), kept: count of transactions whose id couldn't be traced and so kept their + // old id, plan: migratePlanLinks() result }. + // Also gives plan items their ids and rewrites old transaction links (v1.16.7, below). migrateState(s) { const changed = [], idMap = new Map(); let kept = 0; - if (!s || typeof s !== 'object') return { changed, idMap, kept }; + if (!s || typeof s !== 'object') return { changed, codes: [], idMap, kept, plan: this.migratePlanLinks(null) }; const txs = Array.isArray(s.transactions) ? s.transactions.filter((t) => t && typeof t === 'object') : []; const oldAccounts = [...new Set([...Object.keys(s.accounts || {}), ...txs.map((t) => t.account)])] @@ -243,7 +248,101 @@ const IdMigration = { if (Array.isArray(s.fileMeta)) { s.fileMeta = s.fileMeta.map((f) => (f && this.KINDS[f.kind]) ? { ...f, kind: this.kind(f.kind), account: this.accountName(f.account) } : f); } - return { changed, idMap, kept }; + + // v1.16.7: plan item ids and transaction links (below) + const codes = changed.slice(); + const plan = this.migratePlanLinks(s); + plan.changed.forEach((k) => { if (!changed.includes(k)) changed.push(k); }); + return { changed, codes, idMap, kept, plan }; + }, + + /* ---------- v1.16.7: plan item ids and transaction links ---------- */ + // Up to v1.16.6 a transaction's link to a budget, bucket or debt (txOverrides[id].link) + // was { type, idx }: the item's position in its list. Deleting an item moved the ones + // after it up a place, so their links pointed at the wrong item. Items now have a stable + // `id` and a link is { type, id } (PLAN_LINK_TYPES and newPlanId() in core.js). + // + // An item without an id gets `_m`, n being its position when this runs. The id + // depends only on the position, so the same old data gets the same ids wherever it's + // migrated (browser storage, finlens-state.json, an export), and running it again + // changes nothing. A link { type, idx } becomes { type, id: list[idx].id }: the item it + // pointed at, so no link changes target. A link past the end of its list pointed at + // nothing and is dropped. + PLAN_KEYS: ['budgets', 'buckets', 'debts', 'txOverrides'], + + _isOldLink(l) { + return !!(l && typeof l === 'object' && PLAN_LINK_TYPES[l.type] && !(typeof l.id === 'string' && l.id)); + }, + + // Gives each item of `list` without an id (or with one an earlier item already has) its + // `_m` id, in place. Returns how many it gave. + _assignPlanIds(type, list) { + const prefix = PLAN_LINK_TYPES[type][1]; + const seen = new Set(), need = []; + list.forEach((it, i) => { + if (!it || typeof it !== 'object') return; + if (typeof it.id === 'string' && it.id && !seen.has(it.id)) seen.add(it.id); + else need.push(i); + }); + for (const i of need) { + let id = `${prefix}_m${i}`; + for (let k = 2; seen.has(id); k++) id = `${prefix}_m${i}_${k}`; + list[i].id = id; + seen.add(id); + } + return need.length; + }, + + // Rewrites s.budgets, s.buckets, s.debts and the links in s.txOverrides, in place. A link + // whose list isn't in `s` (an export without it) is left for the boot step to resolve. + // An edit left with nothing in it once its link is dropped is removed. + // Returns { changed: [keys], ids, links, dropped }. + migratePlanLinks(s) { + const out = { changed: [], ids: 0, links: 0, dropped: 0 }; + if (!s || typeof s !== 'object') return out; + for (const [type, [key]] of Object.entries(PLAN_LINK_TYPES)) { + if (!Array.isArray(s[key])) continue; + const n = this._assignPlanIds(type, s[key]); + if (n) { out.ids += n; out.changed.push(key); } + } + const ovs = s.txOverrides; + if (!ovs || typeof ovs !== 'object' || Array.isArray(ovs)) return out; + let touched = false; + for (const [txId, ov] of Object.entries(ovs)) { + const l = ov && ov.link; + if (!this._isOldLink(l)) continue; + const list = s[PLAN_LINK_TYPES[l.type][0]]; + if (!Array.isArray(list)) continue; + const item = Number.isInteger(l.idx) && l.idx >= 0 ? list[l.idx] : null; + if (item && typeof item === 'object' && item.id) { ov.link = { type: l.type, id: item.id }; out.links++; } + else { delete ov.link; if (!Object.keys(ov).length) delete ovs[txId]; out.dropped++; } + touched = true; + } + if (touched) out.changed.push('txOverrides'); + return out; + }, + + // Boot: browser storage (localStorage + IndexedDB app_state, through lsSet, which also + // schedules the state-file save) gets State's budgets, buckets, debts and txOverrides + // when the migration changed them, or when a copy there still needs it (State came from + // finlens-state.json, which loadStateFromFile() had already migrated). The four are + // written together, so a copy's links always come with the lists they point into. + async storePlanLinks(plan) { + const needs = (copy) => this.migratePlanLinks(JSON.parse(JSON.stringify(copy))).changed.length > 0; + let stale = !!(plan && plan.changed.length); + if (!stale) { + const ls = {}; + for (const k of this.PLAN_KEYS) ls[k] = lsGet(k, null); + stale = needs(ls); + } + if (!stale && typeof DB !== 'undefined' && DB._db) { + const idb = {}; + for (const k of this.PLAN_KEYS) idb[k] = await DB.getState(k, null); + stale = needs(idb); + } + if (!stale) return false; + for (const k of this.PLAN_KEYS) if (State[k] !== undefined) lsSet(k, State[k]); + return true; }, /* ---------- browser storage (IndexedDB finlens_db + localStorage) ---------- */ @@ -346,11 +445,22 @@ const IdMigration = { const mem = this.migrateState(State); const store = await this.migrateStores(new Map(mem.idMap)); if (mem.changed.length) _saveStateDebounced(State); - if (mem.changed.length || store.transactions) { + if (mem.codes.length || store.transactions) { const kept = Math.max(mem.kept, store.kept); console.log(`[FinLens] Renamed old account codes; ${store.idMap.size} transaction ids updated` + (kept ? `, ${kept} kept their old id (couldn't be traced)` : '')); } + // After migrateStores(), so State's txOverrides (account codes already renamed) is + // what browser storage keeps. + await this.storePlanLinks(mem.plan); + this.logPlanLinks(mem.plan, 'browser storage'); + }, + + // One log line when the plan-link step changed something (boot and loadStateFromFile()). + logPlanLinks(p, where) { + if (!p || !p.changed.length) return; + console.log(`[FinLens] Plan links: ${p.ids} budget, bucket or debt ids added, ${p.links} links rewritten, ` + + `${p.dropped} dropped (pointed past the end of the list), in ${where}`); }, // Edits saved under a transaction's old id (an export from an older version, or edits diff --git a/js/ui.js b/js/ui.js index e6840dd..a1cef64 100644 --- a/js/ui.js +++ b/js/ui.js @@ -472,9 +472,55 @@ function _formError(msg, el) { const _drawerFooter=(isEdit, saveId, saveLabel, delId)=> `${isEdit?``:''}`; +/* ---------- PLAN LINKS: transactions → budgets, buckets, debts (v1.16.7) ---------- */ +// A transaction's link is State.txOverrides[txId].link = { type: 'budget'|'bucket'|'debt', id }, +// the id of an item in State.budgets / buckets / debts (PLAN_LINK_TYPES, newPlanId() in core.js). +// Every item gets its id when it's created and keeps it when edited, so deleting one never +// moves another's links. Deleting one, or clearing its list, removes the links to it. +// The item a link points at, or null (no such type or id). +function planItem(type, id) { + const t=PLAN_LINK_TYPES[type]; + if (!t||typeof id!=='string'||!id) return null; + return (State[t[0]]||[]).find(x=>x&&x.id===id)||null; +} +// Transactions linked to item `id` of `type`, newest first. +function linkedTransactions(type, id) { + if (!id) return []; + return State.transactions.filter(t=>{ const l=(State.txOverrides[t.id]||{}).link; return !!l&&l.type===type&&l.id===id; }).sort((x,y)=>y.date-x.date); +} +// Removes the links to items of `type` whose id is `ids` (an id or a list of ids), or to +// every item of `type` when `ids` is 'all' (Data & reset → Clear budgets / buckets / debts). +// A missing id removes nothing. An edit left with nothing else in it goes too. +// Saves txOverrides if anything changed; returns the count. +function unlinkPlanItems(type, ids) { + const only=ids==='all'?null:new Set([].concat(ids).filter(Boolean)); + if (only&&!only.size) return 0; + const ovs=State.txOverrides||{}; + let n=0; + for (const [txId,ov] of Object.entries(ovs)) { + const l=ov&&ov.link; + if (!l||l.type!==type||(only&&!only.has(l.id))) continue; + delete ov.link; n++; + if (!Object.keys(ov).length) delete ovs[txId]; + } + if (n) lsSet('txOverrides',ovs); + return n; +} +// Items without an id (put in by hand, or by an older version in another tab) get one +// before a transaction can be linked to them. Boot gives every stored item one (migrate.js). +function ensurePlanIds() { + for (const [type,[key]] of Object.entries(PLAN_LINK_TYPES)) { + const list=State[key]||[]; + let n=0; + list.forEach(x=>{ if (x&&typeof x==='object'&&!x.id) { x.id=newPlanId(type,list); n++; } }); + if (n) lsSet(key,list); + } +} + /* ---------- BUDGET HELPERS ---------- */ -// State.budgets entries: { name, limit, categories:[…] }. Budgets saved before v1.15.0 may +// State.budgets entries: { id, name, limit, categories:[…] }. Budgets saved before v1.15.0 may // also carry a hex `color`; it's kept but no longer shown (rows are colored by status). +// id (v1.16.7): 'bud_…', given when the budget is created; transaction links point at it. // The suggested set is the starter budget when there's no spending to build one from. const SUGGESTED_BUDGETS=[ {name:'Food & Dining',limit:600,categories:['Food & Dining','Groceries']}, @@ -497,7 +543,7 @@ function starterBudgetsToAdd() { } function seedBudgets() { const add=starterBudgetsToAdd(); - if (add.length) { State.budgets.push(...add); lsSet('budgets',State.budgets); } + if (add.length) { add.forEach(b=>State.budgets.push({ ...b, id:newPlanId('budget',State.budgets) })); lsSet('budgets',State.budgets); } renderActive(); return add.length; } @@ -534,6 +580,7 @@ function saveBudget(i) { if (!categories.length) return _formError('Pick at least one category.', $('#bnCats input')); const prev=i>=0?State.budgets[i]:{}; const obj={ ...prev, name, limit:Math.max(0,parseFloat($('#bnLimit').value)||0), categories }; + obj.id=prev.id||newPlanId('budget',State.budgets); // kept when edited if (i>=0) State.budgets[i]=obj; else State.budgets.push(obj); lsSet('budgets',State.budgets); closeDrawer(); renderActive(); @@ -545,10 +592,12 @@ function setBudgetLimit(i, v) { lsSet('budgets',State.budgets); } // No confirm() here: the edit drawer's Delete button asks for a second click. -function deleteBudget(i){ State.budgets.splice(i,1); lsSet('budgets',State.budgets); renderActive(); } +// Links to the deleted budget go; links to the others point at them by id, so they stay. +function deleteBudget(i){ const [b]=State.budgets.splice(i,1); lsSet('budgets',State.budgets); if (b) unlinkPlanItems('budget',b.id); renderActive(); } /* ---------- SAVINGS BUCKET HELPERS ---------- */ -// State.buckets entries: { name, goal, current, targetDate:'YYYY-MM-DD'|'', icon, hue }. +// State.buckets entries: { id, name, goal, current, targetDate:'YYYY-MM-DD'|'', icon, hue }. +// id (v1.16.7): 'bkt_…', given when the bucket is created; transaction links point at it. // icon: a BUCKET_ICONS key, hue: one of BUCKET_HUES (v1.15.0). Buckets saved before have an // emoji icon and a hex color: until edited they show an icon guessed from the name and a // hue by position (the old values stay in the record). @@ -583,12 +632,12 @@ function bucketHue(b, i) { return BUCKET_HUES.includes(b.hue)?b.hue:BUCKET_HUES[ function bucketIconSvg(key, size=20) { return ``; } -function addBucket(b) { State.buckets.push(b); lsSet('buckets',State.buckets); } +function addBucket(b) { if (!b.id) b.id=newPlanId('bucket',State.buckets); State.buckets.push(b); lsSet('buckets',State.buckets); } // Edit bucket i in the drawer, or add one (i < 0). function editBucket(i) { const b=i>=0?State.buckets[i]:{name:'',goal:'',current:0,targetDate:''}; const icon=i>=0?bucketIconKey(b):'star', hue=i>=0?bucketHue(b,i):BUCKET_HUES[State.buckets.length%BUCKET_HUES.length]; - const linked=i<0?[]:State.transactions.filter(t=>{ const l=State.txOverrides[t.id]?.link; return l&&l.type==='bucket'&&l.idx===i; }).sort((x,y)=>y.date-x.date); + const linked=i<0?[]:linkedTransactions('bucket',b.id); openDrawer(`
@@ -620,15 +669,18 @@ function saveBucket(i) { targetDate:$('#bkDate').value||'', icon:($('input[name="bkIcon"]:checked')||{}).value||guessBucketIcon(name), hue:($('input[name="bkHue"]:checked')||{}).value||BUCKET_HUES[0] }; + obj.id=prev.id||newPlanId('bucket',State.buckets); // kept when edited if (i>=0) State.buckets[i]=obj; else State.buckets.push(obj); lsSet('buckets',State.buckets); closeDrawer(); renderActive(); } // No confirm() here: the edit drawer's Delete button asks for a second click. -function deleteBucket(i){ State.buckets.splice(i,1); lsSet('buckets',State.buckets); renderActive(); } +// Links to the deleted bucket go; links to the others point at them by id, so they stay. +function deleteBucket(i){ const [b]=State.buckets.splice(i,1); lsSet('buckets',State.buckets); if (b) unlinkPlanItems('bucket',b.id); renderActive(); } /* ---------- DEBT HELPERS ---------- */ -// State.debts entries: { name, type, balance, apr, minPayment, limit, dueDay, account? }. +// State.debts entries: { id, name, type, balance, apr, minPayment, limit, dueDay, account? }. +// id (v1.16.7): 'dbt_…', given when the debt is created; transaction links point at it. // account (v1.15.0): a credit card account from your CSVs. The balance and credit limit // then come from that account (debtBalance(), debtLimit() in aggregation.js); `balance` // keeps the value it had when last saved, used if the account is gone. @@ -706,12 +758,14 @@ function saveDebt(i) { obj.balance=Math.max(0,parseFloat($('#dtBal').value)||0); obj.limit=Math.max(0,parseFloat(limRaw)||0); } + obj.id=prev.id||newPlanId('debt',State.debts); // kept when edited (also a new debt started from a card) if (i>=0) State.debts[i]=obj; else State.debts.push(obj); lsSet('debts',State.debts); closeDrawer(); renderActive(); } // No confirm() here: the edit drawer's Delete button asks for a second click. -function deleteDebt(i){ State.debts.splice(i,1); lsSet('debts',State.debts); renderActive(); } +// Links to the deleted debt go; links to the others point at them by id, so they stay. +function deleteDebt(i){ const [d]=State.debts.splice(i,1); lsSet('debts',State.debts); if (d) unlinkPlanItems('debt',d.id); renderActive(); } // Older payoff simulation (before v1.15.0), kept unchanged for compatibility: pays every // minimum, then `extra` goes to the first debt in the given order that still has a diff --git a/js/views-cleanup.js b/js/views-cleanup.js index a3c712f..74245a0 100644 --- a/js/views-cleanup.js +++ b/js/views-cleanup.js @@ -98,6 +98,9 @@ const DataCleanup = { State[key] = fresh(item[2] !== undefined ? item[2] : []); lsSet(storageKey(key), State[key]); (this.PLAN_ALSO[key] || []).forEach(([sk, empty]) => { State[sk] = fresh(empty); lsSet(storageKey(sk), State[sk]); }); + // Budgets, buckets and debts: transaction links to them go too (saved as edits, v1.16.7). + const linkType = Object.keys(PLAN_LINK_TYPES).find(t => PLAN_LINK_TYPES[t][0] === key); + if (linkType) unlinkPlanItems(linkType, 'all'); await this._finish(`${item[1]} cleared.`); }, diff --git a/js/views-db.js b/js/views-db.js index 6ec69ac..1402d29 100644 --- a/js/views-db.js +++ b/js/views-db.js @@ -70,7 +70,7 @@ registerView('db-schema', 'DB Schema', (root) => { { name: 'isBill', type: 'boolean?', key: '' }, { name: 'isSubscription',type: 'boolean?', key: '' }, { name: 'accountOverride',type:'string?', key: '' }, - { name: 'link', type: 'object?', key: '', note: '{type,idx}' }, + { name: 'link', type: 'object?', key: '', note: '{type,id}' }, { name: 'modifiedAt', type: 'Date', key: '' }, ], }, diff --git a/js/views-main.js b/js/views-main.js index 602ef7c..95aad7f 100644 --- a/js/views-main.js +++ b/js/views-main.js @@ -747,10 +747,13 @@ function showTxDrawer(id) { const cur=t.categories&&t.categories.length?t.categories:[t.category]; const opts=[...new Set([...State.categories,...cur])]; const extra=cur.slice(1); - const lnk=ov.link; - const canLink=State.budgets.length||State.buckets.length||State.debts.length||lnk; - const linkItems=(type)=>type==='budget'?State.budgets:type==='bucket'?State.buckets:type==='debt'?State.debts:[]; - const linkOpts=(type,sel)=>linkItems(type).map((item,i)=>``).join(''); + // Links point at a budget, bucket or debt by its id (v1.16.7). One to an item that's + // gone shows as None, and saving drops it. + ensurePlanIds(); + const lnk=ov.link&&planItem(ov.link.type,ov.link.id)?ov.link:null; + const canLink=State.budgets.length||State.buckets.length||State.debts.length; + const linkItems=(type)=>PLAN_LINK_TYPES[type]?State[PLAN_LINK_TYPES[type][0]]||[]:[]; + const linkOpts=(type,sel)=>linkItems(type).map((item,i)=>``).join(''); openDrawer(`
${fmtSigned(t.amount)} @@ -778,11 +781,11 @@ function showTxDrawer(id) {
- +
`:''}

Edits are stored separately from the imported row, so re-importing the CSV never overwrites them.

`,{ title:'Transaction detail', @@ -790,7 +793,7 @@ function showTxDrawer(id) { const lt=$('#dLinkType'); if (lt) lt.onchange=()=>{ const tgt=$('#dLinkTarget'); - tgt.innerHTML=lt.value?linkOpts(lt.value,0):''; + tgt.innerHTML=lt.value?linkOpts(lt.value,null):''; tgt.hidden=!lt.value; }; $('#dSave').onclick=()=>{ @@ -807,7 +810,8 @@ function showTxDrawer(id) { o.isRecurring=$('#dRec').checked; o.isSubscription=$('#dSub').checked; const linkType=lt?lt.value:''; - if (linkType) o.link={ type:linkType, idx:parseInt($('#dLinkTarget').value)||0 }; + const linkId=linkType?$('#dLinkTarget').value:''; + if (linkType&&planItem(linkType,linkId)) o.link={ type:linkType, id:linkId }; else delete o.link; State.txOverrides[t.id]=o; lsSet('txOverrides',State.txOverrides); diff --git a/js/views-settings.js b/js/views-settings.js index 6507705..769b035 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) { /* ---- About (the Theme row is gone: light only for now) ---- */ appendHtml(root,`

About

-
VersionFinLens v1.16.6
+
VersionFinLens v1.16.7
`); /* ---- Anthropic API key ---- */