From 3a982561ba798c572a8660bf882e1ddd79d3bc58 Mon Sep 17 00:00:00 2001 From: animehart Date: Thu, 24 Oct 2024 08:06:51 -0700 Subject: [PATCH] addressing pr comments --- .../src/hooks/use_get_navigation_url_params.ts | 6 +++--- .../public/src/hooks/use_navigate_findings.ts | 12 ++++-------- .../public/src/utils/query_utils.test.ts | 10 +++++----- .../public/src/utils/query_utils.ts | 3 ++- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_get_navigation_url_params.ts b/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_get_navigation_url_params.ts index 218fb6caf358c..792ac7b9c5a35 100644 --- a/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_get_navigation_url_params.ts +++ b/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_get_navigation_url_params.ts @@ -9,7 +9,7 @@ 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, queryFilters } from '../utils/query_utils'; +import { NavFilter, encodeQueryUrl, composeQueryFilters } from '../utils/query_utils'; export const useGetNavigationUrlParams = () => { const { services } = useKibana(); @@ -20,13 +20,13 @@ export const useGetNavigationUrlParams = () => { findingsType?: 'configurations' | 'vulnerabilities', groupBy?: string[] ) => { - const filters = queryFilters(filterParams); + const filters = composeQueryFilters(filterParams); const searchParams = new URLSearchParams(encodeQueryUrl(services.data, filters, groupBy)); return `${findingsType ? findingsType : ''}?${searchParams.toString()}`; }, - [services] + [services.data] ); return getNavUrlParams; diff --git a/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_navigate_findings.ts b/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_navigate_findings.ts index 6f6211b2374c5..5028b53b90ec9 100644 --- a/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_navigate_findings.ts +++ b/x-pack/packages/kbn-cloud-security-posture/public/src/hooks/use_navigate_findings.ts @@ -7,25 +7,21 @@ import { useCallback } from 'react'; import { useHistory } from 'react-router-dom'; -import { - SECURITY_DEFAULT_DATA_VIEW_ID, - CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX, -} from '@kbn/cloud-security-posture-common'; +import { CDR_MISCONFIGURATIONS_DATA_VIEW_ID_PREFIX } from '@kbn/cloud-security-posture-common'; import type { CoreStart } from '@kbn/core/public'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { findingsNavigation } from '../constants/navigation'; import { useDataView } from './use_data_view'; import { CspClientPluginStartDeps } from '../..'; -import { NavFilter, encodeQueryUrl, queryFilters } from '../utils/query_utils'; +import { NavFilter, encodeQueryUrl, composeQueryFilters } from '../utils/query_utils'; -// dataViewId is used to prevent FilterManager from falling back to the default in the sorcerer (logs-*) -const useNavigate = (pathname: string, dataViewId = SECURITY_DEFAULT_DATA_VIEW_ID) => { +const useNavigate = (pathname: string, dataViewId?: string) => { const history = useHistory(); const { services } = useKibana(); return useCallback( (filterParams: NavFilter = {}, groupBy?: string[]) => { - const filters = queryFilters(filterParams, dataViewId); + const filters = composeQueryFilters(filterParams, dataViewId); history.push({ pathname, diff --git a/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.test.ts b/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.test.ts index 954afb8421b75..1302702b54287 100644 --- a/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.test.ts +++ b/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.test.ts @@ -5,12 +5,12 @@ * 2.0. */ -import { encodeQueryUrl, queryFilters } from './query_utils'; +import { encodeQueryUrl, composeQueryFilters } from './query_utils'; import { dataPluginMock } from '@kbn/data-plugin/public/mocks'; const DEFAULT_DATA_VIEW_ID = 'security-solution-default'; -describe('queryFilters', () => { +describe('composeQueryFilters', () => { it('Should return correct filters given some filterParams', () => { const testFilterParams = { test_field: 'test_value', @@ -28,11 +28,11 @@ describe('queryFilters', () => { query: { match_phrase: { test_field: 'test_value' } }, }, ]; - expect(queryFilters(testFilterParams)).toEqual(testResult); + expect(composeQueryFilters(testFilterParams)).toEqual(testResult); }); it('Should return empty filters given empty filterParams', () => { - expect(queryFilters({})).toEqual([]); + expect(composeQueryFilters({})).toEqual([]); }); it('Should return correct filters given some filterParams and dataviewId', () => { @@ -52,7 +52,7 @@ describe('queryFilters', () => { query: { match_phrase: { test_field: 'test_value' } }, }, ]; - expect(queryFilters(testFilterParams, 'test-data-view')).toEqual(testResult); + expect(composeQueryFilters(testFilterParams, 'test-data-view')).toEqual(testResult); }); }); diff --git a/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.ts b/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.ts index feb6a6c5fe204..6cb5c1384e732 100644 --- a/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.ts +++ b/x-pack/packages/kbn-cloud-security-posture/public/src/utils/query_utils.ts @@ -64,7 +64,8 @@ export const encodeQueryUrl = ( }); }; -export const queryFilters = ( +// dataViewId is used to prevent FilterManager from falling back to the default in the sorcerer (logs-*) +export const composeQueryFilters = ( filterParams: NavFilter = {}, dataViewId = SECURITY_DEFAULT_DATA_VIEW_ID ): Filter[] => {