keyboard navigation has been added to the suggestions under the querycopilot search bar

This commit is contained in:
Sampath 2023-12-11 23:44:54 +05:30
parent b19aa3fbca
commit 13fafb624e
2 changed files with 59 additions and 11 deletions

View File

@ -14,7 +14,11 @@
.throughputInputSpacing > :not(:last-child) { .throughputInputSpacing > :not(:last-child) {
margin-bottom: @DefaultSpace; margin-bottom: @DefaultSpace;
} }
.capacitycalculator-link:focus{ .capacitycalculator-link:focus {
text-decoration: underline; text-decoration: underline;
outline-offset: 2px; outline-offset: 2px;
} }
.highlighted-buttonstyles {
outline: 1px dashed back;
background-color: #cccccc;
}

View File

@ -36,13 +36,14 @@ import { SamplePrompts, SamplePromptsProps } from "Explorer/QueryCopilot/Shared/
import { Action } from "Shared/Telemetry/TelemetryConstants"; import { Action } from "Shared/Telemetry/TelemetryConstants";
import { userContext } from "UserContext"; import { userContext } from "UserContext";
import { useQueryCopilot } from "hooks/useQueryCopilot"; import { useQueryCopilot } from "hooks/useQueryCopilot";
import React, { useRef, useState } from "react"; import React, { useCallback, useRef, useState } from "react";
import HintIcon from "../../../images/Hint.svg"; import HintIcon from "../../../images/Hint.svg";
import CopilotIcon from "../../../images/QueryCopilotNewLogo.svg"; import CopilotIcon from "../../../images/QueryCopilotNewLogo.svg";
import RecentIcon from "../../../images/Recent.svg"; import RecentIcon from "../../../images/Recent.svg";
import errorIcon from "../../../images/close-black.svg"; import errorIcon from "../../../images/close-black.svg";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import { useTabs } from "../../hooks/useTabs"; import { useTabs } from "../../hooks/useTabs";
import "../Controls/ThroughputInput/ThroughputInput.less";
import { useCopilotStore } from "../QueryCopilot/QueryCopilotContext"; import { useCopilotStore } from "../QueryCopilot/QueryCopilotContext";
import { useSelectedNode } from "../useSelectedNode"; import { useSelectedNode } from "../useSelectedNode";
@ -110,6 +111,8 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
errorMessage, errorMessage,
} = useCopilotStore(); } = useCopilotStore();
const [focusedindex, setFocusedindex] = useState(-1);
const sampleProps: SamplePromptsProps = { const sampleProps: SamplePromptsProps = {
isSamplePromptsOpen: isSamplePromptsOpen, isSamplePromptsOpen: isSamplePromptsOpen,
setIsSamplePromptsOpen: setIsSamplePromptsOpen, setIsSamplePromptsOpen: setIsSamplePromptsOpen,
@ -308,6 +311,45 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
useTabs.getState().setIsQueryErrorThrown(false); useTabs.getState().setIsQueryErrorThrown(false);
}, []); }, []);
const suggestionsnhistory = filteredHistories.concat(filteredSuggestedPrompts.map((item) => item.text));
const handlekeydown: React.KeyboardEventHandler = (e) => {
const { key } = e;
let nexIndexCount = 0;
if (key === "ArrowDown") {
nexIndexCount = (focusedindex + 1) % suggestionsnhistory.length;
console.log(nexIndexCount);
}
if (key === "ArrowUp") {
nexIndexCount = (focusedindex + suggestionsnhistory.length - 1) % suggestionsnhistory.length;
console.log(nexIndexCount);
}
if (key === "Enter") {
e.preventDefault();
console.log(focusedindex);
handleSelection(focusedindex);
}
setFocusedindex(nexIndexCount);
};
const handleSelection = (selectedIndex: number) => {
const selecteditem = suggestionsnhistory[selectedIndex];
if (!selecteditem) return resetSearchComplete();
else {
handlepromptset(selecteditem);
}
};
const resetSearchComplete = useCallback(() => {
setFocusedindex(-1);
setShowSamplePrompts(false);
}, []);
const handlepromptset = (prompttext: string) => {
inputEdited.current = true;
setUserPrompt(prompttext);
console.log("prompt", userPrompt);
};
return ( return (
<Stack className="copilot-prompt-pane" styles={{ root: { backgroundColor: "#FAFAFA", padding: "16px 24px 0px" } }}> <Stack className="copilot-prompt-pane" styles={{ root: { backgroundColor: "#FAFAFA", padding: "16px 24px 0px" } }}>
<Stack horizontal> <Stack horizontal>
@ -337,17 +379,14 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
inputEdited.current = true; inputEdited.current = true;
setShowSamplePrompts(true); setShowSamplePrompts(true);
}} }}
onKeyDown={(e) => { onKeyDown={handlekeydown}
if (e.key === "Enter" && userPrompt) { onFocus={() => setShowSamplePrompts(true)}
inputEdited.current = true;
startGenerateQueryProcess();
}
}}
style={{ lineHeight: 30 }} style={{ lineHeight: 30 }}
styles={{ root: { width: "95%" }, fieldGroup: { borderRadius: 6 } }} styles={{ root: { width: "95%" }, fieldGroup: { borderRadius: 6 } }}
disabled={isGeneratingQuery} disabled={isGeneratingQuery}
autoComplete="off" autoComplete="off"
placeholder="Ask a question in natural language and well generate the query for you." placeholder="Ask a question in natural language and well generate the query for you."
tabIndex={0}
/> />
{copilotTeachingBubbleVisible && ( {copilotTeachingBubbleVisible && (
<TeachingBubble <TeachingBubble
@ -376,7 +415,10 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
iconProps={{ iconName: "Send" }} iconProps={{ iconName: "Send" }}
disabled={isGeneratingQuery || !userPrompt.trim()} disabled={isGeneratingQuery || !userPrompt.trim()}
style={{ marginLeft: 8 }} style={{ marginLeft: 8 }}
onClick={() => startGenerateQueryProcess()} onClick={() => {
startGenerateQueryProcess();
setShowSamplePrompts(false);
}}
/> />
{isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />} {isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />}
{showSamplePrompts && ( {showSamplePrompts && (
@ -415,6 +457,7 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
}} }}
onRenderIcon={() => <Image src={RecentIcon} styles={{ root: { overflow: "unset" } }} />} onRenderIcon={() => <Image src={RecentIcon} styles={{ root: { overflow: "unset" } }} />}
styles={promptStyles} styles={promptStyles}
className={focusedindex === i ? "highlighted-buttonstyles" : "buttonstyles"}
> >
{history} {history}
</DefaultButton> </DefaultButton>
@ -435,7 +478,7 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
> >
Suggested Prompts Suggested Prompts
</Text> </Text>
{filteredSuggestedPrompts.map((prompt) => ( {filteredSuggestedPrompts.map((prompt, index) => (
<DefaultButton <DefaultButton
key={prompt.id} key={prompt.id}
onClick={() => { onClick={() => {
@ -445,6 +488,7 @@ export const QueryCopilotPromptbar: React.FC<QueryCopilotPromptProps> = ({
}} }}
onRenderIcon={() => <Image src={HintIcon} />} onRenderIcon={() => <Image src={HintIcon} />}
styles={promptStyles} styles={promptStyles}
className={focusedindex === filteredHistories.length + index ? "highlighted-buttonstyles" : ""}
> >
{prompt.text} {prompt.text}
</DefaultButton> </DefaultButton>