diff --git a/apps/webapp/app/components/alerts/QueryAlertTranscript.tsx b/apps/webapp/app/components/alerts/QueryAlertTranscript.tsx index 9e71a8b2afd..c5e96d897b2 100644 --- a/apps/webapp/app/components/alerts/QueryAlertTranscript.tsx +++ b/apps/webapp/app/components/alerts/QueryAlertTranscript.tsx @@ -39,6 +39,8 @@ export type QueryWatchPrefill = { mode?: QueryAlertMode; measure?: string; operator?: ">" | "<"; + value?: number; + windowSec?: number; }; export function queryWatchPrefill( @@ -105,6 +107,8 @@ export function QueryAlertTranscript({ mode: prefill.mode, measure: prefill.measure, operator: prefill.operator, + value: prefill.value, + windowSec: prefill.windowSec, ...analyzed, } : undefined; diff --git a/apps/webapp/app/components/alerts/queryAlertLink.ts b/apps/webapp/app/components/alerts/queryAlertLink.ts index fe3470848dc..6a24f676a41 100644 --- a/apps/webapp/app/components/alerts/queryAlertLink.ts +++ b/apps/webapp/app/components/alerts/queryAlertLink.ts @@ -15,6 +15,8 @@ export type QueryAlertPrefill = { mode?: QueryAlertMode; measure?: string; operator?: ">" | "<"; + value?: number; + windowSec?: number; }; export function queryAlertNameKey(mode: QueryAlertMode, measure?: string) { diff --git a/apps/webapp/app/components/alerts/useQueryAlertDraft.ts b/apps/webapp/app/components/alerts/useQueryAlertDraft.ts index 6fc3e3ba899..0e5b73d41e6 100644 --- a/apps/webapp/app/components/alerts/useQueryAlertDraft.ts +++ b/apps/webapp/app/components/alerts/useQueryAlertDraft.ts @@ -56,13 +56,23 @@ export function useQueryAlertDraft( const measure = mode === "match" ? undefined : signal.measure; const [operator, setOperator] = useState<">" | "<">(prefill.operator ?? ">"); - const [valueText, setValueText] = useState(""); + const [valueText, setValueText] = useState( + prefill.value !== undefined ? String(prefill.value) : "" + ); const value = valueText.trim() === "" ? undefined : Number(valueText); const valueValid = mode !== "threshold" || (value !== undefined && Number.isFinite(value)); const bounds = queryWindowBounds(analysis.limits); const defaultWindow = defaultQueryWindowMinutes(prefill.period, analysis.limits); - const [windowText, setWindowText] = useState(() => String(defaultWindow)); + const prefillWindowMinutes = + prefill.windowSec !== undefined ? Math.round(prefill.windowSec / 60) : undefined; + const initialWindow = + prefillWindowMinutes !== undefined && + prefillWindowMinutes >= bounds.min && + prefillWindowMinutes <= bounds.max + ? prefillWindowMinutes + : defaultWindow; + const [windowText, setWindowText] = useState(() => String(initialWindow)); const windowMinutes = mode === "match" ? defaultWindow : Number(windowText); const windowValid = mode === "match" || diff --git a/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.test.ts b/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.test.ts index 5e85b128bc4..8255111ec39 100644 --- a/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.test.ts +++ b/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.test.ts @@ -13,6 +13,7 @@ import { alertDraftPatchSchema, applyDraftPatch, errorGroupToResolve, + queryWatchFromPatch, type AlertDraftPatch, } from "./draftPatch"; import { draftResultLines } from "./useCreationAgentSend"; @@ -265,6 +266,23 @@ describe("below-threshold operator", () => { const patch = { area: "query", query: "SELECT 1", condition: { operator: "<" } }; expect(alertDraftPatchSchema.safeParse(patch).success).toBe(true); }); + + it("forwards condition value and windowSec in queryWatchFromPatch", () => { + const patch = { + area: "query", + query: "SELECT count() FROM runs", + querySignalChoice: { mode: "threshold" as const, measure: "count" }, + condition: { operator: ">" as const, value: 42, windowSec: 1800 }, + }; + expect(queryWatchFromPatch(patch)).toEqual({ + query: "SELECT count() FROM runs", + mode: "threshold", + measure: "count", + operator: ">", + value: 42, + windowSec: 1800, + }); + }); }); describe("unknown-key rejection", () => { diff --git a/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.ts b/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.ts index 8f24aa78e21..d20bb98f0ba 100644 --- a/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.ts +++ b/apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.ts @@ -67,6 +67,8 @@ export function queryWatchFromPatch(patch: AlertDraftPatch): QueryWatchPrefill | mode: patch.querySignalChoice?.mode, measure: patch.querySignalChoice?.measure, operator: patch.condition?.operator, + value: patch.condition?.value, + windowSec: patch.condition?.windowSec, }; }