feat(console): sort the monitor list and put monitors in an order of one's own
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s

The monitor list gets a sort switcher: the organization's own order, by
default, or by name, status (problems first), uptime (worst first) or
latency (slowest first). The choice is remembered in a cookie; paging
follows it.

"Arrange monitors" shows the whole tree with each group's monitors to
drag, or move with up and down, into the order wanted; every change is
saved at once through PUT /api/v1/org/monitors/order, which needs write
access to every monitor given and is audited. Monitors without a position
follow the positioned ones, by name.

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-25 23:35:02 +01:00
1 parent ca852c8299
commit b0d4bcc002
16 files changed
+3389 -2653

No files matched your search

+80 -6
View File
@@ -31,6 +31,11 @@ type MonitorRow struct {
// Unchecked is set when no region has reported recently: nobody is
// checking the monitor.
Unchecked bool
// Position is the organization's own order, -1 when not set; Ratio
// the uptime in the range, -1 without data; LatencyMS -1 without data.
Position int
Ratio float64
LatencyMS int
}
// GroupNode is a monitor group with its monitors and subgroups.
@@ -72,6 +77,13 @@ type DashboardView struct {
Filter Status
// AllURL leaves the status filter, keeping the search and range.
AllURL string
// Sorts switch the order of the list; Sort is the active one.
Sorts []SortOption
Sort string
// Arrange shows the tree for putting monitors in order by hand;
// ArrangeURL turns it on or off, empty when not offered.
Arrange bool
ArrangeURL string
Range string
Ranges []RangeOption
// Unchecked counts the monitors no region has reported for recently.
@@ -80,6 +92,13 @@ type DashboardView struct {
DeadRegions []DeadRegion
}
// SortOption is an entry of the sort switcher.
type SortOption struct {
Key string
URL string
Active bool
}
// StatusFilter is one status count; URL shows only its monitors, or all
// again when it is the active filter.
type StatusFilter struct {
@@ -179,6 +198,7 @@ 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)
@sortSwitch(v.Sorts)
<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
@@ -266,17 +286,31 @@ templ Dashboard(p Page, me Me, v DashboardView) {
<span class="font-medium">{ v.Focus }</span>
</p>
}
if v.Arrange {
<p class="mb-3 border-l-2 border-ink pl-3 text-sm">{ i18n.T(ctx, "monitors.arrange_hint") }</p>
}
<div class="border-t border-rule">
@monitorList(v.Root.Monitors)
@treeList(v.Root.Monitors, v.Arrange)
@moreLink(v.Root)
for _, g := range v.Root.Children {
@groupBlock(g)
@groupBlock(g, v.Arrange)
}
</div>
@pager(v.Pager, "previous", "next")
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
}
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
<p class="mt-8 flex flex-wrap gap-x-6 gap-y-2 text-sm">
<a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a>
if v.ArrangeURL != "" {
<a href={ templ.SafeURL(v.ArrangeURL) } class="text-muted hover:text-ink">
if v.Arrange {
{ i18n.T(ctx, "monitors.arrange_done") }
} else {
{ i18n.T(ctx, "monitors.arrange") }
}
</a>
}
</p>
}
}
@@ -316,7 +350,7 @@ templ moreLink(g GroupNode) {
// groupBlock renders a group and, recursively, its subgroups. <details>
// makes groups collapsible without JavaScript.
templ groupBlock(g GroupNode) {
templ groupBlock(g GroupNode, arrange bool) {
<details open class="border-b border-rule">
<summary class="flex cursor-pointer items-center gap-2.5 py-2.5 text-sm font-medium select-none hover:bg-rule/30">
@statusDot(g.Status)
@@ -324,10 +358,10 @@ templ groupBlock(g GroupNode) {
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(g.Total) }</span>
</summary>
<div class="ml-4 border-l border-rule pl-4">
@monitorList(g.Monitors)
@treeList(g.Monitors, arrange)
@moreLink(g)
for _, c := range g.Children {
@groupBlock(c)
@groupBlock(c, arrange)
}
</div>
</details>
@@ -1639,3 +1673,43 @@ func filterTitle(ctx context.Context, f StatusFilter) string {
}
return i18n.T(ctx, "monitors.filter_show", "Status", i18n.T(ctx, "status."+string(f.Status)), "Count", f.Count)
}
templ sortSwitch(opts []SortOption) {
<nav class="flex min-w-0 max-w-full overflow-x-auto border border-rule font-mono text-xs" aria-label={ i18n.T(ctx, "monitors.sort") }>
for _, o := range opts {
if o.Active {
<span class="whitespace-nowrap bg-ink px-2 py-1 text-paper" aria-current="true">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</span>
} else {
<a href={ templ.SafeURL(o.URL) } class="whitespace-nowrap px-2 py-1 text-muted hover:text-ink">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</a>
}
}
</nav>
}
// treeList is a group's own monitors, as links or, while arranging, as
// rows to put in order.
templ treeList(ms []MonitorRow, arrange bool) {
if arrange {
@arrangeList(ms)
} else {
@monitorList(ms)
}
}
// arrangeList lets monitors be dragged or moved up and down; every change
// is saved at once.
templ arrangeList(ms []MonitorRow) {
if len(ms) > 0 {
<ul data-sortable="/org/monitors/order" class="divide-y divide-rule border-b border-rule text-sm">
for _, m := range ms {
<li data-sort-id={ m.ID } draggable="true" class="flex cursor-move items-center gap-3 py-2.5">
<span class="select-none text-muted" aria-hidden="true">⠿</span>
@statusDot(m.Status)
<span class="min-w-0 flex-1 truncate">{ m.Name }</span>
<button type="button" data-sort-move="up" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) }>↑</button>
<button type="button" data-sort-move="down" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) }>↓</button>
</li>
}
</ul>
}
}