status usage bars should all line up
This commit is contained in:
@@ -79,15 +79,7 @@ struct StatusView: View {
|
||||
section("Running turns")
|
||||
TurnList(status: status)
|
||||
section("Rate limits")
|
||||
let vendors = status.rateLimits.additionalProperties.keys.sorted()
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ForEach(vendors, id: \.self) { v in
|
||||
RateLimitCard(vendor: v, info: status.rateLimits.additionalProperties[v]!.value)
|
||||
}
|
||||
}
|
||||
if vendors.isEmpty {
|
||||
Text("No vendor has reported a rate-limit status since byre started.").foregroundStyle(Palette.muted)
|
||||
}
|
||||
RateLimits(limits: status.rateLimits.additionalProperties.mapValues { $0.value })
|
||||
section("Clients")
|
||||
ClientTable(status: status)
|
||||
section("Server")
|
||||
@@ -270,16 +262,33 @@ private struct TurnList: View {
|
||||
}
|
||||
}
|
||||
|
||||
private struct RateLimitCard: View {
|
||||
let vendor: String
|
||||
let info: JSONDict
|
||||
private struct RateLimits: View {
|
||||
let limits: [String: JSONDict]
|
||||
|
||||
var body: some View {
|
||||
if limits.isEmpty {
|
||||
Text("No vendor has reported a rate-limit status 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]!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func vendorRows(_ vendor: String, _ info: JSONDict) -> some View {
|
||||
let statusText = info["status"].map { jsString($0) } ?? "unknown"
|
||||
let tone = statusText == "allowed" ? Palette.ok : statusText == "rejected" ? Palette.danger : Palette.warn
|
||||
let windows = dict(info, "unifiedWindows") ?? [:]
|
||||
let rest = info.filter { !["status", "rateLimitType", "resetsAt", "unifiedWindows"].contains($0.key) }.sorted { $0.key < $1.key }
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
GridRow {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 10) {
|
||||
Text(vendor).font(Fonts.font(13, weight: 700)).foregroundStyle(Palette.text)
|
||||
Text(statusText).font(Fonts.font(11, weight: 700)).foregroundStyle(tone)
|
||||
@@ -293,40 +302,30 @@ private struct RateLimitCard: View {
|
||||
}
|
||||
.font(Fonts.font(11))
|
||||
.foregroundStyle(Palette.muted)
|
||||
if !windows.isEmpty {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
ForEach(windows.keys.sorted(), id: \.self) { name in
|
||||
let w = dict(windows, name) ?? [:]
|
||||
let used = number(w["utilization"])
|
||||
let elapsed = elapsedFraction(w)
|
||||
GridRow {
|
||||
Text(name)
|
||||
Text(used.map { "\(Int(($0 * 100).rounded()))%" } ?? "—")
|
||||
.foregroundStyle(used.map { $0 >= 0.9 ? Palette.danger : $0 >= 0.7 ? Palette.warn : Palette.text } ?? Palette.text)
|
||||
Text(elapsed.map { "\(Int(($0 * 100).rounded()))%" } ?? "—")
|
||||
PaceBar(used: used, elapsed: elapsed)
|
||||
.gridColumnAlignment(.leading)
|
||||
Text(number(w["resetsAt"]).map(resetText) ?? "—")
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
}
|
||||
}
|
||||
.padding(.top, 12)
|
||||
.gridCellColumns(5)
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
ForEach(windows.keys.sorted(), id: \.self) { name in
|
||||
let w = dict(windows, name) ?? [:]
|
||||
let used = number(w["utilization"])
|
||||
let elapsed = elapsedFraction(w)
|
||||
GridRow {
|
||||
Text(name)
|
||||
Text(used.map { "\(Int(($0 * 100).rounded()))%" } ?? "—")
|
||||
.foregroundStyle(used.map { $0 >= 0.9 ? Palette.danger : $0 >= 0.7 ? Palette.warn : Palette.text } ?? Palette.text)
|
||||
Text(elapsed.map { "\(Int(($0 * 100).rounded()))%" } ?? "—")
|
||||
PaceBar(used: used, elapsed: elapsed)
|
||||
Text(number(w["resetsAt"]).map(resetText) ?? "—")
|
||||
}
|
||||
if !rest.isEmpty {
|
||||
Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 2) {
|
||||
ForEach(rest, id: \.key) { k, v in
|
||||
GridRow {
|
||||
Text(k).foregroundStyle(Palette.muted)
|
||||
Text(v is JSONDict || v is [(any Sendable)?] ? compactJSONText(v) : jsString(v)).textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
Divider().overlay(Palette.border)
|
||||
}
|
||||
ForEach(rest, id: \.key) { k, v in
|
||||
GridRow {
|
||||
Text(k).foregroundStyle(Palette.muted)
|
||||
Text(v is JSONDict || v is [(any Sendable)?] ? compactJSONText(v) : jsString(v))
|
||||
.textSelection(.enabled)
|
||||
.gridCellColumns(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user