Skip to content

Commit 6ee18b5

Browse files
fix(webapp): forward condition value and windowSec in queryWatchFromPatch (#5065)
1 parent aed0848 commit 6ee18b5

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎apps/webapp/app/components/alerts/QueryAlertTranscript.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export type QueryWatchPrefill = {
3939
mode?: QueryAlertMode;
4040
measure?: string;
4141
operator?: ">" | "<";
42+
value?: number;
43+
windowSec?: number;
4244
};
4345

4446
export function queryWatchPrefill(
@@ -105,6 +107,8 @@ export function QueryAlertTranscript({
105107
mode: prefill.mode,
106108
measure: prefill.measure,
107109
operator: prefill.operator,
110+
value: prefill.value,
111+
windowSec: prefill.windowSec,
108112
...analyzed,
109113
}
110114
: undefined;

‎apps/webapp/app/components/alerts/queryAlertLink.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type QueryAlertPrefill = {
1515
mode?: QueryAlertMode;
1616
measure?: string;
1717
operator?: ">" | "<";
18+
value?: number;
19+
windowSec?: number;
1820
};
1921

2022
export function queryAlertNameKey(mode: QueryAlertMode, measure?: string) {

‎apps/webapp/app/components/alerts/useQueryAlertDraft.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,23 @@ export function useQueryAlertDraft(
5656
const measure = mode === "match" ? undefined : signal.measure;
5757

5858
const [operator, setOperator] = useState<">" | "<">(prefill.operator ?? ">");
59-
const [valueText, setValueText] = useState("");
59+
const [valueText, setValueText] = useState(
60+
prefill.value !== undefined ? String(prefill.value) : ""
61+
);
6062
const value = valueText.trim() === "" ? undefined : Number(valueText);
6163
const valueValid = mode !== "threshold" || (value !== undefined && Number.isFinite(value));
6264

6365
const bounds = queryWindowBounds(analysis.limits);
6466
const defaultWindow = defaultQueryWindowMinutes(prefill.period, analysis.limits);
65-
const [windowText, setWindowText] = useState(() => String(defaultWindow));
67+
const prefillWindowMinutes =
68+
prefill.windowSec !== undefined ? Math.round(prefill.windowSec / 60) : undefined;
69+
const initialWindow =
70+
prefillWindowMinutes !== undefined &&
71+
prefillWindowMinutes >= bounds.min &&
72+
prefillWindowMinutes <= bounds.max
73+
? prefillWindowMinutes
74+
: defaultWindow;
75+
const [windowText, setWindowText] = useState(() => String(initialWindow));
6676
const windowMinutes = mode === "match" ? defaultWindow : Number(windowText);
6777
const windowValid =
6878
mode === "match" ||

‎apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
alertDraftPatchSchema,
1414
applyDraftPatch,
1515
errorGroupToResolve,
16+
queryWatchFromPatch,
1617
type AlertDraftPatch,
1718
} from "./draftPatch";
1819
import { draftResultLines } from "./useCreationAgentSend";
@@ -265,6 +266,23 @@ describe("below-threshold operator", () => {
265266
const patch = { area: "query", query: "SELECT 1", condition: { operator: "<" } };
266267
expect(alertDraftPatchSchema.safeParse(patch).success).toBe(true);
267268
});
269+
270+
it("forwards condition value and windowSec in queryWatchFromPatch", () => {
271+
const patch = {
272+
area: "query",
273+
query: "SELECT count() FROM runs",
274+
querySignalChoice: { mode: "threshold" as const, measure: "count" },
275+
condition: { operator: ">" as const, value: 42, windowSec: 1800 },
276+
};
277+
expect(queryWatchFromPatch(patch)).toEqual({
278+
query: "SELECT count() FROM runs",
279+
mode: "threshold",
280+
measure: "count",
281+
operator: ">",
282+
value: 42,
283+
windowSec: 1800,
284+
});
285+
});
268286
});
269287

270288
describe("unknown-key rejection", () => {

‎apps/webapp/app/components/dashboard-agent/alert-creation/draftPatch.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export function queryWatchFromPatch(patch: AlertDraftPatch): QueryWatchPrefill |
6767
mode: patch.querySignalChoice?.mode,
6868
measure: patch.querySignalChoice?.measure,
6969
operator: patch.condition?.operator,
70+
value: patch.condition?.value,
71+
windowSec: patch.condition?.windowSec,
7072
};
7173
}
7274

0 commit comments

Comments
 (0)