Skip to content

Commit

Permalink
fix: alert threshold form is resetting to default query option on sta…
Browse files Browse the repository at this point in the history
…ge & run (#4876)

* fix: alert threshold form is resetting to default query option on stage & run

* fix: alert threshold - added safety check when the queryOption is deleted
  • Loading branch information
SagarRajput-7 authored Apr 24, 2024
1 parent 1a8f063 commit 1306e99
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions frontend/src/container/FormAlertRules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1306e99

Please sign in to comment.