feat(statuspages): page every group on its own and filter outages
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m3s
ci / test (pull_request) Successful in 12m33s
ci / build (pull_request) Successful in 18m44s
ci / image (pull_request) Successful in 5m29s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m3s
ci / test (pull_request) Successful in 12m33s
ci / build (pull_request) Successful in 18m44s
ci / image (pull_request) Successful in 5m29s
Paging all components of a status page at once left out whole groups on every page, which confused visitors. Every group now shows its first 25 components and pages them on its own (?p.<group>=N), keeping the pages of the other groups. Links jump back to the group. Visitors can also show only the components with an outage or degraded (?problems=1); groups without any are left out. The search stays. 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
9d01b62b98
commit
282ab27f81
7 files changed
+1057
-913
No files matched your search
+117
-90
@@ -31,33 +31,104 @@ type PublicAssets struct {
|
||||
Now time.Time
|
||||
// NoRefresh leaves out the periodic reload, on pages with a form.
|
||||
NoRefresh bool
|
||||
// PageSize is how many components the page lists at a time; 0 lists
|
||||
// all, as in a single-file export.
|
||||
// PageSize is how many of a section's own components the page lists
|
||||
// at a time; 0 lists all, as in a single-file export.
|
||||
PageSize int
|
||||
// Page is the zero-based page of components to show and Query what the
|
||||
// visitor searched them for.
|
||||
Page int
|
||||
Query string
|
||||
// Pages holds the zero-based page shown of the sections paged, by
|
||||
// their PublicSection.Key.
|
||||
Pages map[string]int
|
||||
// Query is what the visitor searched the components for; OnlyProblems
|
||||
// keeps those with an outage or degraded.
|
||||
Query string
|
||||
OnlyProblems bool
|
||||
}
|
||||
|
||||
// ComponentPage is the part of a status page's components one page of it
|
||||
// lists: the sections holding them, keeping the status and count of the
|
||||
// whole section.
|
||||
type ComponentPage struct {
|
||||
Sections []agentapi.Section
|
||||
// Page is the zero-based page shown, of Pages; Matches counts the
|
||||
// components the query found, of all of them.
|
||||
// PublicSection is a section of a status page as a request for it shows
|
||||
// it: the components of one page of the section's own, its status and
|
||||
// count those of the whole section.
|
||||
type PublicSection struct {
|
||||
Name string
|
||||
Status string
|
||||
Total int
|
||||
// Key identifies the section in the URLs paging it, e.g. "0.2".
|
||||
Key string
|
||||
Components []agentapi.Component
|
||||
Children []PublicSection
|
||||
// Page is the zero-based page of the section's own components shown,
|
||||
// of Pages.
|
||||
Page, Pages int
|
||||
Matches int
|
||||
Query string
|
||||
}
|
||||
|
||||
// PageComponents picks the components of page from sections, of those whose
|
||||
// name or section contains query. size 0 shows all of them.
|
||||
func PageComponents(sections []agentapi.Section, page, size int, query string) ComponentPage {
|
||||
query = strings.TrimSpace(query)
|
||||
needle := strings.ToLower(query)
|
||||
// ComponentView is what a request for a status page shows of its
|
||||
// components: every section paged on its own, filtered by a search and to
|
||||
// those with problems if the visitor asked.
|
||||
type ComponentView struct {
|
||||
Sections []PublicSection
|
||||
// Total counts all components, Matches those the filters leave and
|
||||
// Problems those with an outage or degraded.
|
||||
Total, Matches, Problems int
|
||||
Query string
|
||||
OnlyProblems bool
|
||||
|
||||
base string
|
||||
size int
|
||||
pages map[string]int
|
||||
}
|
||||
|
||||
// Filterable reports whether the page lists enough components to offer the
|
||||
// search and filter, or uses them.
|
||||
func (v ComponentView) Filterable() bool {
|
||||
return v.size > 0 && v.Total > v.size || v.Query != "" || v.OnlyProblems
|
||||
}
|
||||
|
||||
// Filtered reports whether a search or filter is in use.
|
||||
func (v ComponentView) Filtered() bool { return v.Query != "" || v.OnlyProblems }
|
||||
|
||||
// PageHref links page of the section key, keeping the other sections' pages
|
||||
// and the filters.
|
||||
func (v ComponentView) PageHref(key string, page int) string {
|
||||
q := url.Values{}
|
||||
if v.Query != "" {
|
||||
q.Set("q", v.Query)
|
||||
}
|
||||
if v.OnlyProblems {
|
||||
q.Set("problems", "1")
|
||||
}
|
||||
for k, p := range v.pages {
|
||||
if k != key && p > 0 {
|
||||
q.Set("p."+k, strconv.Itoa(p+1))
|
||||
}
|
||||
}
|
||||
if page > 0 {
|
||||
q.Set("p."+key, strconv.Itoa(page+1))
|
||||
}
|
||||
href := BackHref(v.base)
|
||||
if len(q) > 0 {
|
||||
href += "?" + q.Encode()
|
||||
}
|
||||
return href + "#g-" + key
|
||||
}
|
||||
|
||||
// ResetHref links the page without search, filter and paging.
|
||||
func (v ComponentView) ResetHref() string { return BackHref(v.base) }
|
||||
|
||||
// Problem reports whether a component counts as an outage for the filter.
|
||||
func Problem(c agentapi.Component) bool {
|
||||
return c.Status == agentapi.PageOutage || c.Status == agentapi.PageDegraded
|
||||
}
|
||||
|
||||
// PublicComponents decides which components of sections a request for the
|
||||
// page shows, as a.Query, a.OnlyProblems and a.Pages ask.
|
||||
func PublicComponents(sections []agentapi.Section, a PublicAssets) ComponentView {
|
||||
v := ComponentView{
|
||||
Query: strings.TrimSpace(a.Query), OnlyProblems: a.OnlyProblems,
|
||||
base: a.ComponentBase, size: a.PageSize, pages: a.Pages,
|
||||
}
|
||||
needle := strings.ToLower(v.Query)
|
||||
match := func(path []string, c agentapi.Component) bool {
|
||||
if v.OnlyProblems && !Problem(c) {
|
||||
return false
|
||||
}
|
||||
if needle == "" || strings.Contains(strings.ToLower(c.Name), needle) {
|
||||
return true
|
||||
}
|
||||
@@ -68,90 +139,46 @@ func PageComponents(sections []agentapi.Section, page, size int, query string) C
|
||||
}
|
||||
return false
|
||||
}
|
||||
// Components are counted in the order the page renders them: a
|
||||
// section's own, then its children's. Unnamed sections are top-level
|
||||
// lists without children.
|
||||
var count func(sec agentapi.Section, path []string) int
|
||||
count = func(sec agentapi.Section, path []string) int {
|
||||
filtered := v.Filtered()
|
||||
var walk func(sec agentapi.Section, key string, path []string) (PublicSection, bool)
|
||||
walk = func(sec agentapi.Section, key string, path []string) (PublicSection, bool) {
|
||||
ps := PublicSection{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec), Key: key, Pages: 1}
|
||||
if sec.Name != "" {
|
||||
path = append(path, sec.Name)
|
||||
}
|
||||
n := 0
|
||||
var own []agentapi.Component
|
||||
for _, c := range sec.Components {
|
||||
v.Total++
|
||||
if Problem(c) {
|
||||
v.Problems++
|
||||
}
|
||||
if match(path, c) {
|
||||
n++
|
||||
own = append(own, c)
|
||||
}
|
||||
}
|
||||
v.Matches += len(own)
|
||||
if v.size > 0 && len(own) > v.size {
|
||||
ps.Pages = (len(own) + v.size - 1) / v.size
|
||||
ps.Page = min(max(v.pages[key], 0), ps.Pages-1)
|
||||
own = own[ps.Page*v.size : min((ps.Page+1)*v.size, len(own))]
|
||||
}
|
||||
ps.Components = own
|
||||
// Unnamed sections are top-level lists without children.
|
||||
if sec.Name != "" {
|
||||
for _, child := range sec.Children {
|
||||
n += count(child, path)
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
total := 0
|
||||
for _, sec := range sections {
|
||||
total += count(sec, nil)
|
||||
}
|
||||
out := ComponentPage{Pages: 1, Matches: total, Query: query}
|
||||
if needle == "" && (size <= 0 || total <= size) {
|
||||
out.Sections = sections
|
||||
return out
|
||||
}
|
||||
from, to := 0, total
|
||||
if size > 0 && total > size {
|
||||
out.Pages = (total + size - 1) / size
|
||||
out.Page = min(max(page, 0), out.Pages-1)
|
||||
from, to = out.Page*size, min((out.Page+1)*size, total)
|
||||
}
|
||||
idx := 0
|
||||
var cut func(sec agentapi.Section, path []string) (agentapi.Section, bool)
|
||||
cut = func(sec agentapi.Section, path []string) (agentapi.Section, bool) {
|
||||
part := agentapi.Section{Name: sec.Name, Status: secStatusName(sec), Total: SectionTotal(sec)}
|
||||
if sec.Name != "" {
|
||||
path = append(path, sec.Name)
|
||||
}
|
||||
for _, c := range sec.Components {
|
||||
if !match(path, c) {
|
||||
continue
|
||||
}
|
||||
if idx >= from && idx < to {
|
||||
part.Components = append(part.Components, c)
|
||||
}
|
||||
idx++
|
||||
}
|
||||
if sec.Name != "" {
|
||||
for _, child := range sec.Children {
|
||||
if p, ok := cut(child, path); ok {
|
||||
part.Children = append(part.Children, p)
|
||||
for i, child := range sec.Children {
|
||||
if c, ok := walk(child, key+"."+strconv.Itoa(i), path); ok {
|
||||
ps.Children = append(ps.Children, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
return part, len(part.Components) > 0 || len(part.Children) > 0
|
||||
return ps, !filtered || len(ps.Components) > 0 || len(ps.Children) > 0
|
||||
}
|
||||
for _, sec := range sections {
|
||||
if p, ok := cut(sec, nil); ok {
|
||||
out.Sections = append(out.Sections, p)
|
||||
for i, sec := range sections {
|
||||
if ps, ok := walk(sec, strconv.Itoa(i), nil); ok {
|
||||
v.Sections = append(v.Sections, ps)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ComponentPageHref links page of the components of the status page at
|
||||
// base, keeping the search for query.
|
||||
func ComponentPageHref(base string, page int, query string) string {
|
||||
v := url.Values{}
|
||||
if page > 0 {
|
||||
v.Set("page", strconv.Itoa(page+1))
|
||||
}
|
||||
if query != "" {
|
||||
v.Set("q", query)
|
||||
}
|
||||
href := BackHref(base)
|
||||
if len(v) > 0 {
|
||||
href += "?" + v.Encode()
|
||||
}
|
||||
return href
|
||||
return v
|
||||
}
|
||||
|
||||
// BarPath draws the bars of one status of a chart.
|
||||
|
||||
Reference in new issue
Block a user