Skip to content

Commit

Permalink
fixes search on load
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwin P Chandran <[email protected]>
  • Loading branch information
ashwin-pc committed Sep 22, 2023
1 parent f14c199 commit f1c2af9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
getResponseInspectorStats,
} from '../../../opensearch_dashboards_services';
import { SEARCH_ON_PAGE_LOAD_SETTING } from '../../../../common';
import { SortOrder } from '../../../saved_searches/types';

export enum ResultStatus {
UNINITIALIZED = 'uninitialized',
Expand Down Expand Up @@ -240,18 +239,29 @@ export const useSearch = (services: DiscoverServices) => {
})();
});

// kick off initial fetch
refetch$.next();
// kick off initial refetch on page load
if (shouldSearchOnPageLoad()) {
refetch$.next();
}

return () => {
subscription.unsubscribe();
};
}, [data$, data.query.queryString, filterManager, refetch$, timefilter, fetch, core.fatalErrors]);
}, [
data$,
data.query.queryString,
filterManager,
refetch$,
timefilter,
fetch,
core.fatalErrors,
shouldSearchOnPageLoad,
]);

// Get savedSearch if it exists
useEffect(() => {
(async () => {
const savedSearchInstance = await getSavedSearchById(savedSearchId || '');
const savedSearchInstance = await getSavedSearchById(savedSearchId);
setSavedSearch(savedSearchInstance);
})();

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface DiscoverServices {
urlForwarding: UrlForwardingStart;
timefilter: TimefilterContract;
toastNotifications: ToastsStart;
getSavedSearchById: (id: string) => Promise<SavedSearch>;
getSavedSearchById: (id?: string) => Promise<SavedSearch>;
getSavedSearchUrlById: (id: string) => Promise<string>;
uiSettings: IUiSettingsClient;
visualizations: VisualizationsStart;
Expand Down Expand Up @@ -107,7 +107,7 @@ export function buildServices(
docLinks: core.docLinks,
theme: plugins.charts.theme,
filterManager: plugins.data.query.filterManager,
getSavedSearchById: async (id: string) => savedObjectService.get(id),
getSavedSearchById: async (id?: string) => savedObjectService.get(id),
getSavedSearchUrlById: async (id: string) => savedObjectService.urlFor(id),
history: getHistory,
indexPatterns: plugins.data.indexPatterns,
Expand Down

0 comments on commit f1c2af9

Please sign in to comment.