Skip to content

Commit

Permalink
[SecuritySolution] Global search bar Edit Additional Filter not worki…
Browse files Browse the repository at this point in the history
…ng (elastic#168955)

## Summary

The issue and steps to reproduce:
elastic#164406

Root cause:
https://github.com/elastic/kibana/pull/168955/files#r1360612921

After:

https://github.com/elastic/kibana/assets/6295984/dc338c53-2f04-4f8b-a794-ff188606332a

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
(cherry picked from commit c054a2d)
  • Loading branch information
angorayc committed Oct 31, 2023
1 parent 5312779 commit 2dbb5fc
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('SearchBarComponent', () => {
fields: [],
title: '',
},
sourcererDataView: {},
updateSearch: jest.fn(),
setSavedQuery: jest.fn(),
setSearchBarFilter: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -60,13 +61,13 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
hideFilterBar = false,
hideQueryInput = false,
id,
indexPattern,
isLoading = false,
pollForSignalIndex,
queries,
savedQuery,
setSavedQuery,
setSearchBarFilter,
sourcererDataView,
start,
toStr,
updateSearch,
Expand All @@ -82,6 +83,7 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
unifiedSearch: {
ui: { SearchBar },
},
fieldFormats,
} = useKibana().services;

const dispatch = useDispatch();
Expand Down Expand Up @@ -294,7 +296,14 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
// 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');
Expand All @@ -312,12 +321,12 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
},
[filterManager, id, setTablesActivePageToZero, updateSearch]
);
return (
return dataViews ? (
<div data-test-subj={`${id}DatePicker`}>
<SearchBar
appName="siem"
isLoading={isLoading}
indexPatterns={indexPatterns as DataView[]}
indexPatterns={dataViews}
query={filterQuery}
onClearSavedQuery={onClearSavedQuery}
onQuerySubmit={onQuerySubmit}
Expand All @@ -333,12 +342,13 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
dataTestSubj={dataTestSubj}
/>
</div>
);
) : 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 &&
Expand All @@ -348,7 +358,6 @@ export const SearchBarComponent = memo<SiemSearchBarProps & PropsFromRedux>(
prevProps.toStr === nextProps.toStr &&
prevProps.updateSearch === nextProps.updateSearch &&
prevProps.dataTestSubj === nextProps.dataTestSubj &&
deepEqual(prevProps.indexPattern, nextProps.indexPattern) &&
deepEqual(prevProps.queries, nextProps.queries)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DashboardViewComponent: React.FC<DashboardViewProps> = ({
);
const query = useDeepEqualSelector(getGlobalQuerySelector);
const filters = useDeepEqualSelector(getGlobalFiltersQuerySelector);
const { indexPattern } = useSourcererDataView();
const { sourcererDataView } = useSourcererDataView();

const { show: canReadDashboard } =
useCapabilities<DashboardCapabilities>(LEGACY_DASHBOARD_APP_ID);
Expand All @@ -72,7 +72,7 @@ const DashboardViewComponent: React.FC<DashboardViewProps> = ({
return (
<>
<FiltersGlobal>
<SiemSearchBar id={InputsModelId.global} indexPattern={indexPattern} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>
<SecuritySolutionPageWrapper>
<EuiFlexGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
useListsConfig();

const {
indexPattern,
sourcererDataView,
runtimeMappings,
loading: isLoadingIndexPattern,
} = useSourcererDataView(SourcererScopeName.detections);
Expand Down Expand Up @@ -542,7 +542,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
<SiemSearchBar
id={InputsModelId.global}
pollForSignalIndex={pollForSignalIndex}
indexPattern={indexPattern}
sourcererDataView={sourcererDataView}
/>
</FiltersGlobal>
<RuleDetailsContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const DetectionEnginePageComponent: React.FC<DetectionEngineComponentProps> = ({
>();

const {
indexPattern,
sourcererDataView,
runtimeMappings,
loading: isLoadingIndexPattern,
} = useSourcererDataView(SourcererScopeName.detections);
Expand Down Expand Up @@ -440,7 +440,7 @@ const DetectionEnginePageComponent: React.FC<DetectionEngineComponentProps> = ({
<SiemSearchBar
id={InputsModelId.global}
pollForSignalIndex={pollForSignalIndex}
indexPattern={indexPattern}
sourcererDataView={sourcererDataView}
/>
</FiltersGlobal>
<SecuritySolutionPageWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ const HostDetailsComponent: React.FC<HostDetailsProps> = ({ 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,
Expand Down Expand Up @@ -172,7 +173,7 @@ const HostDetailsComponent: React.FC<HostDetailsProps> = ({ detailName, hostDeta
<>
<EuiWindowEvent event="resize" handler={noop} />
<FiltersGlobal show={showGlobalFilters({ globalFullScreen, graphEventId })}>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>

<SecuritySolutionPageWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const HostsComponent = () => {
},
[dispatch]
);
const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView();
const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } =
useSourcererDataView();
const [globalFilterQuery, kqlError] = useMemo(
() =>
convertToBuildEsQuery({
Expand Down Expand Up @@ -189,7 +190,7 @@ const HostsComponent = () => {
<StyledFullHeightContainer onKeyDown={onKeyDown} ref={containerElement}>
<EuiWindowEvent event="resize" handler={noop} />
<FiltersGlobal show={showGlobalFilters({ globalFullScreen, graphEventId })}>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>

<SecuritySolutionPageWrapper noPadding={globalFullScreen}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -164,7 +165,7 @@ const NetworkDetailsComponent: React.FC = () => {
{indicesExist ? (
<>
<FiltersGlobal>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar sourcererDataView={sourcererDataView} id={InputsModelId.global} />
</FiltersGlobal>

<SecuritySolutionPageWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const NetworkComponent = React.memo<NetworkComponentProps>(
[dispatch]
);

const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView();
const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } =
useSourcererDataView();

const onSkipFocusBeforeEventsTable = useCallback(() => {
containerElement.current
Expand Down Expand Up @@ -157,7 +158,7 @@ const NetworkComponent = React.memo<NetworkComponentProps>(
<StyledFullHeightContainer onKeyDown={onKeyDown} ref={containerElement}>
<EuiWindowEvent event="resize" handler={noop} />
<FiltersGlobal show={showGlobalFilters({ globalFullScreen, graphEventId })}>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar sourcererDataView={sourcererDataView} id={InputsModelId.global} />
</FiltersGlobal>

<SecuritySolutionPageWrapper noPadding={globalFullScreen}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ const UsersDetailsComponent: React.FC<UsersDetailsProps> = ({
[detailName]
);

const { indicesExist, indexPattern, selectedPatterns } = useSourcererDataView();
const { indicesExist, indexPattern, selectedPatterns, sourcererDataView } =
useSourcererDataView();

const [rawFilteredQuery, kqlError] = useMemo(() => {
try {
Expand Down Expand Up @@ -175,7 +176,7 @@ const UsersDetailsComponent: React.FC<UsersDetailsProps> = ({
<>
<EuiWindowEvent event="resize" handler={noop} />
<FiltersGlobal show={showGlobalFilters({ globalFullScreen, graphEventId })}>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar sourcererDataView={sourcererDataView} id={InputsModelId.global} />
</FiltersGlobal>

<SecuritySolutionPageWrapper noPadding={globalFullScreen}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -188,7 +189,7 @@ const UsersComponent = () => {
<StyledFullHeightContainer onKeyDown={onKeyDown} ref={containerElement}>
<EuiWindowEvent event="resize" handler={noop} />
<FiltersGlobal>
<SiemSearchBar indexPattern={indexPattern} id={InputsModelId.global} />
<SiemSearchBar sourcererDataView={sourcererDataView} id={InputsModelId.global} />
</FiltersGlobal>

<SecuritySolutionPageWrapper noPadding={globalFullScreen}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -81,7 +81,7 @@ export const KubernetesContainer = React.memo(() => {
{kubernetesSecurity.getKubernetesPage({
filter: (
<FiltersGlobal show={showGlobalFilters({ globalFullScreen, graphEventId: undefined })}>
<SiemSearchBar id={InputsModelId.global} indexPattern={indexPattern} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>
),
indexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,7 +49,7 @@ const DetectionResponseComponent = () => {
{indicesExist ? (
<>
<FiltersGlobal>
<SiemSearchBar id={InputsModelId.global} indexPattern={indexPattern} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>
<SecuritySolutionPageWrapper data-test-subj="detectionResponsePage">
<HeaderPage title={i18n.DETECTION_RESPONSE_TITLE} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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 (
<>
{indicesExist ? (
<>
<FiltersGlobal>
<SiemSearchBar id={InputsModelId.global} indexPattern={indexPattern} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>

<SecuritySolutionPageWrapper data-test-subj="entityAnalyticsPage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>(() => {
return [ENDPOINT_METADATA_INDEX];
Expand Down Expand Up @@ -71,7 +72,7 @@ const OverviewComponent = () => {
{indicesExist ? (
<>
<FiltersGlobal>
<SiemSearchBar id={InputsModelId.global} indexPattern={indexPattern} />
<SiemSearchBar id={InputsModelId.global} sourcererDataView={sourcererDataView} />
</FiltersGlobal>

<SecuritySolutionPageWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export const useAggregatedIndicators = ({
const userTimeZone = useTimeZone();
const userFormat = useDateFormat();

const { selectedPatterns } = useSourcererDataView();
const {
sourcererDataView: { selectedPatterns },
} = useSourcererDataView();

const { inspectorAdapters } = useInspector();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const useIndicators = ({
data: { search: searchService },
},
} = useKibana();
const { selectedPatterns } = useSourcererDataView();
const {
sourcererDataView: { selectedPatterns },
} = useSourcererDataView();

const { inspectorAdapters } = useInspector();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const useSourcererDataView = () => {

return useMemo(
() => ({
...sourcererDataView,
sourcererDataView,
indexPatterns,
indexPattern: updatedPattern,
browserFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const useIndicatorsTotalCount = () => {
const [count, setCount] = useState<number>(0);
const [isLoading, setIsLoading] = useState<boolean>(true);

const { selectedPatterns, loading: loadingDataView } = useSourcererDataView();
const {
sourcererDataView: { selectedPatterns, loading: loadingDataView },
} = useSourcererDataView();

useEffect(() => {
const query = {
Expand Down
Loading

0 comments on commit 2dbb5fc

Please sign in to comment.