feat(console): status filter, own monitor order, page limits and smaller fixes #157
No files matched your search
+49
-1
@@ -97,6 +97,7 @@ func (s *Server) dashboard(c *gin.Context) {
|
||||
v.Unchecked++
|
||||
}
|
||||
}
|
||||
v.Filters = statusFilters(c, v.Counts, v.Filter)
|
||||
for id, since := range s.regionsWithoutChecker(c.Request.Context(), data.usedRegions) {
|
||||
v.DeadRegions = append(v.DeadRegions, web.DeadRegion{Name: data.regionOf[id].Name, Since: since.Local().Format("2006-01-02 15:04")})
|
||||
}
|
||||
@@ -127,6 +128,46 @@ func sortMonitors(ms []web.MonitorRow) {
|
||||
})
|
||||
}
|
||||
|
||||
// dashboardStatuses are the statuses the dashboard counts, in order.
|
||||
var dashboardStatuses = []web.Status{web.StatusUp, web.StatusDegraded, web.StatusDown, web.StatusUnknown, web.StatusMaintenance, web.StatusPaused}
|
||||
|
||||
// dashboardURL is the dashboard with key set to value, or removed when
|
||||
// value is empty, keeping the search and range but not the page.
|
||||
func dashboardURL(c *gin.Context, key, value string) string {
|
||||
q := url.Values{}
|
||||
for _, k := range []string{"q", "range", "status"} {
|
||||
if v := c.Query(k); v != "" {
|
||||
q.Set(k, v)
|
||||
}
|
||||
}
|
||||
if value == "" {
|
||||
q.Del(key)
|
||||
} else {
|
||||
q.Set(key, value)
|
||||
}
|
||||
if len(q) == 0 {
|
||||
return "/"
|
||||
}
|
||||
return "/?" + q.Encode()
|
||||
}
|
||||
|
||||
// statusFilters are the counts of the statuses present, each linking to
|
||||
// its monitors, the active one back to all.
|
||||
func statusFilters(c *gin.Context, counts map[web.Status]int, active web.Status) []web.StatusFilter {
|
||||
var out []web.StatusFilter
|
||||
for _, st := range dashboardStatuses {
|
||||
if counts[st] == 0 && st != active {
|
||||
continue
|
||||
}
|
||||
f := web.StatusFilter{Status: st, Count: counts[st], Active: st == active, URL: dashboardURL(c, "status", string(st))}
|
||||
if f.Active {
|
||||
f.URL = dashboardURL(c, "status", "")
|
||||
}
|
||||
out = append(out, f)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// dashboardPage narrows the dashboard to a search or one group, pages it
|
||||
// and caps every group's own monitors. It reports false after answering
|
||||
// with an error.
|
||||
@@ -155,12 +196,19 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
||||
}
|
||||
}
|
||||
var info pageInfo
|
||||
if f := web.Status(c.Query("status")); slices.Contains(dashboardStatuses, f) {
|
||||
v.Filter = f
|
||||
v.AllURL = dashboardURL(c, "status", "")
|
||||
}
|
||||
switch group := c.Query("group"); {
|
||||
case strings.TrimSpace(c.Query("q")) != "":
|
||||
case strings.TrimSpace(c.Query("q")) != "" || v.Filter != "":
|
||||
v.Search = strings.TrimSpace(c.Query("q"))
|
||||
needle := strings.ToLower(v.Search)
|
||||
var hits []web.MonitorRow
|
||||
for _, m := range data.rows {
|
||||
if v.Filter != "" && m.Status != v.Filter {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(m.Name), needle) || strings.Contains(strings.ToLower(m.Target), needle) {
|
||||
hits = append(hits, m)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDashboardFiltersByStatus(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
_, region := e.platformChecker(t, uniq("eu-"))
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("flt")+".test", uniq("flt-"))
|
||||
create := func(name string) string {
|
||||
t.Helper()
|
||||
st, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": name, "type": "http", "target": "https://" + strings.ToLower(name) + ".test", "interval_seconds": 60, "regions": []string{region}})
|
||||
if st != http.StatusCreated {
|
||||
t.Fatalf("create %s = %d %v", name, st, m)
|
||||
}
|
||||
return m["id"].(string)
|
||||
}
|
||||
create("Alpha")
|
||||
create("Beta")
|
||||
gamma := create("Gamma")
|
||||
owner.do("PUT", "/api/v1/org/monitors/"+gamma, map[string]any{"name": "Gamma", "type": "http", "target": "https://gamma.test", "interval_seconds": 60, "regions": []string{region}, "enabled": false})
|
||||
|
||||
_, _, all := owner.page("/")
|
||||
for _, want := range []string{`href="/?status=unknown"`, `href="/?status=paused"`, "Show only the 2 monitors that are no data", "Show only the 1 monitor that is paused"} {
|
||||
if !strings.Contains(all, want) {
|
||||
t.Errorf("the dashboard lacks %q", want)
|
||||
}
|
||||
}
|
||||
|
||||
_, _, paused := owner.page("/?status=paused")
|
||||
if !strings.Contains(paused, "Gamma") || strings.Contains(paused, "Alpha") || strings.Contains(paused, "Beta") {
|
||||
t.Error("?status=paused does not show only the paused monitor")
|
||||
}
|
||||
// The active filter links back to all, and the search keeps it.
|
||||
if !strings.Contains(paused, `aria-current="true"`) || !strings.Contains(paused, `title="Show all statuses"`) {
|
||||
t.Error("the active filter is not marked")
|
||||
}
|
||||
if !strings.Contains(paused, `name="status" value="paused"`) {
|
||||
t.Error("the search form drops the status filter")
|
||||
}
|
||||
|
||||
_, _, both := owner.page("/?status=unknown&q=alp")
|
||||
if !strings.Contains(both, "Alpha") || strings.Contains(both, "Beta") || strings.Contains(both, "Gamma") {
|
||||
t.Error("status filter and search do not combine")
|
||||
}
|
||||
if _, _, none := owner.page("/?status=down"); !strings.Contains(none, "No monitor has this status right now.") {
|
||||
t.Error("an empty filter does not say so")
|
||||
}
|
||||
// An unknown status shows everything.
|
||||
if _, _, bogus := owner.page("/?status=bogus"); !strings.Contains(bogus, "Alpha") || !strings.Contains(bogus, "Gamma") {
|
||||
t.Error("an unknown status filter hides monitors")
|
||||
}
|
||||
}
|
||||
@@ -1064,6 +1064,13 @@
|
||||
"monitors.docker_host": "Docker-Host (unix://-Socket oder tcp://host:2375)",
|
||||
"monitors.edit": "Monitor bearbeiten",
|
||||
"monitors.expect_status": "Erwarteter Status (z. B. 2xx, 301)",
|
||||
"monitors.filter_clear": "Alle Status anzeigen",
|
||||
"monitors.filter_label": "Monitore nach Status anzeigen",
|
||||
"monitors.filter_only": "Nur",
|
||||
"monitors.filter_show": {
|
||||
"one": "Nur den {{.Count}} Monitor mit Status „{{.Status}}“ anzeigen",
|
||||
"other": "Nur die {{.Count}} Monitore mit Status „{{.Status}}“ anzeigen"
|
||||
},
|
||||
"monitors.follow_redirects": "Weiterleitungen folgen",
|
||||
"monitors.game_min_free_slots": "Mindestens freie Plätze",
|
||||
"monitors.game_min_free_slots_hint": "0 prüft nur, ob der Server antwortet.",
|
||||
@@ -1094,6 +1101,7 @@
|
||||
"monitors.no_data_since": "keine Daten seit {{.Time}}",
|
||||
"monitors.no_match": "Kein Monitor gefunden.",
|
||||
"monitors.no_results": "Noch keine Ergebnisse.",
|
||||
"monitors.no_status_match": "Gerade hat kein Monitor diesen Status.",
|
||||
"monitors.op_absent": "fehlt",
|
||||
"monitors.op_contains": "enthält",
|
||||
"monitors.op_eq": "gleich",
|
||||
|
||||
@@ -1064,6 +1064,13 @@
|
||||
"monitors.docker_host": "Docker host (unix:// socket or tcp://host:2375)",
|
||||
"monitors.edit": "Edit monitor",
|
||||
"monitors.expect_status": "Expected status (e.g. 2xx, 301)",
|
||||
"monitors.filter_clear": "Show all statuses",
|
||||
"monitors.filter_label": "Show monitors by status",
|
||||
"monitors.filter_only": "Only",
|
||||
"monitors.filter_show": {
|
||||
"one": "Show only the {{.Count}} monitor that is {{.Status}}",
|
||||
"other": "Show only the {{.Count}} monitors that are {{.Status}}"
|
||||
},
|
||||
"monitors.follow_redirects": "Follow redirects",
|
||||
"monitors.game_min_free_slots": "Minimum free slots",
|
||||
"monitors.game_min_free_slots_hint": "0 only checks that the server answers.",
|
||||
@@ -1094,6 +1101,7 @@
|
||||
"monitors.no_data_since": "no data since {{.Time}}",
|
||||
"monitors.no_match": "No monitor matches.",
|
||||
"monitors.no_results": "No results yet.",
|
||||
"monitors.no_status_match": "No monitor has this status right now.",
|
||||
"monitors.op_absent": "is absent",
|
||||
"monitors.op_contains": "contains",
|
||||
"monitors.op_eq": "equals",
|
||||
|
||||
+61
-11
@@ -65,7 +65,14 @@ type DashboardView struct {
|
||||
Empty bool
|
||||
CanWrite bool
|
||||
Counts map[Status]int
|
||||
Range string
|
||||
// Filters are the status counts, each linking to the monitors of
|
||||
// that status.
|
||||
Filters []StatusFilter
|
||||
// Filter, if set, lists Results of that status instead of the tree.
|
||||
Filter Status
|
||||
// AllURL leaves the status filter, keeping the search and range.
|
||||
AllURL string
|
||||
Range string
|
||||
Ranges []RangeOption
|
||||
// Unchecked counts the monitors no region has reported for recently.
|
||||
Unchecked int
|
||||
@@ -73,6 +80,15 @@ type DashboardView struct {
|
||||
DeadRegions []DeadRegion
|
||||
}
|
||||
|
||||
// StatusFilter is one status count; URL shows only its monitors, or all
|
||||
// again when it is the active filter.
|
||||
type StatusFilter struct {
|
||||
Status Status
|
||||
Count int
|
||||
URL string
|
||||
Active bool
|
||||
}
|
||||
|
||||
// DeadRegion is a region without a live checker since Since.
|
||||
type DeadRegion struct {
|
||||
Name, Since string
|
||||
@@ -163,14 +179,24 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
|
||||
<div class="flex flex-wrap items-center gap-x-5 gap-y-3 font-mono text-xs text-muted">
|
||||
@rangeSwitch(v.Ranges)
|
||||
for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusUnknown, StatusMaintenance, StatusPaused} {
|
||||
if v.Counts[s] > 0 {
|
||||
<span class="flex items-center gap-1.5">
|
||||
@statusDot(s)
|
||||
<span>{ strconv.Itoa(v.Counts[s]) }</span>
|
||||
</span>
|
||||
<nav class="flex flex-wrap items-center gap-x-1 gap-y-2" aria-label={ i18n.T(ctx, "monitors.filter_label") }>
|
||||
for _, f := range v.Filters {
|
||||
<a
|
||||
href={ templ.SafeURL(f.URL) }
|
||||
class={ "flex items-center gap-1.5 border px-1.5 py-0.5 hover:text-ink",
|
||||
templ.KV("border-ink text-ink", f.Active),
|
||||
templ.KV("border-transparent hover:border-rule", !f.Active) }
|
||||
title={ filterTitle(ctx, f) }
|
||||
aria-label={ filterTitle(ctx, f) }
|
||||
if f.Active {
|
||||
aria-current="true"
|
||||
}
|
||||
>
|
||||
@statusDot(f.Status)
|
||||
<span>{ strconv.Itoa(f.Count) }</span>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
</nav>
|
||||
if v.CanWrite {
|
||||
<a href="/monitors/new" class="whitespace-nowrap bg-ink px-3 py-1.5 font-sans text-sm text-paper hover:opacity-90">{ i18n.T(ctx, "monitors.new") }</a>
|
||||
}
|
||||
@@ -191,6 +217,9 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
if v.Range != "" {
|
||||
<input type="hidden" name="range" value={ v.Range }/>
|
||||
}
|
||||
if v.Filter != "" {
|
||||
<input type="hidden" name="status" value={ string(v.Filter) }/>
|
||||
}
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
@@ -205,10 +234,24 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
||||
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>
|
||||
case v.Search != "" || v.Filter != "":
|
||||
<p class="mb-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
|
||||
<a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "monitors.all") }</a>
|
||||
if v.Filter != "" {
|
||||
<span class="flex items-center gap-1.5">
|
||||
{ i18n.T(ctx, "monitors.filter_only") }
|
||||
@statusDot(v.Filter)
|
||||
<span class="font-medium">{ i18n.T(ctx, "status."+string(v.Filter)) }</span>
|
||||
<a href={ templ.SafeURL(v.AllURL) } class="ml-1 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.filter_clear") } title={ i18n.T(ctx, "monitors.filter_clear") }>×</a>
|
||||
</span>
|
||||
}
|
||||
</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>
|
||||
if v.Search == "" {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_status_match") }</p>
|
||||
} else {
|
||||
<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)
|
||||
@@ -1589,3 +1632,10 @@ templ IncidentStatusesPage(p Page, me Me, statuses []CustomIncidentStatus, canMa
|
||||
</section>
|
||||
}
|
||||
}
|
||||
|
||||
func filterTitle(ctx context.Context, f StatusFilter) string {
|
||||
if f.Active {
|
||||
return i18n.T(ctx, "monitors.filter_clear")
|
||||
}
|
||||
return i18n.T(ctx, "monitors.filter_show", "Status", i18n.T(ctx, "status."+string(f.Status)), "Count", f.Count)
|
||||
}
|
||||
+2509
-2266
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user