feat(console): set an incident's status right in the incident list #145
No files matched your search
@@ -136,7 +136,7 @@ var endpoints = []endpoint{
|
||||
{method: "PATCH", path: "/api/v1/org/incidents/:id", tag: "Monitors", summary: "Name an incident", perm: "incidents.write",
|
||||
description: "The title status pages show; empty shows the monitor's name.", req: incidentTitleRequest{}, status: http.StatusNoContent},
|
||||
{method: "POST", path: "/api/v1/org/incidents/:id/updates", tag: "Monitors", summary: "Post an update with a status", perm: "incidents.write",
|
||||
description: "`status` is a built-in status or the `id` of one of the organization's own. `message` is Markdown. `public` (default true) shows it on status pages; false keeps it an internal note. The update's status becomes the incident's.",
|
||||
description: "`status` is a built-in status or the `id` of one of the organization's own. `message` is Markdown and may be empty to just change the status. `public` (default true) shows it on status pages; false keeps it an internal note. The update's status becomes the incident's.",
|
||||
req: incidentUpdateRequest{}, resp: incidentUpdateView{}, status: http.StatusCreated},
|
||||
{method: "DELETE", path: "/api/v1/org/incidents/:id/updates/:update", tag: "Monitors", summary: "Delete an update", perm: "incidents.write",
|
||||
status: http.StatusNoContent},
|
||||
|
||||
@@ -909,12 +909,16 @@ func (s *Server) incidentsView(c *gin.Context, p *principal, page web.Page, me w
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v := web.IncidentsView{Rows: make([]web.IncidentRow, len(rows)), Pager: pager(c, info)}
|
||||
v := web.IncidentsView{Rows: make([]web.IncidentRow, len(rows)), Pager: pager(c, info), Custom: d.statuses.list()}
|
||||
for i, r := range rows {
|
||||
v.Rows[i] = d.incidentRow(store.Incident{
|
||||
inc := store.Incident{
|
||||
ID: r.ID, OrgID: r.OrgID, MonitorID: r.MonitorID, StartedAt: r.StartedAt, ResolvedAt: r.ResolvedAt, Cause: r.Cause,
|
||||
Title: r.Title, Status: r.Status, StatusID: r.StatusID,
|
||||
}, r.MonitorName)
|
||||
}
|
||||
v.Rows[i] = d.incidentRow(inc, r.MonitorName)
|
||||
// Whoever may write the monitor's incidents sets the status here.
|
||||
v.Rows[i].CanWrite = canInGroup(p, authz.IncidentsWrite, d.tree, d.byID[r.MonitorID].GroupID)
|
||||
v.Rows[i].NextStatus = nextIncidentStatus(inc)
|
||||
}
|
||||
if monitor != nil {
|
||||
if m, ok := d.byID[*monitor]; ok {
|
||||
|
||||
@@ -47,6 +47,16 @@ func (cs customStatuses) info(key *string, id *uuid.UUID) web.IncidentStatusInfo
|
||||
return web.IncidentStatusInfo{Key: *key}
|
||||
}
|
||||
|
||||
// list returns the statuses for a form, by name.
|
||||
func (cs customStatuses) list() []web.CustomIncidentStatus {
|
||||
out := make([]web.CustomIncidentStatus, 0, len(cs))
|
||||
for _, st := range cs {
|
||||
out = append(out, web.CustomIncidentStatus{ID: st.ID.String(), Name: st.Name, Color: st.Color})
|
||||
}
|
||||
slices.SortFunc(out, func(a, b web.CustomIncidentStatus) int { return strings.Compare(a.Name, b.Name) })
|
||||
return out
|
||||
}
|
||||
|
||||
// of is what an incident shows: resolved once its monitor recovered,
|
||||
// otherwise the status of its latest update, empty before one.
|
||||
func (cs customStatuses) of(i store.Incident) web.IncidentStatusInfo {
|
||||
@@ -207,14 +217,16 @@ func (s *Server) setIncidentTitle(c *gin.Context) {
|
||||
|
||||
type incidentUpdateRequest struct {
|
||||
// Status is a built-in status or the ID of a custom one.
|
||||
Status string `json:"status" binding:"required"`
|
||||
Message string `json:"message" binding:"required,max=5000"`
|
||||
Status string `json:"status" binding:"required"`
|
||||
// Message is Markdown; empty just changes the status.
|
||||
Message string `json:"message" binding:"max=5000"`
|
||||
// Public shows the update on status pages; otherwise it is an internal
|
||||
// note. Defaults to public.
|
||||
Public *bool `json:"public"`
|
||||
}
|
||||
|
||||
// addIncidentUpdate tells what is going on: a status and a message.
|
||||
// addIncidentUpdate tells what is going on: a status and, usually, a
|
||||
// message.
|
||||
func (s *Server) addIncidentUpdate(c *gin.Context) {
|
||||
var req incidentUpdateRequest
|
||||
if !bind(c, &req) {
|
||||
@@ -233,7 +245,7 @@ func (s *Server) addIncidentUpdate(c *gin.Context) {
|
||||
}
|
||||
key, statusID = "custom", &id
|
||||
}
|
||||
if (statusID == nil && !slices.Contains(web.IncidentStatuses, key)) || req.Message == "" {
|
||||
if statusID == nil && !slices.Contains(web.IncidentStatuses, key) {
|
||||
fail(c, http.StatusUnprocessableEntity, "invalid_input")
|
||||
return
|
||||
}
|
||||
@@ -345,10 +357,7 @@ func (s *Server) incidentDetailView(c *gin.Context, p *principal, page web.Page,
|
||||
v.Timeline = append(v.Timeline, x.e)
|
||||
}
|
||||
v.NextStatus = nextIncidentStatus(inc)
|
||||
for _, st := range d.statuses {
|
||||
v.Custom = append(v.Custom, web.CustomIncidentStatus{ID: st.ID.String(), Name: st.Name, Color: st.Color})
|
||||
}
|
||||
slices.SortFunc(v.Custom, func(a, b web.CustomIncidentStatus) int { return strings.Compare(a.Name, b.Name) })
|
||||
v.Custom = d.statuses.list()
|
||||
return web.IncidentDetailPage(page, me, v), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,8 @@ func TestIncidentUpdates(t *testing.T) {
|
||||
}
|
||||
|
||||
// Updates with a status, public or internal, and a title.
|
||||
for _, bad := range []map[string]any{
|
||||
{"status": "panicking", "message": "x"},
|
||||
{"status": "investigating", "message": " "},
|
||||
} {
|
||||
st, body := owner.do("POST", base+"/updates", bad)
|
||||
expect(t, "invalid update", st, body, http.StatusUnprocessableEntity, "invalid_input")
|
||||
}
|
||||
st, body := owner.do("POST", base+"/updates", map[string]any{"status": "panicking", "message": "x"})
|
||||
expect(t, "invalid status", st, body, http.StatusUnprocessableEntity, "invalid_input")
|
||||
if st, body := owner.do("POST", base+"/updates", map[string]any{"status": "investigating", "message": "We are **looking** into it."}); st != http.StatusCreated {
|
||||
t.Fatalf("post update = %d %v", st, body)
|
||||
}
|
||||
@@ -95,12 +90,26 @@ func TestIncidentUpdates(t *testing.T) {
|
||||
if st, _ := viewer.do("GET", base, nil); st != http.StatusOK {
|
||||
t.Errorf("viewer reads incident = %d", st)
|
||||
}
|
||||
st, body := viewer.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "x"})
|
||||
st, body = viewer.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "x"})
|
||||
expect(t, "viewer posts update", st, body, http.StatusForbidden, "forbidden")
|
||||
// The incident list sets the status right there, for writers only.
|
||||
if _, _, html := owner.page("/incidents"); !strings.Contains(html, "Set status") || !strings.Contains(html, `data-api="/org/incidents/`+incident.String()+`/updates"`) {
|
||||
t.Error("the incident list lacks the set-status button")
|
||||
}
|
||||
if _, _, html := viewer.page("/incidents"); strings.Contains(html, "Set status") {
|
||||
t.Error("the viewer is offered setting the status")
|
||||
}
|
||||
if _, _, html := viewer.page("/incidents/" + incident.String()); strings.Contains(html, "Post update") {
|
||||
t.Error("the viewer is offered the update form")
|
||||
}
|
||||
|
||||
// A status change needs no message.
|
||||
_, quick := owner.do("POST", base+"/updates", map[string]any{"status": "monitoring", "message": "", "public": true})
|
||||
if quick["status"] != "monitoring" || status() != "monitoring" {
|
||||
t.Errorf("status-only update = %v", quick)
|
||||
}
|
||||
owner.do("DELETE", base+"/updates/"+quick["id"].(string), nil)
|
||||
|
||||
// Deleting an update falls back to the previous status; the monitor
|
||||
// recovering resolves the incident whatever was said.
|
||||
if st, _ := owner.do("DELETE", base+"/updates/"+note["id"].(string), nil); st != http.StatusNoContent || status() != "investigating" {
|
||||
|
||||
@@ -820,11 +820,13 @@
|
||||
"incident.delete_confirm": "Dieses Update löschen? Es verschwindet auch von den Statusseiten.",
|
||||
"incident.internal": "intern",
|
||||
"incident.message": "Was ist los",
|
||||
"incident.message_optional": "Nachricht (optional, Markdown)",
|
||||
"incident.post": "Update veröffentlichen",
|
||||
"incident.post_update": "Update veröffentlichen",
|
||||
"incident.public": "Auf Statusseiten zeigen",
|
||||
"incident.public_hint": "Ausgeschaltet bleibt es eine interne Notiz für dein Team.",
|
||||
"incident.recovered": "Monitor wieder erreichbar",
|
||||
"incident.set_status": "Status setzen",
|
||||
"incident.status": "Status",
|
||||
"incident.status.identified": "Ursache gefunden",
|
||||
"incident.status.investigating": "Untersuchung läuft",
|
||||
|
||||
@@ -820,11 +820,13 @@
|
||||
"incident.delete_confirm": "Delete this update? It disappears from status pages too.",
|
||||
"incident.internal": "internal",
|
||||
"incident.message": "What is going on",
|
||||
"incident.message_optional": "Message (optional, Markdown)",
|
||||
"incident.post": "Post update",
|
||||
"incident.post_update": "Post an update",
|
||||
"incident.public": "Show on status pages",
|
||||
"incident.public_hint": "Off keeps it an internal note for your team.",
|
||||
"incident.recovered": "Monitor recovered",
|
||||
"incident.set_status": "Set status",
|
||||
"incident.status": "Status",
|
||||
"incident.status.identified": "Identified",
|
||||
"incident.status.investigating": "Investigating",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
-- +goose Up
|
||||
-- An update may just change the status, without a message.
|
||||
ALTER TABLE incident_updates DROP CONSTRAINT incident_updates_message_check;
|
||||
ALTER TABLE incident_updates ADD CONSTRAINT incident_updates_message_check CHECK (length(message) <= 5000);
|
||||
|
||||
-- +goose Down
|
||||
UPDATE incident_updates SET message = '–' WHERE message = '';
|
||||
ALTER TABLE incident_updates DROP CONSTRAINT incident_updates_message_check;
|
||||
ALTER TABLE incident_updates ADD CONSTRAINT incident_updates_message_check CHECK (length(message) BETWEEN 1 AND 5000);
|
||||
@@ -289,6 +289,10 @@ type IncidentRow struct {
|
||||
// Title and Status are what the organization said about it.
|
||||
Title string
|
||||
Status IncidentStatusInfo
|
||||
// CanWrite offers setting the status right in the list, NextStatus
|
||||
// preselected.
|
||||
CanWrite bool
|
||||
NextStatus string
|
||||
}
|
||||
|
||||
// MonitorDetailView is the data of a monitor page.
|
||||
@@ -425,7 +429,7 @@ templ MonitorDetail(p Page, me Me, v MonitorDetailView) {
|
||||
if len(v.Incidents) > 0 {
|
||||
<section class="mb-10">
|
||||
@sectionHeading("incidents.title")
|
||||
@incidentList(v.Incidents, false)
|
||||
@incidentList(v.Incidents, false, nil)
|
||||
if v.MoreIncidents {
|
||||
<a href={ templ.SafeURL("/incidents?monitor=" + v.Row.ID) } class="mt-3 inline-block text-sm text-muted hover:text-ink">{ i18n.T(ctx, "incidents.all_of_monitor") } →</a>
|
||||
}
|
||||
@@ -494,7 +498,7 @@ templ ResultsPage(p Page, me Me, v ResultsView) {
|
||||
}
|
||||
}
|
||||
|
||||
templ incidentList(rows []IncidentRow, showMonitor bool) {
|
||||
templ incidentList(rows []IncidentRow, showMonitor bool, custom []CustomIncidentStatus) {
|
||||
<ul class="divide-y divide-rule border-y border-rule text-sm">
|
||||
for _, r := range rows {
|
||||
<li class="py-2.5">
|
||||
@@ -508,6 +512,9 @@ templ incidentList(rows []IncidentRow, showMonitor bool) {
|
||||
}
|
||||
<a href={ templ.SafeURL("/incidents/" + r.ID) } class="font-mono text-xs text-muted hover:text-ink">{ r.Started }</a>
|
||||
<span class="ml-auto font-mono text-xs">{ r.Duration }</span>
|
||||
if r.CanWrite {
|
||||
@quickStatus(r, custom)
|
||||
}
|
||||
</div>
|
||||
if len(r.Cause) > 0 {
|
||||
<p class="mt-1 font-mono text-xs text-muted">{ strings.Join(r.Cause, " · ") }</p>
|
||||
@@ -517,11 +524,38 @@ templ incidentList(rows []IncidentRow, showMonitor bool) {
|
||||
</ul>
|
||||
}
|
||||
|
||||
// quickStatus sets an incident's status right in the list, with an
|
||||
// optional message.
|
||||
templ quickStatus(r IncidentRow, custom []CustomIncidentStatus) {
|
||||
<details class="group w-full sm:w-auto">
|
||||
<summary class="cursor-pointer list-none border border-ink px-2 py-0.5 text-xs hover:bg-ink hover:text-paper">{ i18n.T(ctx, "incident.set_status") }</summary>
|
||||
<form data-api={ "/org/incidents/" + r.ID + "/updates" } data-next="/incidents" class="mt-3 grid gap-2 border border-rule p-3 sm:w-80">
|
||||
@formError()
|
||||
<select name="status" class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
|
||||
for _, st := range IncidentStatuses {
|
||||
<option value={ st } selected?={ st == r.NextStatus }>{ i18n.T(ctx, "incident.status."+st) }</option>
|
||||
}
|
||||
for _, st := range custom {
|
||||
<option value={ st.ID } selected?={ st.ID == r.NextStatus }>{ st.Name }</option>
|
||||
}
|
||||
</select>
|
||||
<textarea name="message" rows="2" maxlength="5000" placeholder={ i18n.T(ctx, "incident.message_optional") } class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm outline-none focus:border-ink"></textarea>
|
||||
<label class="flex items-center gap-2 text-xs">
|
||||
<input type="checkbox" name="public" checked class="accent-ink"/>
|
||||
{ i18n.T(ctx, "incident.public") }
|
||||
</label>
|
||||
<button type="submit" class="bg-ink px-3 py-1.5 text-sm text-paper">{ i18n.T(ctx, "incident.set_status") }</button>
|
||||
</form>
|
||||
</details>
|
||||
}
|
||||
|
||||
// IncidentsView is a page of incidents, of one monitor if Monitor is set.
|
||||
type IncidentsView struct {
|
||||
Rows []IncidentRow
|
||||
Pager Pager
|
||||
Monitor, MonitorID string
|
||||
// Custom are the organization's own statuses to set.
|
||||
Custom []CustomIncidentStatus
|
||||
}
|
||||
|
||||
templ IncidentsPage(p Page, me Me, v IncidentsView) {
|
||||
@@ -537,7 +571,7 @@ templ IncidentsPage(p Page, me Me, v IncidentsView) {
|
||||
if len(v.Rows) == 0 {
|
||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "incidents.none") }</p>
|
||||
} else {
|
||||
@incidentList(v.Rows, v.Monitor == "")
|
||||
@incidentList(v.Rows, v.Monitor == "", v.Custom)
|
||||
}
|
||||
@pager(v.Pager, "newer", "older")
|
||||
}
|
||||
|
||||
+1874
-1670
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user