Skip to content

Commit 8c975fc

Browse files
committed
Fix edit default rules popover.
1 parent 6c3e7c9 commit 8c975fc

File tree

1 file changed

+10
-3
lines changed
  • x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/alerts/hooks

1 file changed

+10
-3
lines changed

x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/alerts/hooks/use_synthetics_rules.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useSyntheticsSettingsContext } from '../../../contexts';
1616
import {
1717
selectSyntheticsAlerts,
1818
selectSyntheticsAlertsLoading,
19+
selectSyntheticsAlertsLoaded,
1920
} from '../../../state/alert_rules/selectors';
2021
import {
2122
enableDefaultAlertingSilentlyAction,
@@ -35,17 +36,23 @@ export const useSyntheticsRules = (isOpen: boolean) => {
3536

3637
const defaultRules = useSelector(selectSyntheticsAlerts);
3738
const loading = useSelector(selectSyntheticsAlertsLoading);
39+
const rulesLoaded = useSelector(selectSyntheticsAlertsLoaded);
3840
const alertFlyoutVisible = useSelector(selectAlertFlyoutVisibility);
3941
const isNewRule = useSelector(selectIsNewRule);
4042
const { settings } = useSelector(selectDynamicSettings);
41-
43+
const defaultRulesEnabled =
44+
settings && (settings?.defaultStatusRuleEnabled || settings?.defaultTLSRuleEnabled);
45+
// Fetch default rules when popover opens if they haven't been loaded yet
46+
useEffect(() => {
47+
if (isOpen && !loading && rulesLoaded === null && defaultRulesEnabled) {
48+
dispatch(getDefaultAlertingAction.get());
49+
}
50+
}, [isOpen, loading, rulesLoaded, dispatch, defaultRulesEnabled]);
4251
const { canSave } = useSyntheticsSettingsContext();
4352

4453
const { loaded, data: monitors } = useSelector(selectMonitorListState);
4554

4655
const hasMonitors = loaded && monitors.absoluteTotal && monitors.absoluteTotal > 0;
47-
const defaultRulesEnabled =
48-
settings && (settings?.defaultStatusRuleEnabled || settings?.defaultTLSRuleEnabled);
4956

5057
const getOrCreateAlerts = useCallback(() => {
5158
if (canSave) {

0 commit comments

Comments
 (0)