mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Alerting] Fix error when saving a rule after toggling alerts filter properties on and off (#192522)
## Summary Closes #184170 Fixes a bug where the `alertsFilter` property gets added to `action`s configured in the rule form when toggled on, but then never gets deleted when toggled off. This would throw a validation error on the server for an empty `alertsFilter` object, which is only meant to throw for user-configured API requests and not for form usage. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ## Release notes Fixed a bug where toggling on and off the "If alert matches a query" or "If alert is generated during timeframe" toggles makes it unable to save the rule due to validation errors. --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
233fe603b5
commit
f22067fbc9
2 changed files with 36 additions and 2 deletions
|
@ -240,4 +240,38 @@ describe('rule reducer', () => {
|
|||
);
|
||||
expect(updatedRule.rule.alertDelay?.active).toBe(10);
|
||||
});
|
||||
|
||||
test('if rule action alerts filter was toggled on, then off', () => {
|
||||
initialRule.actions.push({
|
||||
id: '',
|
||||
actionTypeId: 'testId',
|
||||
group: 'Rule',
|
||||
params: {},
|
||||
uuid: '123-456',
|
||||
});
|
||||
let updatedRule = ruleReducer(
|
||||
{ rule: initialRule },
|
||||
{
|
||||
command: { type: 'setRuleActionAlertsFilter' },
|
||||
payload: {
|
||||
key: 'query',
|
||||
value: 'hello',
|
||||
index: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
expect((updatedRule.rule.actions[0] as SanitizedRuleAction).alertsFilter).toBeDefined();
|
||||
updatedRule = ruleReducer(
|
||||
{ rule: initialRule },
|
||||
{
|
||||
command: { type: 'setRuleActionAlertsFilter' },
|
||||
payload: {
|
||||
key: 'query',
|
||||
value: undefined,
|
||||
index: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
expect((updatedRule.rule.actions[0] as SanitizedRuleAction).alertsFilter).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { SavedObjectAttribute } from '@kbn/core/public';
|
||||
import { isEqual } from 'lodash';
|
||||
import { isEqual, isUndefined, omitBy } from 'lodash';
|
||||
import { Reducer } from 'react';
|
||||
import {
|
||||
RuleActionParam,
|
||||
|
@ -262,7 +262,7 @@ export const getRuleReducer =
|
|||
return state;
|
||||
|
||||
const { alertsFilter, ...rest } = oldSanitizedAction;
|
||||
const updatedAlertsFilter = { ...alertsFilter, [key]: value };
|
||||
const updatedAlertsFilter = omitBy({ ...alertsFilter, [key]: value }, isUndefined);
|
||||
|
||||
const updatedAction = {
|
||||
...rest,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue