diff --git a/messages/en-US.json b/messages/en-US.json index 29e904416..299e64044 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -1450,8 +1450,11 @@ "alertingSelectRoles": "Select roles…", "alertingRolesSelected": "{count} roles selected", "alertingSummarySites": "Sites ({count})", + "alertingSummaryAllSites": "All sites", "alertingSummaryHealthChecks": "Health checks ({count})", + "alertingSummaryAllHealthChecks": "All health checks", "alertingSummaryResources": "Resources ({count})", + "alertingSummaryAllResources": "All resources", "alertingErrorNameRequired": "Enter a name", "alertingErrorActionsMin": "Add at least one action", "alertingErrorPickSites": "Select at least one site", diff --git a/src/components/AlertingRulesTable.tsx b/src/components/AlertingRulesTable.tsx index 3ddcc4c13..9ee70b205 100644 --- a/src/components/AlertingRulesTable.tsx +++ b/src/components/AlertingRulesTable.tsx @@ -18,6 +18,11 @@ import { usePaidStatus } from "@app/hooks/usePaidStatus"; import { createApiClient, formatAxiosError } from "@app/lib/api"; import { orgQueries } from "@app/lib/queries"; import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn"; +import { + alertRuleAllHealthChecksSelected, + alertRuleAllResourcesSelected, + alertRuleAllSitesSelected +} from "@app/lib/alertRuleForm"; import { tierMatrix } from "@server/lib/billing/tierMatrix"; import { ArrowDown01Icon, @@ -71,6 +76,9 @@ function sourceSummary( rule: AlertRuleRow, t: (k: string, o?: Record) => string ) { + if (alertRuleAllSitesSelected(rule.eventType, rule.siteIds)) { + return t("alertingSummaryAllSites"); + } if ( rule.eventType === "site_online" || rule.eventType === "site_offline" || @@ -78,11 +86,17 @@ function sourceSummary( ) { return t("alertingSummarySites", { count: rule.siteIds.length }); } + if (alertRuleAllResourcesSelected(rule.eventType, rule.resourceIds)) { + return t("alertingSummaryAllResources"); + } if (rule.eventType.startsWith("resource_")) { return t("alertingSummaryResources", { count: rule.resourceIds.length }); } + if (alertRuleAllHealthChecksSelected(rule.eventType, rule.healthCheckIds)) { + return t("alertingSummaryAllHealthChecks"); + } return t("alertingSummaryHealthChecks", { count: rule.healthCheckIds.length }); diff --git a/src/lib/alertRuleForm.ts b/src/lib/alertRuleForm.ts index 426a6d309..f4bcf9cee 100644 --- a/src/lib/alertRuleForm.ts +++ b/src/lib/alertRuleForm.ts @@ -321,6 +321,43 @@ export function defaultFormValues(): AlertRuleFormValues { }; } +// --------------------------------------------------------------------------- +// List/API row semantics: empty ID arrays mean "all" for that source kind +// --------------------------------------------------------------------------- + +export function alertRuleAllSitesSelected( + eventType: string, + siteIds: number[] +): boolean { + const siteEvent = + eventType === "site_online" || + eventType === "site_offline" || + eventType === "site_toggle"; + return siteEvent && siteIds.length === 0; +} + +export function alertRuleAllResourcesSelected( + eventType: string, + resourceIds: number[] | undefined +): boolean { + return eventType.startsWith("resource_") && (resourceIds?.length ?? 0) === 0; +} + +export function alertRuleAllHealthChecksSelected( + eventType: string, + healthCheckIds: number[] +): boolean { + if ( + eventType === "site_online" || + eventType === "site_offline" || + eventType === "site_toggle" || + eventType.startsWith("resource_") + ) { + return false; + } + return healthCheckIds.length === 0; +} + // --------------------------------------------------------------------------- // API response → form values // --------------------------------------------------------------------------- @@ -372,11 +409,15 @@ export function apiResponseToFormValues( }); } - const allSites = sourceType === "site" && rule.siteIds.length === 0; - const allHealthChecks = - sourceType === "health_check" && rule.healthCheckIds.length === 0; - const allResources = - sourceType === "resource" && (rule.resourceIds?.length ?? 0) === 0; + const allSites = alertRuleAllSitesSelected(rule.eventType, rule.siteIds); + const allHealthChecks = alertRuleAllHealthChecksSelected( + rule.eventType, + rule.healthCheckIds + ); + const allResources = alertRuleAllResourcesSelected( + rule.eventType, + rule.resourceIds + ); return { name: rule.name,