Skip to content

Commit

Permalink
feature(studio): test generation toast (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzim authored Aug 8, 2024
1 parent 89f006d commit e21ecc2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import { cn } from "@/utils";
import type { useCodemodAI } from "@chatbot/useAiService/codemodAI/useCodemodAI";
import { MagicWand } from "@phosphor-icons/react";
import Tooltip from "@studio/components/Tooltip/Tooltip";
import { useEffect } from "react";
import toast from "react-hot-toast";

export const GenerateTestCasesButton = ({
handleButtonClick,
isTestCaseGenerated,
}: {
handleButtonClick: ReturnType<typeof useCodemodAI>["autogenerateTestCases"];
handleButtonClick: () => void;
isTestCaseGenerated: boolean;
}) => {
useEffect(() => {
const t = toast;
if (isTestCaseGenerated) {
t.loading("Test case generation in progress...");
} else {
t.dismiss();
}
}, [isTestCaseGenerated]);
return (
<Tooltip
trigger={
<button
onClick={handleButtonClick}
className={cn(
"cursor-pointer border-hidden align-text-top bg-transparent hover:bg-transparent p-3",
"cursor-pointer border-hidden align-text-top p-3 bg-green hover:bg-[#D6FF62]",
isTestCaseGenerated && "bg-[#D6FF62]",
)}
>
<MagicWand size={"30px"} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const useCodemodAI = ({
const [isWsConnected, setIsWsConnected] = useState(false);
const [serviceBusy, setServiceBusy] = useState(false);
const { getToken } = useAuth();
const [isTestCaseGenerated, setIsTestCaseGenerated] = useState(false);

const emitMessage = async (message: MessageToSend) => {
const token = await getToken();
Expand Down Expand Up @@ -60,6 +61,7 @@ export const useCodemodAI = ({
});
setServiceBusy(false);
} else if (data.before) {
setIsTestCaseGenerated(false);
setWsMessage({
content: `Test cases created and added to a new test tab`,
role: "assistant",
Expand Down Expand Up @@ -107,6 +109,7 @@ export const useCodemodAI = ({

const autogenerateTestCases = async () => {
if (isEnvPrepared) {
setIsTestCaseGenerated(true);
setWsMessage({
content: `Generate test cases`,
role: "user",
Expand Down Expand Up @@ -160,5 +163,6 @@ export const useCodemodAI = ({
wsMessage,
serviceBusy,
autogenerateTestCases,
isTestCaseGenerated,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const useAiService = ({
startIterativeCodemodGeneration,
serviceBusy,
stopCodemodAi,
isTestCaseGenerated,
} = useCodemodAI({
messages,
engine,
Expand Down Expand Up @@ -107,5 +108,6 @@ export const useAiService = ({
modGptSubmit,
startIterativeCodemodGeneration,
autogenerateTestCases,
isTestCaseGenerated,
};
};
1 change: 1 addition & 0 deletions apps/frontend/app/(website)/studio/main/5PaneSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const Main = () => {
className="bg-gray-bg"
>
<TestTabsComponent
isTestCaseGenerated={aiAssistantData.isTestCaseGenerated}
autogenerateTestCases={aiAssistantData.autogenerateTestCases}
/>
<PanelGroup direction="horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import type { useAiService } from "@chatbot/useAiService";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
import * as Tabs from "@radix-ui/react-tabs";
import { useSnippetsStore } from "@studio/store/snippets";
import { useViewStore } from "@studio/store/view";
import { useEffect, useRef, useState } from "react";

export const TestTabsComponent = ({
autogenerateTestCases,
isTestCaseGenerated,
}: {
autogenerateTestCases: ReturnType<
typeof useAiService
>["autogenerateTestCases"];
autogenerateTestCases: ReturnType<typeof useAiService>[
| "autogenerateTestCases"
| "isTestCaseGenerated"];
}) => {
const {
getSelectedEditors,
Expand All @@ -30,6 +32,8 @@ export const TestTabsComponent = ({
const inputRef = useRef(null);
const [isEditedNameAlreadyInUse, setIsEditedNameAlreadyInUse] =
useState(false);
const { activateModGpt } = useViewStore();

useEffect(() => {
if (inputRef.current) {
setTimeout(() => inputRef.current.focus(), 0);
Expand Down Expand Up @@ -121,6 +125,7 @@ export const TestTabsComponent = ({
+
</button>
<GenerateTestCasesButton
isTestCaseGenerated={isTestCaseGenerated}
handleButtonClick={autogenerateTestCases}
/>
</>
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/app/(website)/studio/src/store/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ export enum TabNames {
}

type ViewState = {
activateModGpt: () => void;
activeTab: TabNames;
astViewCollapsed: boolean;
setActiveTab: (tab: TabNames) => void;
setASTViewCollapsed: (collapsed: boolean) => void;
};

export const useViewStore = create<ViewState>((set) => ({
export const useViewStore = create<ViewState>((set, get) => ({
activeTab: TabNames.MODGPT,
astViewCollapsed: true,
activateModGpt: () => get().setActiveTab(TabNames.MODGPT),
setActiveTab: (tab) => set(() => ({ activeTab: tab })),
setASTViewCollapsed: (collapsed) =>
set(() => ({ astViewCollapsed: collapsed })),
Expand Down

0 comments on commit e21ecc2

Please sign in to comment.