From 6693c6239681feabfd70e0378bdca160fdba984b Mon Sep 17 00:00:00 2001 From: Rishabh Rathod Date: Mon, 18 Oct 2021 23:08:34 +0530 Subject: [PATCH] hotfix: Add check to confirm variable are string (#8358) --- .../editorComponents/GlobalSearch/index.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/client/src/components/editorComponents/GlobalSearch/index.tsx b/app/client/src/components/editorComponents/GlobalSearch/index.tsx index de842fb348..7c6d955c56 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/index.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/index.tsx @@ -116,8 +116,12 @@ const isModalOpenSelector = (state: AppState) => const searchQuerySelector = (state: AppState) => state.ui.globalSearch.query; -const isMatching = (text = "", query = "") => - text?.toLowerCase().indexOf(query?.toLowerCase()) > -1; +const isMatching = (text = "", query = "") => { + if (typeof text === "string" && typeof query === "string") { + return text.toLowerCase().indexOf(query.toLowerCase()) > -1; + } + return false; +}; const getQueryIndexForSorting = (item: SearchItem, query: string) => { if (item.kind === SEARCH_ITEM_TYPES.document) { @@ -169,6 +173,13 @@ function GlobalSearch() { const modalOpen = useSelector(isModalOpenSelector); const dispatch = useDispatch(); const [snippets, setSnippetsState] = useState([]); + const [query, setQueryInState] = useState(""); + const setQuery = useCallback( + (value: string) => { + setQueryInState(value); + }, + [setQueryInState], + ); const optionalFilterMeta = useSelector( (state: AppState) => state.ui.globalSearch.filterContext.fieldMeta, ); @@ -202,10 +213,7 @@ function GlobalSearch() { dispatch(toggleShowGlobalSearchModal()); dispatch(cancelSnippet()); }; - const [query, setQueryInState] = useState(""); - const setQuery = useCallback((query: string) => { - setQueryInState(query); - }, []); + const scrollPositionRef = useRef(0); const [