feat: page long and truncated lists
Lists that were cut off by a fixed LIMIT, or could grow without bound, are paged by keyset: the cursor holds the sort key and an ID, so pages neither skip nor repeat items as others are added. The audit logs had a timestamp-only cursor that could skip entries with equal times. The API returns at most 100 items per list (limit takes up to 500) with next_cursor and prev_cursor, passed back as after and before. The console shows Newer/Older (or Previous/Next) links and To the start, without JavaScript. Paged: incidents (optionally of one monitor), a monitor's results and evidence, a checker's results, the audit logs, members, maintenance windows, firing Alertmanager alerts, the monitors API and the admin lists of status pages and organizations, which move to their own admin pages. A monitor's page shows its latest incidents and results and links to all of them. The dashboard caps every group at 50 of its own monitors with a link to a paged view of the group, and gains a search by name or target. Lists filtered by permission after reading may show fewer items on a page. Closes #116 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
98fb5d3a82
commit
d7c5cd711e
63 files changed
+5427
-3041
No files matched your search
+142
-40
@@ -38,6 +38,9 @@ type GroupNode struct {
|
||||
Total int
|
||||
Monitors []MonitorRow
|
||||
Children []GroupNode
|
||||
// More counts the group's own monitors not shown; MoreURL shows them.
|
||||
More int
|
||||
MoreURL string
|
||||
}
|
||||
|
||||
// GroupOption is a group in a select; Label is indented by depth.
|
||||
@@ -49,7 +52,13 @@ type GroupOption struct {
|
||||
// DashboardView is the data of the monitor list. Root holds ungrouped
|
||||
// monitors and the top-level groups.
|
||||
type DashboardView struct {
|
||||
Root GroupNode
|
||||
Root GroupNode
|
||||
// Search, if set, lists Results instead of the tree.
|
||||
Search string
|
||||
Results []MonitorRow
|
||||
// Focus, if set, names the one group Root holds, paged by Pager.
|
||||
Focus string
|
||||
Pager Pager
|
||||
Empty bool
|
||||
CanWrite bool
|
||||
Counts map[Status]int
|
||||
@@ -155,16 +164,52 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
if v.Empty {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
||||
} else {
|
||||
<div class="border-t border-rule">
|
||||
@monitorList(v.Root.Monitors)
|
||||
for _, g := range v.Root.Children {
|
||||
@groupBlock(g)
|
||||
if !v.Empty {
|
||||
<form method="get" action="/" class="mb-4 flex max-w-md gap-2">
|
||||
if v.Range != "" {
|
||||
<input type="hidden" name="range" value={ v.Range }/>
|
||||
}
|
||||
</div>
|
||||
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
value={ v.Search }
|
||||
placeholder={ i18n.T(ctx, "monitors.search") }
|
||||
aria-label={ i18n.T(ctx, "monitors.search") }
|
||||
class="w-full border border-rule bg-transparent px-2.5 py-1.5 text-sm outline-none focus:border-ink"
|
||||
/>
|
||||
<button type="submit" class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "moderation.search_button") }</button>
|
||||
</form>
|
||||
}
|
||||
switch {
|
||||
case v.Empty:
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
||||
case v.Search != "":
|
||||
<p class="mb-3 text-sm"><a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "monitors.all") }</a></p>
|
||||
if len(v.Results) == 0 {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_match") }</p>
|
||||
} else {
|
||||
<div class="border-t border-rule">
|
||||
@monitorList(v.Results)
|
||||
</div>
|
||||
}
|
||||
@pager(v.Pager, "previous", "next")
|
||||
default:
|
||||
if v.Focus != "" {
|
||||
<p class="mb-3 text-sm">
|
||||
<a href="/" class="text-muted hover:text-ink">{ i18n.T(ctx, "monitors.all") }</a>
|
||||
<span class="text-muted">›</span>
|
||||
<span class="font-medium">{ v.Focus }</span>
|
||||
</p>
|
||||
}
|
||||
<div class="border-t border-rule">
|
||||
@monitorList(v.Root.Monitors)
|
||||
@moreLink(v.Root)
|
||||
for _, g := range v.Root.Children {
|
||||
@groupBlock(g)
|
||||
}
|
||||
</div>
|
||||
@pager(v.Pager, "previous", "next")
|
||||
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
|
||||
}
|
||||
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
|
||||
}
|
||||
@@ -193,6 +238,13 @@ templ monitorList(ms []MonitorRow) {
|
||||
}
|
||||
}
|
||||
|
||||
// moreLink leads to the monitors of a group that are not shown.
|
||||
templ moreLink(g GroupNode) {
|
||||
if g.More > 0 {
|
||||
<a href={ templ.SafeURL(g.MoreURL) } class="block border-b border-rule py-2.5 text-sm text-muted hover:text-ink">{ i18n.T(ctx, "monitors.show_all", "Count", g.More+len(g.Monitors)) } →</a>
|
||||
}
|
||||
}
|
||||
|
||||
// groupBlock renders a group and, recursively, its subgroups. <details>
|
||||
// makes groups collapsible without JavaScript.
|
||||
templ groupBlock(g GroupNode) {
|
||||
@@ -204,6 +256,7 @@ templ groupBlock(g GroupNode) {
|
||||
</summary>
|
||||
<div class="ml-4 border-l border-rule pl-4">
|
||||
@monitorList(g.Monitors)
|
||||
@moreLink(g)
|
||||
for _, c := range g.Children {
|
||||
@groupBlock(c)
|
||||
}
|
||||
@@ -248,6 +301,10 @@ type MonitorDetailView struct {
|
||||
Latency LatencyLine
|
||||
Recent []ResultRow
|
||||
Incidents []IncidentRow
|
||||
// MoreIncidents is set when the monitor has more incidents than shown.
|
||||
MoreIncidents bool
|
||||
// MoreResults is set when the monitor has more results than shown.
|
||||
MoreResults bool
|
||||
CanWrite bool
|
||||
// Maintenance lists current and upcoming maintenance.
|
||||
Maintenance []MaintenanceItem
|
||||
@@ -366,6 +423,9 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("incidents.title")
|
||||
@incidentList(v.Incidents, false)
|
||||
if v.MoreIncidents {
|
||||
<a href={ templ.SafeURL("/incidents?monitor=" + v.Row.ID) } class="mt-3 inline-block text-sm text-muted hover:text-ink">{ i18n.T(ctx, "incidents.all_of_monitor") } →</a>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
if len(v.Evidence) > 0 {
|
||||
@@ -373,37 +433,64 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
}
|
||||
<section>
|
||||
@sectionHeading("monitors.recent")
|
||||
<table class="w-full text-left text-sm">
|
||||
<tbody class="divide-y divide-rule border-y border-rule">
|
||||
for _, r := range v.Recent {
|
||||
<tr>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs whitespace-nowrap text-muted">{ r.Time }</td>
|
||||
<td class="py-1.5 pr-4">{ r.Region }</td>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs">
|
||||
@checkerCell(r.Checker)
|
||||
</td>
|
||||
<td class="py-1.5 pr-4">
|
||||
if r.OK {
|
||||
<span class="text-up">●</span>
|
||||
} else {
|
||||
<span class="text-down">●</span>
|
||||
}
|
||||
</td>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs">{ r.Latency }</td>
|
||||
<td class="py-1.5 font-mono text-xs text-muted">
|
||||
{ r.Detail }
|
||||
if r.EvidenceURL != "" {
|
||||
<a href={ templ.SafeURL(r.EvidenceURL) } class="ml-2 underline underline-offset-2 hover:text-ink">{ i18n.T(ctx, "evidence.show") }</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@resultTable(v.Recent)
|
||||
if v.MoreResults {
|
||||
<a href={ templ.SafeURL("/monitors/" + v.Row.ID + "/results") } class="mt-3 inline-block text-sm text-muted hover:text-ink">{ i18n.T(ctx, "monitors.all_results") } →</a>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
templ resultTable(rows []ResultRow) {
|
||||
<table class="w-full text-left text-sm">
|
||||
<tbody class="divide-y divide-rule border-y border-rule">
|
||||
for _, r := range rows {
|
||||
<tr>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs whitespace-nowrap text-muted">{ r.Time }</td>
|
||||
<td class="py-1.5 pr-4">{ r.Region }</td>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs">
|
||||
@checkerCell(r.Checker)
|
||||
</td>
|
||||
<td class="py-1.5 pr-4">
|
||||
if r.OK {
|
||||
<span class="text-up">●</span>
|
||||
} else {
|
||||
<span class="text-down">●</span>
|
||||
}
|
||||
</td>
|
||||
<td class="py-1.5 pr-4 font-mono text-xs">{ r.Latency }</td>
|
||||
<td class="py-1.5 font-mono text-xs text-muted">
|
||||
{ r.Detail }
|
||||
if r.EvidenceURL != "" {
|
||||
<a href={ templ.SafeURL(r.EvidenceURL) } class="ml-2 underline underline-offset-2 hover:text-ink">{ i18n.T(ctx, "evidence.show") }</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
// ResultsView is a page of a monitor's check results.
|
||||
type ResultsView struct {
|
||||
MonitorID, Monitor string
|
||||
Rows []ResultRow
|
||||
Pager Pager
|
||||
}
|
||||
|
||||
templ ResultsPage(p Page, me Me, v ResultsView) {
|
||||
@consoleShell(p, me) {
|
||||
<p class="mb-4 text-sm"><a href={ templ.SafeURL("/monitors/" + v.MonitorID) } class="text-muted hover:text-ink">← { v.Monitor }</a></p>
|
||||
@settingsHeading("monitors.results_title", "")
|
||||
if len(v.Rows) == 0 {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_results") }</p>
|
||||
} else {
|
||||
@resultTable(v.Rows)
|
||||
}
|
||||
@pager(v.Pager, "newer", "older")
|
||||
}
|
||||
}
|
||||
|
||||
templ incidentList(rows []IncidentRow, showMonitor bool) {
|
||||
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, r := range rows {
|
||||
@@ -428,14 +515,29 @@ templ incidentList(rows []IncidentRow, showMonitor bool) {
|
||||
</ul>
|
||||
}
|
||||
|
||||
templ IncidentsPage(p Page, me Me, rows []IncidentRow) {
|
||||
// IncidentsView is a page of incidents, of one monitor if Monitor is set.
|
||||
type IncidentsView struct {
|
||||
Rows []IncidentRow
|
||||
Pager Pager
|
||||
Monitor, MonitorID string
|
||||
}
|
||||
|
||||
templ IncidentsPage(p Page, me Me, v IncidentsView) {
|
||||
@consoleShell(p, me) {
|
||||
@settingsHeading("incidents.title", "")
|
||||
if len(rows) == 0 {
|
||||
if v.Monitor != "" {
|
||||
<p class="-mt-4 mb-6 text-sm">
|
||||
{ i18n.T(ctx, "incidents.of_monitor") }
|
||||
<a href={ templ.SafeURL("/monitors/" + v.MonitorID) } class="font-medium hover:underline">{ v.Monitor }</a>
|
||||
<a href="/incidents" class="ml-3 text-muted hover:text-ink">{ i18n.T(ctx, "incidents.all") }</a>
|
||||
</p>
|
||||
}
|
||||
if len(v.Rows) == 0 {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "incidents.none") }</p>
|
||||
} else {
|
||||
@incidentList(rows, true)
|
||||
@incidentList(v.Rows, v.Monitor == "")
|
||||
}
|
||||
@pager(v.Pager, "newer", "older")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user