[Query Copilot] Generate query on enter (#1558)

This commit is contained in:
v-darkora 2023-07-27 19:45:42 +02:00 committed by GitHub
parent 4ab93a5a32
commit 38d13cc74e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -297,6 +297,12 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
setShowCallout(false); setShowCallout(false);
}; };
const startGenerateQueryProcess = () => {
updateHistories();
generateSQLQuery();
resetButtonState();
};
React.useEffect(() => { React.useEffect(() => {
useCommandBar.getState().setContextButtons(getCommandbarButtons()); useCommandBar.getState().setContextButtons(getCommandbarButtons());
}, [query, selectedQuery]); }, [query, selectedQuery]);
@ -325,6 +331,11 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
inputEdited.current = true; inputEdited.current = true;
setShowSamplePrompts(true); setShowSamplePrompts(true);
}} }}
onKeyDown={(e) => {
if (e.key === "Enter") {
startGenerateQueryProcess();
}
}}
style={{ lineHeight: 30 }} style={{ lineHeight: 30 }}
styles={{ root: { width: "95%" } }} styles={{ root: { width: "95%" } }}
disabled={isGeneratingQuery} disabled={isGeneratingQuery}
@ -357,11 +368,7 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
iconProps={{ iconName: "Send" }} iconProps={{ iconName: "Send" }}
disabled={isGeneratingQuery || !userPrompt.trim()} disabled={isGeneratingQuery || !userPrompt.trim()}
style={{ marginLeft: 8 }} style={{ marginLeft: 8 }}
onClick={() => { onClick={() => startGenerateQueryProcess()}
updateHistories();
generateSQLQuery();
resetButtonState();
}}
/> />
{isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />} {isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />}
{showSamplePrompts && ( {showSamplePrompts && (

View File

@ -54,6 +54,7 @@ exports[`Query copilot tab snapshot test should render with initial input 1`] =
id="naturalLanguageInput" id="naturalLanguageInput"
onChange={[Function]} onChange={[Function]}
onClick={[Function]} onClick={[Function]}
onKeyDown={[Function]}
style={ style={
Object { Object {
"lineHeight": 30, "lineHeight": 30,