-
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
Merged
jpdjere
merged 22 commits into
elastic:main
from
jpdjere:2022-08-16-showing-rules-display
Aug 23, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
45f33c8
Calculate showingRules data and update label
jpdjere e50da8b
Add pagination label tests
jpdjere 0b1a102
Remove debugger
jpdjere 68fc9e7
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 37cd9a5
Split rules and exception list props
jpdjere 4cf7b00
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine fa63cb1
Fix exception list test
jpdjere 7601b88
Edit e2e tests
jpdjere 66d142a
Fix lint
jpdjere cc2705f
Correct translations
jpdjere 164fce3
Removed complexity warning
jpdjere b2575c2
Fix e2e load prebuilt_rules test
jpdjere 7852288
Fix linting
jpdjere 912194b
Split UtilityBar component
jpdjere 98a65a7
Address comments
jpdjere 7b8894e
Moved getShowingRulesParams and updated tests
jpdjere 2d7a216
Simplify test for component
jpdjere 79de6ce
Lint
jpdjere 08b2045
Delete unused translations
jpdjere e593631
Updated Cypress test
jpdjere 54a51ca
Update Cypress test
jpdjere a5e684d
Update custom_query_rule e2e test
jpdjere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,18 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { rawRules } from '../../../server/lib/detection_engine/rules/prepackaged_rules'; | ||
import { | ||
COLLAPSED_ACTION_BTN, | ||
ELASTIC_RULES_BTN, | ||
pageSelector, | ||
RELOAD_PREBUILT_RULES_BTN, | ||
RULES_EMPTY_PROMPT, | ||
RULE_SWITCH, | ||
SHOWING_RULES_TEXT, | ||
RULES_MONITORING_TABLE, | ||
SELECT_ALL_RULES_ON_PAGE_CHECKBOX, | ||
RULE_NAME, | ||
} from '../../screens/alerts_detection_rules'; | ||
|
||
import { | ||
deleteFirstRule, | ||
deleteSelectedRules, | ||
|
@@ -59,7 +59,16 @@ describe('Prebuilt rules', () => { | |
|
||
changeRowsPerPageTo(rowsPerPage); | ||
|
||
cy.get(SHOWING_RULES_TEXT).should('have.text', `Showing ${expectedNumberOfRules} rules`); | ||
cy.request({ url: '/api/detection_engine/rules/_find' }).then(({ body }) => { | ||
// Assert the total number of loaded rules equals the expected number of in-memory rules | ||
expect(body.total).to.equal(rawRules.length); | ||
banderror marked this conversation as resolved.
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); | ||
}); | ||
Comment on lines
+65
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for adding the comments. They are very useful 🙏 |
||
}); | ||
|
||
cy.get(pageSelector(expectedNumberOfPages)).should('exist'); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ections/pages/detection_engine/rules/all/exceptions/exceptions_table_utility_bar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { TestProviders } from '../../../../../../common/mock'; | ||
import { render, screen, within } from '@testing-library/react'; | ||
import { ExceptionsTableUtilityBar } from './exceptions_table_utility_bar'; | ||
|
||
describe('ExceptionsTableUtilityBar', () => { | ||
banderror marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it('displays correct exception lists label and refresh rules action button', () => { | ||
const EXCEPTION_LISTS_NUMBER = 25; | ||
render( | ||
<TestProviders> | ||
<ExceptionsTableUtilityBar | ||
onRefresh={jest.fn()} | ||
totalExceptionLists={EXCEPTION_LISTS_NUMBER} | ||
/> | ||
</TestProviders> | ||
); | ||
|
||
expect(screen.getByTestId('showingExceptionLists')).toBeInTheDocument(); | ||
expect(screen.getByTestId('refreshRulesAction')).toBeInTheDocument(); | ||
expect(screen.getByText(`Showing ${EXCEPTION_LISTS_NUMBER} lists`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('invokes refresh on refresh action click', () => { | ||
const mockRefresh = jest.fn(); | ||
render( | ||
<TestProviders> | ||
<ExceptionsTableUtilityBar onRefresh={mockRefresh} totalExceptionLists={1} /> | ||
</TestProviders> | ||
); | ||
|
||
const buttonWrapper = screen.getByTestId('refreshRulesAction'); | ||
within(buttonWrapper).getByRole('button').click(); | ||
|
||
expect(mockRefresh).toHaveBeenCalled(); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
...c/detections/pages/detection_engine/rules/all/exceptions/exceptions_table_utility_bar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
UtilityBar, | ||
UtilityBarAction, | ||
UtilityBarGroup, | ||
UtilityBarSection, | ||
UtilityBarText, | ||
} from '../../../../../../common/components/utility_bar'; | ||
import * as i18n from './translations'; | ||
|
||
interface ExceptionsTableUtilityBarProps { | ||
onRefresh?: () => void; | ||
totalExceptionLists: number; | ||
} | ||
|
||
export const ExceptionsTableUtilityBar: React.FC<ExceptionsTableUtilityBarProps> = ({ | ||
onRefresh, | ||
totalExceptionLists, | ||
}) => { | ||
return ( | ||
<UtilityBar border> | ||
<UtilityBarSection> | ||
<UtilityBarGroup> | ||
<UtilityBarText dataTestSubj="showingExceptionLists"> | ||
{i18n.SHOWING_EXCEPTION_LISTS(totalExceptionLists)} | ||
banderror marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</UtilityBarText> | ||
</UtilityBarGroup> | ||
<UtilityBarGroup> | ||
<UtilityBarAction | ||
dataTestSubj="refreshRulesAction" | ||
iconSide="left" | ||
iconType="refresh" | ||
onClick={onRefresh} | ||
> | ||
{i18n.REFRESH_EXCEPTIONS_TABLE} | ||
</UtilityBarAction> | ||
</UtilityBarGroup> | ||
</UtilityBarSection> | ||
</UtilityBar> | ||
); | ||
}; | ||
|
||
ExceptionsTableUtilityBar.displayName = 'ExceptionsTableUtilityBar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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