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 f1c2af9 commit cf28df2
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -204,6 +205,8 @@ export const useSearch = (services: DiscoverServices) => {
});

data.search.showError(error as Error);
} finally {
initalSearchComplete.current = true;
}
}, [
indexPattern,
Expand Down Expand Up @@ -240,7 +243,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 cf28df2

Please sign in to comment.