Merge pull request 'feat(statuspage): show the open incident's status next to its component' (#146) from feat/component-incident-status into main
release / release (push) Successful in 11m48s
ci / image (push) Successful in 5m18s
ci / lint (push) Successful in 10m25s
ci / test (push) Successful in 9m43s
ci / build (push) Successful in 18m40s

This commit was merged in pull request #146.
This commit is contained in:
Sebi committed 2026-11-24 06:11:19 +00:00
commit 442b45b974
4 files changed
+190 -146

No files matched your search

+16
View File
@@ -275,6 +275,22 @@ func (s PageSnapshot) IncidentsForComponent(componentName string) []PageIncident
return out return out
} }
// OpenIncidentStatus returns the newest unresolved incident of
// componentName the organization gave a status, if any.
func (s PageSnapshot) OpenIncidentStatus(componentName string) (PageIncident, bool) {
var found PageIncident
ok := false
for _, inc := range s.Incidents {
if inc.Component != componentName || inc.ResolvedAt != nil || inc.Status == "" {
continue
}
if !ok || inc.StartedAt.After(found.StartedAt) {
found, ok = inc, true
}
}
return found, ok
}
// MaintenanceForComponent splits planned maintenance affecting componentName // MaintenanceForComponent splits planned maintenance affecting componentName
// into ongoing and upcoming occurrences at now. // into ongoing and upcoming occurrences at now.
func (s PageSnapshot) MaintenanceForComponent(componentName string, now time.Time) (ongoing, upcoming []PageMaintenance) { func (s PageSnapshot) MaintenanceForComponent(componentName string, now time.Time) (ongoing, upcoming []PageMaintenance) {
+4
View File
@@ -390,6 +390,10 @@ func TestNestedGroupsAndComponentDetails(t *testing.T) {
if !strings.Contains(body, "Warten auf Anbieter") || !strings.Contains(body, "background-color:#7c3aed") { if !strings.Contains(body, "Warten auf Anbieter") || !strings.Contains(body, "background-color:#7c3aed") {
t.Error("the own status lacks its name or color") t.Error("the own status lacks its name or color")
} }
// The component list names the status of the newest open incident.
if i, j := strings.Index(body, "Beobachtung"), strings.Index(body, "Letzte Vorfälle"); i < 0 || i > j {
t.Error("the component list lacks the status of the open incident")
}
// Recent incidents come before planned maintenance. // Recent incidents come before planned maintenance.
if i, j := strings.Index(body, "Letzte Vorfälle"), strings.Index(body, "Geplante Wartung"); i < 0 || j < 0 || i > j { if i, j := strings.Index(body, "Letzte Vorfälle"), strings.Index(body, "Geplante Wartung"); i < 0 || j < 0 || i > j {
t.Errorf("incidents at %d, planned maintenance at %d: want incidents first", i, j) t.Errorf("incidents at %d, planned maintenance at %d: want incidents first", i, j)
+9 -3
View File
@@ -138,10 +138,10 @@ templ publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a
<li class="py-3"> <li class="py-3">
if href := ComponentHref(a.ComponentBase, comp, s.ShowDetails); href != "" { if href := ComponentHref(a.ComponentBase, comp, s.ShowDetails); href != "" {
<a href={ templ.SafeURL(href) } class="block rounded-sm transition hover:bg-rule/30"> <a href={ templ.SafeURL(href) } class="block rounded-sm transition hover:bg-rule/30">
@publicComponentBody(comp, true) @publicComponentBody(comp, s, true)
</a> </a>
} else { } else {
@publicComponentBody(comp, false) @publicComponentBody(comp, s, false)
if s.ShowDetails && comp.Details != nil { if s.ShowDetails && comp.Details != nil {
<details class="mt-2 border-t border-rule pt-2 text-xs"> <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> <summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "page.details_expand") }</summary>
@@ -160,11 +160,17 @@ templ publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a
} }
} }
templ publicComponentBody(comp agentapi.Component, clickable bool) { templ publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, clickable bool) {
<div class="mb-2 flex items-center gap-2.5"> <div class="mb-2 flex items-center gap-2.5">
@statusDot(PageStatus(comp.Status)) @statusDot(PageStatus(comp.Status))
<span class={ templ.KV("underline-offset-2 hover:underline", clickable) }>{ comp.Name }</span> <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 class="ml-auto flex items-center gap-2 text-sm text-muted">
if inc, ok := s.OpenIncidentStatus(comp.Name); ok {
<span class="text-xs">
@incidentStatusLabel(IncidentStatusInfo{Key: inc.Status, Name: inc.StatusName, Color: inc.StatusColor}, true)
</span>
<span aria-hidden="true">·</span>
}
<span>{ i18n.T(ctx, "page.component."+comp.Status) }</span> <span>{ i18n.T(ctx, "page.component."+comp.Status) }</span>
if clickable { if clickable {
<span aria-hidden="true" class="text-xs">→</span> <span aria-hidden="true" class="text-xs">→</span>
File diff suppressed because it is too large. Load diff