Skip to content

Commit

Permalink
Default to stack rules if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Dec 1, 2023
1 parent 040d0de commit e48be57
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useMemo, useCallback, useEffect } from 'react';
import { EuiComboBox, EuiFormRow, EuiComboBoxOptionOption } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { AlertConsumers, STACK_ALERTS_FEATURE_ID } from '@kbn/rule-data-utils';
import { IErrorObject, RuleCreationValidConsumer } from '../../../types';

const SELECT_LABEL: string = i18n.translate(
Expand Down Expand Up @@ -123,8 +123,14 @@ export const RuleFormConsumerSelection = (props: RuleFormConsumerSelectionProps)
}, [consumers]);

useEffect(() => {
// At initialization, select the first value
if (!validatedSelectedConsumer) onChange(consumers[0] as RuleCreationValidConsumer);
// At initialization, select Stack Alerts, or the first value
if (!validatedSelectedConsumer) {
if (consumers.includes(STACK_ALERTS_FEATURE_ID)) {
onChange(STACK_ALERTS_FEATURE_ID);
return;
}
onChange(consumers[0] as RuleCreationValidConsumer);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit e48be57

Please sign in to comment.