feat(console): filter the monitor list by status
The status counts above the monitor list are now links: one shows only the monitors of that status as a flat list, the active one shows all again. The filter combines with the search and the range and is kept by the search form and the pager; an unknown status shows everything. 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
ebfada4b2c
commit
feaa1e930d
6 files changed
+2692
-2278
No files matched your search
+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)
|
||||
}
|
||||
Reference in new issue
Block a user