fix(monitors): stop selecting more regions than the limit allows
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m31s
ci / test (pull_request) Successful in 13m28s
ci / build (pull_request) Successful in 10m23s
ci / image (pull_request) Successful in 5m51s

The monitor form let users tick any number of regions and only the save
failed with the region limit. The form now knows the organization's
regions-per-monitor limit: it says how many regions a monitor may use,
counts the ticked ones, and once the limit is reached locks the other
regions that count towards it, in the list and on the map, until one is
unticked. Own regions stay free unless they count. The server still
enforces the limit.

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-29 12:17:08 +01:00
1 parent e9984f8271
commit 3a7bed5a3e
9 files changed
+1383 -1187

No files matched your search

+26 -1
View File
@@ -726,6 +726,9 @@ type RegionOption struct {
Lat, Lon *float64
}
// Counted reports whether r counts towards the form's region limit.
func (f MonitorForm) Counted(r RegionOption) bool { return !r.Own || f.OwnRegionsCount }
// RegionsMapped reports whether any region of the form has a location.
func (f MonitorForm) RegionsMapped() bool {
for _, r := range f.Regions {
@@ -753,6 +756,10 @@ type MonitorForm struct {
TopLevel bool
Regions []RegionOption
MinInterval int
// RegionLimit caps the counted regions a monitor uses; 0 is unlimited.
// Own regions count only with OwnRegionsCount.
RegionLimit int
OwnRegionsCount bool
// Type-specific settings.
Method string
ExpectStatus string
@@ -1132,10 +1139,25 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
<fieldset class="mb-4" data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) } disabled?={ f.Type == "heartbeat" }>
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</legend>
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.regions_hint") }</p>
if f.RegionLimit > 0 {
<p class="mb-2 text-xs text-muted" data-region-limit-hint>
if f.OwnRegionsCount {
{ i18n.T(ctx, "monitors.regions_limit", "Max", f.RegionLimit) }
} else {
{ i18n.T(ctx, "monitors.platform_regions_limit", "Max", f.RegionLimit) }
}
<span class="font-mono" data-region-count></span>
</p>
}
if f.RegionsMapped() {
@regionMap("select", "#monitor-regions")
}
<div id="monitor-regions">
<div
id="monitor-regions"
if f.RegionLimit > 0 {
data-region-limit={ strconv.Itoa(f.RegionLimit) }
}
>
for _, r := range f.Regions {
<label class="-mx-2 mb-0.5 flex items-center gap-2 px-2 py-1 text-sm">
<input
@@ -1151,6 +1173,9 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
}
data-name={ r.Name }
data-live={ strconv.FormatInt(r.Live, 10) }
if f.Counted(r) {
data-counted
}
/>
{ r.Name }
<span class="font-mono text-xs text-muted">