Description
openedon Sep 29, 2022
Steps to reproduce
Issue was found, once working on #140593.
Rule actions form is marked as invalid, even though all fields are populated in slack action form
Screen.Recording.2022-09-26.at.12.36.53.mov
- open rule actions form
- add slack action
- remove slack action
- add again slack action
- press Save rule
- validation error is displayed
Technical overview
Once slack rule actions form is rendered:
First setActionIdByIndex
in x-pack/plugins/security_solution/public/detections/components/rules/rule_actions_field/index.tsx fires update to actions
field of form (but w/o params properties, only type of selector in action).
Then, subsequently setActionParamsProperty
updates params in field actions of form with values displayed if form controls through calling field.setValue. In our case, it is a message form field in slack action form.
These updates trigger form validation, defined in schema:
actions: {
validations: [
{
validator: validateRuleActionsField(actionTypeRegistry),
},
],
},
validateRuleActionsField receives in curried function argument field value:
const [{ value, path }] = data as [{ value: RuleAction[]; path: string }];
which doesn't have updates set in setActionParamsProperty
, hence form is marked as invalid. It happens consistently when you add some action, remove it, add again it.
Here is logged form value of actions
in functions calls
setActionIdByIndex [
{
"id": "50a49d70-34d4-11ed-87dc-f3f665e2eedb",
"actionTypeId": ".slack",
"group": "default",
"params": {}
}
]
validateRuleActionsField [
{
"id": "50a49d70-34d4-11ed-87dc-f3f665e2eedb",
"actionTypeId": ".slack",
"group": "default",
"params": {}
}
]
validateRuleActionsField [
{
"id": "50a49d70-34d4-11ed-87dc-f3f665e2eedb",
"actionTypeId": ".slack",
"group": "default",
"params": {}
}
]
setActionParamsProperty [
{
"id": "50a49d70-34d4-11ed-87dc-f3f665e2eedb",
"actionTypeId": ".slack",
"group": "default",
"params": {
"message": "Rule {{context.rule.name}} generated {{state.signals_count}} alerts"
}
}
]
From the log above: validateRuleActionsField
is not getting called after setActionParamsProperty
is called, instead validateRuleActionsField
called twice after setActionIdByIndex
has been triggered.
Expected behaviour
Validation to be triggered once new params values were updated through setActionParamsProperty
.
Workaround
- Wrapping
field.setValue
in setTimeout helped to resolve the issue.
Implemented in https://github.com/elastic/kibana/pull/141811/files for 8.5+, but root cause hasn't been found