feat: update context and show suggestions on select

This commit is contained in:
Yunus M 2025-06-14 23:42:36 +05:30 committed by SagarRajput-7
parent b27901cd70
commit 51a7dae5d9

View File

@ -790,16 +790,28 @@ function QuerySearch(): JSX.Element {
}, [queryKeySuggestions]); }, [queryKeySuggestions]);
useEffect(() => { useEffect(() => {
if (!queryContext?.isInValue) return; if (!queryContext) return;
const { keyToken, currentToken } = queryContext; // Trigger suggestions based on context
const key = keyToken || currentToken; if (editorRef.current) {
// Small delay to ensure the context is fully updated
// Only fetch if needed and if we have a valid key setTimeout(() => {
if (key && key !== activeKey && !isLoadingSuggestions) { if (editorRef.current) {
fetchValueSuggestions(key); 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]); }, [queryContext, activeKey, isLoadingSuggestions, fetchValueSuggestions]);
return ( return (
@ -964,7 +976,7 @@ function QuerySearch(): JSX.Element {
</Card> </Card>
)} )}
{/* {queryContext && ( {queryContext && (
<Card size="small" title="Current Context" className="query-context"> <Card size="small" title="Current Context" className="query-context">
<div className="context-details"> <div className="context-details">
<Space direction="vertical" size={4}> <Space direction="vertical" size={4}>
@ -1004,7 +1016,7 @@ function QuerySearch(): JSX.Element {
</Space> </Space>
</div> </div>
</Card> </Card>
)} */} )}
</div> </div>
); );
} }