Skip to content

v1.9.0: Settings → Data & Reset tab (clean up data, DB, logs; start over) - #3

Merged
gitluis merged 8 commits into
masterfrom
data-cleanup-and-reset
Oct 25, 2026
Merged

gitluis merged 8 commits into
masterfrom
data-cleanup-and-reset

Conversation

@gitluis

@gitluis gitluis commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

#1 and #2 are merged, and this PR now targets master. Released as v1.9.0.

Summary

Adds Settings → 🧹 Data & Reset, one place to clean up imported data, the database and logs, or start over from scratch. Building it uncovered why resets didn't stick, and those bugs are fixed here.

Why "start over" didn't work before

FinLens keeps data in four places: localStorage, two IndexedDB databases (finlens_db, finlens_fs), and finlens-state.json in your CSV folder. Each one could undo a reset:

  • "Clear All Data" cleared nothing. It only removed localStorage keys, so on reload DB.loadAll() restored every transaction, budget and setting. I reproduced this: 257 transactions and the budget came back.
  • Cleared data could return from the state file. It's loaded first at boot but only rewritten 5 seconds after a change, so a quick reload restored it.
  • A connected folder re-imports its CSVs at boot whenever no transactions are loaded. This is now paused after a clear (see below).
  • Clearing transactions left empty account cards, because the accounts store was never cleared.

The new tab

Section What you can do
Imported data & database Clear transactions & accounts · clear the import log · clear transaction edits · Rebuild from folder (clear + re-import every CSV). Live counts from memory and IndexedDB. Plans, account names and balances are kept.
Your plans & history Clear budgets, bills, savings buckets, debts or AI history individually
CSV folder & backup file Disconnect the folder (FinLens forgets it; nothing on disk changes)
Start over from scratch Type RESET. Erases both IndexedDB databases, every finlens_* key (including the API key) and the folder connection, then reloads. finlens-state.json is renamed to finlens-state-backup-DDMMYYYY.json with the API key stripped (a second reset the same day gets -2, -3, … so no copy is overwritten), or deleted, your choice. CSV files are never touched.

Design notes:

  • Immediate file rewrite: after any clear, finlens-state.json is rewritten right away. If write access is refused, the tab warns that a reload may restore the data.
  • Clearing sticks after a reload: with a folder connected, Clear transactions & accounts pauses the boot re-import (csvAutoImportPaused, browser storage only). Any import you start ends the pause: Reload or Reconnect, Rebuild, picking a folder or files. Disconnect and Start over end it too. The banner, the tab and Settings → Import say when it's paused.
  • Click-again-to-confirm buttons replace confirm() dialogs. Browsers only show file-permission prompts within about 5 seconds of a click, and a dialog can outlast that.
  • Moved Danger Zone: the old Danger Zone left General, which keeps Display, the API key and a link to the new tab. clearAllData() now runs the full reset.

Commits

  1. 2bcf358 Fix "Pick CSV Files" landing on Overview. It showed a view that doesn't exist, hiding the file-assignment card. It now opens Settings → Import.
  2. f7e52a9 Primitives:
    • DB.counts/clearStores/destroy, and onversionchange so other tabs release the database.
    • State-file helpers and folder disconnect.
    • idbGet/idbSet/idbDel now close their connections.
    • The auto-save guard during a reset.
  3. a2ee30c The tab (js/views-cleanup.js, DataCleanup namespace), plus the Danger Zone move and the clearAllData() fix.
  4. 4b59df6 Release v1.9.0:
    • CHANGELOG entry.
    • CLAUDE.md §20, a storage map plus cleanup rules, including "any new storage must be added to the reset".
    • README tip and version strings.

Review revisions:

  • 724c0b2 Backup name: the backup file is now finlens-state-backup-DDMMYYYY.json, as requested.
  • b01fd0e Readable gray text across all tabs: --text-3 was about 2.5:1 on white and is now at least 4.7:1 in both themes. Sidebar grays and chart labels are fixed too.
  • 47e24f4 Clear sticks after a reload: in Luis's Edge test, F5 brought all 257 transactions back. The state file was correct, but boot re-imported the folder's CSVs because Edge keeps folder access across a reload while the tab is open. Clearing now pauses that re-import until you import again.

