Skip to content
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

Merged
merged 19 commits into from
Nov 29, 2022

Conversation

WafaaNasr
Copy link
Contributor

@WafaaNasr WafaaNasr commented Nov 23, 2022

Summary

Problem

Manage Rules uses the Add to Rule component and this component under the hood is built on top of the In Memory Table

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 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
The table under the hood, calls clearSelection on pagination
image

@WafaaNasr WafaaNasr requested a review from a team as a code owner November 23, 2022 10:27
@WafaaNasr WafaaNasr self-assigned this Nov 23, 2022
@WafaaNasr WafaaNasr added release_note:fix Team:Security Solution Platform Security Solution Platform Team backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) ci:cloud-deploy Create or update a Cloud deployment labels Nov 23, 2022
@WafaaNasr
Copy link
Contributor Author

@elasticmachine merge upstream


jest.mock(
'../../../../rule_management_ui/components/rules_table/rules_table/use_find_rules_in_memory'
);
// TODO convert this test to RTL
Copy link
Contributor Author

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 }) => {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

tags.forEach((tag) => acc.add(tag));
return acc;
}, new Set());
return [...uniqueTags].map((tag) => ({ value: tag, name: tag }));
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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', () => {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check 6b7f2e7

Copy link
Contributor

@dhurley14 dhurley14 left a 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!!!

@kibana-ci
Copy link
Collaborator

kibana-ci commented Nov 29, 2022

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 3313 3315 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 9.6MB 9.6MB +3.4KB
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 59 65 +6
osquery 109 115 +6
securitySolution 443 449 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 68 74 +6
osquery 110 117 +7
securitySolution 520 526 +6
total +21

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @WafaaNasr

@WafaaNasr WafaaNasr added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix labels Nov 29, 2022
@WafaaNasr WafaaNasr merged commit 3cf1162 into elastic:main Nov 29, 2022
@WafaaNasr WafaaNasr deleted the fix-selection-issue-pagination branch November 29, 2022 18:04
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 29, 2022
…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)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.6

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 29, 2022
…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>
WafaaNasr added a commit that referenced this pull request Dec 2, 2022
## 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
kibanamachine pushed a commit that referenced this pull request Dec 2, 2022
## 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)
WafaaNasr added a commit that referenced this pull request Dec 2, 2022
) (#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) ci:cloud-deploy Create or update a Cloud deployment release_note:skip Skip the PR/issue when compiling release notes Team:Security Solution Platform Security Solution Platform Team v8.6.0 v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants