diff --git a/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx index 71c57edd9191c..915a8fef984cd 100644 --- a/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx @@ -68,6 +68,7 @@ describe('SearchBarComponent', () => { fields: [], title: '', }, + sourcererDataView: {}, updateSearch: jest.fn(), setSavedQuery: jest.fn(), setSearchBarFilter: jest.fn(), diff --git a/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx b/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx index e30789bfe35bf..c9906c6e70eac 100644 --- a/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx @@ -14,11 +14,12 @@ import type { Dispatch } from 'redux'; import { Subscription } from 'rxjs'; import deepEqual from 'fast-deep-equal'; -import type { DataViewBase, Filter, Query, TimeRange } from '@kbn/es-query'; +import type { Filter, Query, TimeRange } from '@kbn/es-query'; import type { FilterManager, SavedQuery } from '@kbn/data-plugin/public'; -import type { DataView } from '@kbn/data-views-plugin/public'; +import { DataView } from '@kbn/data-views-plugin/public'; import type { OnTimeChangeProps } from '@elastic/eui'; +import type { DataViewSpec } from '@kbn/data-views-plugin/public'; import { inputsActions } from '../../store/inputs'; import type { InputsRange } from '../../store/inputs/model'; import type { InputsModelId } from '../../store/inputs/constants'; @@ -44,8 +45,8 @@ import { useSyncTimerangeUrlParam } from '../../hooks/search_bar/use_sync_timera interface SiemSearchBarProps { id: InputsModelId.global | InputsModelId.timeline; - indexPattern: DataViewBase; pollForSignalIndex?: () => void; + sourcererDataView: DataViewSpec | undefined; timelineId?: string; dataTestSubj?: string; hideFilterBar?: boolean; @@ -60,13 +61,13 @@ export const SearchBarComponent = memo( hideFilterBar = false, hideQueryInput = false, id, - indexPattern, isLoading = false, pollForSignalIndex, queries, savedQuery, setSavedQuery, setSearchBarFilter, + sourcererDataView, start, toStr, updateSearch, @@ -82,6 +83,7 @@ export const SearchBarComponent = memo( unifiedSearch: { ui: { SearchBar }, }, + fieldFormats, } = useKibana().services; const dispatch = useDispatch(); @@ -294,7 +296,14 @@ export const SearchBarComponent = memo( // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); + const dataViews: DataView[] | null = useMemo(() => { + if (sourcererDataView != null) { + return [new DataView({ spec: sourcererDataView, fieldFormats })]; + } else { + return null; + } + }, [sourcererDataView, fieldFormats]); + const onTimeRangeChange = useCallback( ({ query, dateRange }) => { const isQuickSelection = dateRange.from.includes('now') || dateRange.to.includes('now'); @@ -312,12 +321,12 @@ export const SearchBarComponent = memo( }, [filterManager, id, setTablesActivePageToZero, updateSearch] ); - return ( + return dataViews ? (
( dataTestSubj={dataTestSubj} />
- ); + ) : null; }, (prevProps, nextProps) => prevProps.end === nextProps.end && prevProps.filterQuery === nextProps.filterQuery && prevProps.fromStr === nextProps.fromStr && + deepEqual(prevProps.sourcererDataView, nextProps.sourcererDataView) && prevProps.id === nextProps.id && prevProps.isLoading === nextProps.isLoading && prevProps.savedQuery === nextProps.savedQuery && @@ -348,7 +358,6 @@ export const SearchBarComponent = memo( prevProps.toStr === nextProps.toStr && prevProps.updateSearch === nextProps.updateSearch && prevProps.dataTestSubj === nextProps.dataTestSubj && - deepEqual(prevProps.indexPattern, nextProps.indexPattern) && deepEqual(prevProps.queries, nextProps.queries) ); diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx b/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx index 6f07b377a22d0..99346602d9453 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx +++ b/x-pack/plugins/security_solution/public/dashboards/pages/details/index.tsx @@ -52,7 +52,7 @@ const DashboardViewComponent: React.FC = ({ ); const query = useDeepEqualSelector(getGlobalQuerySelector); const filters = useDeepEqualSelector(getGlobalFiltersQuerySelector); - const { indexPattern } = useSourcererDataView(); + const { sourcererDataView } = useSourcererDataView(); const { show: canReadDashboard } = useCapabilities(LEGACY_DASHBOARD_APP_ID); @@ -72,7 +72,7 @@ const DashboardViewComponent: React.FC = ({ return ( <> - + = ({ useListsConfig(); const { - indexPattern, + sourcererDataView, runtimeMappings, loading: isLoadingIndexPattern, } = useSourcererDataView(SourcererScopeName.detections); @@ -542,7 +542,7 @@ const RuleDetailsPageComponent: React.FC = ({ diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.tsx index bfaea32518459..772ed680a879a 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/detection_engine.tsx @@ -151,7 +151,7 @@ const DetectionEnginePageComponent: React.FC = ({ >(); const { - indexPattern, + sourcererDataView, runtimeMappings, loading: isLoadingIndexPattern, } = useSourcererDataView(SourcererScopeName.detections); @@ -440,7 +440,7 @@ const DetectionEnginePageComponent: React.FC = ({ = ({ detailName, hostDeta [dispatch] ); - const { indexPattern, indicesExist, selectedPatterns } = useSourcererDataView(); + const { indexPattern, indicesExist, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const [loading, { inspect, hostDetails: hostOverview, id, refetch }] = useHostDetails({ endDate: to, startDate: from, @@ -172,7 +173,7 @@ const HostDetailsComponent: React.FC = ({ detailName, hostDeta <> - + { }, [dispatch] ); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const [globalFilterQuery, kqlError] = useMemo( () => convertToBuildEsQuery({ @@ -189,7 +190,7 @@ const HostsComponent = () => { - + diff --git a/x-pack/plugins/security_solution/public/explore/network/pages/details/index.tsx b/x-pack/plugins/security_solution/public/explore/network/pages/details/index.tsx index 70f3dc56887fe..9b07b232ec050 100644 --- a/x-pack/plugins/security_solution/public/explore/network/pages/details/index.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/pages/details/index.tsx @@ -103,7 +103,8 @@ const NetworkDetailsComponent: React.FC = () => { dispatch(setNetworkDetailsTablesActivePageToZero()); }, [detailName, dispatch]); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const ip = decodeIpv6(detailName); const networkDetailsFilter = useMemo(() => getNetworkDetailsPageFilter(ip), [ip]); @@ -164,7 +165,7 @@ const NetworkDetailsComponent: React.FC = () => { {indicesExist ? ( <> - + diff --git a/x-pack/plugins/security_solution/public/explore/network/pages/network.tsx b/x-pack/plugins/security_solution/public/explore/network/pages/network.tsx index fbc45396712ac..1caafa3ee182c 100644 --- a/x-pack/plugins/security_solution/public/explore/network/pages/network.tsx +++ b/x-pack/plugins/security_solution/public/explore/network/pages/network.tsx @@ -109,7 +109,8 @@ const NetworkComponent = React.memo( [dispatch] ); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const onSkipFocusBeforeEventsTable = useCallback(() => { containerElement.current @@ -157,7 +158,7 @@ const NetworkComponent = React.memo( - + diff --git a/x-pack/plugins/security_solution/public/explore/users/pages/details/index.tsx b/x-pack/plugins/security_solution/public/explore/users/pages/details/index.tsx index b751bc0e73b9f..2e5fc3b3dbbab 100644 --- a/x-pack/plugins/security_solution/public/explore/users/pages/details/index.tsx +++ b/x-pack/plugins/security_solution/public/explore/users/pages/details/index.tsx @@ -103,7 +103,8 @@ const UsersDetailsComponent: React.FC = ({ [detailName] ); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const [rawFilteredQuery, kqlError] = useMemo(() => { try { @@ -175,7 +176,7 @@ const UsersDetailsComponent: React.FC = ({ <> - + diff --git a/x-pack/plugins/security_solution/public/explore/users/pages/users.tsx b/x-pack/plugins/security_solution/public/explore/users/pages/users.tsx index 0666e34e6155e..68318e77da152 100644 --- a/x-pack/plugins/security_solution/public/explore/users/pages/users.tsx +++ b/x-pack/plugins/security_solution/public/explore/users/pages/users.tsx @@ -103,7 +103,8 @@ const UsersComponent = () => { return globalFilters; }, [severitySelection, tabName, globalFilters]); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } = + useSourcererDataView(); const [globalFiltersQuery, kqlError] = useMemo( () => convertToBuildEsQuery({ @@ -188,7 +189,7 @@ const UsersComponent = () => { - + diff --git a/x-pack/plugins/security_solution/public/kubernetes/pages/index.tsx b/x-pack/plugins/security_solution/public/kubernetes/pages/index.tsx index 6388e8dd204d6..a7a74634b3c2c 100644 --- a/x-pack/plugins/security_solution/public/kubernetes/pages/index.tsx +++ b/x-pack/plugins/security_solution/public/kubernetes/pages/index.tsx @@ -30,7 +30,7 @@ export const KubernetesContainer = React.memo(() => { const { kubernetesSecurity, uiSettings } = useKibana().services; const { globalFullScreen } = useGlobalFullScreen(); - const { indexPattern } = useSourcererDataView(); + const { indexPattern, sourcererDataView } = useSourcererDataView(); const { from, to } = useGlobalTime(); const getGlobalFiltersQuerySelector = useMemo( @@ -81,7 +81,7 @@ export const KubernetesContainer = React.memo(() => { {kubernetesSecurity.getKubernetesPage({ filter: ( - + ), indexPattern, diff --git a/x-pack/plugins/security_solution/public/overview/pages/detection_response.tsx b/x-pack/plugins/security_solution/public/overview/pages/detection_response.tsx index 067357734f640..8bdc95fc69aab 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/detection_response.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/detection_response.tsx @@ -34,7 +34,7 @@ import { useGlobalFilterQuery } from '../../common/hooks/use_global_filter_query const DetectionResponseComponent = () => { const { filterQuery } = useGlobalFilterQuery(); - const { indicesExist, indexPattern, loading: isSourcererLoading } = useSourcererDataView(); + const { indicesExist, loading: isSourcererLoading, sourcererDataView } = useSourcererDataView(); const { signalIndexName } = useSignalIndex(); const { hasKibanaREAD, hasIndexRead } = useAlertsPrivileges(); const canReadCases = useGetUserCasesPermissions().read; @@ -49,7 +49,7 @@ const DetectionResponseComponent = () => { {indicesExist ? ( <> - + diff --git a/x-pack/plugins/security_solution/public/overview/pages/entity_analytics.tsx b/x-pack/plugins/security_solution/public/overview/pages/entity_analytics.tsx index 8e7863b46ba3d..96476c90aa180 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/entity_analytics.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/entity_analytics.tsx @@ -28,7 +28,7 @@ import { useHasSecurityCapability } from '../../helper_hooks'; const EntityAnalyticsComponent = () => { const { data: riskScoreEngineStatus } = useRiskEngineStatus(); - const { indicesExist, loading: isSourcererLoading, indexPattern } = useSourcererDataView(); + const { indicesExist, loading: isSourcererLoading, sourcererDataView } = useSourcererDataView(); const isRiskScoreModuleLicenseAvailable = useHasSecurityCapability('entity-analytics'); return ( @@ -36,7 +36,7 @@ const EntityAnalyticsComponent = () => { {indicesExist ? ( <> - + diff --git a/x-pack/plugins/security_solution/public/overview/pages/overview.tsx b/x-pack/plugins/security_solution/public/overview/pages/overview.tsx index 6cccf353e4b1c..e0c50ae193903 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/overview.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/overview.tsx @@ -43,7 +43,8 @@ const OverviewComponent = () => { const filters = useDeepEqualSelector(getGlobalFiltersQuerySelector); const { from, deleteQuery, setQuery, to } = useGlobalTime(); - const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView(); + const { indicesExist, sourcererDataView, indexPattern, selectedPatterns } = + useSourcererDataView(); const endpointMetadataIndex = useMemo(() => { return [ENDPOINT_METADATA_INDEX]; @@ -71,7 +72,7 @@ const OverviewComponent = () => { {indicesExist ? ( <> - + diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_aggregated_indicators.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_aggregated_indicators.ts index 3c3f7ca0ca617..5ee03382c665f 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_aggregated_indicators.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_aggregated_indicators.ts @@ -80,7 +80,9 @@ export const useAggregatedIndicators = ({ const userTimeZone = useTimeZone(); const userFormat = useDateFormat(); - const { selectedPatterns } = useSourcererDataView(); + const { + sourcererDataView: { selectedPatterns }, + } = useSourcererDataView(); const { inspectorAdapters } = useInspector(); diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_indicators.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_indicators.ts index ad18906a95f86..335150d3c19dc 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_indicators.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_indicators.ts @@ -64,7 +64,9 @@ export const useIndicators = ({ data: { search: searchService }, }, } = useKibana(); - const { selectedPatterns } = useSourcererDataView(); + const { + sourcererDataView: { selectedPatterns }, + } = useSourcererDataView(); const { inspectorAdapters } = useInspector(); diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_sourcerer_data_view.ts b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_sourcerer_data_view.ts index d2e12d545036c..947ac663a59cd 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_sourcerer_data_view.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_sourcerer_data_view.ts @@ -54,7 +54,7 @@ export const useSourcererDataView = () => { return useMemo( () => ({ - ...sourcererDataView, + sourcererDataView, indexPatterns, indexPattern: updatedPattern, browserFields, diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_total_count.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_total_count.tsx index d9b7c22f83354..2e98154e620bd 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_total_count.tsx +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/hooks/use_total_count.tsx @@ -24,7 +24,9 @@ export const useIndicatorsTotalCount = () => { const [count, setCount] = useState(0); const [isLoading, setIsLoading] = useState(true); - const { selectedPatterns, loading: loadingDataView } = useSourcererDataView(); + const { + sourcererDataView: { selectedPatterns, loading: loadingDataView }, + } = useSourcererDataView(); useEffect(() => { const query = { diff --git a/x-pack/plugins/threat_intelligence/public/modules/indicators/pages/indicators.tsx b/x-pack/plugins/threat_intelligence/public/modules/indicators/pages/indicators.tsx index 827ad30aa4ea9..45f356ff455f2 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/indicators/pages/indicators.tsx +++ b/x-pack/plugins/threat_intelligence/public/modules/indicators/pages/indicators.tsx @@ -37,7 +37,7 @@ const IndicatorsPageProviders: FC = ({ children }) => ( const IndicatorsPageContent: VFC = () => { const { blockListIndicatorValue } = useBlockListContext(); - const { browserFields, indexPattern } = useSourcererDataView(); + const { browserFields, indexPattern, sourcererDataView } = useSourcererDataView(); const columnSettings = useColumnSettings(); @@ -84,6 +84,7 @@ const IndicatorsPageContent: VFC = () => { diff --git a/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/query_bar.tsx b/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/query_bar.tsx index eed55101e440b..784a25d597959 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/query_bar.tsx +++ b/x-pack/plugins/threat_intelligence/public/modules/query_bar/components/query_bar.tsx @@ -7,7 +7,7 @@ import React, { useEffect, VFC } from 'react'; import { useSecurityContext } from '../../../hooks/use_security_context'; -import { SecuritySolutionDataViewBase } from '../../../types'; +import { SecuritySolutionDataViewBase, SourcererDataView } from '../../../types'; interface QueryBarProps { indexPattern: SecuritySolutionDataViewBase; @@ -16,9 +16,10 @@ interface QueryBarProps { refetch: VoidFunction; loading: boolean; }>; + sourcererDataView: SourcererDataView | undefined; } -export const QueryBar: VFC = ({ indexPattern, queries }) => { +export const QueryBar: VFC = ({ queries, sourcererDataView }) => { const { SiemSearchBar, registerQuery, deregisterQuery } = useSecurityContext(); useEffect(() => { @@ -27,5 +28,5 @@ export const QueryBar: VFC = ({ indexPattern, queries }) => { return () => queries.forEach(deregisterQuery); }, [queries, deregisterQuery, registerQuery]); - return ; + return ; }; diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/header/search_bar.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/header/search_bar.cy.ts index 203e966eef9ad..383a51592e91a 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/header/search_bar.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/header/search_bar.cy.ts @@ -6,7 +6,7 @@ */ import { login } from '../../tasks/login'; -import { visit } from '../../tasks/navigation'; +import { visitWithTimeRange } from '../../tasks/navigation'; import { openAddFilterPopover, fillAddFilterForm, @@ -25,11 +25,18 @@ import { waitForAllHostsToBeLoaded } from '../../tasks/hosts/all_hosts'; describe('SearchBar', { tags: ['@ess', '@serverless'] }, () => { beforeEach(() => { + cy.task('esArchiverResetKibana'); + cy.task('esArchiverLoad', { archiveName: 'auditbeat' }); + login(); - visit(hostsUrl('allHosts')); + visitWithTimeRange(hostsUrl('allHosts')); waitForAllHostsToBeLoaded(); }); + afterEach(() => { + cy.task('esArchiverUnload', 'auditbeat'); + }); + it('adds correctly a filter to the global search bar', () => { openAddFilterPopover(); fillAddFilterForm(getHostIpFilter());