How it was tested

A headless Chromium run with the sample CSVs and a fake folder handle, so permissions can be granted or denied and file writes are captured. 33/33 new checks pass, and the earlier suites still pass (27/27, 18/18, 5/5).

Per-item cleanup:

  • Tab basics:
    • The tab shows the right counts.
    • The first click only arms a button, and it disarms after 4 seconds.
  • Each clear empties exactly its target:
    • The import log goes to 0.
    • Clearing edits restores the original descriptions.
    • Clearing budgets keeps bills.
    • Clearing transactions keeps plans, empties memory and the database, and resets the account filter.
  • State file:
    • It's rewritten immediately after a clear.
    • With write access denied, the warning appears.
  • Rebuild from folder, with seeded leftover duplicate rows, ends with 257 clean rows and 3 fresh log entries.
  • Disconnect forgets the folder and leaves its files untouched. The Rebuild row and the warning then disappear.

Start over:

  • The button stays disabled until exactly RESET is typed.
  • Archive option:
    • The state file is renamed to finlens-state-backup-DDMMYYYY.json, the copy keeps old data but not the API key, and CSVs are untouched.
    • A second reset the same day creates a -2 copy and leaves the first untouched.
    • The alert explains what happened.
  • After the reload: zero transactions, accounts, plans, edits and key; default theme; no folder; empty IndexedDB; no finlens_* keys. A second reload is still empty.
  • Delete option: the file is removed and no backup is made.
  • Without write access, clearAllData() still erases everything else, and the alert says the file couldn't be renamed.
  • "Pick CSV Files" opens Settings → Import with the assignment card.

Screenshots were checked in light and dark themes.

Review-revision tests: 25/25 checks with a simulated folder whose access either survives a reload (Edge or Chrome with the tab open) or drops back to a prompt (after a browser restart):

  • Clear, then reload three times: stays at 0 in memory and in IndexedDB, with no new import-log entries.
  • Ending the pause: Reload, Rebuild, Pick CSV Files and Disconnect each end it, and Start over leaves no flag behind.
  • Stale backup file: a quick F5 right after Reload can load a backup file written before the pause ended. That file can't re-pause the import.
  • Wiped browser storage: if browser storage is wiped, the folder still re-imports as a recovery.
  • Contrast: all 23 views and 6 Settings tabs render without errors in light and dark, and every visible muted/footnote label passes 4.5:1.

Please check before merging

  • Try Start over in a Chrome Guest window or a separate profile with the samples/ folder, not your real data.
    • Chrome will ask for permission to change the folder.
    • Confirm the backup file appears and the app reloads empty.
  • On your real data later: clearing anything while your folder is connected asks for write access, so the backup file can be updated. Allow it.

https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc

https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt


Generated by Claude Code

handleFilePick() showed the non-existent 'db-import' view, so showView() fell
back to Overview and the file-assignment card was never seen. Open
Settings -> Import instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc
- DB: STORES, counts(), clearStores(), destroy(); release the connection on
  versionchange so another tab can't block a reset.
- core.js: lsClearAll(), deleteIndexedDB(), folderWithWriteAccess(),
  saveStateNow(), retireStateFile() (archive with key stripped, or delete),
  forgetDataFolder(); saveStateToFile() is a no-op while a reset is running.
- idbGet/idbSet/idbDel close their connections so finlens_fs can be deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc
New views-cleanup.js (DataCleanup namespace):
- Clear imported transactions & accounts, the import log, or transaction
  edits; clear budgets, bills, buckets, debts or AI history individually.
- Rebuild from folder: clear imported data + log, then re-import every CSV.
- Disconnect the CSV folder (nothing on disk changes).
- Start over (type RESET): retire finlens-state.json (rename to a backup
  or delete), delete both IndexedDB databases and all finlens_* keys, reload.
