[8.8] [Cloud Posture]fix incorrect vuln_mgmt details in flyout (#157745) (#157795)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Cloud Posture]fix incorrect vuln_mgmt details in flyout
(#157745)](https://github.com/elastic/kibana/pull/157745)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Lola","email":"omolola.akinleye@elastic.co"},"sourceCommit":{"committedDate":"2023-05-15T19:48:22Z","message":"[Cloud
Posture]fix incorrect vuln_mgmt details in flyout (#157745)\n\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\nCurrently, after navigating any page after
the first page and clicking\r\non vulnerability, the flyout displays
incorrect details.\r\n\r\nCurrently, we use the `data.page`, which lists
the maximum amount of\r\nvulnerabilities(500 vulnerabilities). The
`vulnerabilityIndex` is set\r\neach time, a user clicks to expand
vulnerability. We were currently only\r\nselecting vulnerabilities from
the first page.\r\n\r\nSolution:\r\n\r\nUse `slicedPage` to get the
vulnerabilities on the current page and then\r\nselect vulnerability by
`vulnerabilityIndex`\r\n\r\n\r\ndf682ecf-d024-45e4-84ca-d7df22a60ec4","sha":"5eb9102bc9313ff46ae72bb6af71e87e09c2ad7c","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Cloud
Security","v8.8.0","v8.9.0"],"number":157745,"url":"https://github.com/elastic/kibana/pull/157745","mergeCommit":{"message":"[Cloud
Posture]fix incorrect vuln_mgmt details in flyout (#157745)\n\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\nCurrently, after navigating any page after
the first page and clicking\r\non vulnerability, the flyout displays
incorrect details.\r\n\r\nCurrently, we use the `data.page`, which lists
the maximum amount of\r\nvulnerabilities(500 vulnerabilities). The
`vulnerabilityIndex` is set\r\neach time, a user clicks to expand
vulnerability. We were currently only\r\nselecting vulnerabilities from
the first page.\r\n\r\nSolution:\r\n\r\nUse `slicedPage` to get the
vulnerabilities on the current page and then\r\nselect vulnerability by
`vulnerabilityIndex`\r\n\r\n\r\ndf682ecf-d024-45e4-84ca-d7df22a60ec4","sha":"5eb9102bc9313ff46ae72bb6af71e87e09c2ad7c"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157745","number":157745,"mergeCommit":{"message":"[Cloud
Posture]fix incorrect vuln_mgmt details in flyout (#157745)\n\n##
Summary\r\n\r\nSummarize your PR. If it involves visual changes include
a screenshot or\r\ngif.\r\nCurrently, after navigating any page after
the first page and clicking\r\non vulnerability, the flyout displays
incorrect details.\r\n\r\nCurrently, we use the `data.page`, which lists
the maximum amount of\r\nvulnerabilities(500 vulnerabilities). The
`vulnerabilityIndex` is set\r\neach time, a user clicks to expand
vulnerability. We were currently only\r\nselecting vulnerabilities from
the first page.\r\n\r\nSolution:\r\n\r\nUse `slicedPage` to get the
vulnerabilities on the current page and then\r\nselect vulnerability by
`vulnerabilityIndex`\r\n\r\n\r\ndf682ecf-d024-45e4-84ca-d7df22a60ec4","sha":"5eb9102bc9313ff46ae72bb6af71e87e09c2ad7c"}}]}]
BACKPORT-->

Co-authored-by: Lola <omolola.akinleye@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-15 17:00:23 -04:00 committed by GitHub
parent 0a574d319c
commit cd47669eeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,7 +116,10 @@ const VulnerabilitiesContent = ({ dataView }: { dataView: DataView }) => {
const slicedPage = usePageSlice(data?.page, pageIndex, pageSize);
const invalidIndex = -1;
const selectedVulnerability = data?.page[urlQuery.vulnerabilityIndex];
const selectedVulnerability = useMemo(() => {
return slicedPage[urlQuery.vulnerabilityIndex];
}, [slicedPage, urlQuery.vulnerabilityIndex]);
const onCloseFlyout = () => {
setUrlQuery({