perf(statuspages): page the monitor list and batch the group import
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m59s
ci / test (pull_request) Successful in 12m44s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Canceled after 1m1s

With thousands of monitors on a status page the editor was tens of
megabytes, as every row carried the options of all groups, and
importing the monitor groups updated each monitor in its own statement.

- The monitors of the editor are shown 50 at a time. All rows stay in
  the form, as saving replaces the page's monitors.
- Rows carry their own group only and get the other options from the
  row template once shown or focused.
- The filter matches a monitor's name and group path only, no longer
  the names of the groups in its select.
- The import creates the groups one nesting level at a time and files
  all monitors in one statement.

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-26 23:38:08 +01:00
1 parent 383b63bc0e
commit 52d2ce25c9
10 files changed
+865 -498

No files matched your search

+42 -31
View File
@@ -256,7 +256,7 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
pageID := uuid.MustParse(c.Param("id")) pageID := uuid.MustParse(c.Param("id"))
p := current(c) p := current(c)
ctx := c.Request.Context() ctx := c.Request.Context()
var created []store.StatusPageGroup var created []pageGroupView
err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
if _, err := q.GetStatusPage(ctx, pageID); err != nil { if _, err := q.GetStatusPage(ctx, pageID); err != nil {
return err return err
@@ -290,54 +290,66 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
if err := q.ClearStatusPageGroups(ctx, pageID); err != nil { if err := q.ClearStatusPageGroups(ctx, pageID); err != nil {
return err return err
} }
mapped := map[uuid.UUID]store.StatusPageGroup{} // Large organizations have thousands of monitors and hundreds of
var createErr error // groups, so both are written in a few statements: the groups one
// level of nesting at a time, as parents must exist before their
// children, the monitors all at once.
mapped := map[uuid.UUID]pageGroupView{}
var levels []store.CreateStatusPageGroupsParams
posByParent := map[uuid.UUID]int32{} posByParent := map[uuid.UUID]int32{}
tree.walk(func(g store.MonitorGroup, _ int) { tree.walk(func(g store.MonitorGroup, depth int) {
if createErr != nil || !needed[g.ID] { if !needed[g.ID] {
return return
} }
var parentKey uuid.UUID
var parentID *uuid.UUID var parentID *uuid.UUID
if g.ParentID != nil { if g.ParentID != nil {
if parent, ok := mapped[*g.ParentID]; ok { if parent, ok := mapped[*g.ParentID]; ok {
pid := parent.ID pid := parent.ID
parentID = &pid parentID = &pid
parentKey = pid
} }
} }
var parentKey uuid.UUID
if parentID != nil {
parentKey = *parentID
}
pos := posByParent[parentKey] pos := posByParent[parentKey]
posByParent[parentKey] = pos + 1 posByParent[parentKey] = pos + 1
row, err := q.CreateStatusPageGroup(ctx, store.CreateStatusPageGroupParams{ row := pageGroupView{ID: uuid.New(), Name: g.Name, ParentID: parentID, Position: pos}
PageID: pageID,
OrgID: p.Org.ID,
ParentID: parentID,
Name: g.Name,
Position: pos,
})
if err != nil {
createErr = err
return
}
mapped[g.ID] = row mapped[g.ID] = row
created = append(created, row) created = append(created, row)
}) for len(levels) <= depth {
if createErr != nil { levels = append(levels, store.CreateStatusPageGroupsParams{PageID: pageID, OrgID: p.Org.ID})
return createErr
} }
l := &levels[depth]
l.Ids = append(l.Ids, row.ID)
l.ParentIds = append(l.ParentIds, parentKey)
l.Names = append(l.Names, row.Name)
l.Positions = append(l.Positions, row.Position)
})
for _, l := range levels {
if len(l.Ids) == 0 {
continue
}
if err := q.CreateStatusPageGroups(ctx, l); err != nil {
return err
}
}
set := store.SetStatusPageMonitorGroupsParams{PageID: pageID}
for _, m := range listed { for _, m := range listed {
var gid *uuid.UUID var gid uuid.UUID
section := "" section := ""
if m.MonitorGroupID != nil { if m.MonitorGroupID != nil {
if g, ok := mapped[*m.MonitorGroupID]; ok { if g, ok := mapped[*m.MonitorGroupID]; ok {
id := g.ID gid = g.ID
gid = &id
section = g.Name section = g.Name
} }
} }
if err := q.SetStatusPageMonitorGroup(ctx, store.SetStatusPageMonitorGroupParams{ set.MonitorIds = append(set.MonitorIds, m.MonitorID)
PageID: pageID, MonitorID: m.MonitorID, GroupID: gid, Section: section, set.GroupIds = append(set.GroupIds, gid)
}); err != nil { set.Sections = append(set.Sections, section)
}
if len(set.MonitorIds) > 0 {
if err := q.SetStatusPageMonitorGroups(ctx, set); err != nil {
return err return err
} }
} }
@@ -351,11 +363,10 @@ func (s *Server) importStatusPageGroups(c *gin.Context) {
internalError(c, err) internalError(c, err)
return return
} }
out := make([]pageGroupView, 0, len(created)) if created == nil {
for _, g := range created { created = []pageGroupView{}
out = append(out, pageGroupView{ID: g.ID, Name: g.Name, ParentID: g.ParentID, Position: g.Position})
} }
c.JSON(http.StatusOK, gin.H{"groups": out}) c.JSON(http.StatusOK, gin.H{"groups": created})
} }
// resolvePageMonitorGroup returns the status page group ID and section label // resolvePageMonitorGroup returns the status page group ID and section label
+1
View File
@@ -1310,6 +1310,7 @@
"pages.monitors_filter": "Monitore filtern", "pages.monitors_filter": "Monitore filtern",
"pages.monitors_all": "Alle hinzufügen", "pages.monitors_all": "Alle hinzufügen",
"pages.monitors_none": "Alle entfernen", "pages.monitors_none": "Alle entfernen",
"pages.monitors_range": "{from}–{to} von {total}",
"pages.no_group": "Ohne Gruppe", "pages.no_group": "Ohne Gruppe",
"pages.open": "Öffnen", "pages.open": "Öffnen",
"pages.own_servers": "Die Statusseiten dieser Organisation liefern nur ihre eigenen Statusseiten-Server aus, nicht die der Plattform. Ruf sie über die Adresse deiner Server auf oder verbinde eine eigene Domain, die auf sie zeigt.", "pages.own_servers": "Die Statusseiten dieser Organisation liefern nur ihre eigenen Statusseiten-Server aus, nicht die der Plattform. Ruf sie über die Adresse deiner Server auf oder verbinde eine eigene Domain, die auf sie zeigt.",
+1
View File
@@ -1310,6 +1310,7 @@
"pages.monitors_filter": "Filter monitors", "pages.monitors_filter": "Filter monitors",
"pages.monitors_all": "Add all", "pages.monitors_all": "Add all",
"pages.monitors_none": "Remove all", "pages.monitors_none": "Remove all",
"pages.monitors_range": "{from}–{to} of {total}",
"pages.no_group": "No group", "pages.no_group": "No group",
"pages.open": "Open", "pages.open": "Open",
"pages.own_servers": "Your organization's own status page servers serve its pages; the platform's do not. Open them at the address of your servers or connect a custom domain pointing at them.", "pages.own_servers": "Your organization's own status page servers serve its pages; the platform's do not. Open them at the address of your servers or connect a custom domain pointing at them.",
+7 -1
View File
@@ -90,6 +90,10 @@ type Querier interface {
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error) CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error) CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error)
CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error) CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error)
// Creates many groups of a page at once, with ids the caller chose. Parents
// must exist before their children are created; a nil parent id (all
// zeros) means none.
CreateStatusPageGroups(ctx context.Context, arg CreateStatusPageGroupsParams) error
CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error) CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error)
CreateUser(ctx context.Context, arg CreateUserParams) (User, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
@@ -395,7 +399,9 @@ type Querier interface {
SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error
// Changing the domain drops a previous verification and its checks. // Changing the domain drops a previous verification and its checks.
SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error)
SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error // Files many monitors of a page at once; a nil group id (all zeros) files
// a monitor under none.
SetStatusPageMonitorGroups(ctx context.Context, arg SetStatusPageMonitorGroupsParams) error
SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error) SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error)
SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error)
SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error
+17 -3
View File
@@ -100,9 +100,23 @@ DELETE FROM status_page_monitors WHERE page_id = $1;
INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, group_id, label, position) INSERT INTO status_page_monitors (page_id, monitor_id, org_id, section, group_id, label, position)
VALUES ($1, $2, $3, $4, $5, $6, $7); VALUES ($1, $2, $3, $4, $5, $6, $7);
-- name: SetStatusPageMonitorGroup :exec -- name: SetStatusPageMonitorGroups :exec
UPDATE status_page_monitors SET group_id = $3, section = $4 -- Files many monitors of a page at once; a nil group id (all zeros) files
WHERE page_id = $1 AND monitor_id = $2; -- a monitor under none.
UPDATE status_page_monitors spm
SET group_id = nullif(v.group_id, '00000000-0000-0000-0000-000000000000'::uuid), section = v.section
FROM (SELECT unnest(sqlc.arg(monitor_ids)::uuid[]) AS monitor_id, unnest(sqlc.arg(group_ids)::uuid[]) AS group_id,
unnest(sqlc.arg(sections)::text[]) AS section) AS v
WHERE spm.page_id = sqlc.arg(page_id) AND spm.monitor_id = v.monitor_id;
-- name: CreateStatusPageGroups :exec
-- Creates many groups of a page at once, with ids the caller chose. Parents
-- must exist before their children are created; a nil parent id (all
-- zeros) means none.
INSERT INTO status_page_groups (id, page_id, org_id, parent_id, name, position)
SELECT v.id, sqlc.arg(page_id), sqlc.arg(org_id), nullif(v.parent_id, '00000000-0000-0000-0000-000000000000'::uuid), v.name, v.position
FROM (SELECT unnest(sqlc.arg(ids)::uuid[]) AS id, unnest(sqlc.arg(parent_ids)::uuid[]) AS parent_id,
unnest(sqlc.arg(names)::text[]) AS name, unnest(sqlc.arg(positions)::int[]) AS position) AS v;
-- name: ListStatusPageGroups :many -- name: ListStatusPageGroups :many
SELECT * FROM status_page_groups SELECT * FROM status_page_groups
+48 -12
View File
@@ -150,6 +150,37 @@ func (q *Queries) CreateStatusPageGroup(ctx context.Context, arg CreateStatusPag
return i, err return i, err
} }
const createStatusPageGroups = `-- name: CreateStatusPageGroups :exec
INSERT INTO status_page_groups (id, page_id, org_id, parent_id, name, position)
SELECT v.id, $1, $2, nullif(v.parent_id, '00000000-0000-0000-0000-000000000000'::uuid), v.name, v.position
FROM (SELECT unnest($3::uuid[]) AS id, unnest($4::uuid[]) AS parent_id,
unnest($5::text[]) AS name, unnest($6::int[]) AS position) AS v
`
type CreateStatusPageGroupsParams struct {
PageID uuid.UUID
OrgID uuid.UUID
Ids []uuid.UUID
ParentIds []uuid.UUID
Names []string
Positions []int32
}
// Creates many groups of a page at once, with ids the caller chose. Parents
// must exist before their children are created; a nil parent id (all
// zeros) means none.
func (q *Queries) CreateStatusPageGroups(ctx context.Context, arg CreateStatusPageGroupsParams) error {
_, err := q.db.Exec(ctx, createStatusPageGroups,
arg.PageID,
arg.OrgID,
arg.Ids,
arg.ParentIds,
arg.Names,
arg.Positions,
)
return err
}
const deleteStatusPage = `-- name: DeleteStatusPage :execrows const deleteStatusPage = `-- name: DeleteStatusPage :execrows
DELETE FROM status_pages WHERE id = $1 DELETE FROM status_pages WHERE id = $1
` `
@@ -563,24 +594,29 @@ func (q *Queries) SetStatusPageDomain(ctx context.Context, arg SetStatusPageDoma
return i, err return i, err
} }
const setStatusPageMonitorGroup = `-- name: SetStatusPageMonitorGroup :exec const setStatusPageMonitorGroups = `-- name: SetStatusPageMonitorGroups :exec
UPDATE status_page_monitors SET group_id = $3, section = $4 UPDATE status_page_monitors spm
WHERE page_id = $1 AND monitor_id = $2 SET group_id = nullif(v.group_id, '00000000-0000-0000-0000-000000000000'::uuid), section = v.section
FROM (SELECT unnest($2::uuid[]) AS monitor_id, unnest($3::uuid[]) AS group_id,
unnest($4::text[]) AS section) AS v
WHERE spm.page_id = $1 AND spm.monitor_id = v.monitor_id
` `
type SetStatusPageMonitorGroupParams struct { type SetStatusPageMonitorGroupsParams struct {
PageID uuid.UUID PageID uuid.UUID
MonitorID uuid.UUID MonitorIds []uuid.UUID
GroupID *uuid.UUID GroupIds []uuid.UUID
Section string Sections []string
} }
func (q *Queries) SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error { // Files many monitors of a page at once; a nil group id (all zeros) files
_, err := q.db.Exec(ctx, setStatusPageMonitorGroup, // a monitor under none.
func (q *Queries) SetStatusPageMonitorGroups(ctx context.Context, arg SetStatusPageMonitorGroupsParams) error {
_, err := q.db.Exec(ctx, setStatusPageMonitorGroups,
arg.PageID, arg.PageID,
arg.MonitorID, arg.MonitorIds,
arg.GroupID, arg.GroupIds,
arg.Section, arg.Sections,
) )
return err return err
} }
+62 -5
View File
@@ -241,7 +241,7 @@
if (checkAll) { if (checkAll) {
const on = checkAll.dataset.checkAll === "on"; const on = checkAll.dataset.checkAll === "on";
checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => { checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => {
if (box.closest("[data-row]")?.hidden) return; if (box.closest("[data-row]")?.hasAttribute("data-filtered-out")) return;
box.checked = on; box.checked = on;
if (on) addRowFields(box); if (on) addRowFields(box);
}); });
@@ -341,15 +341,72 @@
if (ev.target.matches('[data-row] [data-field="include"]') && ev.target.checked) addRowFields(ev.target); if (ev.target.matches('[data-row] [data-field="include"]') && ev.target.checked) addRowFields(ev.target);
}); });
// [data-filter-rows] hides the rows of the list it names whose text does // Lists with data-page-size show that many of their rows at a time, of
// not contain what is typed. // those a filter leaves; the [data-row-pager] naming the list turns the
// pages. The other rows stay in the DOM, so forms still send them.
// Selects with data-lazy-options hold their chosen option only; the full
// list comes from the form's row template once the row is shown or used.
const fillOptions = (sel) => {
const tpl = sel.closest("form")?.querySelector("template[data-row-fields]");
const full = tpl?.content.querySelector(`select[data-field="${sel.dataset.field}"]`);
if (!full) return;
const value = sel.value;
sel.replaceChildren(...[...full.options].map((o) => o.cloneNode(true)));
sel.value = value;
sel.removeAttribute("data-lazy-options");
};
document.addEventListener("focusin", (ev) => {
if (ev.target.matches?.("select[data-lazy-options]")) fillOptions(ev.target);
});
const showRowPage = (list, page) => {
const rows = [...list.querySelectorAll(":scope > [data-row]")];
const size = Number(list.dataset.pageSize) || rows.length || 1;
const shown = rows.filter((row) => !row.hasAttribute("data-filtered-out"));
const pages = Math.max(1, Math.ceil(shown.length / size));
page = Math.min(Math.max(0, page), pages - 1);
list.dataset.page = String(page);
for (const row of rows) row.hidden = true;
for (const row of shown.slice(page * size, (page + 1) * size)) {
row.hidden = false;
row.querySelectorAll("select[data-lazy-options]").forEach(fillOptions);
}
for (const nav of document.querySelectorAll(`[data-row-pager="#${list.id}"]`)) {
nav.hidden = pages < 2;
nav.querySelector('[data-row-page="prev"]').disabled = page === 0;
nav.querySelector('[data-row-page="next"]').disabled = page >= pages - 1;
const status = nav.querySelector("[data-row-page-status]");
if (status) {
const values = {
from: shown.length ? page * size + 1 : 0,
to: Math.min((page + 1) * size, shown.length),
total: shown.length,
};
status.textContent = status.dataset.template.replace(/\{(\w+)\}/g, (m, k) => values[k] ?? m);
}
}
};
for (const list of document.querySelectorAll("[data-page-size][id]")) showRowPage(list, 0);
document.addEventListener("click", (ev) => {
const btn = ev.target.closest("[data-row-page]");
if (!btn) return;
const list = document.querySelector(btn.closest("[data-row-pager]").dataset.rowPager);
showRowPage(list, Number(list.dataset.page || 0) + (btn.dataset.rowPage === "next" ? 1 : -1));
});
// [data-filter-rows] hides the rows of the list it names whose text, or
// that of their [data-filter-text], does not contain what is typed.
document.addEventListener("input", (ev) => { document.addEventListener("input", (ev) => {
const input = ev.target.closest("[data-filter-rows]"); const input = ev.target.closest("[data-filter-rows]");
if (!input) return; if (!input) return;
const needle = input.value.trim().toLowerCase(); const needle = input.value.trim().toLowerCase();
for (const row of document.querySelectorAll(input.dataset.filterRows + " > [data-row]")) { const list = document.querySelector(input.dataset.filterRows);
row.hidden = needle !== "" && !row.textContent.toLowerCase().includes(needle); for (const row of list.querySelectorAll(":scope > [data-row]")) {
const text = (row.querySelector("[data-filter-text]") ?? row).textContent;
const out = needle !== "" && !text.toLowerCase().includes(needle);
row.toggleAttribute("data-filtered-out", out);
row.hidden = out;
} }
if (list.dataset.pageSize) showRowPage(list, 0);
}); });
// Only the settings of the selected check type are shown and submitted. // Only the settings of the selected check type are shown and submitted.
+29 -3
View File
@@ -320,11 +320,11 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
<template data-row-fields> <template data-row-fields>
@pageMonitorFields(e, PageMonitorOption{}) @pageMonitorFields(e, PageMonitorOption{})
</template> </template>
<ul id="page-monitors" class="mb-4 divide-y divide-rule border-y border-rule text-sm"> <ul id="page-monitors" class="mb-4 divide-y divide-rule border-y border-rule text-sm" data-page-size={ strconv.Itoa(monitorPageSize) }>
for _, m := range e.Monitors { 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"> <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 }/> <input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
<span class="flex flex-wrap items-baseline gap-x-2"> <span data-filter-text class="flex flex-wrap items-baseline gap-x-2">
<span>{ m.Name }</span> <span>{ m.Name }</span>
if m.MonitorGroupPath != "" { if m.MonitorGroupPath != "" {
<span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span> <span class="font-mono text-xs text-muted">{ m.MonitorGroupPath }</span>
@@ -339,6 +339,15 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
</li> </li>
} }
</ul> </ul>
if len(e.Monitors) > monitorPageSize {
// All rows stay in the form, as saving replaces the page's
// monitors; the pager only shows them a page at a time.
<nav data-row-pager="#page-monitors" class="-mt-2 mb-4 flex flex-wrap items-center gap-x-5 gap-y-2 text-sm" aria-label={ i18n.T(ctx, "pager.label") }>
<button type="button" data-row-page="prev" class="text-muted hover:text-ink disabled:opacity-40">← { i18n.T(ctx, "pager.previous") }</button>
<span data-row-page-status data-template={ i18n.T(ctx, "pages.monitors_range") } class="text-xs text-muted"></span>
<button type="button" data-row-page="next" class="text-muted hover:text-ink disabled:opacity-40">{ i18n.T(ctx, "pager.next") } →</button>
</nav>
}
@submit(i18n.T(ctx, "common.save")) @submit(i18n.T(ctx, "common.save"))
</form> </form>
</section> </section>
@@ -416,16 +425,33 @@ templ verifyButton(pageID, label string) {
// offers to filter them. // offers to filter them.
const monitorFilterFrom = 15 const monitorFilterFrom = 15
// monitorPageSize is how many monitors the page editor shows at a time.
const monitorPageSize = 50
// pageMonitorFields are the group and label of m on the page. // pageMonitorFields are the group and label of m on the page.
templ pageMonitorFields(e PageEditor, m PageMonitorOption) { templ pageMonitorFields(e PageEditor, m PageMonitorOption) {
<span data-row-extra></span> <span data-row-extra></span>
<span class="flex gap-2"> <span class="flex gap-2">
if m.ID == "" {
<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"> <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> <option value="">{ i18n.T(ctx, "pages.no_group") }</option>
for _, opt := range e.Groups { for _, opt := range e.Groups {
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option> <option value={ opt.ID }>{ opt.Label }</option>
} }
</select> </select>
} else {
// With thousands of monitors and hundreds of groups the options of
// every row would make the page tens of megabytes: rows carry their
// group only and get the others from the template when shown.
<select data-field="group_id" data-nullable data-lazy-options 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 {
if opt.ID == m.GroupID {
<option value={ opt.ID } selected>{ 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"/> <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> </span>
} }
File diff suppressed because it is too large. Load diff
+72
View File
@@ -0,0 +1,72 @@
<!doctype html><html><body data-msg-network="net">
<form data-api="/org/statuspages/p1/monitors" data-method="put" data-rows="monitors" data-next="#saved" id="sp">
<p><button type="button" id="all" data-check-all="on" data-check-target="[data-field=include]">all</button></p>
<input type="search" id="filter" data-filter-rows="#rows">
<template data-row-fields><span data-row-extra></span><select data-field="group_id" data-nullable><option value="">none</option><option value="g1">G1</option><option value="g2">G2</option></select></template>
<ul id="rows" data-page-size="2"></ul>
<nav data-row-pager="#rows">
<button type="button" id="prev" data-row-page="prev">prev</button>
<span id="status" data-row-page-status data-template="{from}-{to}/{total}"></span>
<button type="button" id="next" data-row-page="next">next</button>
</nav>
<button type="submit">save</button>
</form>
<pre id="out"></pre>
<script>
const sent = [];
window.axios = { create: () => ({ interceptors: { request: { use() {} } }, request: async (cfg) => { sent.push(cfg.data); return { data: {} }; }, post: async () => ({ data: {} }) }) };
const list = document.getElementById("rows");
for (const [id, name, on] of [["m1", "alpha", true], ["m2", "beta", false], ["m3", "gamma", false], ["m4", "alpine", false], ["m5", "delta", true]]) {
list.insertAdjacentHTML("beforeend", `<li data-row><input type="checkbox" data-field="include"${on ? " checked" : ""}><span data-filter-text>${name}</span><input type="hidden" data-field="monitor_id" value="${id}">${on ? '<span data-row-extra></span><select data-field="group_id" data-nullable data-lazy-options><option value="">none</option><option value="g2" selected>G2</option></select>' : ""}</li>`);
}
</script>
<script src="../assets/app.js"></script>
<script>
(async () => {
const out = [];
const check = (name, got, want) => {
const g = JSON.stringify(got), w = JSON.stringify(want);
out.push((g === w ? "PASS " : "FAIL ") + name + (g === w ? "" : " got=" + g + " want=" + w));
};
const visible = () => [...list.children].filter((r) => !r.hidden).map((r) => r.querySelector("[data-filter-text]").textContent);
const status = () => document.getElementById("status").textContent;
const submit = async () => {
sent.length = 0;
document.getElementById("sp").dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
await new Promise((r) => setTimeout(r, 50));
return sent[0] ? (typeof sent[0] === "string" ? JSON.parse(sent[0]) : sent[0]).monitors.map((m) => m.monitor_id) : null;
};
const sel = (id) => document.querySelector(`[value="${id}"]`).closest("[data-row]").querySelector("select");
check("shown row gets all options", [...sel("m1").options].map((o) => o.value), ["", "g1", "g2"]);
check("shown row keeps its group", sel("m1").value, "g2");
check("hidden row stays lean", sel("m5").options.length, 2);
check("first page", visible(), ["alpha", "beta"]);
check("first status", status(), "1-2/5");
check("prev disabled", document.getElementById("prev").disabled, true);
document.getElementById("next").click();
document.getElementById("next").click();
check("last page", visible(), ["delta"]);
check("last status", status(), "5-5/5");
check("next disabled", document.getElementById("next").disabled, true);
check("row shown later gets all options", sel("m5").options.length, 3);
check("rows of all pages sent", await submit(), ["m1", "m5"]);
const filter = document.getElementById("filter");
filter.value = "g1";
filter.dispatchEvent(new Event("input", { bubbles: true }));
check("group options are not searched", visible(), []);
filter.value = "alp";
filter.dispatchEvent(new Event("input", { bubbles: true }));
check("filtered", visible(), ["alpha", "alpine"]);
check("filtered status", status(), "1-2/2");
check("pager hidden for one page", document.querySelector("[data-row-pager]").hidden, true);
filter.value = "a";
filter.dispatchEvent(new Event("input", { bubbles: true }));
check("filter restarts at first page", visible(), ["alpha", "beta"]);
filter.value = "alp";
filter.dispatchEvent(new Event("input", { bubbles: true }));
document.getElementById("all").click();
check("check all ticks filtered rows only", await submit(), ["m1", "m4", "m5"]);
document.getElementById("out").textContent = out.join("\n");
})();
</script>
</body></html>