feat(statuspage): add nested status page groups and optional component details
ci / image (pull_request) Successful in 4m23s
ci / lint (pull_request) Canceled after 6m9s
ci / test (pull_request) Canceled after 6m8s
ci / build (pull_request) Canceled after 6m7s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-22 20:07:30 +01:00
1 parent 1c31003baf
commit 9b26b4150e
26 files changed
+4566 -760

No files matched your search

+4 -1
View File
@@ -73,7 +73,9 @@
.map((row) => {
const obj = {};
for (const f of row.querySelectorAll("[data-field]")) {
if (f.dataset.field !== "include") obj[f.dataset.field] = f.value;
if (f.dataset.field !== "include") {
obj[f.dataset.field] = f.dataset.nullable !== undefined ? (f.value || null) : f.value;
}
}
return obj;
});
@@ -165,6 +167,7 @@
}
const post = ev.target.closest("[data-post]");
if (post) {
if (post.dataset.confirm && !confirm(post.dataset.confirm)) return;
post.disabled = true;
try {
await api.post(post.dataset.post);
+98 -2
View File
@@ -1,7 +1,10 @@
package web
import (
"fmt"
"io/fs"
"strconv"
"strings"
"time"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
@@ -19,6 +22,9 @@ type PublicAssets struct {
// "/acme/" or "/" on a custom domain. Empty leaves them out, as in a
// single-file export, which can only link elsewhere.
LegalBase string
// ComponentBase prefixes links to component detail pages, e.g. "/acme/"
// or "/". Empty in static single-file exports where subpages do not exist.
ComponentBase string
// Now is the moment the page shows, deciding which maintenance is in
// progress.
Now time.Time
@@ -39,7 +45,7 @@ func StylesheetText() (string, error) {
return string(b), err
}
// DayBars turns a component's history into bars.
// DayBars turns a component's 90-day history into bars.
func DayBars(days []agentapi.Day) []Bar {
out := make([]Bar, len(days))
for i, d := range days {
@@ -52,6 +58,54 @@ func DayBars(days []agentapi.Day) []Bar {
return out
}
// HourBars turns a component's 24-hour history into bars.
func HourBars(hours []agentapi.HourBucket) []Bar {
out := make([]Bar, len(hours))
for i, h := range hours {
label := h.Time.UTC().Format("15:04") + " UTC"
if h.Uptime < 0 {
out[i] = Bar{Status: StatusUnknown, Title: label + " · –"}
continue
}
title := label + " · " + Percent(h.Uptime)
if h.AvgLatencyMS > 0 {
title += fmt.Sprintf(" · %d ms", h.AvgLatencyMS)
}
out[i] = Bar{Status: ratioStatus(h.Uptime), Title: title}
}
return out
}
// HourLatency builds the SVG polyline for a component's 24-hour latency.
func HourLatency(hours []agentapi.HourBucket, width, height int) LatencyLine {
if len(hours) < 2 {
return LatencyLine{Width: width, Height: height}
}
buckets := make([]Bucket, 0, len(hours))
for _, h := range hours {
if h.Uptime < 0 || h.AvgLatencyMS <= 0 {
continue
}
buckets = append(buckets, Bucket{Start: h.Time, Total: 1, OK: 1, Latency: float32(h.AvgLatencyMS)})
}
return Latency(buckets, hours[0].Time, hours[len(hours)-1].Time, width, height)
}
// AvgLatencyText formats the mean latency across hourly buckets with data.
func AvgLatencyText(hours []agentapi.HourBucket) string {
var sum, count int
for _, h := range hours {
if h.Uptime >= 0 && h.AvgLatencyMS > 0 {
sum += h.AvgLatencyMS
count++
}
}
if count == 0 {
return "–"
}
return strconv.Itoa(sum/count) + " ms"
}
// PageStatus maps a page state to the chart statuses used for colors.
func PageStatus(s string) Status {
switch s {
@@ -67,7 +121,49 @@ func PageStatus(s string) Status {
return StatusUnknown
}
// UptimeText formats a component's 90-day uptime.
// SectionStatus returns a section's aggregated status, falling back to
// summarizing its direct components for legacy cached snapshots.
func SectionStatus(sec agentapi.Section) Status {
if sec.Status != "" {
return PageStatus(sec.Status)
}
states := make([]string, len(sec.Components))
for i, c := range sec.Components {
states[i] = c.Status
}
return PageStatus(agentapi.Summarize(states))
}
// SectionTotal returns the total component count in sec and its descendants.
func SectionTotal(sec agentapi.Section) int {
if sec.Total > 0 {
return sec.Total
}
total := len(sec.Components)
for _, child := range sec.Children {
total += SectionTotal(child)
}
return total
}
// ComponentHref returns the detail link for comp when clickable details are
// enabled on a live status page server, or "" otherwise.
func ComponentHref(base string, comp agentapi.Component, showDetails bool) string {
if !showDetails || base == "" || comp.ID == "" {
return ""
}
return base + "components/" + comp.ID
}
// BackHref turns a page base prefix ("/acme/" or "/") into the page's root URL.
func BackHref(base string) string {
if base == "" || base == "/" {
return "/"
}
return strings.TrimSuffix(base, "/")
}
// UptimeText formats a component's uptime ratio, or "–" without data.
func UptimeText(r float64) string {
if r < 0 {
return "–"
+266 -80
View File
@@ -1,6 +1,7 @@
package web
import (
"strconv"
"strings"
"time"
@@ -8,14 +9,14 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
templ publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) {
<!DOCTYPE html>
<html lang={ i18n.Lang(ctx) }>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="refresh" content="60"/>
<title>{ s.Title }</title>
<title>{ docTitle }</title>
if a.InlineCSS == "" {
@faviconLinks()
}
@@ -33,84 +34,7 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
</head>
<body class="min-h-screen">
<main class="mx-auto max-w-3xl px-6 py-14">
<header class="mb-10">
if s.Theme.LogoURL != "" {
<img src={ s.Theme.LogoURL } alt={ s.Title } class="mb-6 h-10"/>
}
<h1 class="text-2xl font-semibold" style="color:var(--page-accent,inherit)">{ s.Title }</h1>
if s.Description != "" {
<div class="legal-text mt-2 text-muted">
@templ.Raw(Markdown(s.Description))
</div>
}
</header>
if !a.StaleSince.IsZero() {
<p class="mb-6 border border-degraded/50 bg-degraded/10 px-4 py-2 text-sm">
{ i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC") }
</p>
}
<section
class={ "mb-12 border-l-4 py-3 pl-4",
templ.KV("border-up", s.Status == agentapi.PageOperational),
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
templ.KV("border-down", s.Status == agentapi.PageOutage),
templ.KV("border-unknown", s.Status == agentapi.PageUnknown),
templ.KV("border-maintenance", s.Status == agentapi.PageUnderMaintenance) }
>
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
</section>
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
for _, sec := range s.Sections {
<section class="mb-10">
if sec.Name != "" {
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ sec.Name }</h2>
}
<ul class="divide-y divide-rule border-y border-rule">
for _, comp := range sec.Components {
<li class="py-3">
<div class="mb-2 flex items-center gap-2.5">
@statusDot(PageStatus(comp.Status))
<span>{ comp.Name }</span>
<span class="ml-auto text-sm text-muted">{ i18n.T(ctx, "page.component."+comp.Status) }</span>
</div>
@bars(DayBars(comp.Days), 22)
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
<span>{ UptimeText(comp.Uptime) }</span>
<span>{ i18n.T(ctx, "page.today") }</span>
</div>
</li>
}
</ul>
</section>
}
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), s.Upcoming(a.Now))
<section class="mb-12">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.incidents") }</h2>
if len(s.Incidents) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "page.no_incidents") }</p>
} else {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, inc := range s.Incidents {
<li class="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5">
if inc.ResolvedAt == nil {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
<span>{ inc.Component }</span>
<span class="ml-auto font-mono text-xs text-muted">
{ inc.StartedAt.UTC().Format("2006-01-02 15:04") }
if inc.ResolvedAt != nil {
– { inc.ResolvedAt.UTC().Format("15:04") }
}
UTC
</span>
</li>
}
</ul>
}
</section>
{ children... }
<footer class="flex justify-between border-t border-rule pt-4 font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.updated", "Time", s.GeneratedAt.UTC().Format(time.DateTime)+" UTC") }</span>
<span class="flex gap-4">
@@ -128,6 +52,268 @@ templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
</html>
}
templ publicStaleNotice(a PublicAssets) {
if !a.StaleSince.IsZero() {
<p class="mb-6 border border-degraded/50 bg-degraded/10 px-4 py-2 text-sm">
{ i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC") }
</p>
}
}
templ PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) {
@publicShell(s, a, s.Title) {
<header class="mb-10">
if s.Theme.LogoURL != "" {
<img src={ s.Theme.LogoURL } alt={ s.Title } class="mb-6 h-10"/>
}
<h1 class="text-2xl font-semibold" style="color:var(--page-accent,inherit)">{ s.Title }</h1>
if s.Description != "" {
<div class="legal-text mt-2 text-muted">
@templ.Raw(Markdown(s.Description))
</div>
}
</header>
@publicStaleNotice(a)
<section
class={ "mb-12 border-l-4 py-3 pl-4",
templ.KV("border-up", s.Status == agentapi.PageOperational),
templ.KV("border-degraded", s.Status == agentapi.PageDegraded),
templ.KV("border-down", s.Status == agentapi.PageOutage),
templ.KV("border-unknown", s.Status == agentapi.PageUnknown),
templ.KV("border-maintenance", s.Status == agentapi.PageUnderMaintenance) }
>
<p class="text-lg font-medium">{ i18n.T(ctx, "page.status."+s.Status) }</p>
</section>
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), s.Ongoing(a.Now))
if len(s.Sections) > 0 {
<section class="mb-12 border-t border-rule">
for _, sec := range s.Sections {
@publicSection(sec, s, a)
}
</section>
}
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), s.Upcoming(a.Now))
@publicIncidents(s.Incidents)
}
}
// publicSection renders an unnamed root component list or a collapsible nested
// group matching the monitor dashboard hierarchy.
templ publicSection(sec agentapi.Section, s agentapi.PageSnapshot, a PublicAssets) {
if sec.Name == "" {
@publicComponentList(sec.Components, s, a)
} else {
<details open class="border-b border-rule">
<summary class="flex cursor-pointer items-center gap-2.5 py-3 text-sm font-medium select-none hover:bg-rule/30">
@statusDot(SectionStatus(sec))
<span>{ sec.Name }</span>
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(SectionTotal(sec)) }</span>
<span class="ml-auto text-xs font-normal text-muted">{ i18n.T(ctx, "page.component."+string(secStatusName(sec))) }</span>
</summary>
<div class="ml-4 border-l border-rule pl-4">
@publicComponentList(sec.Components, s, a)
for _, child := range sec.Children {
@publicSection(child, s, a)
}
</div>
</details>
}
}
func secStatusName(sec agentapi.Section) string {
if sec.Status != "" {
return sec.Status
}
states := make([]string, len(sec.Components))
for i, c := range sec.Components {
states[i] = c.Status
}
return agentapi.Summarize(states)
}
templ publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a PublicAssets) {
if len(comps) > 0 {
<ul class="divide-y divide-rule border-b border-rule last:border-b-0">
for _, comp := range comps {
<li class="py-3">
if href := ComponentHref(a.ComponentBase, comp, s.ShowDetails); href != "" {
<a href={ templ.SafeURL(href) } class="block rounded-sm transition hover:bg-rule/30">
@publicComponentBody(comp, true)
</a>
} else {
@publicComponentBody(comp, false)
if s.ShowDetails && comp.Details != nil {
<details class="mt-2 border-t border-rule pt-2 text-xs">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "page.details_expand") }</summary>
<div class="mt-3">
@publicSLAGrid(comp.Details)
if len(comp.Details.Regions) > 0 {
@publicRegionsList(comp.Details.Regions)
}
</div>
</details>
}
}
</li>
}
</ul>
}
}
templ publicComponentBody(comp agentapi.Component, clickable bool) {
<div class="mb-2 flex items-center gap-2.5">
@statusDot(PageStatus(comp.Status))
<span class={ templ.KV("underline-offset-2 hover:underline", clickable) }>{ comp.Name }</span>
<span class="ml-auto flex items-center gap-2 text-sm text-muted">
<span>{ i18n.T(ctx, "page.component."+comp.Status) }</span>
if clickable {
<span aria-hidden="true" class="text-xs">→</span>
}
</span>
</div>
@bars(DayBars(comp.Days), 22)
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
<span>{ UptimeText(comp.Uptime) }</span>
<span>{ i18n.T(ctx, "page.today") }</span>
</div>
}
templ PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a PublicAssets) {
@publicShell(s, a, comp.Name+" · "+s.Title) {
<p class="mb-6 text-sm">
<a href={ templ.SafeURL(BackHref(a.ComponentBase)) } class="text-muted hover:text-ink">← { s.Title }</a>
</p>
<header class="mb-8">
<h1 class="flex items-center gap-2.5 text-2xl font-semibold" style="color:var(--page-accent,inherit)">
@statusDot(PageStatus(comp.Status))
<span>{ comp.Name }</span>
</h1>
</header>
@publicStaleNotice(a)
<section
class={ "mb-10 border-l-4 py-3 pl-4",
templ.KV("border-up", comp.Status == agentapi.PageOperational),
templ.KV("border-degraded", comp.Status == agentapi.PageDegraded),
templ.KV("border-down", comp.Status == agentapi.PageOutage),
templ.KV("border-unknown", comp.Status == agentapi.PageUnknown),
templ.KV("border-maintenance", comp.Status == agentapi.PageUnderMaintenance) }
>
<p class="text-base font-medium">{ i18n.T(ctx, "page.component."+comp.Status) }</p>
</section>
{{ ongoing, upcoming := s.MaintenanceForComponent(comp.Name, a.Now) }}
@pageMaintenance(i18n.T(ctx, "page.maintenance_ongoing"), ongoing)
if comp.Details != nil {
<section class="mb-10">
<div class="mb-2 flex items-baseline justify-between">
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.details_last_24h") }</h2>
<span class="font-mono text-sm">{ UptimeText(comp.Details.SLA24h) }</span>
</div>
@bars(HourBars(comp.Details.Hours), 24)
{{ lat := HourLatency(comp.Details.Hours, 600, 96) }}
if lat.Points != "" {
<div class="mt-4 mb-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "monitors.latency") }</span>
<span>{ i18n.T(ctx, "page.details_latency_summary", "Avg", AvgLatencyText(comp.Details.Hours), "Max", strconv.Itoa(lat.MaxMS)+" ms") }</span>
</div>
<svg viewBox={ "0 0 " + strconv.Itoa(lat.Width) + " " + strconv.Itoa(lat.Height) } preserveAspectRatio="none" class="block h-24 w-full border-b border-rule">
<polyline points={ lat.Points } fill="none" class="stroke-ink" stroke-width="1.5" vector-effect="non-scaling-stroke"></polyline>
</svg>
}
</section>
<section class="mb-10">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.sla_table") }</h2>
@publicSLAGrid(comp.Details)
</section>
if len(comp.Details.Regions) > 0 {
<section class="mb-10">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</h2>
@publicRegionsList(comp.Details.Regions)
</section>
}
}
<section class="mb-10">
<div class="mb-2 flex items-baseline justify-between">
<h2 class="text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.last_90d") }</h2>
<span class="font-mono text-sm">{ UptimeText(comp.Uptime) }</span>
</div>
@bars(DayBars(comp.Days), 24)
<div class="mt-1 flex justify-between font-mono text-xs text-muted">
<span>{ i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)) }</span>
<span>{ UptimeText(comp.Uptime) }</span>
<span>{ i18n.T(ctx, "page.today") }</span>
</div>
</section>
@pageMaintenance(i18n.T(ctx, "page.maintenance_upcoming"), upcoming)
@publicIncidents(s.IncidentsForComponent(comp.Name))
}
}
templ publicSLAGrid(d *agentapi.ComponentDetails) {
<dl class="grid grid-cols-2 gap-px border border-rule bg-rule sm:grid-cols-4">
for _, item := range []struct {
label string
value float64
}{
{"24h", d.SLA24h},
{"7d", d.SLA7d},
{"30d", d.SLA30d},
{"90d", d.SLA90d},
} {
<div class="bg-paper px-3 py-2">
<dt class="font-mono text-xs text-muted">{ item.label }</dt>
<dd class="font-mono text-sm">{ UptimeText(item.value) }</dd>
</div>
}
</dl>
}
templ publicRegionsList(regions []agentapi.ComponentRegion) {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, r := range regions {
<li class="flex items-center gap-2.5 py-2">
@statusDot(PageStatus(r.Status))
<span>{ r.Name }</span>
<span class="ml-auto font-mono text-xs text-muted">
{ i18n.T(ctx, "page.component."+r.Status) }
if r.LatencyMS > 0 {
{ " · " + strconv.Itoa(r.LatencyMS) + " ms" }
}
</span>
</li>
}
</ul>
}
templ publicIncidents(incidents []agentapi.PageIncident) {
<section class="mb-12">
<h2 class="mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "page.incidents") }</h2>
if len(incidents) == 0 {
<p class="text-sm text-muted">{ i18n.T(ctx, "page.no_incidents") }</p>
} else {
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, inc := range incidents {
<li class="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2.5">
if inc.ResolvedAt == nil {
<span class="font-medium text-down">{ i18n.T(ctx, "incidents.ongoing") }</span>
} else {
<span class="text-up">{ i18n.T(ctx, "incidents.resolved") }</span>
}
<span>{ inc.Component }</span>
<span class="ml-auto font-mono text-xs text-muted">
{ inc.StartedAt.UTC().Format("2006-01-02 15:04") }
if inc.ResolvedAt != nil {
– { inc.ResolvedAt.UTC().Format("15:04") }
}
UTC
</span>
</li>
}
</ul>
}
</section>
}
templ pageMaintenance(heading string, items []agentapi.PageMaintenance) {
if len(items) > 0 {
<section class="mb-12">
+1216 -307
View File
File diff suppressed because it is too large. Load diff
+121 -7
View File
@@ -1,6 +1,10 @@
package web
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
import (
"strconv"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
// PageRow is a status page in the list.
type PageRow struct {
@@ -58,15 +62,26 @@ templ StatusPagesPage(p Page, me Me, v PagesView) {
}
}
// PageMonitorOption is a monitor in the page editor.
type PageMonitorOption struct {
// PageGroupRow is one nested group of a status page in tree order.
type PageGroupRow struct {
ID string
Name string
Included bool
Section string
ParentID string
Position int
Depth int
Label string
}
// PageMonitorOption is a monitor in the page editor.
type PageMonitorOption struct {
ID string
Name string
MonitorGroupPath string
Included bool
GroupID string
Label string
}
// PageEditor is the data of the status page editor.
type PageEditor struct {
ID string
@@ -74,6 +89,7 @@ type PageEditor struct {
Slug string
Description string
Published bool
ShowDetails bool
Accent string
LogoURL string
CSS string
@@ -82,6 +98,8 @@ type PageEditor struct {
DomainVerified bool
RecordName string
RecordValue string
Groups []PageGroupRow
HasOrgGroups bool
Monitors []PageMonitorOption
}
@@ -109,6 +127,8 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
@MarkdownEditor("description", e.Description, 5, 10000, MarkdownInline)
</div>
@checkbox(i18n.T(ctx, "pages.published"), "published", e.Published)
@checkbox(i18n.T(ctx, "pages.show_details"), "show_component_details", e.ShowDetails)
<p class="-mt-2 mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.show_details_hint") }</p>
<h3 class="mt-6 mb-3 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.theme") }</h3>
@valueField(i18n.T(ctx, "pages.accent"), "theme.accent", e.Accent, "#1f6feb", false)
@valueField(i18n.T(ctx, "pages.logo"), "theme.logo_url", e.LogoURL, "https://example.com/logo.svg", false)
@@ -127,6 +147,90 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
>{ i18n.T(ctx, "pages.delete") }</button>
</section>
<div>
<section class="mb-12">
<div class="mb-3 flex flex-wrap items-baseline justify-between gap-2">
@sectionHeading("pages.groups")
if e.HasOrgGroups {
<button
type="button"
data-post={ "/org/statuspages/" + e.ID + "/groups/import" }
data-confirm={ i18n.T(ctx, "pages.groups_import_confirm") }
data-ok={ i18n.T(ctx, "pages.groups_imported") }
data-reload
class="border border-rule px-2.5 py-1 text-xs hover:border-ink"
>{ i18n.T(ctx, "pages.groups_import") }</button>
}
</div>
<p class="mb-4 text-xs text-muted">{ i18n.T(ctx, "pages.groups_intro") }</p>
if len(e.Groups) > 0 {
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
for _, g := range e.Groups {
<li class="py-2" style={ indent(g.Depth) }>
<details>
<summary class="flex cursor-pointer items-center justify-between gap-2 select-none hover:text-ink">
<span>{ g.Name }</span>
<span class="text-xs text-muted">{ i18n.T(ctx, "common.edit") }</span>
</summary>
<form data-api={ "/org/statuspages/" + e.ID + "/groups/" + g.ID } data-method="put" data-next={ "/statuspages/" + e.ID } class="mt-3 max-w-sm">
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", g.Name, "", true)
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "groups.parent") }</span>
<select name="parent_id" data-nullable class={ inputClass }>
<option value="">{ i18n.T(ctx, "groups.none") }</option>
for _, opt := range e.Groups {
if opt.ID != g.ID {
<option value={ opt.ID } selected?={ opt.ID == g.ParentID }>{ opt.Label }</option>
}
}
</select>
</label>
<label class="mb-3 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
<input type="number" name="position" data-number value={ strconv.Itoa(g.Position) } class={ inputClass }/>
</label>
<div class="flex items-center gap-4">
@submit(i18n.T(ctx, "common.save"))
<button
type="button"
data-delete={ "/org/statuspages/" + e.ID + "/groups/" + g.ID }
data-confirm={ i18n.T(ctx, "groups.delete_confirm") }
data-next={ "/statuspages/" + e.ID }
class="text-sm text-down hover:underline"
>{ i18n.T(ctx, "common.delete") }</button>
</div>
</form>
</details>
</li>
}
</ul>
}
<form data-api={ "/org/statuspages/" + e.ID + "/groups" } data-next={ "/statuspages/" + e.ID } class="border border-rule p-3">
@formError()
<div class="grid gap-3 sm:grid-cols-[1fr_1fr_5rem]">
<label class="block">
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.create") }</span>
<input name="name" required maxlength="100" placeholder={ i18n.T(ctx, "sso.field.name") } class={ inputClass }/>
</label>
<label class="block">
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "groups.parent") }</span>
<select name="parent_id" data-nullable class={ inputClass }>
<option value="">{ i18n.T(ctx, "groups.none") }</option>
for _, opt := range e.Groups {
<option value={ opt.ID }>{ opt.Label }</option>
}
</select>
</label>
<label class="block">
<span class="mb-1 block text-xs text-muted">{ i18n.T(ctx, "pages.group_position") }</span>
<input type="number" name="position" data-number value={ strconv.Itoa(len(e.Groups)) } class={ inputClass }/>
</label>
</div>
<div class="mt-3">
@submit(i18n.T(ctx, "groups.create"))
</div>
</form>
</section>
<section class="mb-12">
@sectionHeading("pages.components")
<form data-api={ "/org/statuspages/" + e.ID + "/monitors" } data-method="put" data-rows="monitors" data-next={ "/statuspages/" + e.ID }>
@@ -138,11 +242,21 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
for _, m := range e.Monitors {
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
<span>{ m.Name }</span>
<span class="flex flex-wrap items-baseline gap-x-2">
<span>{ m.Name }</span>
if m.MonitorGroupPath != "" {
<span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span>
}
</span>
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
<span></span>
<span class="flex gap-2">
<input data-field="section" value={ m.Section } placeholder={ i18n.T(ctx, "pages.section") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
for _, opt := range e.Groups {
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
}
</select>
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
</span>
</li>
File diff suppressed because it is too large. Load diff
+25
View File
@@ -43,6 +43,21 @@ X-Empty:
</div>
<button type="submit">save</button>
</form>
<form data-api="/org/statuspages/p1/monitors" data-method="put" data-rows="monitors" id="sp">
<div data-row>
<input type="checkbox" data-field="include" checked>
<input type="hidden" data-field="monitor_id" value="m1">
<select data-field="group_id" data-nullable><option value="" selected>none</option><option value="g1">G1</option></select>
<input data-field="label" value="Web">
</div>
<div data-row>
<input type="checkbox" data-field="include" checked>
<input type="hidden" data-field="monitor_id" value="m2">
<select data-field="group_id" data-nullable><option value="">none</option><option value="g1" selected>G1</option></select>
<input data-field="label" value="">
</div>
<button type="submit">save</button>
</form>
<pre id="out"></pre>
<script>
const sent = [];
@@ -114,6 +129,16 @@ window.axios = { create: () => ({ interceptors: { request: { use() {} } }, reque
]);
qhForm.querySelector("[data-quiet-remove]").click();
check("removing all quiet_hours rows sends empty array", (await submitQH()).quiet_hours, []);
const spForm = document.getElementById("sp");
spForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
await new Promise((r) => setTimeout(r, 20));
check("data-rows respects data-nullable on group_id", sent.at(-1), {
monitors: [
{ monitor_id: "m1", group_id: null, label: "Web" },
{ monitor_id: "m2", group_id: "g1", label: "" },
],
});
document.getElementById("out").textContent = out.join("\n");
})();
</script></body></html>