forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Cloud Security] Clicking on Contextual Flyout popout Icon now …
…opens page in new tab (elastic#196763) (elastic#197935) # Backport This will backport the following commits from `main` to `8.x`: - [[Cloud Security] Clicking on Contextual Flyout popout Icon now opens page in new tab (elastic#196763)](elastic#196763) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Rickyanto Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-27T16:47:01Z","message":"[Cloud Security] Clicking on Contextual Flyout popout Icon now opens page in new tab (elastic#196763)\n\n## Summary\r\n\r\nCurrently when user clicks on Popout icon on Misconfiguration or\r\nVulnerabilities Contextual flyout, user gets redirected to Findings page\r\nbut in the same tab. Popout Icon implies that it should navigate user to\r\nother page on separate Tabs as such the current behaviour is not right.\r\n\r\nThis PR addresses that issue\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"37a4691ab6b33886b20126b54120f37002f26125","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud Security","backport:prev-minor","v8.16.0"],"title":"[Cloud Security] Clicking on Contextual Flyout popout Icon now opens page in new tab","number":196763,"url":"https://github.com/elastic/kibana/pull/196763","mergeCommit":{"message":"[Cloud Security] Clicking on Contextual Flyout popout Icon now opens page in new tab (elastic#196763)\n\n## Summary\r\n\r\nCurrently when user clicks on Popout icon on Misconfiguration or\r\nVulnerabilities Contextual flyout, user gets redirected to Findings page\r\nbut in the same tab. Popout Icon implies that it should navigate user to\r\nother page on separate Tabs as such the current behaviour is not right.\r\n\r\nThis PR addresses that issue\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"37a4691ab6b33886b20126b54120f37002f26125"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196763","number":196763,"mergeCommit":{"message":"[Cloud Security] Clicking on Contextual Flyout popout Icon now opens page in new tab (elastic#196763)\n\n## Summary\r\n\r\nCurrently when user clicks on Popout icon on Misconfiguration or\r\nVulnerabilities Contextual flyout, user gets redirected to Findings page\r\nbut in the same tab. Popout Icon implies that it should navigate user to\r\nother page on separate Tabs as such the current behaviour is not right.\r\n\r\nThis PR addresses that issue\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"37a4691ab6b33886b20126b54120f37002f26125"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Rickyanto Ang <[email protected]>
- Loading branch information
1 parent
75e4b69
commit 894baca
Showing
11 changed files
with
280 additions
and
96 deletions.
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
33 changes: 33 additions & 0 deletions
33
x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_get_navigation_url_params.ts
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,33 @@ | ||
/* | ||
* 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 { CoreStart } from '@kbn/core-lifecycle-browser'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { useCallback } from 'react'; | ||
import { CspClientPluginStartDeps } from '../types'; | ||
import { NavFilter, encodeQueryUrl, composeQueryFilters } from '../utils/query_utils'; | ||
|
||
export const useGetNavigationUrlParams = () => { | ||
const { services } = useKibana<CoreStart & CspClientPluginStartDeps>(); | ||
|
||
const getNavUrlParams = useCallback( | ||
( | ||
filterParams: NavFilter = {}, | ||
findingsType?: 'configurations' | 'vulnerabilities', | ||
groupBy?: string[] | ||
) => { | ||
const filters = composeQueryFilters(filterParams); | ||
|
||
const searchParams = new URLSearchParams(encodeQueryUrl(services.data, filters, groupBy)); | ||
|
||
return `${findingsType ? findingsType : ''}?${searchParams.toString()}`; | ||
}, | ||
[services.data] | ||
); | ||
|
||
return getNavUrlParams; | ||
}; |
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
107 changes: 107 additions & 0 deletions
107
x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.test.ts
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,107 @@ | ||
/* | ||
* 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 { encodeQueryUrl, composeQueryFilters } from './query_utils'; | ||
import { dataPluginMock } from '@kbn/data-plugin/public/mocks'; | ||
|
||
const DEFAULT_DATA_VIEW_ID = 'security-solution-default'; | ||
|
||
describe('composeQueryFilters', () => { | ||
it('Should return correct filters given some filterParams', () => { | ||
const testFilterParams = { | ||
test_field: 'test_value', | ||
}; | ||
const testResult = [ | ||
{ | ||
meta: { | ||
alias: null, | ||
negate: false, | ||
disabled: false, | ||
type: 'phrase', | ||
key: 'test_field', | ||
index: DEFAULT_DATA_VIEW_ID, | ||
}, | ||
query: { match_phrase: { test_field: 'test_value' } }, | ||
}, | ||
]; | ||
expect(composeQueryFilters(testFilterParams)).toEqual(testResult); | ||
}); | ||
|
||
it('Should return empty filters given empty filterParams', () => { | ||
expect(composeQueryFilters({})).toEqual([]); | ||
}); | ||
|
||
it('Should return correct filters given some filterParams and dataviewId', () => { | ||
const testFilterParams = { | ||
test_field: 'test_value', | ||
}; | ||
const testResult = [ | ||
{ | ||
meta: { | ||
alias: null, | ||
negate: false, | ||
disabled: false, | ||
type: 'phrase', | ||
key: 'test_field', | ||
index: 'test-data-view', | ||
}, | ||
query: { match_phrase: { test_field: 'test_value' } }, | ||
}, | ||
]; | ||
expect(composeQueryFilters(testFilterParams, 'test-data-view')).toEqual(testResult); | ||
}); | ||
}); | ||
|
||
describe('encodeQueryUrl', () => { | ||
const getServicesMock = () => ({ | ||
data: dataPluginMock.createStartContract(), | ||
}); | ||
|
||
it('Should return correct URL given empty filters', () => { | ||
const result = 'cspq=(filters:!())'; | ||
expect(encodeQueryUrl(getServicesMock().data, [])).toEqual(result); | ||
}); | ||
|
||
it('should return correct URL given filters', () => { | ||
const filter = [ | ||
{ | ||
meta: { | ||
alias: null, | ||
negate: false, | ||
disabled: false, | ||
type: 'phrase', | ||
key: 'test_field', | ||
index: DEFAULT_DATA_VIEW_ID, | ||
}, | ||
query: { match_phrase: { test_field: 'test_value' } }, | ||
}, | ||
]; | ||
const result = | ||
'cspq=(filters:!((meta:(alias:!n,disabled:!f,index:security-solution-default,key:test_field,negate:!f,type:phrase),query:(match_phrase:(test_field:test_value)))))'; | ||
expect(encodeQueryUrl(getServicesMock().data, filter)).toEqual(result); | ||
}); | ||
|
||
it('should return correct URL given filters and group by', () => { | ||
const filter = [ | ||
{ | ||
meta: { | ||
alias: null, | ||
negate: false, | ||
disabled: false, | ||
type: 'phrase', | ||
key: 'test_field', | ||
index: DEFAULT_DATA_VIEW_ID, | ||
}, | ||
query: { match_phrase: { test_field: 'test_value' } }, | ||
}, | ||
]; | ||
const groupByFilter = ['filterA']; | ||
const result = | ||
'cspq=(filters:!((meta:(alias:!n,disabled:!f,index:security-solution-default,key:test_field,negate:!f,type:phrase),query:(match_phrase:(test_field:test_value)))),groupBy:!(filterA))'; | ||
expect(encodeQueryUrl(getServicesMock().data, filter, groupByFilter)).toEqual(result); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -35,5 +35,6 @@ | |
"@kbn/ui-theme", | ||
"@kbn/i18n-react", | ||
"@kbn/rison", | ||
"@kbn/core-lifecycle-browser", | ||
] | ||
} |
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
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.