Merge pull request 'feat(statuspage): show the open incident's status next to its component' (#146) from feat/component-incident-status into main
This commit is contained in:
commit
1a89c193a7
4 files changed
+190
-146
No files matched your search
@@ -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) {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
+161
-143
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user