- After clearing, finlens-state.json is rewritten immediately so a reload
  can't restore the cleared data.
- Two-step confirm buttons keep a fresh user gesture for permission prompts.

The Danger Zone moves out of General. clearAllData() now runs the full reset;
before, it only cleared localStorage and IndexedDB restored everything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc
…anup-and-reset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc
Requested in review. A second reset on the same day gets -2, -3, … so an
earlier copy is never overwritten. Updated .gitignore, the radio label (now
shows the real name), CLAUDE.md, README and CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AT1Bh6Sscb8ogzzuf8U3Jc
Review feedback on #3: gray-on-white text was hard to read.

- --text-3 #94A3B8 -> #5B6B80 (light) and #64748B -> #8190A6 (dark).
  Was 2.3-2.6:1 on light surfaces and 3.3-3.9:1 on dark; now at least
  4.7:1 everywhere (WCAG AA). Used by .muted, .footnote and ~20 inline
  styles, so the fix reaches every tab.
- Sidebar group headers, brand subtitle and footer: hard-coded
  #475569/#64748b (2.3-3.6:1) -> new --sidebar-muted token (6.7:1).
- applyTheme() sets Chart.defaults.color to --text-2, replacing
  Chart.js's #666 (hard to read in dark mode).
- CHANGELOG (1.9.0) and CLAUDE.md §6 contrast rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
@gitluis gitluis removed their assignment Oct 25, 2026
Review feedback on #3 (Test 5): with a folder connected, F5 brought all
257 transactions back. The state file was correctly rewritten with 0,
but init.js re-imports the folder's CSVs whenever it boots with no
transactions and still has read access, which Edge/Chrome keep across a
reload while the tab is open.

- clearImported() sets State.csvAutoImportPaused when a folder is
  connected; init.js skips the boot re-import while it's set.
- loadFiles() clears it, so any import the user starts ends the pause
  (Reload/Reconnect, Rebuild, Pick a Folder, Pick CSV Files).
  forgetDataFolder() clears it; Start over removes it with the rest.
- Browser storage only (localStorage + app_state), not
  finlens-state.json: a debounced, older backup file must not be able to
  re-pause after the user imported again.
- The banner, the Data & Reset note and the Import tab say when
  automatic import is paused and how to end it.
- CHANGELOG (1.9.0), CLAUDE.md §4.1, §14, §20.

Tested headless with a simulated folder (permission kept across reloads,
and reset to prompt): 25/25 new checks, plus every view in both themes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
gitluis pushed a commit that referenced this pull request Oct 25, 2026
…lder-permission

