show all sites|resources|health-checks in alert table

This commit is contained in:
miloschwartz
2026-04-21 16:23:08 -07:00
parent a68ba9e04d
commit ccfa165632
3 changed files with 63 additions and 5 deletions

View File

@@ -1450,8 +1450,11 @@
"alertingSelectRoles": "Select roles…", "alertingSelectRoles": "Select roles…",
"alertingRolesSelected": "{count} roles selected", "alertingRolesSelected": "{count} roles selected",
"alertingSummarySites": "Sites ({count})", "alertingSummarySites": "Sites ({count})",
"alertingSummaryAllSites": "All sites",
"alertingSummaryHealthChecks": "Health checks ({count})", "alertingSummaryHealthChecks": "Health checks ({count})",
"alertingSummaryAllHealthChecks": "All health checks",
"alertingSummaryResources": "Resources ({count})", "alertingSummaryResources": "Resources ({count})",
"alertingSummaryAllResources": "All resources",
"alertingErrorNameRequired": "Enter a name", "alertingErrorNameRequired": "Enter a name",
"alertingErrorActionsMin": "Add at least one action", "alertingErrorActionsMin": "Add at least one action",
"alertingErrorPickSites": "Select at least one site", "alertingErrorPickSites": "Select at least one site",

View File

@@ -18,6 +18,11 @@ import { usePaidStatus } from "@app/hooks/usePaidStatus";
import { createApiClient, formatAxiosError } from "@app/lib/api"; import { createApiClient, formatAxiosError } from "@app/lib/api";
import { orgQueries } from "@app/lib/queries"; import { orgQueries } from "@app/lib/queries";
import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn"; import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn";
import {
alertRuleAllHealthChecksSelected,
alertRuleAllResourcesSelected,
alertRuleAllSitesSelected
} from "@app/lib/alertRuleForm";
import { tierMatrix } from "@server/lib/billing/tierMatrix"; import { tierMatrix } from "@server/lib/billing/tierMatrix";
import { import {
ArrowDown01Icon, ArrowDown01Icon,
@@ -71,6 +76,9 @@ function sourceSummary(
rule: AlertRuleRow, rule: AlertRuleRow,
t: (k: string, o?: Record<string, number | string>) => string t: (k: string, o?: Record<string, number | string>) => string
) { ) {
if (alertRuleAllSitesSelected(rule.eventType, rule.siteIds)) {
return t("alertingSummaryAllSites");
}
if ( if (
rule.eventType === "site_online" || rule.eventType === "site_online" ||
rule.eventType === "site_offline" || rule.eventType === "site_offline" ||
@@ -78,11 +86,17 @@ function sourceSummary(
) { ) {
return t("alertingSummarySites", { count: rule.siteIds.length }); return t("alertingSummarySites", { count: rule.siteIds.length });
} }
if (alertRuleAllResourcesSelected(rule.eventType, rule.resourceIds)) {
return t("alertingSummaryAllResources");
}
if (rule.eventType.startsWith("resource_")) { if (rule.eventType.startsWith("resource_")) {
return t("alertingSummaryResources", { return t("alertingSummaryResources", {
count: rule.resourceIds.length count: rule.resourceIds.length
}); });
} }
if (alertRuleAllHealthChecksSelected(rule.eventType, rule.healthCheckIds)) {
return t("alertingSummaryAllHealthChecks");
}
return t("alertingSummaryHealthChecks", { return t("alertingSummaryHealthChecks", {
count: rule.healthCheckIds.length count: rule.healthCheckIds.length
}); });

View File

@@ -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 // API response → form values
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -372,11 +409,15 @@ export function apiResponseToFormValues(
}); });
} }
const allSites = sourceType === "site" && rule.siteIds.length === 0; const allSites = alertRuleAllSitesSelected(rule.eventType, rule.siteIds);
const allHealthChecks = const allHealthChecks = alertRuleAllHealthChecksSelected(
sourceType === "health_check" && rule.healthCheckIds.length === 0; rule.eventType,
const allResources = rule.healthCheckIds
sourceType === "resource" && (rule.resourceIds?.length ?? 0) === 0; );
const allResources = alertRuleAllResourcesSelected(
rule.eventType,
rule.resourceIds
);
return { return {
name: rule.name, name: rule.name,