diff --git a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx index 409cd9aee4fd..4ae61500081e 100644 --- a/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryV2/QuerySearch/QuerySearch.tsx @@ -790,16 +790,28 @@ function QuerySearch(): JSX.Element { }, [queryKeySuggestions]); useEffect(() => { - if (!queryContext?.isInValue) return; + if (!queryContext) return; - const { keyToken, currentToken } = queryContext; - const key = keyToken || currentToken; - - // Only fetch if needed and if we have a valid key - if (key && key !== activeKey && !isLoadingSuggestions) { - fetchValueSuggestions(key); + // Trigger suggestions based on context + if (editorRef.current) { + // Small delay to ensure the context is fully updated + setTimeout(() => { + if (editorRef.current) { + startCompletion(editorRef.current); + } + }, 50); + } + + // Handle value suggestions for value context + if (queryContext.isInValue) { + const { keyToken, currentToken } = queryContext; + const key = keyToken || currentToken; + + // Only fetch if needed and if we have a valid key + if (key && key !== activeKey && !isLoadingSuggestions) { + fetchValueSuggestions(key); + } } - // Use only the specific properties of queryContext we need to avoid unnecessary renders }, [queryContext, activeKey, isLoadingSuggestions, fetchValueSuggestions]); return ( @@ -964,7 +976,7 @@ function QuerySearch(): JSX.Element { )} - {/* {queryContext && ( + {queryContext && (
@@ -1004,7 +1016,7 @@ function QuerySearch(): JSX.Element {
- )} */} + )} ); }