Skip to content

Commit

Permalink
Fixes search after initial page 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 25, 2023
1 parent 09ad642 commit 3748b61
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type RefetchSubject = Subject<SearchRefetch>;
* }, [data$]);
*/
export const useSearch = (services: DiscoverServices) => {
const initalSearchComplete = useRef(false);
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(undefined);
const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover);
const indexPattern = useIndexPattern(services);
Expand Down Expand Up @@ -205,6 +206,8 @@ export const useSearch = (services: DiscoverServices) => {
});

data.search.showError(error as Error);
} finally {
initalSearchComplete.current = true;
}
}, [
indexPattern,
Expand Down Expand Up @@ -241,7 +244,7 @@ export const useSearch = (services: DiscoverServices) => {
});

// kick off initial refetch on page load
if (shouldSearchOnPageLoad()) {
if (shouldSearchOnPageLoad() || initalSearchComplete.current === true) {
refetch$.next();
}

Expand Down

0 comments on commit 3748b61

Please sign in to comment.