diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts index e8064715f7af..0764b061e699 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.ts @@ -24,6 +24,7 @@ export const indexPatternTypeConfig: DatasetTypeConfig = { meta: { icon: { type: 'indexPatternApp' }, tooltip: 'OpenSearch Index Patterns', + searchOnLoad: true, }, toDataset: (path) => { diff --git a/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts b/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts index cd2e45b8d25b..018fa90df397 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/lib/index_type.ts @@ -21,6 +21,7 @@ export const indexTypeConfig: DatasetTypeConfig = { meta: { icon: { type: 'logoOpenSearch' }, tooltip: 'OpenSearch Indexes', + searchOnLoad: true, }, toDataset: (path) => { diff --git a/src/plugins/data/public/query/query_string/dataset_service/types.ts b/src/plugins/data/public/query/query_string/dataset_service/types.ts index 6b84dd630c2c..46b9bdabb5f4 100644 --- a/src/plugins/data/public/query/query_string/dataset_service/types.ts +++ b/src/plugins/data/public/query/query_string/dataset_service/types.ts @@ -30,6 +30,8 @@ export interface DatasetTypeConfig { icon: EuiIconProps; /** Optional tooltip text */ tooltip?: string; + /** Optional preference for search on page load else defaulted to true */ + searchOnLoad?: boolean; }; /** * Converts a DataStructure to a Dataset. diff --git a/src/plugins/discover/public/application/view_components/utils/use_search.ts b/src/plugins/discover/public/application/view_components/utils/use_search.ts index 70fca506af68..3796faea1142 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_search.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_search.ts @@ -88,6 +88,7 @@ export const useSearch = (services: DiscoverViewServices) => { const [savedSearch, setSavedSearch] = useState(undefined); const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover); const indexPattern = useIndexPattern(services); + const skipInitialFetch = useRef(false); const { data, filterManager, @@ -111,6 +112,15 @@ export const useSearch = (services: DiscoverViewServices) => { requests: new RequestAdapter(), }; + const getDatasetAutoSearchOnPageLoadPreference = () => { + // Checks the searchOnpageLoadPreference for the current dataset if not specifed defaults to true + const datasetType = data.query.queryString.getQuery().dataset?.type; + + const datasetService = data.query.queryString.getDatasetService(); + + return !datasetType || (datasetService?.getType(datasetType)?.meta?.searchOnLoad ?? true); + }; + const shouldSearchOnPageLoad = useCallback(() => { // A saved search is created on every page load, so we check the ID to see if we're loading a // previously saved search or if it is just transient @@ -125,10 +135,13 @@ export const useSearch = (services: DiscoverViewServices) => { const data$ = useMemo( () => new BehaviorSubject({ - status: shouldSearchOnPageLoad() ? ResultStatus.LOADING : ResultStatus.UNINITIALIZED, + status: + shouldSearchOnPageLoad() && !skipInitialFetch.current + ? ResultStatus.LOADING + : ResultStatus.UNINITIALIZED, queryStatus: { startTime }, }), - [shouldSearchOnPageLoad, startTime] + [shouldSearchOnPageLoad, startTime, skipInitialFetch] ); const refetch$ = useMemo(() => new Subject(), []); @@ -289,6 +302,9 @@ export const useSearch = (services: DiscoverViewServices) => { ]); useEffect(() => { + if (!getDatasetAutoSearchOnPageLoadPreference()) { + skipInitialFetch.current = true; + } const fetch$ = merge( refetch$, filterManager.getFetches$(), @@ -297,8 +313,11 @@ export const useSearch = (services: DiscoverViewServices) => { timefilter.getAutoRefreshFetch$(), data.query.queryString.getUpdates$() ).pipe(debounceTime(100)); - const subscription = fetch$.subscribe(() => { + if (skipInitialFetch.current) { + skipInitialFetch.current = false; // Reset so future fetches will proceed normally + return; // Skip the first fetch + } (async () => { try { await fetch(); @@ -316,6 +335,8 @@ export const useSearch = (services: DiscoverViewServices) => { return () => { subscription.unsubscribe(); }; + // disabling the eslint since we are not adding getDatasetAutoSearchOnPageLoadPreference since this changes when dataset changes and these chnages are already part of data.query.queryString + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ data$, data.query.queryString, diff --git a/src/plugins/query_enhancements/public/datasets/s3_type.ts b/src/plugins/query_enhancements/public/datasets/s3_type.ts index bedb2efc78a6..a550464c4e66 100644 --- a/src/plugins/query_enhancements/public/datasets/s3_type.ts +++ b/src/plugins/query_enhancements/public/datasets/s3_type.ts @@ -24,6 +24,7 @@ export const s3TypeConfig: DatasetTypeConfig = { meta: { icon: { type: S3_ICON }, tooltip: 'Amazon S3 Connections', + searchOnLoad: true, }, toDataset: (path: DataStructure[]): Dataset => {