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
+17
-10
@@ -325,15 +325,17 @@ type adminOwner struct {
|
||||
Orgs int `json:"orgs"`
|
||||
}
|
||||
|
||||
func (s *Server) adminOrgs(ctx context.Context, search string) ([]adminOrg, error) {
|
||||
func (s *Server) adminOrgs(ctx context.Context, search string, pg pageReq) ([]adminOrg, pageInfo, error) {
|
||||
var rows []store.AdminListOrgsRow
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.AdminListOrgs(ctx, store.AdminListOrgsParams{
|
||||
Search: truncate(strings.TrimSpace(search), 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.AdminListOrgsRow) cursor { return cursor{T: r.CreatedAt, ID: r.ID} })
|
||||
defaults := s.platformLimits(ctx)
|
||||
out := make([]adminOrg, len(rows))
|
||||
for i, r := range rows {
|
||||
@@ -355,16 +357,20 @@ func (s *Server) adminOrgs(ctx context.Context, search string) ([]adminOrg, erro
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, err
|
||||
return out, info, err
|
||||
}
|
||||
|
||||
func (s *Server) adminListOrgs(c *gin.Context) {
|
||||
orgs, err := s.adminOrgs(c.Request.Context(), c.Query("q"))
|
||||
pg, ok := parsePage(c, apiPageSize)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
orgs, info, err := s.adminOrgs(c.Request.Context(), c.Query("q"), pg)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"orgs": orgs})
|
||||
c.JSON(http.StatusOK, gin.H{"orgs": orgs, "next_cursor": info.Next, "prev_cursor": info.Prev})
|
||||
}
|
||||
|
||||
func webLimits(l Limits) web.LimitsView { return web.LimitsView(l) }
|
||||
@@ -376,12 +382,13 @@ func optInt(v *int32) string {
|
||||
return strconv.Itoa(int(*v))
|
||||
}
|
||||
|
||||
func (s *Server) orgsView(c *gin.Context) (web.OrgsView, error) {
|
||||
func (s *Server) orgsView(c *gin.Context, pg pageReq) (web.OrgsView, error) {
|
||||
ctx := c.Request.Context()
|
||||
// The admin page searches organizations with oq; q is the status page
|
||||
// search.
|
||||
orgs, err := s.adminOrgs(ctx, c.Query("oq"))
|
||||
v := web.OrgsView{Search: strings.TrimSpace(c.Query("oq")), Limited: len(orgs) == moderationRows, Defaults: webLimits(s.platformLimits(ctx))}
|
||||
orgs, info, err := s.adminOrgs(ctx, c.Query("q"), pg)
|
||||
v := web.OrgsView{
|
||||
Search: strings.TrimSpace(c.Query("q")), Pager: pager(c, info), Next: c.Request.URL.RequestURI(),
|
||||
Defaults: webLimits(s.platformLimits(ctx)),
|
||||
}
|
||||
state := func(at *time.Time, reason string) string {
|
||||
switch {
|
||||
case at == nil:
|
||||
|
||||
Reference in new issue
Block a user