Skip to content

Commit 793ed4a

Browse files
committed
fix: persist filter state across tab switches and clear on table replacement
1 parent 945994a commit 793ed4a

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

TablePro/Views/Main/Extensions/MainContentCoordinator+Filtering.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ extension MainContentCoordinator {
5959
self.filterStateManager.saveLastFilters(for: capturedTableName)
6060
}
6161

62+
// Persist filter state to tab so it survives tab switches
63+
self.tabManager.tabs[capturedTabIndex].filterState = self.filterStateManager.saveToTabState()
64+
6265
self.runQuery()
6366
}
6467
}
@@ -107,6 +110,7 @@ extension MainContentCoordinator {
107110
}
108111

109112
self.tabManager.tabs[capturedTabIndex].query = newQuery
113+
self.tabManager.tabs[capturedTabIndex].filterState = self.filterStateManager.saveToTabState()
110114
self.runQuery()
111115
}
112116
}
@@ -146,6 +150,7 @@ extension MainContentCoordinator {
146150
}
147151

148152
self.tabManager.tabs[capturedTabIndex].query = newQuery
153+
self.tabManager.tabs[capturedTabIndex].filterState = self.filterStateManager.saveToTabState()
149154
self.runQuery()
150155
}
151156
}

TablePro/Views/Main/Extensions/MainContentCoordinator+Navigation.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extension MainContentCoordinator {
113113
databaseType: connection.type,
114114
databaseName: currentDatabase
115115
) {
116+
filterStateManager.clearAll()
116117
if let tabIndex = tabManager.selectedTabIndex {
117118
tabManager.tabs[tabIndex].pagination.reset()
118119
toolbarState.isTableTab = true
@@ -180,6 +181,7 @@ extension MainContentCoordinator {
180181
databaseName: databaseName,
181182
isPreview: true
182183
)
184+
previewCoordinator.filterStateManager.clearAll()
183185
if let tabIndex = previewCoordinator.tabManager.selectedTabIndex {
184186
previewCoordinator.tabManager.tabs[tabIndex].showStructure = showStructure
185187
previewCoordinator.tabManager.tabs[tabIndex].pagination.reset()
@@ -206,6 +208,7 @@ extension MainContentCoordinator {
206208
databaseName: databaseName,
207209
isPreview: true
208210
)
211+
filterStateManager.clearAll()
209212
if let tabIndex = tabManager.selectedTabIndex {
210213
tabManager.tabs[tabIndex].showStructure = showStructure
211214
tabManager.tabs[tabIndex].pagination.reset()

TablePro/Views/Main/Extensions/MainContentCoordinator+TabSwitch.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ extension MainContentCoordinator {
1818
isHandlingTabSwitch = true
1919
defer { isHandlingTabSwitch = false }
2020

21-
// Persist the outgoing tab's unsaved changes so they survive the switch
21+
// Persist the outgoing tab's unsaved changes and filter state so they survive the switch
2222
if let oldId = oldTabId,
23-
let oldIndex = tabManager.tabs.firstIndex(where: { $0.id == oldId }),
24-
changeManager.hasChanges
23+
let oldIndex = tabManager.tabs.firstIndex(where: { $0.id == oldId })
2524
{
26-
tabManager.tabs[oldIndex].pendingChanges = changeManager.saveState()
25+
if changeManager.hasChanges {
26+
tabManager.tabs[oldIndex].pendingChanges = changeManager.saveState()
27+
}
28+
tabManager.tabs[oldIndex].filterState = filterStateManager.saveToTabState()
2729
}
2830

2931
if tabManager.tabs.count > 2 {

0 commit comments

Comments
 (0)