77
88import SwiftUI
99
10- /// Status bar at the bottom of the results section
10+ struct StatusBarSnapshot : Equatable {
11+ let tabId : UUID ?
12+ let tabType : TabType ?
13+ let hasRows : Bool
14+ let hasColumns : Bool
15+ let rowCount : Int
16+ let hasTableName : Bool
17+ let pagination : PaginationState
18+ let statusMessage : String ?
19+
20+ init ( tab: QueryTab ? ) {
21+ self . tabId = tab? . id
22+ self . tabType = tab? . tabType
23+ self . hasRows = !( tab? . resultRows. isEmpty ?? true )
24+ self . hasColumns = !( tab? . resultColumns. isEmpty ?? true )
25+ self . rowCount = tab? . resultRows. count ?? 0
26+ self . hasTableName = tab? . tableContext. tableName != nil
27+ self . pagination = tab? . pagination ?? PaginationState ( )
28+ self . statusMessage = tab? . execution. statusMessage
29+ }
30+ }
31+
1132struct MainStatusBarView : View {
12- let tab : QueryTab ?
33+ let snapshot : StatusBarSnapshot
1334 let filterStateManager : FilterStateManager
1435 let columnVisibilityManager : ColumnVisibilityManager
1536 let allColumns : [ String ]
@@ -33,9 +54,8 @@ struct MainStatusBarView: View {
3354
3455 var body : some View {
3556 HStack {
36- // Left: View mode toggle
37- if let tab = tab {
38- if tab. tabType == . table, tab. tableContext. tableName != nil {
57+ if snapshot. tabId != nil {
58+ if snapshot. tabType == . table, snapshot. hasTableName {
3959 Picker ( String ( localized: " View Mode " ) , selection: $viewMode) {
4060 Label ( " Data " , systemImage: " tablecells " ) . tag ( ResultsViewMode . data)
4161 Label ( " Structure " , systemImage: " list.bullet.rectangle " ) . tag ( ResultsViewMode . structure)
@@ -45,7 +65,7 @@ struct MainStatusBarView: View {
4565 . pickerStyle ( . segmented)
4666 . frame ( width: 260 )
4767 . controlSize ( . small)
48- } else if !tab . resultColumns . isEmpty {
68+ } else if snapshot . hasColumns {
4969 Picker ( String ( localized: " View Mode " ) , selection: $viewMode) {
5070 Label ( " Data " , systemImage: " tablecells " ) . tag ( ResultsViewMode . data)
5171 Label ( " JSON " , systemImage: " curlybraces " ) . tag ( ResultsViewMode . json)
@@ -60,21 +80,21 @@ struct MainStatusBarView: View {
6080 Spacer ( )
6181
6282 // Center: Row info (selection or pagination summary) and status message
63- if let tab = tab , !tab . resultRows . isEmpty {
83+ if snapshot . hasRows {
6484 HStack ( spacing: 4 ) {
65- if tab . pagination. isLoadingMore {
85+ if snapshot . pagination. isLoadingMore {
6686 ProgressView ( )
6787 . controlSize ( . mini)
6888 Text ( " Loading… " )
6989 . font ( . caption)
7090 . foregroundStyle ( . secondary)
7191 } else {
72- Text ( rowInfoText ( for : tab ) )
92+ Text ( rowInfoText)
7393 . font ( . caption)
7494 . foregroundStyle ( . secondary)
7595 }
7696
77- if tab . tabType == . query && tab . pagination. hasMoreRows && !tab . pagination. isLoadingMore {
97+ if snapshot . tabType == . query && snapshot . pagination. hasMoreRows && !snapshot . pagination. isLoadingMore {
7898 Text ( " — " )
7999 . font ( . caption)
80100 . foregroundStyle ( . quaternary)
@@ -100,7 +120,7 @@ struct MainStatusBarView: View {
100120 . foregroundStyle ( . secondary)
101121 }
102122
103- if let statusMessage = tab . execution . statusMessage {
123+ if let statusMessage = snapshot . statusMessage {
104124 Text ( " · " )
105125 . foregroundStyle ( . tertiary)
106126 Text ( statusMessage)
@@ -115,7 +135,7 @@ struct MainStatusBarView: View {
115135 // Right: Columns, Filters toggle and Pagination controls
116136 HStack ( spacing: 8 ) {
117137 // Columns visibility button (works for both table and query tabs)
118- if let tab = tab , !tab . resultColumns . isEmpty {
138+ if snapshot . hasColumns {
119139 Button {
120140 showColumnPopover. toggle ( )
121141 } label: {
@@ -141,7 +161,7 @@ struct MainStatusBarView: View {
141161 }
142162
143163 // Filters toggle button
144- if let tab = tab , tab . tabType == . table, tab . tableContext . tableName != nil {
164+ if snapshot . tabType == . table, snapshot . hasTableName {
145165 Toggle ( isOn: Binding (
146166 get: { filterStateManager. isVisible } ,
147167 set: { _ in filterStateManager. toggle ( ) }
@@ -163,10 +183,10 @@ struct MainStatusBarView: View {
163183 }
164184
165185 // Pagination controls for table tabs
166- if let tab = tab , tab . tabType == . table, tab . tableContext . tableName != nil ,
167- let total = tab . pagination. totalRowCount, total > 0 {
186+ if snapshot . tabType == . table, snapshot . hasTableName ,
187+ let total = snapshot . pagination. totalRowCount, total > 0 {
168188 PaginationControlsView (
169- pagination: tab . pagination,
189+ pagination: snapshot . pagination,
170190 onFirst: onFirstPage,
171191 onPrevious: onPreviousPage,
172192 onNext: onNextPage,
@@ -181,16 +201,16 @@ struct MainStatusBarView: View {
181201 . padding ( . horizontal, 0 )
182202 . padding ( . vertical, 4 )
183203 . background ( Color ( nsColor: . controlBackgroundColor) )
184- . onChange ( of: tab ? . id ) { _, _ in
204+ . onChange ( of: snapshot . tabId ) { _, _ in
185205 showColumnPopover = false
186206 }
187207 }
188208
189209 /// Generate row info text based on selection and pagination state
190- private func rowInfoText( for tab : QueryTab ) -> String {
191- let loadedCount = tab . resultRows . count
210+ private var rowInfoText : String {
211+ let loadedCount = snapshot . rowCount
192212 let selectedCount = selectedRowIndices. count
193- let pagination = tab . pagination
213+ let pagination = snapshot . pagination
194214 let total = pagination. totalRowCount
195215
196216 if selectedCount > 0 {
@@ -199,15 +219,15 @@ struct MainStatusBarView: View {
199219 } else {
200220 return String ( format: String ( localized: " %d of %d rows selected " ) , selectedCount, loadedCount)
201221 }
202- } else if tab . tabType == . query && pagination. hasMoreRows {
222+ } else if snapshot . tabType == . query && pagination. hasMoreRows {
203223 let formattedCount = loadedCount. formatted ( . number. grouping ( . automatic) )
204224 if let total = total, total > 0 {
205225 let formattedTotal = total. formatted ( . number. grouping ( . automatic) )
206226 let prefix = pagination. isApproximateRowCount ? " ~ " : " "
207227 return String ( format: String ( localized: " %@ of %@%@ rows " ) , formattedCount, prefix, formattedTotal)
208228 }
209229 return String ( format: String ( localized: " %@ rows (more available) " ) , formattedCount)
210- } else if tab . tabType == . table, let total = total, total > 0 {
230+ } else if snapshot . tabType == . table, let total = total, total > 0 {
211231 let formattedTotal = total. formatted ( . number. grouping ( . automatic) )
212232 let prefix = pagination. isApproximateRowCount ? " ~ " : " "
213233
0 commit comments