Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
animehart committed Oct 24, 2024
1 parent d32c49b commit 3a98256
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreStart & CspClientPluginStartDeps>();
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreStart & CspClientPluginStartDeps>();
return useCallback(
(filterParams: NavFilter = {}, groupBy?: string[]) => {
const filters = queryFilters(filterParams, dataViewId);
const filters = composeQueryFilters(filterParams, dataViewId);

history.push({
pathname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand All @@ -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);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => {
Expand Down

0 comments on commit 3a98256

Please sign in to comment.