diff --git a/public/pages/Correlations/containers/CreateCorrelationRule.tsx b/public/pages/Correlations/containers/CreateCorrelationRule.tsx index 3c060f58..d4e28334 100644 --- a/public/pages/Correlations/containers/CreateCorrelationRule.tsx +++ b/public/pages/Correlations/containers/CreateCorrelationRule.tsx @@ -85,7 +85,7 @@ export interface CreateCorrelationRuleProps extends DataSourceProps { history: RouteComponentProps< any, any, - { rule: CorrelationRuleModel; isReadOnly: boolean } + { rule: CorrelationRule; isReadOnly: boolean } >['history']; notifications: NotificationsStart | null; notificationsService: NotificationsService; @@ -234,20 +234,20 @@ export const CreateCorrelationRule: React.FC = ( setNotificationChannels(parsedChannels); setLoadingNotifications(false); }; + const setInitialRuleValues = async (ruleId: string) => { + const ruleRes = await correlationStore.getCorrelationRule(ruleId); + if (ruleRes) { + setInitialValues(ruleRes); + } + }; + if (props.history.location.state?.rule) { setAction('Edit'); - setInitialValues(props.history.location.state?.rule); + setInitialRuleValues(props.history.location.state?.rule.id); } else if (params.ruleId) { - const setInitialRuleValues = async () => { - const ruleRes = await correlationStore.getCorrelationRule(params.ruleId); - if (ruleRes) { - setInitialValues(ruleRes); - } - }; - - setAction('Edit'); - setInitialRuleValues(); + setInitialRuleValues(params.ruleId); } + const setupLogTypeOptions = async () => { const options = await getLogTypeOptions(); setLogTypeOptions(options); @@ -388,7 +388,6 @@ export const CreateCorrelationRule: React.FC = ( query.field = ''; }); } - // Modify or set default values for trigger if present if (values.trigger) { // Set default values for ids diff --git a/public/store/CorrelationsStore.ts b/public/store/CorrelationsStore.ts index b117d97b..639d275e 100644 --- a/public/store/CorrelationsStore.ts +++ b/public/store/CorrelationsStore.ts @@ -148,6 +148,7 @@ export class CorrelationsStore implements ICorrelationsStore { name: hit._source.name, time_window: hit._source.time_window || 300000, queries, + trigger: hit._source?.trigger }; } diff --git a/types/Correlations.ts b/types/Correlations.ts index 1bb33189..6a10fb2a 100644 --- a/types/Correlations.ts +++ b/types/Correlations.ts @@ -54,7 +54,7 @@ export interface CorrelationRuleModel { name: string; time_window: number; // Time in milliseconds queries: CorrelationRuleQuery[]; - trigger: CorrelationRuleTrigger | undefined; + trigger?: CorrelationRuleTrigger; } export interface CorrelationRule extends CorrelationRuleModel { @@ -76,7 +76,7 @@ export interface CorrelationRuleSource { name: string; time_window: number; correlate: CorrelationRuleSourceQueries[]; - trigger?: CorrelationRuleTrigger | undefined; + trigger?: CorrelationRuleTrigger; } export interface CorrelationRuleHit {