-
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][List details page]: Manage rules - Selection cleared on navigation #146121
[Security Solution][List details page]: Manage rules - Selection cleared on navigation #146121
Conversation
@elasticmachine merge upstream |
…ection-issue-pagination
…afaaNasr/kibana into fix-selection-issue-pagination
|
||
jest.mock( | ||
'../../../../rule_management_ui/components/rules_table/rules_table/use_find_rules_in_memory' | ||
); | ||
// TODO convert this test to RTL |
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.
disabling Test for now as anyway I need to convert this test to use react-testing-library
]), | ||
[initiallySelectedRules, rules] | ||
// eslint-disable-next-line react/display-name | ||
const LinkRuleSwitch = memo(({ rule }: { rule: Rule }) => { |
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.
should either move this out of the functional ExceptionsAddToRulesTableComponent or just make it a useMemo, as it is now this is a functional component that will get redefined on every render
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, @kqualters-elastic for the review :)
I already have the component pushed before in a previous commit but wanted the team to test with me while working on refactoring 😄 8bc0c26#diff-a70ea5db87eca5d28626b248345bb344c1527a752fda8504ec21a04bd08169e5R1
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.
Please validate the new commit cfff10d
…-ref HEAD~1..HEAD --fix'
tags.forEach((tag) => acc.add(tag)); | ||
return acc; | ||
}, new Set()); | ||
return [...uniqueTags].map((tag) => ({ value: tag, name: tag })); |
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: this could be done in the reduce probably
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.
Good point! I thought about, but was worried about readability, but I will give it a try
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.
We discussed it and we found it we need to implement it in two steps as we need to remove duplicates and map the string (tag) to object of { value: tag, name: tag }
|
||
const [linkedRules, setLinkedRules] = useState<Rule[]>(initiallySelectedRules || []); | ||
useEffect(() => { | ||
if (typeof onRuleSelectionChange === 'function') onRuleSelectionChange(linkedRules); |
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: i see this is typed as function | undefined, but all uses of it seem to be defined as a function, could probably change the type and remove this if
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.
please check 6b7f2e7
/> | ||
</TestProviders> | ||
); | ||
// it('it displays fetched 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.
instead of commenting out the code, consider just it.skip and creating an issue to track unskipping eventually, think that is the kibana standard way of doing so
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.
please check 6b7f2e7
…afaaNasr/kibana into fix-selection-issue-pagination
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.
Tested locally - looks great!!!
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @WafaaNasr |
…red on navigation (elastic#146121) ## Summary - This PR, is for adding the new `Link` column Switch instead of using table selection based on the below bug - Addresses elastic#145683 - Remove `Tags` duplications and filter by tags ## Problem Manage Rules uses the `Add to Rule` component and this component under the hood is built on top of the [In Memory Table](https://elastic.github.io/eui/#/tabular-content/in-memory-tables#in-memory-table-selection) Currently, this table doesn't preserve the selection when the user navigates through the pages, which means if the user had some rules selected on the first page, then navigated to any other page the selection will be cleared if the user clicked on `Save` which will cause the linked rules to be unlinked from the list without notifying the user. This could be solved by: - Removing the `pagination` but the component won't fit in the `Add Exception Flyout` - **Add another column to the table to toggle (link/unlink) using a [Switch component](https://elastic.github.io/eui/#/forms/selection-controls#switch) with making the table's row not selectable** - Make use of the `toolsLeft` property given by the `In Memory Table` to design a new way of linking/unlinking - Control the height of the `Add to Rule` component ### **We decided in the Sync meeting to try the second option as it will give us full control over the Table data as well as we found some issues in the selection with the search** Not sure still what could be the quicker solution before the release, could you please advise @peluja1012 @jethr0null After investigating why the table removes the selected item: [euiOnPageChange](https://github.com/elastic/eui/blob/main/src/components/basic_table/basic_table.tsx#L480) The table under the hood, calls `clearSelection` on pagination <img width="712" alt="image" src="https://user-images.githubusercontent.com/12671903/203592532-6309bdd4-c0fe-41fb-b9c3-f2f6f5766dd9.png"> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 3cf1162)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…n cleared on navigation (#146121) (#146607) # Backport This will backport the following commits from `main` to `8.6`: - [[Security Solution][List details page]: Manage rules - Selection cleared on navigation (#146121)](#146121) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Wafaa Nasr","email":"wafaa.nasr@elastic.co"},"sourceCommit":{"committedDate":"2022-11-29T18:04:50Z","message":"[Security Solution][List details page]: Manage rules - Selection cleared on navigation (#146121)\n\n## Summary\r\n\r\n- This PR, is for adding the new `Link` column Switch instead of using\r\ntable selection based on the below bug\r\n- Addresses https://github.com/elastic/kibana/issues/145683\r\n- Remove `Tags` duplications and filter by tags\r\n\r\n\r\n## Problem\r\n\r\nManage Rules uses the `Add to Rule` component and this component under\r\nthe hood is built on top of the [In Memory\r\nTable](https://elastic.github.io/eui/#/tabular-content/in-memory-tables#in-memory-table-selection)\r\n\r\nCurrently, this table doesn't preserve the selection when the user\r\nnavigates through the pages, which means if the user had some rules\r\nselected on the first page, then navigated to any other page the\r\nselection will be cleared if the user clicked on `Save` which will cause\r\nthe linked rules to be unlinked from the list without notifying the\r\nuser.\r\n\r\nThis could be solved by:\r\n\r\n- Removing the `pagination` but the component won't fit in the `Add\r\nException Flyout`\r\n- **Add another column to the table to toggle (link/unlink) using a\r\n[Switch\r\ncomponent](https://elastic.github.io/eui/#/forms/selection-controls#switch)\r\nwith making the table's row not selectable**\r\n- Make use of the `toolsLeft` property given by the `In Memory Table` to\r\ndesign a new way of linking/unlinking\r\n - Control the height of the `Add to Rule` component\r\n\r\n### **We decided in the Sync meeting to try the second option as it will\r\ngive us full control over the Table data as well as we found some issues\r\nin the selection with the search**\r\n\r\nNot sure still what could be the quicker solution before the release,\r\ncould you please advise @peluja1012 @jethr0null\r\n\r\nAfter investigating why the table removes the selected item:\r\n\r\n[euiOnPageChange](https://github.com/elastic/eui/blob/main/src/components/basic_table/basic_table.tsx#L480)\r\nThe table under the hood, calls `clearSelection` on pagination\r\n<img width=\"712\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/12671903/203592532-6309bdd4-c0fe-41fb-b9c3-f2f6f5766dd9.png\">\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"3cf11629e4409a83ce599d16af0398dc0d62dbe8","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Security Solution Platform","backport:prev-minor","ci:cloud-deploy","v8.7.0"],"number":146121,"url":"https://github.com/elastic/kibana/pull/146121","mergeCommit":{"message":"[Security Solution][List details page]: Manage rules - Selection cleared on navigation (#146121)\n\n## Summary\r\n\r\n- This PR, is for adding the new `Link` column Switch instead of using\r\ntable selection based on the below bug\r\n- Addresses https://github.com/elastic/kibana/issues/145683\r\n- Remove `Tags` duplications and filter by tags\r\n\r\n\r\n## Problem\r\n\r\nManage Rules uses the `Add to Rule` component and this component under\r\nthe hood is built on top of the [In Memory\r\nTable](https://elastic.github.io/eui/#/tabular-content/in-memory-tables#in-memory-table-selection)\r\n\r\nCurrently, this table doesn't preserve the selection when the user\r\nnavigates through the pages, which means if the user had some rules\r\nselected on the first page, then navigated to any other page the\r\nselection will be cleared if the user clicked on `Save` which will cause\r\nthe linked rules to be unlinked from the list without notifying the\r\nuser.\r\n\r\nThis could be solved by:\r\n\r\n- Removing the `pagination` but the component won't fit in the `Add\r\nException Flyout`\r\n- **Add another column to the table to toggle (link/unlink) using a\r\n[Switch\r\ncomponent](https://elastic.github.io/eui/#/forms/selection-controls#switch)\r\nwith making the table's row not selectable**\r\n- Make use of the `toolsLeft` property given by the `In Memory Table` to\r\ndesign a new way of linking/unlinking\r\n - Control the height of the `Add to Rule` component\r\n\r\n### **We decided in the Sync meeting to try the second option as it will\r\ngive us full control over the Table data as well as we found some issues\r\nin the selection with the search**\r\n\r\nNot sure still what could be the quicker solution before the release,\r\ncould you please advise @peluja1012 @jethr0null\r\n\r\nAfter investigating why the table removes the selected item:\r\n\r\n[euiOnPageChange](https://github.com/elastic/eui/blob/main/src/components/basic_table/basic_table.tsx#L480)\r\nThe table under the hood, calls `clearSelection` on pagination\r\n<img width=\"712\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/12671903/203592532-6309bdd4-c0fe-41fb-b9c3-f2f6f5766dd9.png\">\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"3cf11629e4409a83ce599d16af0398dc0d62dbe8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146121","number":146121,"mergeCommit":{"message":"[Security Solution][List details page]: Manage rules - Selection cleared on navigation (#146121)\n\n## Summary\r\n\r\n- This PR, is for adding the new `Link` column Switch instead of using\r\ntable selection based on the below bug\r\n- Addresses https://github.com/elastic/kibana/issues/145683\r\n- Remove `Tags` duplications and filter by tags\r\n\r\n\r\n## Problem\r\n\r\nManage Rules uses the `Add to Rule` component and this component under\r\nthe hood is built on top of the [In Memory\r\nTable](https://elastic.github.io/eui/#/tabular-content/in-memory-tables#in-memory-table-selection)\r\n\r\nCurrently, this table doesn't preserve the selection when the user\r\nnavigates through the pages, which means if the user had some rules\r\nselected on the first page, then navigated to any other page the\r\nselection will be cleared if the user clicked on `Save` which will cause\r\nthe linked rules to be unlinked from the list without notifying the\r\nuser.\r\n\r\nThis could be solved by:\r\n\r\n- Removing the `pagination` but the component won't fit in the `Add\r\nException Flyout`\r\n- **Add another column to the table to toggle (link/unlink) using a\r\n[Switch\r\ncomponent](https://elastic.github.io/eui/#/forms/selection-controls#switch)\r\nwith making the table's row not selectable**\r\n- Make use of the `toolsLeft` property given by the `In Memory Table` to\r\ndesign a new way of linking/unlinking\r\n - Control the height of the `Add to Rule` component\r\n\r\n### **We decided in the Sync meeting to try the second option as it will\r\ngive us full control over the Table data as well as we found some issues\r\nin the selection with the search**\r\n\r\nNot sure still what could be the quicker solution before the release,\r\ncould you please advise @peluja1012 @jethr0null\r\n\r\nAfter investigating why the table removes the selected item:\r\n\r\n[euiOnPageChange](https://github.com/elastic/eui/blob/main/src/components/basic_table/basic_table.tsx#L480)\r\nThe table under the hood, calls `clearSelection` on pagination\r\n<img width=\"712\" alt=\"image\"\r\nsrc=\"https://user-images.githubusercontent.com/12671903/203592532-6309bdd4-c0fe-41fb-b9c3-f2f6f5766dd9.png\">\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"3cf11629e4409a83ce599d16af0398dc0d62dbe8"}}]}] BACKPORT--> Co-authored-by: Wafaa Nasr <wafaa.nasr@elastic.co>
## Summary - Continuing from [PR](#146121) to apply the same changes to the `Add to Shared Lists`. - Fix showing the number of Linked rules correctly => in `route.ts` use the `list.namespaceType` instead of namespaceTypes array - Apply docs comment on the text - Use the HeaderMenu item from the `kbn` package for the `Number of Linked rules` menu - Allow displaying the HeaderMenu without iconType - Update snapshots and add tests in HeaderMenu
## Summary - Continuing from [PR](#146121) to apply the same changes to the `Add to Shared Lists`. - Fix showing the number of Linked rules correctly => in `route.ts` use the `list.namespaceType` instead of namespaceTypes array - Apply docs comment on the text - Use the HeaderMenu item from the `kbn` package for the `Number of Linked rules` menu - Allow displaying the HeaderMenu without iconType - Update snapshots and add tests in HeaderMenu (cherry picked from commit 78b4851)
) (#146887) # Backport This will backport the following commits from `main` to `8.6`: - [[Security Solution][Exception]: Add to shared lists fixes (#146750)](#146750) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Wafaa Nasr","email":"wafaa.nasr@elastic.co"},"sourceCommit":{"committedDate":"2022-12-02T14:02:33Z","message":"[Security Solution][Exception]: Add to shared lists fixes (#146750)\n\n## Summary\r\n\r\n- Continuing from [PR](#146121) to\r\napply the same changes to the `Add to Shared Lists`.\r\n- Fix showing the number of Linked rules correctly => in `route.ts` use\r\nthe `list.namespaceType` instead of namespaceTypes array\r\n- Apply docs comment on the text\r\n- Use the HeaderMenu item from the `kbn` package for the `Number of\r\nLinked rules` menu\r\n- Allow displaying the HeaderMenu without iconType\r\n- Update snapshots and add tests in HeaderMenu","sha":"78b4851a214e5018c8ea6535477ca9374ffb377f","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","auto-backport","Team:Security Solution Platform","ci:cloud-deploy","v8.6.0"],"number":146750,"url":"https://github.com/elastic/kibana/pull/146750","mergeCommit":{"message":"[Security Solution][Exception]: Add to shared lists fixes (#146750)\n\n## Summary\r\n\r\n- Continuing from [PR](#146121) to\r\napply the same changes to the `Add to Shared Lists`.\r\n- Fix showing the number of Linked rules correctly => in `route.ts` use\r\nthe `list.namespaceType` instead of namespaceTypes array\r\n- Apply docs comment on the text\r\n- Use the HeaderMenu item from the `kbn` package for the `Number of\r\nLinked rules` menu\r\n- Allow displaying the HeaderMenu without iconType\r\n- Update snapshots and add tests in HeaderMenu","sha":"78b4851a214e5018c8ea6535477ca9374ffb377f"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Wafaa Nasr <wafaa.nasr@elastic.co>
Summary
Link
column Switch instead of using table selection based on the below bugTags
duplications and filter by tagsProblem
Manage Rules uses the
Add to Rule
component and this component under the hood is built on top of the In Memory TableCurrently, this table doesn't preserve the selection when the user navigates through the pages, which means if the user had some rules selected on the first page, then navigated to any other page the selection will be cleared if the user clicked on
Save
which will cause the linked rules to be unlinked from the list without notifying the user.This could be solved by:
pagination
but the component won't fit in theAdd Exception Flyout
toolsLeft
property given by theIn Memory Table
to design a new way of linking/unlinkingAdd to Rule
componentWe decided in the Sync meeting to try the second option as it will give us full control over the Table data as well as we found some issues in the selection with the search
Not sure still what could be the quicker solution before the release, could you please advise @peluja1012 @jethr0null
After investigating why the table removes the selected item:
![image](https://user-images.githubusercontent.com/12671903/203592532-6309bdd4-c0fe-41fb-b9c3-f2f6f5766dd9.png)
euiOnPageChange
The table under the hood, calls
clearSelection
on pagination