Skip to content

Commit d3be879

Browse files
committed
fix: pagination label truncation, duplicate PK row in card preview
1 parent 7dfb59f commit d3be879

1 file changed

Lines changed: 36 additions & 30 deletions

File tree

TableProMobile/TableProMobile/Views/DataBrowserView.swift

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,35 +97,33 @@ struct DataBrowserView: View {
9797
}
9898
}
9999
}
100+
.toolbar(rows.isEmpty ? .hidden : .visible, for: .bottomBar)
100101
.toolbar {
101-
if !rows.isEmpty {
102-
ToolbarItem(placement: .bottomBar) {
103-
Button {
104-
Task { await goToPreviousPage() }
105-
} label: {
106-
Image(systemName: "chevron.left")
107-
}
108-
.disabled(pagination.currentPage == 0 || isLoading)
109-
}
110-
ToolbarItem(placement: .bottomBar) {
111-
Spacer()
112-
}
113-
ToolbarItem(placement: .bottomBar) {
114-
Text(paginationLabel)
115-
.font(.footnote)
116-
.foregroundStyle(.secondary)
117-
}
118-
ToolbarItem(placement: .bottomBar) {
119-
Spacer()
102+
ToolbarItemGroup(placement: .bottomBar) {
103+
Button {
104+
Task { await goToPreviousPage() }
105+
} label: {
106+
Image(systemName: "chevron.left")
120107
}
121-
ToolbarItem(placement: .bottomBar) {
122-
Button {
123-
Task { await goToNextPage() }
124-
} label: {
125-
Image(systemName: "chevron.right")
126-
}
127-
.disabled(!pagination.hasNextPage || isLoading)
108+
.disabled(pagination.currentPage == 0 || isLoading)
109+
110+
Spacer()
111+
112+
Text(paginationLabel)
113+
.font(.footnote)
114+
.monospacedDigit()
115+
.foregroundStyle(.secondary)
116+
.lineLimit(1)
117+
.fixedSize()
118+
119+
Spacer()
120+
121+
Button {
122+
Task { await goToNextPage() }
123+
} label: {
124+
Image(systemName: "chevron.right")
128125
}
126+
.disabled(!pagination.hasNextPage || isLoading)
129127
}
130128
}
131129
.task { await loadData(isInitial: true) }
@@ -198,6 +196,7 @@ struct DataBrowserView: View {
198196
} label: {
199197
RowCard(
200198
columns: columns,
199+
columnDetails: columnDetails,
201200
row: row,
202201
maxPreviewColumns: maxPreviewColumns
203202
)
@@ -317,11 +316,17 @@ struct DataBrowserView: View {
317316

318317
private struct RowCard: View {
319318
let columns: [ColumnInfo]
319+
let columnDetails: [ColumnInfo]
320320
let row: [String?]
321321
let maxPreviewColumns: Int
322322

323+
private var pkColumnNames: Set<String> {
324+
Set(columnDetails.filter(\.isPrimaryKey).map(\.name))
325+
}
326+
323327
private var pkPair: (name: String, value: String)? {
324-
for (col, val) in zip(columns, row) where col.isPrimaryKey {
328+
let pkNames = pkColumnNames
329+
for (col, val) in zip(columns, row) where pkNames.contains(col.name) {
325330
return (col.name, val ?? "NULL")
326331
}
327332
if let first = columns.first {
@@ -331,9 +336,10 @@ private struct RowCard: View {
331336
}
332337

333338
private var previewPairs: [(name: String, value: String)] {
334-
let paired = zip(columns, row)
335-
return paired
336-
.filter { !$0.0.isPrimaryKey }
339+
let pkNames = pkColumnNames
340+
let titleName = pkPair?.name
341+
return zip(columns, row)
342+
.filter { !pkNames.contains($0.0.name) && $0.0.name != titleName }
337343
.prefix(maxPreviewColumns - 1)
338344
.map { ($0.0.name, $0.1 ?? "NULL") }
339345
}

0 commit comments

Comments
 (0)