-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Security] Clicking on Contextual Flyout popout Icon now opens …
…page in new tab (#196763) ## Summary Currently when user clicks on Popout icon on Misconfiguration or Vulnerabilities Contextual flyout, user gets redirected to Findings page but in the same tab. Popout Icon implies that it should navigate user to other page on separate Tabs as such the current behaviour is not right. This PR addresses that issue --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
fa77597
commit 37a4691
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.