Align rate limit table: one-line cells, separate Used percentage
This commit is contained in:
@@ -60,9 +60,9 @@ private func percentText(_ v: Double) -> String {
|
||||
"\(v.formatted(.number.precision(.fractionLength(0)).grouping(.never)))%"
|
||||
}
|
||||
|
||||
private func usedText(_ w: UsageWindow, _ fraction: Double?) -> String {
|
||||
private func amountText(_ w: UsageWindow) -> String {
|
||||
if w.unit == "percent" {
|
||||
return percentText(w.used)
|
||||
return ""
|
||||
}
|
||||
var s = amount(w.used, w.unit)
|
||||
if let limit = w.limit {
|
||||
@@ -71,12 +71,16 @@ private func usedText(_ w: UsageWindow, _ fraction: Double?) -> String {
|
||||
if w.unit != "usd" {
|
||||
s += " \(w.unit)"
|
||||
}
|
||||
if let fraction {
|
||||
s += " · \(percentText(fraction * 100))"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
private func usedText(_ w: UsageWindow, _ fraction: Double?) -> String {
|
||||
if w.unit == "percent" {
|
||||
return percentText(w.used)
|
||||
}
|
||||
return fraction.map { percentText($0 * 100) } ?? "—"
|
||||
}
|
||||
|
||||
struct StatusView: View {
|
||||
@Environment(Store.self) private var store
|
||||
@ViewState private var status: ServerStatus?
|
||||
@@ -287,19 +291,35 @@ private struct RateLimits: View {
|
||||
if limits.isEmpty {
|
||||
Text("No vendor has reported usage since byre started.").foregroundStyle(Palette.muted)
|
||||
} else {
|
||||
Grid(alignment: .leading, horizontalSpacing: 12, verticalSpacing: 2) {
|
||||
GridRow {
|
||||
ForEach(["Window", "Used", "Elapsed", "Pace", "Resets"], id: \.self) { h in
|
||||
Text(h).font(Fonts.font(11)).foregroundStyle(Palette.muted)
|
||||
}
|
||||
}
|
||||
ForEach(limits.keys.sorted(), id: \.self) { vendor in
|
||||
vendorRows(vendor, limits[vendor]!)
|
||||
ViewThatFits(in: .horizontal) {
|
||||
grid
|
||||
ScrollView(.horizontal) {
|
||||
grid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var grid: some View {
|
||||
Grid(alignment: .leading, horizontalSpacing: 12, verticalSpacing: 2) {
|
||||
GridRow {
|
||||
header("Window")
|
||||
header("Amount")
|
||||
header("Used").gridColumnAlignment(.trailing)
|
||||
header("Elapsed").gridColumnAlignment(.trailing)
|
||||
header("Pace")
|
||||
header("Resets")
|
||||
}
|
||||
ForEach(limits.keys.sorted(), id: \.self) { vendor in
|
||||
vendorRows(vendor, limits[vendor]!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func header(_ title: String) -> some View {
|
||||
Text(title).font(Fonts.font(11)).foregroundStyle(Palette.muted)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func vendorRows(_ vendor: String, _ usage: VendorUsage) -> some View {
|
||||
let rejected = usage.rejected != nil || usage.windows.contains { w in w.limit.map { w.used >= $0 } ?? false }
|
||||
@@ -311,19 +331,21 @@ private struct RateLimits: View {
|
||||
Text("as of \(since(usage.updatedAt))").font(Fonts.font(11)).foregroundStyle(Palette.muted)
|
||||
}
|
||||
.padding(.top, 12)
|
||||
.gridCellColumns(5)
|
||||
.gridCellColumns(6)
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
ForEach(Array(usage.windows.enumerated()), id: \.offset) { _, w in
|
||||
let used = w.limit.flatMap { $0 > 0 && (w.used / $0).isFinite ? w.used / $0 : nil }
|
||||
let elapsed = elapsedFraction(w)
|
||||
GridRow {
|
||||
Text(w.label)
|
||||
Text(w.label).fixedSize()
|
||||
Text(amountText(w)).fixedSize()
|
||||
Text(usedText(w, used))
|
||||
.foregroundStyle(used.map { $0 >= 0.9 ? Palette.danger : $0 >= 0.7 ? Palette.warn : Palette.text } ?? Palette.text)
|
||||
Text(elapsed.map { percentText($0 * 100) } ?? "—")
|
||||
.fixedSize()
|
||||
Text(elapsed.map { percentText($0 * 100) } ?? "—").fixedSize()
|
||||
PaceBar(used: used, elapsed: elapsed)
|
||||
Text(w.resetsAt.map(resetText) ?? "—")
|
||||
Text(w.resetsAt.map(resetText) ?? "—").fixedSize()
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user