From a616cf8bda929745a4100b671859614e49919144 Mon Sep 17 00:00:00 2001 From: sunghyunkang1111 Date: Wed, 17 Jan 2024 10:33:47 -0600 Subject: [PATCH] Fix the teaching bubble popup and enable copilot card --- .../Panes/SettingsPane/SettingsPane.tsx | 2 +- .../QueryCopilot/QueryCopilotContext.tsx | 3 +++ .../QueryCopilot/QueryCopilotPromptbar.tsx | 22 +++++++++++++------ src/Explorer/SplashScreen/SplashScreen.tsx | 2 +- src/hooks/useQueryCopilot.ts | 4 +++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx index ef25a7d73..ca60458f5 100644 --- a/src/Explorer/Panes/SettingsPane/SettingsPane.tsx +++ b/src/Explorer/Panes/SettingsPane/SettingsPane.tsx @@ -234,7 +234,7 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({ const handleSampleDatabaseChange = async (ev: React.MouseEvent, checked?: boolean): Promise => { setCopilotSampleDBEnabled(checked); useQueryCopilot.getState().setCopilotSampleDBEnabled(checked); - setRefreshExplorer(!refreshExplorer); + setRefreshExplorer(false); }; const choiceButtonStyles = { diff --git a/src/Explorer/QueryCopilot/QueryCopilotContext.tsx b/src/Explorer/QueryCopilot/QueryCopilotContext.tsx index 1ec2530d5..e1a5106ea 100644 --- a/src/Explorer/QueryCopilot/QueryCopilotContext.tsx +++ b/src/Explorer/QueryCopilot/QueryCopilotContext.tsx @@ -30,6 +30,7 @@ const CopilotProvider = ({ children }: { children: React.ReactNode }): JSX.Eleme queryResults: undefined, errorMessage: "", isSamplePromptsOpen: false, + showPromptTeachingBubble: true, showDeletePopup: false, showFeedbackBar: false, showCopyPopup: false, @@ -65,6 +66,7 @@ const CopilotProvider = ({ children }: { children: React.ReactNode }): JSX.Eleme setQueryResults: (queryResults: QueryResults | undefined) => set({ queryResults }), setErrorMessage: (errorMessage: string) => set({ errorMessage }), setIsSamplePromptsOpen: (isSamplePromptsOpen: boolean) => set({ isSamplePromptsOpen }), + setShowPromptTeachingBubble: (showPromptTeachingBubble: boolean) => set({ showPromptTeachingBubble }), setShowDeletePopup: (showDeletePopup: boolean) => set({ showDeletePopup }), setShowFeedbackBar: (showFeedbackBar: boolean) => set({ showFeedbackBar }), setshowCopyPopup: (showCopyPopup: boolean) => set({ showCopyPopup }), @@ -103,6 +105,7 @@ const CopilotProvider = ({ children }: { children: React.ReactNode }): JSX.Eleme queryResults: undefined, errorMessage: "", isSamplePromptsOpen: false, + showPromptTeachingBubble: true, showDeletePopup: false, showFeedbackBar: false, showCopyPopup: false, diff --git a/src/Explorer/QueryCopilot/QueryCopilotPromptbar.tsx b/src/Explorer/QueryCopilot/QueryCopilotPromptbar.tsx index d3ed8b24c..34abe0e72 100644 --- a/src/Explorer/QueryCopilot/QueryCopilotPromptbar.tsx +++ b/src/Explorer/QueryCopilot/QueryCopilotPromptbar.tsx @@ -18,7 +18,6 @@ import { Text, TextField, } from "@fluentui/react"; -import { useBoolean } from "@fluentui/react-hooks"; import { HttpStatusCodes } from "Common/Constants"; import { handleError } from "Common/ErrorHandlingUtils"; import { createUri } from "Common/UrlUtility"; @@ -71,7 +70,7 @@ export const QueryCopilotPromptbar: React.FC = ({ databaseId, containerId, }: QueryCopilotPromptProps): JSX.Element => { - const [copilotTeachingBubbleVisible, { toggle: toggleCopilotTeachingBubbleVisible }] = useBoolean(false); + const [copilotTeachingBubbleVisible, setCopilotTeachingBubbleVisible] = useState(false); const inputEdited = useRef(false); const { openFeedbackModal, @@ -94,6 +93,8 @@ export const QueryCopilotPromptbar: React.FC = ({ setIsSamplePromptsOpen, showSamplePrompts, setShowSamplePrompts, + showPromptTeachingBubble, + setShowPromptTeachingBubble, showDeletePopup, setShowDeletePopup, showFeedbackBar, @@ -272,16 +273,23 @@ export const QueryCopilotPromptbar: React.FC = ({ }; const showTeachingBubble = (): void => { - if (!inputEdited.current) { + if (showPromptTeachingBubble && !inputEdited.current) { setTimeout(() => { if (!inputEdited.current && !isWelcomModalVisible()) { - toggleCopilotTeachingBubbleVisible(); + setCopilotTeachingBubbleVisible(true); inputEdited.current = true; } }, 30000); + } else { + toggleCopilotTeachingBubbleVisible(false); } }; + const toggleCopilotTeachingBubbleVisible = (visible: boolean): void => { + setCopilotTeachingBubbleVisible(visible); + setShowPromptTeachingBubble(visible); + }; + const isWelcomModalVisible = (): boolean => { return localStorage.getItem("hideWelcomeModal") !== "true"; }; @@ -364,13 +372,13 @@ export const QueryCopilotPromptbar: React.FC = ({ placeholder="Ask a question in natural language and we’ll generate the query for you." aria-labelledby="copilot-textfield-label" /> - {copilotTeachingBubbleVisible && ( + {showPromptTeachingBubble && copilotTeachingBubbleVisible && ( toggleCopilotTeachingBubbleVisible(false)} hasSmallHeadline={true} headline="Write a prompt" > @@ -378,7 +386,7 @@ export const QueryCopilotPromptbar: React.FC = ({ { setShowSamplePrompts(true); - toggleCopilotTeachingBubbleVisible(); + toggleCopilotTeachingBubbleVisible(false); }} style={{ color: "white", fontWeight: 600 }} > diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index ce5385329..aa7e7dcd9 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -148,7 +148,7 @@ export class SplashScreen extends React.Component { /> - {useQueryCopilot.getState().copilotEnabled && useQueryCopilot.getState().copilotSampleDBEnabled && ( + {useQueryCopilot.getState().copilotEnabled && ( void; setErrorMessage: (errorMessage: string) => void; setIsSamplePromptsOpen: (isSamplePromptsOpen: boolean) => void; + setShowPromptTeachingBubble: (showPromptTeachingBubble: boolean) => void; setShowDeletePopup: (showDeletePopup: boolean) => void; setShowFeedbackBar: (showFeedbackBar: boolean) => void; setshowCopyPopup: (showCopyPopup: boolean) => void; @@ -93,7 +95,7 @@ export interface QueryCopilotState { resetQueryCopilotStates: () => void; } -type QueryCopilotStore = UseStore; +type QueryCopilotStore = UseStore>; export const useQueryCopilot: QueryCopilotStore = create((set) => ({ copilotEnabled: false,