Conflict in forgetDataFolder(): kept both resets (#7's folder-access
banner and #3's csvAutoImportPaused).

Also makes #7's Reconnect respect the pause: reconnectDataFolder() no
longer re-imports the CSVs, and _restoreStateIfBrowserEmpty() no longer
loads finlens-state.json over a browser that was cleared on purpose.
The Import tab's paused text matches the Reconnect button. CHANGELOG 1.9.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QoR1wxcaDjVVk3xmd5rRCt
@gitluis

gitluis commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

Review: manual test of data-cleanup-and-reset (47e24f4)

Tester: Luis
Date: 2026-10-24
Environment: Windows, Edge InPrivate, index.html opened via file://
Test data: the synthetic CSVs in samples/ (257 transactions across 3 accounts). No real data was used.

All tests below were run on the final commit, 47e24f4, and passed.

Earlier feedback, now addressed: two things came up while testing 724c0b2. Both are fixed on this branch:

  • b01fd0e Readable gray text: the gray secondary text (descriptions, counts, footnotes) was hard to read.
    • --text-3 went from about 2.5:1 contrast to at least 4.7:1 in light and dark mode (WCAG AA).
    • The sidebar headers, subtitle and version footer were also too faint and are fixed.
    • Chart axis labels now follow the theme's text color.
  • 47e24f4 Clear sticks after a reload: with a folder connected, Clear transactions & accounts came back after F5, because the folder's CSVs re-imported on load.
    • Clearing now pauses that automatic import until you start one yourself: Reload, Rebuild, picking a folder or files, Disconnect or Start over.
    • The banner, the Data & Reset note and the Import tab all say when it's paused.
Contrast before / after

Light, before:

09-contrast-before-light

Light, after:

10-contrast-after-light

Dark, before (sidebar headers, footnotes and chart labels):

11-contrast-before-dark

Dark, after:

12-contrast-after-dark

Results (47e24f4)

I started fresh: new InPrivate window, and old finlens-state*.json files removed from the folder.

# Test Expected Result
1 Settings → Import → Pick CSV Files Stays on Import with the file-assignment card (used to jump to Overview) ✅ Pass
2 Pick a Folder → samples 257 transactions loaded ✅ Pass
3 Data & Reset counts 257 loaded · 257 in database · 3 accounts; import log 3 entries ✅ Pass
4 Click-again-to-confirm on Import log First click arms the button, second clears it to 0 ✅ Pass
5 Clear transactions & accounts, then F5 (×3) Banner says they stay cleared; yellow "paused" note; 0 · 0 · 0 accounts after every reload; Import tab says automatic import is paused ✅ Pass
5b Settings → Import → Reload, then F5 257 transactions, and still 257 after F5 ✅ Pass
6 Clear again, then Rebuild "Rebuilt from 'samples': 257 transactions re-imported. Backup file updated."; import log 3 entries; note back to teal ✅ Pass
7 Disconnect Rebuild row and note gone; "No CSV folder is connected"; files on disk unchanged ✅ Pass
8 Pick the folder again → type RESET → Start over (Keep a copy) Alert names finlens-state-backup-24102026.json (API key removed); app reloads empty; finlens-state.json gone; CSVs untouched ✅ Pass
10 Readability in light and dark Descriptions, counts, sidebar headers and chart labels clearly readable ✅ Pass

Note on Test 8:

  • First run: the alert only said the app was reset, with no rename line. That's the expected message when the folder has no finlens-state.json at that moment, since there's nothing to archive.
  • Second run: after a backup was saved (11:16 PM), the alert named the renamed file.
  • Folder afterward: finlens-state-backup-24102026.json (117 KB), no finlens-state.json, and the three CSVs and README with their original dates.
Screenshots

Test 1: Pick CSV Files opens the assignment card

02-pick-csv-files

Test 2: 257 transactions loaded from the folder

03-pick-folder-257

Test 3: Data & Reset counts

04-data-reset-counts

Test 4: click again to confirm, then Import log cleared

05-click-again-to-confirm 06-import-log-cleared

Test 5: cleared, with the new banner and the paused note

16-r2-test5-clear-banner

Test 5: after F5, still 0 · 0 · 0 accounts

17-r2-test5-after-f5-still-0

Test 5: Import tab explains the pause

18-r2-test5-import-tab-paused

Test 5b: Reload brings back 257

19-r2-test5b-reload-257

Test 6: Rebuild from folder

20-r2-test6-rebuild-257

Test 7: Disconnect

21-r2-test7-disconnect

Test 8: Start over, first run (no finlens-state.json in the folder yet)

22-r2-test8-start-over-no-state-file

Test 8: Start over, second run (backup renamed)

23-r2-test8-start-over-renamed

Test 8: the folder afterward

24-r2-test8-folder-after-reset

Found along the way (not caused by this PR, fixed separately)

Not tested

  • Test 9: a second Start over on the same day (the -2 backup name). The run above didn't produce a second archive, so the -2 file wasn't observed here. It's covered by the headless tests.
  • Start over → Delete option: headless-tested only.
  • Real data: clearing data with my real CSV folder connected.

Verdict

Approved for 47e24f4. Every test passed, and the earlier feedback is addressed.

@gitluis
gitluis merged commit 005be61 into master Oct 25, 2026
@gitluis
gitluis deleted the data-cleanup-and-reset branch October 25, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants