-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Detections] Update rules count indicator in the Rules table to show pagination info #138902
[Security Solution][Detections] Update rules count indicator in the Rules table to show pagination info #138902
Conversation
b2febab
to
36add26
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
c6e53cc
to
6681359
Compare
...plugins/security_solution/public/detections/pages/detection_engine/rules/all/utility_bar.tsx
Outdated
Show resolved
Hide resolved
d6818d9
to
89845f7
Compare
89845f7
to
52c90b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix, @jpdjere 👍 Verified locally, rule counts work as expected. Left a couple of minor comments, but other than that, code changes LGTM 🎉
it.each([ | ||
[0, 0, 0, 'Showing 0-0 of 0 rules'], | ||
[1, 1, 1, 'Showing 1-1 of 1 rule'], | ||
[1, 10, 21, 'Showing 1-10 of 21 rules'], | ||
[1, 10, 8, 'Showing 1-8 of 8 rules'], | ||
[2, 10, 31, 'Showing 11-20 of 31 rules'], | ||
[4, 10, 31, 'Showing 31-31 of 31 rules'], | ||
[1, 5, 4, 'Showing 1-4 of 4 rules'], | ||
[1, 100, 100, 'Showing 1-100 of 100 rules'], | ||
[2, 100, 101, 'Showing 101-101 of 101 rules'], | ||
])( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need all of these test cases, do they all contribute to the coverage? Maybe it would be possible to ensure coverage with fewer cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. But I still consider the following cases to be necessary:
Showing 0-0 of 0 rules -----> When there are 0 rules to show
Showing 1-1 of 1 rule -----> Special case for a single rule (singular instead of plural)
Showing 1-10 of 21 rules -----> Displaying first page, with rules per page being less than total rules
Showing 1-8 of 8 rules -----> Displaying first page, with rules per page being more than total rules
Showing 11-20 of 31 rules -----> Displaying any other page, with rules per page being less than total rules
Showing 101-101 of 101 rules -----> Displaying the last page, which shows the remaining rules, which are less than the rules per page (in this case, just 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think the fewer tests we have, the better (without harming coverage). So if we could get rid of three extra test cases, that's already something.
Also, if you decide to stick with test.each
, it would be great to add some comments to the cases (as you did in the comment above) to clarify what they are supposed to test. Without comments, it's a bit hard to figure out the meaning of tests by looking at the input args only.
...solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.test.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts
Outdated
Show resolved
Hide resolved
...rity_solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the changes, checked out, and tested locally -- all good and works as expected, including the Exception Lists page! 👍
Thank you for splitting the utility bar into two components and adding test coverage. The code is nice and clean - love it!
Great PR overall @jpdjere. Left a few minor comments.
x-pack/plugins/security_solution/cypress/integration/detection_rules/prebuilt_rules.spec.ts
Outdated
Show resolved
Hide resolved
...blic/detections/pages/detection_engine/rules/all/exceptions/exceptions_table_utility_bar.tsx
Show resolved
Hide resolved
...solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.test.tsx
Outdated
Show resolved
Hide resolved
...solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.test.tsx
Outdated
Show resolved
Hide resolved
...solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.test.tsx
Outdated
Show resolved
Hide resolved
...detections/pages/detection_engine/rules/all/exceptions/exceptions_table_utility_bar.test.tsx
Show resolved
Hide resolved
...rity_solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.tsx
Show resolved
Hide resolved
...rity_solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.tsx
Outdated
Show resolved
Hide resolved
...rity_solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts
Outdated
Show resolved
Hide resolved
}); | ||
}); | ||
|
||
describe('getShowingRulesParams creates correct label when', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved getShowingRulesParams
to the same (and only) file in which it is used (rules_table_utility_bar.tsx
) and moved its tests to x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/rules_table_utility_bar.test.tsx
.
Also, changed style of tests and improved description of test cases. What do you think? @banderror @xcrzx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect!
2c80fbd
to
a27ed0e
Compare
x-pack/plugins/security_solution/cypress/integration/detection_rules/prebuilt_rules.spec.ts
Outdated
Show resolved
Hide resolved
a27ed0e
to
a5e684d
Compare
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsESLint disabled in files
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @jpdjere |
@@ -218,18 +217,21 @@ describe('Custom query rules', () => { | |||
const initialNumberOfRules = rules.length; | |||
const expectedNumberOfRulesAfterDeletion = initialNumberOfRules - 1; | |||
|
|||
cy.get(SHOWING_RULES_TEXT).should('have.text', `Showing ${initialNumberOfRules} rules`); | |||
cy.request({ url: '/api/detection_engine/rules/_find' }).then(({ body }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we could introduce a constant for this path.
The constant would be defined here:
kibana/x-pack/plugins/security_solution/common/constants.ts
Lines 254 to 263 in 0212338
/** | |
* Detection engine routes | |
*/ | |
export const DETECTION_ENGINE_URL = '/api/detection_engine' as const; | |
export const DETECTION_ENGINE_RULES_URL = `${DETECTION_ENGINE_URL}/rules` as const; | |
export const DETECTION_ENGINE_PREPACKAGED_URL = | |
`${DETECTION_ENGINE_RULES_URL}/prepackaged` as const; | |
export const DETECTION_ENGINE_PRIVILEGES_URL = `${DETECTION_ENGINE_URL}/privileges` as const; | |
export const DETECTION_ENGINE_INDEX_URL = `${DETECTION_ENGINE_URL}/index` as const; | |
We would use it in the tests and in the route handler:
kibana/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_route.ts
Line 26 in 0212338
path: `${DETECTION_ENGINE_RULES_URL}/_find`, |
x-pack/plugins/security_solution/cypress/integration/detection_rules/prebuilt_rules.spec.ts
Show resolved
Hide resolved
// Assert the table was refreshed with the rules returned by the API request | ||
const ruleNames = rawRules.map((rule) => rule.name); | ||
cy.get(RULE_NAME).each(($item) => { | ||
expect($item.text()).to.be.oneOf(ruleNames); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding the comments. They are very useful 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpdjere Alright, I think you addressed all my annoying comments! 😄 The PR looks great. Thank you for your efforts in improving the reliability of tests, much appreciated 🙏
Left a small nit for your consideration.
When you're ready for merging it, let's chat about how to do that and what will be the next steps after the merge.
…ules table to show pagination info (elastic#138902) **Fixes:** elastic#121754 ## Summary Changes rules count pagination count to format: **"Showing 1-10 of 596 rules"** -> when page 1, rules per page is 10 and total rules is 596 **"Showing 6-6 of 6 rules"** -> when page 2, rules per page is 5 and total rules is 6 See other cases in tests. **Before changes** ![image](https://user-images.githubusercontent.com/5354282/184883106-118f0041-5567-4cf8-bfd5-8383e8146018.png) ![image](https://user-images.githubusercontent.com/5354282/184884145-22d30482-cc2d-4796-8f84-d809a8ca6d8a.png) **After changes** ![image](https://user-images.githubusercontent.com/5354282/184882149-d6c55dff-39a0-4a72-94a9-217b2e5ca7ac.png) ![image](https://user-images.githubusercontent.com/5354282/184886334-a107a2c5-31dc-4a7b-9e70-54c87c1630e0.png) ## Codebase changes - Refactors `AllRulesUtilityBar` component to separate usage of the utility bar between the all-rules table use-case and the Exceptions table use-case, by creating a new `ExceptionsTableUtilityBar` component. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 147e414)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…ules table to show pagination info (elastic#138902) **Fixes:** elastic#121754 ## Summary Changes rules count pagination count to format: **"Showing 1-10 of 596 rules"** -> when page 1, rules per page is 10 and total rules is 596 **"Showing 6-6 of 6 rules"** -> when page 2, rules per page is 5 and total rules is 6 See other cases in tests. **Before changes** ![image](https://user-images.githubusercontent.com/5354282/184883106-118f0041-5567-4cf8-bfd5-8383e8146018.png) ![image](https://user-images.githubusercontent.com/5354282/184884145-22d30482-cc2d-4796-8f84-d809a8ca6d8a.png) **After changes** ![image](https://user-images.githubusercontent.com/5354282/184882149-d6c55dff-39a0-4a72-94a9-217b2e5ca7ac.png) ![image](https://user-images.githubusercontent.com/5354282/184886334-a107a2c5-31dc-4a7b-9e70-54c87c1630e0.png) ## Codebase changes - Refactors `AllRulesUtilityBar` component to separate usage of the utility bar between the all-rules table use-case and the Exceptions table use-case, by creating a new `ExceptionsTableUtilityBar` component. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 147e414)
…ules table to show pagination info (#138902) (#139288) **Fixes:** #121754 ## Summary Changes rules count pagination count to format: **"Showing 1-10 of 596 rules"** -> when page 1, rules per page is 10 and total rules is 596 **"Showing 6-6 of 6 rules"** -> when page 2, rules per page is 5 and total rules is 6 See other cases in tests. **Before changes** ![image](https://user-images.githubusercontent.com/5354282/184883106-118f0041-5567-4cf8-bfd5-8383e8146018.png) ![image](https://user-images.githubusercontent.com/5354282/184884145-22d30482-cc2d-4796-8f84-d809a8ca6d8a.png) **After changes** ![image](https://user-images.githubusercontent.com/5354282/184882149-d6c55dff-39a0-4a72-94a9-217b2e5ca7ac.png) ![image](https://user-images.githubusercontent.com/5354282/184886334-a107a2c5-31dc-4a7b-9e70-54c87c1630e0.png) ## Codebase changes - Refactors `AllRulesUtilityBar` component to separate usage of the utility bar between the all-rules table use-case and the Exceptions table use-case, by creating a new `ExceptionsTableUtilityBar` component. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 147e414) Co-authored-by: Juan Pablo Djeredjian <[email protected]>
…ules table to show pagination info (elastic#138902) **Fixes:** elastic#121754 ## Summary Changes rules count pagination count to format: **"Showing 1-10 of 596 rules"** -> when page 1, rules per page is 10 and total rules is 596 **"Showing 6-6 of 6 rules"** -> when page 2, rules per page is 5 and total rules is 6 See other cases in tests. **Before changes** ![image](https://user-images.githubusercontent.com/5354282/184883106-118f0041-5567-4cf8-bfd5-8383e8146018.png) ![image](https://user-images.githubusercontent.com/5354282/184884145-22d30482-cc2d-4796-8f84-d809a8ca6d8a.png) **After changes** ![image](https://user-images.githubusercontent.com/5354282/184882149-d6c55dff-39a0-4a72-94a9-217b2e5ca7ac.png) ![image](https://user-images.githubusercontent.com/5354282/184886334-a107a2c5-31dc-4a7b-9e70-54c87c1630e0.png) ## Codebase changes - Refactors `AllRulesUtilityBar` component to separate usage of the utility bar between the all-rules table use-case and the Exceptions table use-case, by creating a new `ExceptionsTableUtilityBar` component. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Fixes: #121754
Summary
Changes rules count pagination count to format:
"Showing 1-10 of 596 rules" -> when page 1, rules per page is 10 and total rules is 596
"Showing 6-6 of 6 rules" -> when page 2, rules per page is 5 and total rules is 6
See other cases in tests.
Before changes
After changes
Codebase changes
AllRulesUtilityBar
component to separate usage of the utility bar between the all-rules table use-case and the Exceptions table use-case, by creating a newExceptionsTableUtilityBar
component.Checklist
Delete any items that are not applicable to this PR.
For maintainers