fix: alert threshold form is resetting to default query option on stage & 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
This commit is contained in:
SagarRajput-7 2024-04-24 15:58:59 +05:30 committed by GitHub
parent 1a8f063b4b
commit 1306e99ca8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -139,15 +139,21 @@ function FormAlertRules({
useEffect(() => { useEffect(() => {
// Set selectedQueryName based on the length of queryOptions // Set selectedQueryName based on the length of queryOptions
setAlertDef((def) => ({ const selectedQueryName = alertDef?.condition?.selectedQueryName;
...def, if (
condition: { !selectedQueryName ||
...def.condition, !queryOptions.some((option) => option.value === selectedQueryName)
selectedQueryName: ) {
queryOptions.length > 0 ? String(queryOptions[0].value) : undefined, setAlertDef((def) => ({
}, ...def,
})); condition: {
}, [currentQuery?.queryType, queryOptions]); ...def.condition,
selectedQueryName:
queryOptions.length > 0 ? String(queryOptions[0].value) : undefined,
},
}));
}
}, [alertDef, currentQuery?.queryType, queryOptions]);
const onCancelHandler = useCallback(() => { const onCancelHandler = useCallback(() => {
history.replace(ROUTES.LIST_ALL_ALERT); history.replace(ROUTES.LIST_ALL_ALERT);