Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit correlation Alert Trigger fix #1180

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions public/pages/Correlations/containers/CreateCorrelationRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -234,20 +234,20 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
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);
riysaxen-amzn marked this conversation as resolved.
Show resolved Hide resolved
} 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);
Expand Down Expand Up @@ -388,7 +388,6 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
query.field = '';
});
}

// Modify or set default values for trigger if present
if (values.trigger) {
// Set default values for ids
Expand Down Expand Up @@ -1079,7 +1078,11 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
data-test-subj="delete-alert-trigger-icon"
iconType="trash"
color="danger"
onClick={() => setShowForm(false)}
onClick={() => {
// Clear the trigger values by setting them to an empty object or your initial state
props.setFieldValue('trigger', {});
setShowForm(false);
}}
/>
</EuiCompressedFormRow>
</EuiFlexItem>
Expand Down
1 change: 1 addition & 0 deletions public/store/CorrelationsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
4 changes: 2 additions & 2 deletions types/Correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -76,7 +76,7 @@ export interface CorrelationRuleSource {
name: string;
time_window: number;
correlate: CorrelationRuleSourceQueries[];
trigger?: CorrelationRuleTrigger | undefined;
trigger?: CorrelationRuleTrigger;
}

export interface CorrelationRuleHit {
Expand Down
Loading