Skip to content

feat(datagrid): restore a table's saved filter without running it - #3026

Merged
datlechin merged 1 commit into
mainfrom
feat/filter-restore-without-applying
Sep 20, 2026
Merged

datlechin merged 1 commit into
mainfrom
feat/filter-restore-without-applying

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #3006

Reopening a table now brings its filter rows back without necessarily running them, and rows typed into the filter bar and never applied survive closing the tab.

Root cause

TabFilterState.commit was answering three different questions with one bit:

  1. Which rows the grid's query was built from. Read everywhere downstream through appliedFilters / hasAppliedFilters / executedFilters: query building, pagination, refresh, the status bar, tab reuse.
  2. Whether this table's filters are worth writing to disk. persistedState opened with guard commit != nil, and FilterSettingsStorage.saveLastFilters treats an empty array as a delete. So a filter that was not running did not merely fail to save, it deleted the table's saved filter.
  3. Whether restored rows are visible at all. resolvedRestoredState set commit = .all unconditionally so the rows would show.

Nothing in TabFilterState or PersistedFilterState could say "these rows exist and are not running", so the request was not expressible, and the same conflation was already producing four defects on its own.

What changed

commit keeps meaning (1) and only (1). Persistence and restore each get their own answer.

  • PersistedFilterState carries isApplied. A plain flag rather than the FilterCommit: persistedState drops invalid rows, and nothing clears a .solo commit whose row became invalid, so that id could reach disk pointing at a row no longer in the file and restore to nothing applied over a panel full of rows. An applied set restores as .all over the rows that survived, each keeping its own enabled flag. A file with no flag decodes as applied, which is what every file written so far means.
  • persistedState saves the rows whether or not they are running. An empty row list still saves nothing, which the storage reads as a delete, and Remove All Filters is the gesture that produces one.
  • resolvedRestoredState never fabricates a commit.
  • FilterPanelDefaultState split into the two axes it was conflating. Saved Filters (Restore and apply / Restore without applying / Don't save) decides what happens to the rows; Always Show Filter Bar decides whether the bar opens on a table that has no filter. Both stay in the filter bar's own popover: the HIG's Settings guidance names filtering a list as its example of an option that belongs in the screen it affects.
  • Migration runs in FilterSettings.init(from:) rather than behind a one-shot UserDefaults flag. The flag version rewrote a stored alwaysHide once and stranded anyone who set it again afterwards; that block is removed.
  • Restore and apply stays the default, so nothing changes for anyone who has not gone looking for the option.
  • Don't save stops reading and stops writing, and never deletes. Falling through to an empty write would delete the file, so the option could never be turned back on.

Pre-existing defects fixed with it

Each one makes the new behaviour wrong or unsafe, so they could not be left for later.

A filter row typed and never applied already counted as applied. resolvedRestoredState set commit = .all even when nothing was saved, so every table tab opened in that state. Typing a valid row then resolved through appliedFilters immediately: the status bar read "1 filters applied", its icon filled, and the next page turn or Cmd+R ran the filter, landing on an offset taken in the unfiltered set.

Only the selected tab restored its filters. applyRestoredGroup restored for tabManager.selectedTab alone, and PersistedTab carries no filter state, so every other restored table tab came back empty. The next tab switch then called saveLastFilters on it, which wrote an empty set over the filters on disk and deleted them. This is the reporter's own sentence, and it failed for every tab but one.

Apply committed and wrote to disk before the unsaved-changes guard. applyAllFilters set commit and persisted, and only then did onApply take the guard. Cancelling left the filter marked applied and saved over rows it had never run.

Clear deleted the table's saved rows. The one gesture that produces "rows kept, nothing running" was also the one that destroyed the saved state. It now saves them unapplied, which is the whole point of the issue.

Closing a tab never saved its filters. closeTabsByUser removes the tab before the selection moves, so the tab-switch save never sees it. An applied filter was written when it was applied; rows that were never applied had no save point at all, which is the reporter's second sentence.

Restore never dropped a stale WHERE. A tab reopened from the recently closed history carries the last filtered SQL it ran in its persisted query. Bringing the filter back unapplied without rebuilding would keep running that WHERE while the panel reported nothing applied. Restore now rebuilds for the selected tab, and prepareTableTabFirstLoad rebuilds unconditionally. Session restore was already safe, because handleRestoreOrDefault rewrites every table tab's query to a base query first.

A tab that is not selected gets its filter state and nothing else. Its schema columns are not loaded (prepareTableTabFirstLoad gates that on selection) so a query built then would type its values by guessing at their text, and rebuildTableQuery writes executedFilters, which foreign-key navigation trusts as the record of what the rows on screen were fetched with. That tab has no rows.

Tests

103 cases pass across FilterRestoreTests, FilterSettingsStorageTests, TabFilterStateTests, MainContentCoordinatorTabSwitchTests and the new FilterPersistenceRoundTripTests.

New coverage: each restore option end to end; a typed-and-never-applied row surviving a reopen; a background tab restoring its own filters; a closed tab saving the rows left in its bar; a stale WHERE dropped on an unapplied restore; Don't save leaving the file on disk; the legacy panelState file mapping onto both axes, read twice for idempotence; a filter file with no isApplied key decoding as applied.

TableProUITests/FilterPersistenceUITests covers the flow: apply a filter, press Clear, browse to another table and back, and the rows are in the bar with Clear dimmed. Clear is the observable state on both counts, since it exists only inside the filter bar and is enabled only while a filter is running. The Saved Filters picker itself is not driven from a UI test: reaching it means a menu and a popover, and the scrolling-menu click lands unreliably on the runner. Its three options are covered by unit tests over resolvedRestoredState and by the round-trip suite.

Two existing tests changed because the specification changed, not to match new output. TabFilterStateTests.persistedStateIsEmptyWithNothingCommitted asserted that an unapplied set saves nothing, which is defect 2 above. MainContentCoordinatorTabSwitchTests.tabSwitchAfterClearKeepsSavedFiltersCleared asserted that Clear leaves nothing on disk, which is what this issue asks to change.

Verification

  • verify.sh build: PASS
  • verify.sh test (the five suites above): PASS, 103 executed, 103 passed
  • build-for-testing over TableProUITests: TEST BUILD SUCCEEDED
  • verify.sh lint over every changed Swift file: PASS
  • docs/scripts/check-writing-style.sh and check-docs-against-source.py: both pass

Review

Codex was unavailable (the workspace is out of credits until 22 September), so the second-model pass was Skill(code-review) at high effort. It raised five findings. Three are fixed here: FilterSettings.encode(to:) dropped panelState, so a rollback to an older build would throw keyNotFound and reset Default Column and Default Operator along with the restore behaviour; the restore loop ran before the hidden-columns restore, inverting the previous order; and the loop's !content.query.isEmpty gate left open the hole its own comment describes. It also caught that restoreFiltersForTable(_:) no longer used its parameter, now restoreFiltersForSelectedTab().

Two were declined. Remove All Filters cannot delete while Saved Filters is Don't save, which is that option's contract and what its footer states: nothing is written in either direction, which is what makes turning it off reversible. Reaching through to delete a file the setting says is being left alone is the more surprising behaviour, so the doc comment was corrected instead. And isApplied follows commit, so Restore without applying leaves the flag false, which is what the flag means: whether the rows were running when they were saved. Pressing Apply sets commit and saves true.

It also caught a factual error in two comments: handleRestoreOrDefault rewrites every restored table tab's query to a base query, so the stale WHERE is the Reopen-Closed-Tab path and not session restore. Both are corrected.

Not in this change

  • Hidden-column restore is selection-bound in the same way, so a restored background tab still comes back with its hidden columns showing. It persists only on explicit mutation, so nothing is destroyed, and it is a separate feature's gap.
  • Redis key-pattern search ignores Saved Filters. FilterSettingsPopover is unreachable on a browse-search connection, which swaps in KeyPatternSearchBar instead, and BrowseSearchState has no draft-versus-applied distinction: its pattern is the query.
  • A dropped table, schema or database leaves its saved filter file behind, because CatalogEditAdoption has no hook into TableScopedSettingsRegistry for a drop. Reported separately.

@mintlify

mintlify Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
TablePro 🟢 Ready View Preview Sep 20, 2026, 4:43 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

This branch was successfully deployed

1 active deployment
staging - docs — 7b624cfe Deployed Sep 20, 2026 by mintlify[bot]
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.

Add support persist filter without apply filter

1 participant