[Query Copilot] Add toggle on feedback buttons (#1512)
* Add toggle on feedback buttons, clear state when new query generated or deleted * Update test
This commit is contained in:
parent
ebfc9d4b36
commit
90178178c4
|
@ -5,7 +5,15 @@ import { DeletePopup } from "./DeletePopup";
|
||||||
|
|
||||||
describe("Delete Popup snapshot test", () => {
|
describe("Delete Popup snapshot test", () => {
|
||||||
it("should render when showDeletePopup is true", () => {
|
it("should render when showDeletePopup is true", () => {
|
||||||
const wrapper = shallow(<DeletePopup showDeletePopup={true} setShowDeletePopup={() => any} setQuery={() => any} />);
|
const wrapper = shallow(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={true}
|
||||||
|
setShowDeletePopup={() => any}
|
||||||
|
setQuery={() => any}
|
||||||
|
clearFeedback={() => any}
|
||||||
|
showFeedbackBar={() => any}
|
||||||
|
/>
|
||||||
|
);
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,14 +5,20 @@ export const DeletePopup = ({
|
||||||
showDeletePopup,
|
showDeletePopup,
|
||||||
setShowDeletePopup,
|
setShowDeletePopup,
|
||||||
setQuery,
|
setQuery,
|
||||||
|
clearFeedback,
|
||||||
|
showFeedbackBar,
|
||||||
}: {
|
}: {
|
||||||
showDeletePopup: boolean;
|
showDeletePopup: boolean;
|
||||||
setShowDeletePopup: Dispatch<SetStateAction<boolean>>;
|
setShowDeletePopup: Dispatch<SetStateAction<boolean>>;
|
||||||
setQuery: Dispatch<SetStateAction<string>>;
|
setQuery: Dispatch<SetStateAction<string>>;
|
||||||
|
clearFeedback: Dispatch<SetStateAction<void>>;
|
||||||
|
showFeedbackBar: Dispatch<SetStateAction<boolean>>;
|
||||||
}): JSX.Element => {
|
}): JSX.Element => {
|
||||||
const deleteCode = () => {
|
const deleteCode = () => {
|
||||||
setQuery("");
|
setQuery("");
|
||||||
setShowDeletePopup(false);
|
setShowDeletePopup(false);
|
||||||
|
clearFeedback();
|
||||||
|
showFeedbackBar(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -87,6 +87,7 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
const [isGeneratingQuery, setIsGeneratingQuery] = useState<boolean>(false);
|
const [isGeneratingQuery, setIsGeneratingQuery] = useState<boolean>(false);
|
||||||
const [isExecuting, setIsExecuting] = useState<boolean>(false);
|
const [isExecuting, setIsExecuting] = useState<boolean>(false);
|
||||||
const [likeQuery, setLikeQuery] = useState<boolean>();
|
const [likeQuery, setLikeQuery] = useState<boolean>();
|
||||||
|
const [dislikeQuery, setDislikeQuery] = useState<boolean>();
|
||||||
const [showCallout, setShowCallout] = useState<boolean>(false);
|
const [showCallout, setShowCallout] = useState<boolean>(false);
|
||||||
const [showSamplePrompts, setShowSamplePrompts] = useState<boolean>(false);
|
const [showSamplePrompts, setShowSamplePrompts] = useState<boolean>(false);
|
||||||
const [queryIterator, setQueryIterator] = useState<MinimalQueryIterator>();
|
const [queryIterator, setQueryIterator] = useState<MinimalQueryIterator>();
|
||||||
|
@ -263,6 +264,12 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
return [executeQueryBtn, saveQueryBtn, samplePromptsBtn];
|
return [executeQueryBtn, saveQueryBtn, samplePromptsBtn];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resetButtonState = () => {
|
||||||
|
setDislikeQuery(false);
|
||||||
|
setLikeQuery(false);
|
||||||
|
setShowCallout(false);
|
||||||
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
useCommandBar.getState().setContextButtons(getCommandbarButtons());
|
useCommandBar.getState().setContextButtons(getCommandbarButtons());
|
||||||
}, [query, selectedQuery]);
|
}, [query, selectedQuery]);
|
||||||
|
@ -291,6 +298,7 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateHistories();
|
updateHistories();
|
||||||
generateSQLQuery();
|
generateSQLQuery();
|
||||||
|
resetButtonState();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />}
|
{isGeneratingQuery && <Spinner style={{ marginLeft: 8 }} />}
|
||||||
|
@ -434,17 +442,23 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
style={{ marginLeft: 20 }}
|
style={{ marginLeft: 20 }}
|
||||||
iconProps={{ iconName: likeQuery === true ? "LikeSolid" : "Like" }}
|
iconProps={{ iconName: likeQuery === true ? "LikeSolid" : "Like" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLikeQuery(true);
|
setShowCallout(!likeQuery);
|
||||||
setShowCallout(true);
|
setLikeQuery(!likeQuery);
|
||||||
|
if (dislikeQuery) {
|
||||||
|
setDislikeQuery(!dislikeQuery);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
style={{ margin: "0 10px" }}
|
style={{ margin: "0 10px" }}
|
||||||
iconProps={{ iconName: likeQuery === false ? "DislikeSolid" : "Dislike" }}
|
iconProps={{ iconName: dislikeQuery === true ? "DislikeSolid" : "Dislike" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLikeQuery(false);
|
if (!dislikeQuery) {
|
||||||
|
useQueryCopilot.getState().openFeedbackModal(generatedQuery, false, userPrompt);
|
||||||
|
setLikeQuery(false);
|
||||||
|
}
|
||||||
|
setDislikeQuery(!dislikeQuery);
|
||||||
setShowCallout(false);
|
setShowCallout(false);
|
||||||
useQueryCopilot.getState().openFeedbackModal(generatedQuery, false, userPrompt);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Separator vertical style={{ color: "#EDEBE9" }} />
|
<Separator vertical style={{ color: "#EDEBE9" }} />
|
||||||
|
@ -456,7 +470,9 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
Copy code
|
Copy code
|
||||||
</CommandBarButton>
|
</CommandBarButton>
|
||||||
<CommandBarButton
|
<CommandBarButton
|
||||||
onClick={() => setShowDeletePopup(true)}
|
onClick={() => {
|
||||||
|
setShowDeletePopup(true);
|
||||||
|
}}
|
||||||
iconProps={{ iconName: "Delete" }}
|
iconProps={{ iconName: "Delete" }}
|
||||||
style={{ margin: "0 10px", backgroundColor: "#FFF8F0", transition: "background-color 0.3s ease" }}
|
style={{ margin: "0 10px", backgroundColor: "#FFF8F0", transition: "background-color 0.3s ease" }}
|
||||||
>
|
>
|
||||||
|
@ -491,7 +507,13 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
||||||
<WelcomeModal visible={localStorage.getItem("hideWelcomeModal") !== "true"}></WelcomeModal>
|
<WelcomeModal visible={localStorage.getItem("hideWelcomeModal") !== "true"}></WelcomeModal>
|
||||||
{isSamplePromptsOpen ? <SamplePrompts sampleProps={sampleProps} /> : <></>}
|
{isSamplePromptsOpen ? <SamplePrompts sampleProps={sampleProps} /> : <></>}
|
||||||
{query !== "" && query.trim().length !== 0 ? (
|
{query !== "" && query.trim().length !== 0 ? (
|
||||||
<DeletePopup showDeletePopup={showDeletePopup} setShowDeletePopup={setShowDeletePopup} setQuery={setQuery} />
|
<DeletePopup
|
||||||
|
showDeletePopup={showDeletePopup}
|
||||||
|
setShowDeletePopup={setShowDeletePopup}
|
||||||
|
setQuery={setQuery}
|
||||||
|
clearFeedback={resetButtonState}
|
||||||
|
showFeedbackBar={setShowFeedbackBar}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in New Issue