feat: page long and truncated lists
ci / image (pull_request) Successful in 3m18s
ci / build (pull_request) Successful in 8m38s
ci / test (pull_request) Successful in 12m6s
ci / lint (pull_request) Successful in 15m0s

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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 21:40:25 +01:00
1 parent 98fb5d3a82
commit d7c5cd711e
63 files changed
+5427 -3041

No files matched your search

+15 -11
View File
@@ -1,6 +1,7 @@
package api
import (
"context"
"errors"
"net/http"
"strings"
@@ -51,18 +52,17 @@ type moderatedUser struct {
Admin bool `json:"admin,omitempty"`
}
const moderationRows = 500
func (s *Server) moderatedPages(c *gin.Context) ([]moderatedPage, error) {
ctx := c.Request.Context()
func (s *Server) moderatedPages(ctx context.Context, search string, pg pageReq) ([]moderatedPage, pageInfo, error) {
var rows []store.AdminListStatusPagesRow
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
var err error
rows, err = q.AdminListStatusPages(ctx, store.AdminListStatusPagesParams{
Search: truncate(strings.TrimSpace(c.Query("q")), 200), MaxRows: moderationRows,
Search: truncate(strings.TrimSpace(search), 200), MaxRows: pg.fetch(),
AfterT: pg.afterT(), AfterID: pg.afterID(), BeforeT: pg.beforeT(), BeforeID: pg.beforeID(),
})
return err
})
rows, info := paginate(pg, rows, func(r store.AdminListStatusPagesRow) cursor { return cursor{T: r.CreatedAt, ID: r.ID} })
out := make([]moderatedPage, len(rows))
for i, r := range rows {
p := &out[i]
@@ -75,16 +75,20 @@ func (s *Server) moderatedPages(c *gin.Context) ([]moderatedPage, error) {
p.Owner = &moderatedUser{r.OwnerID, r.OwnerEmail, r.OwnerDisabledAt, r.OwnerDisabledReason, r.OwnerIsAdmin}
}
}
return out, err
return out, info, err
}
func (s *Server) adminListStatusPages(c *gin.Context) {
pages, err := s.moderatedPages(c)
pg, ok := parsePage(c, apiPageSize)
if !ok {
return
}
pages, info, err := s.moderatedPages(c.Request.Context(), c.Query("q"), pg)
if err != nil {
internalError(c, err)
return
}
c.JSON(http.StatusOK, gin.H{"status_pages": pages})
c.JSON(http.StatusOK, gin.H{"status_pages": pages, "next_cursor": info.Next, "prev_cursor": info.Prev})
}
type suspensionRequest struct {
@@ -273,9 +277,9 @@ func (s *Server) adminDeleteUser(c *gin.Context) {
c.Status(http.StatusNoContent)
}
func (s *Server) moderationView(c *gin.Context) (web.ModerationView, error) {
pages, err := s.moderatedPages(c)
v := web.ModerationView{Search: strings.TrimSpace(c.Query("q")), Limited: len(pages) == moderationRows}
func (s *Server) moderationView(c *gin.Context, pg pageReq) (web.ModerationView, error) {
pages, info, err := s.moderatedPages(c.Request.Context(), c.Query("q"), pg)
v := web.ModerationView{Search: strings.TrimSpace(c.Query("q")), Pager: pager(c, info), Next: c.Request.URL.RequestURI()}
state := func(at *time.Time, reason string) string {
switch {
case at == nil: