@@ -30,6 +30,7 @@ import {
30
30
trackAlertRuleFormSaved ,
31
31
} from '../../../Analytics' ;
32
32
import { useDeleteRuleFromGroup } from '../../../hooks/ruleGroup/useDeleteRuleFromGroup' ;
33
+ import { useReturnTo } from '../../../hooks/useReturnTo' ;
33
34
import { useUnifiedAlertingSelector } from '../../../hooks/useUnifiedAlertingSelector' ;
34
35
import { saveRuleFormAction } from '../../../state/actions' ;
35
36
import { RuleFormType , RuleFormValues } from '../../../types/rule-form' ;
@@ -72,7 +73,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
72
73
const ruleType = translateRouteParamToRuleType ( routeParams . type ) ;
73
74
const uidFromParams = routeParams . id ;
74
75
75
- const returnTo = ! queryParams . returnTo ? '/alerting/list' : String ( queryParams . returnTo ) ;
76
+ const { returnTo } = useReturnTo ( '/alerting/list' ) ;
76
77
const [ showDeleteModal , setShowDeleteModal ] = useState < boolean > ( false ) ;
77
78
78
79
const defaultValues : RuleFormValues = useMemo ( ( ) => {
@@ -163,7 +164,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
163
164
const ruleGroupIdentifier = getRuleGroupLocationFromRuleWithLocation ( existing ) ;
164
165
165
166
await deleteRuleFromGroup . execute ( ruleGroupIdentifier , existing . rule ) ;
166
- locationService . replace ( returnTo ) ;
167
+ locationService . replace ( returnTo ?? '/alerting/list' ) ;
167
168
}
168
169
} ;
169
170
@@ -210,7 +211,7 @@ export const AlertRuleForm = ({ existing, prefill }: Props) => {
210
211
{ submitState . loading && < Spinner className = { styles . buttonSpinner } inline = { true } /> }
211
212
Save rule and exit
212
213
</ Button >
213
- < Link to = { returnTo } >
214
+ < Link to = { returnTo ?? '/alerting/list' } >
214
215
< Button variant = "secondary" disabled = { submitState . loading } type = "button" onClick = { cancelRuleCreation } size = "sm" >
215
216
Cancel
216
217
</ Button >
0 commit comments