Skip to content

Commit

Permalink
[Security Solution] Fix rules filtering after enabling/disabling a ru…
Browse files Browse the repository at this point in the history
…le (elastic#151284)

**Addresses:** elastic#151151

## Summary

It fixes rules filtering after enabling or disabling a rule.

### Details

The problem is caused by improper cache invalidation. Rules cache used to be modified upon enabling or disabling one or more rules but it started causing troubles after introduction a filter by enabled or disabled state. Cached rules modification is  is complex and bug prone especially taking into account it will need to mirror backend logic and further plans on extending rule filers. So the simplest solution is invalidation of the whole rules cache. Though it may also lead to unfriendly UX when disabled or enabled rules "jump" in the table. The best approach is marking find rule request cached data as stale so data is refetched each time use changes filter state, sort by field or use pagination.

**Before:**

https://user-images.githubusercontent.com/1938181/218776621-f8903a88-1685-4a2c-9074-02fac0623dc4.mov

**After:**

https://user-images.githubusercontent.com/3775283/219630525-af109575-3a01-4988-bb6b-690473d33b80.mov

### Checklist

- [ ] [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

(cherry picked from commit 9683beb)
  • Loading branch information
maximpn committed Feb 22, 2023
1 parent 7e9bdd4 commit 91ca592
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const useFetchRuleByIdQuery = (id: string, options?: UseQueryOptions<Rule
{
...DEFAULT_QUERY_OPTIONS,
...options,
// Mark this query as immediately stale helps to avoid problems related to filtering.
// e.g. enabled and disabled state filter require data update which happens at the backend side
staleTime: 0,
enabled: !!id,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const useFindRulesQuery = (
},
{
...DEFAULT_QUERY_OPTIONS,
// Mark this query as immediately stale helps to avoid problems related to filtering.
// e.g. enabled and disabled state filter require data update which happens at the backend side
staleTime: 0,
...queryOptions,
}
);
Expand Down

0 comments on commit 91ca592

Please sign in to comment.