[ResponseOps][Alerts] Implement alerts filters form#214982
[ResponseOps][Alerts] Implement alerts filters form#214982umbopepato merged 28 commits intoelastic:mainfrom
Conversation
03c52ed to
1647136
Compare
0ba7dbc to
9876eba
Compare
9876eba to
9982fb6
Compare
|
Pinging @elastic/response-ops (Team:ResponseOps) |
| isDisabled?: boolean; | ||
| } | ||
|
|
||
| const DEFAULT_VALUE: AlertsFiltersExpression = { |
There was a problem hiding this comment.
This ensures that the form is initialized with an initially empty "Filter by" selector
There was a problem hiding this comment.
nit: this comment here could be a comment in code for future us
2b3bc5c to
1d8fca4
Compare
js-jankisalvi
left a comment
There was a problem hiding this comment.
Great work! looks really good 🎉
Could you please add an integration test or functional test to check different roles and users to verify solutions and rule types privileges?
I have a user with `security` and `stack rules` privileges. However the solution shows `observability`. Shouldn't it be security and stack like serverless?
security_and_stack.mov
security_and_stack_permissions.mov
...kages/shared/response-ops/alerts-filters-form/components/alerts_filter_by_rule_tags.test.tsx
Outdated
Show resolved
Hide resolved
Thanks for taking a look Janki! 😊
I was hoping to test the complete creation flow with the Dashboard panel as well 🙂
Yes, that's normal since in non-serverless envs when enabling the Stack rules privilege you also get access to multi-consumer rule types, one of which is categorized under |
cnasikas
left a comment
There was a problem hiding this comment.
Thanks for your patience and with addressing my comments!
| export const getRuleTypeIdsForSolution = ( | ||
| ruleTypes: InternalRuleType[], | ||
| solution: RuleTypeSolution, | ||
| includeStackInObservability = true |
There was a problem hiding this comment.
nit: Do not forget to remove this.
| }); | ||
|
|
||
| it.each([null, undefined])('should return false for %s items', (filter) => { | ||
| expect(isFilter(filter as Parameters<typeof isFilter>[0])).toBeFalsy(); |
There was a problem hiding this comment.
| expect(isFilter(filter as Parameters<typeof isFilter>[0])).toBeFalsy(); | |
| // @ts-expect-error: testing empty values | |
| expect(isFilter(filter)).toBeFalsy(); |
| return null; | ||
| } | ||
| const FilterComponent = alertsFiltersMetadata[type].component as AlertsFilterComponentType<T>; | ||
| return <FilterComponent value={value} onChange={onValueChange} isDisabled={isDisabled} />; |
There was a problem hiding this comment.
I was referring to const filter = useMemo(() => {. Any idea on that?
| if (options.length < 2) { | ||
| if (options.length === 1) { | ||
| // Select the only available solution and | ||
| // don't show the selector | ||
| onSolutionChange(options[0].value); | ||
| } | ||
| return null; | ||
| } |
There was a problem hiding this comment.
A pseudo example of how it can be done without any useEffects or call of onSolutionChange.
// top-level component
const { data: ruleTypes, isLoading, isError } = useGetInternalRuleTypesQuery({ http });
if (isLoading) {
return null;
}
return <AlertsFilterFormWraper ruleTypes={ruleTypes}> // name tbd
// AlertsFilterFormWraper
// ruleTypes always available as the component will render after the fetch
const AlertsFilterFormWraper = ({ ruleTypes }) => {
const availableSolutions = useMemo(() => getAvailableSolutions(ruleTypes), [ruleTypes]);
const [selectedSolution, setSelectedSolution] = useState(availableSolutions.length === 1 ? availableSolutions[0].value : undefined) // or whatever default we want.
availableSolutions.length > 1 && <AlertsSolutionSelector availableSolutions={availableSolutions} selectedSolution={selectedSolution} onSolutionChange={setSolution}>
}
It is very similar to what you have in the sandbox with some tweaks. We can do it on the final PR.
…ato/kibana into 213061-alerts-boolean-filters-ui
azasypkin
left a comment
There was a problem hiding this comment.
Changes in package.json LGTM
|
Starting backport for target branches: 8.19 https://github.com/elastic/kibana/actions/runs/14517822494 |
💚 Build Succeeded
Metrics [docs]Async chunks
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
|
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
Summary
Implements the alerts filters form that will be used to pre-filter the alerts table embeddable.
Note
I'm using the terminology "form" to distinguish this from the alert filter controls or other type of more KQL-bar-like filters. Other alternatives that came to mind were
alerts-boolean-filters-...oralerts-filters-builder.Implementation details
Filters expression state
I opted for a tree state representation of the form's boolean expression to accommodate potential future requirements such as more complex boolean expressions (negation, parenthesized subexpressions to manually control operators precedence):
This state is saved in the embeddable panel state and represents the editor form. The embeddable alerts table wrapper component will then transform this to an actual ES query.
To simplify interactions inside the form, an intermediate equivalent flattened state is used:
Filters model
Each filter is described by an
AlertsFilterMetadata<T>object, whereTis the type of the filter value:Verification steps
yarn start --run-examples)/app/triggersActionsUiExample/alerts_filters_form7.1. having access to rule types from just one solution (in this case the solution selector shouldn't appear at all),
7.2. having access just to Observability and Stack but not Security (in this case the solution selector shouldn't appear at all),
8.1. ES project types should have access only to Stack rules (no selector)
8.2. Observability project types should have access only to Observability and Stack rules (no selector)
8.3. Security project types should have access only to Security and Stack rules (selector shows Stack instead of Observability)
References
Depends on #214187
Closes #213061
Checklist