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

@@ -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, number | string>) => 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
});

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
// ---------------------------------------------------------------------------
@@ -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,