Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: alert threshold form is resetting to default query option on stage & run (#4876)

SagarRajput-71306e99ca87a
diff --git a/frontend/src/container/FormAlertRules/index.tsx b/frontend/src/container/FormAlertRules/index.tsx
index 8aa8dc7d9c..00b8c6e6c4 100644
--- a/frontend/src/container/FormAlertRules/index.tsx
+++ b/frontend/src/container/FormAlertRules/index.tsx
@@ -139,15 +139,21 @@ function FormAlertRules({
useEffect(() => {
// Set selectedQueryName based on the length of queryOptions
- setAlertDef((def) => ({
- ...def,
- condition: {
- ...def.condition,
- selectedQueryName:
- queryOptions.length > 0 ? String(queryOptions[0].value) : undefined,
- },
- }));
- }, [currentQuery?.queryType, queryOptions]);
+ const selectedQueryName = alertDef?.condition?.selectedQueryName;
+ if (
+ !selectedQueryName ||
+ !queryOptions.some((option) => option.value === selectedQueryName)
+ ) {
+ setAlertDef((def) => ({
+ ...def,
+ condition: {
+ ...def.condition,
+ selectedQueryName:
+ queryOptions.length > 0 ? String(queryOptions[0].value) : undefined,
+ },
+ }));
+ }
+ }, [alertDef, currentQuery?.queryType, queryOptions]);
const onCancelHandler = useCallback(() => {
history.replace(ROUTES.LIST_ALL_ALERT);