From 370a245a5b4dbb0bfabfbe6a69ec7e0ae3ae9689 Mon Sep 17 00:00:00 2001 From: Richard Li <742829+rli@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:34:53 -0800 Subject: [PATCH] Limit number of times user is given Q welcome page (#5152) --- .../services/amazonq/webview/Browser.kt | 3 +++ .../amazonq/webview/BrowserConnector.kt | 9 ++++++++- .../amazonq/mynah-ui/src/mynah-ui/ui/main.ts | 18 ++++++++++++++++-- .../jetbrains/settings/MeetQSettings.kt | 7 +++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt index 9bd49041e4..a7fa9e7b13 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/Browser.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.util.Disposer import com.intellij.ui.jcef.JBCefJSQuery import org.cef.CefApp import software.aws.toolkits.jetbrains.services.amazonq.util.createBrowser +import software.aws.toolkits.jetbrains.settings.MeetQSettings /* Displays the web view for the Amazon Q tool window @@ -85,6 +86,7 @@ class Browser(parent: Disposable) : Disposable { $postMessageToJavaJsCode } }, + ${MeetQSettings.getInstance().reinvent2024OnboardingCount < MAX_ONBOARDING_PAGE_COUNT}, $isFeatureDevAvailable, // whether /dev is available $isCodeTransformAvailable, // whether /transform is available $isDocAvailable, // whether /doc is available @@ -110,5 +112,6 @@ class Browser(parent: Disposable) : Disposable { companion object { private const val WEB_SCRIPT_URI = "http://mynah/js/mynah-ui.js" + private const val MAX_ONBOARDING_PAGE_COUNT = 3 } } diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt index 6fac4c8940..d3093fa660 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/webview/BrowserConnector.kt @@ -4,6 +4,7 @@ package software.aws.toolkits.jetbrains.services.amazonq.webview import com.intellij.ide.BrowserUtil +import com.intellij.ide.util.RunOnceUtil import com.intellij.ui.jcef.JBCefJSQuery.Response import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.channels.awaitClose @@ -22,6 +23,7 @@ import software.aws.toolkits.jetbrains.services.amazonq.util.command import software.aws.toolkits.jetbrains.services.amazonq.util.tabType import software.aws.toolkits.jetbrains.services.amazonq.webview.theme.AmazonQTheme import software.aws.toolkits.jetbrains.services.amazonq.webview.theme.ThemeBrowserAdapter +import software.aws.toolkits.jetbrains.settings.MeetQSettings import software.aws.toolkits.telemetry.Telemetry import java.util.function.Function @@ -40,7 +42,12 @@ class BrowserConnector( .onEach { json -> val node = serializer.toNode(json) when (node.command) { - "ui-is-ready" -> uiReady.complete(true) + "ui-is-ready" -> { + uiReady.complete(true) + RunOnceUtil.runOnceForApp("AmazonQ-UI-Ready") { + MeetQSettings.getInstance().reinvent2024OnboardingCount += 1 + } + } // some weird issue preventing deserialization from working "open-user-guide" -> { diff --git a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts index dbe0dfb2b7..cb9fef9a6a 100644 --- a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts +++ b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts @@ -33,6 +33,7 @@ import {createClickTelemetry, createOpenAgentTelemetry} from "./telemetry/action export const createMynahUI = ( ideApi: any, + showWelcomePage: boolean, featureDevInitEnabled: boolean, codeTransformInitEnabled: boolean, docInitEnabled: boolean, @@ -61,7 +62,7 @@ export const createMynahUI = ( tabsStorage.addTab({ id: 'tab-1', status: 'free', - type: 'cwc', + type: showWelcomePage ? 'welcome' : 'cwc', isSelected: true, }) @@ -598,6 +599,17 @@ export const createMynahUI = ( } } + if (tabsStorage.getTab(tabID)?.type === 'welcome') { + mynahUI.updateStore(tabID, { + tabHeaderDetails: void 0, + compactMode: false, + tabBackground: false, + promptInputText: '', + promptInputLabel: void 0, + chatItems: [], + }) + } + if (prompt.command !== undefined && prompt.command.trim() !== '') { quickActionHandler.handleCommand(prompt, tabID, eventId) @@ -678,7 +690,9 @@ export const createMynahUI = ( tabs: { 'tab-1': { isSelected: true, - store: welcomeScreenTabData(tabDataGenerator).store, + store: showWelcomePage + ? welcomeScreenTabData(tabDataGenerator).store + : tabDataGenerator.getTabData('cwc', true), }, }, onInBodyButtonClicked: (tabId, messageId, action, eventId) => { diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/MeetQSettings.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/MeetQSettings.kt index e23dda3070..53d851c6a9 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/MeetQSettings.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/MeetQSettings.kt @@ -26,10 +26,17 @@ class MeetQSettings : PersistentStateComponent { state.shouldDisplayPage = value } + var reinvent2024OnboardingCount: Int + get() = state.reinvent2024OnboardingCount + set(value) { + state.reinvent2024OnboardingCount = value + } + companion object { fun getInstance(): MeetQSettings = service() } } data class MeetQSettingsConfiguration( var shouldDisplayPage: Boolean = true, + var reinvent2024OnboardingCount: Int = 0, )