Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add a mock prompt input when the feature is not enabled (#5108)

Liu Ji9e5a09c5cc57
diff --git a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
index 6eed499c90..735ab779a2 100644
--- a/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
+++ b/frontend/src/components/GeneralSetting/AIAugmentationSetting.vue
@@ -1,5 +1,5 @@
<template>
- <div class="px-4 py-6 lg:flex">
+ <div ref="containerRef" class="px-4 py-6 lg:flex">
<div class="text-left lg:w-1/4">
<h1 class="text-2xl font-bold">
{{ $t("settings.general.workspace.plugin.openai.ai-augmentation") }}
@@ -77,7 +77,7 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, watchEffect } from "vue";
+import { computed, onMounted, reactive, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import {
hasFeature,
@@ -89,6 +89,7 @@ import {
import { hasWorkspacePermission } from "@/utils";
import FeatureBadge from "@/components/FeatureBadge.vue";
import FeatureModal from "@/components/FeatureModal.vue";
+import scrollIntoView from "scroll-into-view-if-needed";
interface LocalState {
openAIKey: string;
@@ -98,6 +99,7 @@ interface LocalState {
const { t } = useI18n();
const settingStore = useSettingStore();
const currentUser = useCurrentUser();
+const containerRef = ref<HTMLDivElement>();
const state = reactive<LocalState>({
openAIKey: "",
@@ -118,11 +120,7 @@ const allowEdit = computed((): boolean => {
});
const allowSave = computed((): boolean => {
- return (
- allowEdit.value &&
- state.openAIKey !== "" &&
- state.openAIKey !== openAIKeySetting.value?.value
- );
+ return allowEdit.value && state.openAIKey !== openAIKeySetting.value?.value;
});
const handleOpenAIKeyChange = (event: InputEvent) => {
@@ -149,4 +147,14 @@ const updateOpenAIKey = async () => {
title: t("settings.general.workspace.config-updated"),
});
};
+
+onMounted(() => {
+ if (location.hash === "#ai-augmentation") {
+ const container = containerRef.value;
+ if (!container) return;
+ scrollIntoView(container, {
+ scrollMode: "if-needed",
+ });
+ }
+});
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 189c228026..9e4babb692 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2021,6 +2021,7 @@
"ai": {
"examples": "Examples",
"text-to-sql-placeholder": "Use natural language and Bytebase will convert it into SQL",
+ "text-to-sql-disabled-placeholder": "Enable ChatSQL capability by supplying an OpenAI API Key.",
"run-automatically": "Run automatically",
"conversation": {
"conversations": "Conversations",
@@ -2044,7 +2045,8 @@
"2": "Which manager has most direct reports in each department?",
"3": "What's the gender ratio in each department?"
},
- "statement-copied": "Statement copied to clipboard"
+ "statement-copied": "Statement copied to clipboard",
+ "dont-show-again": "Don't show again"
}
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 51038cf5dd..531c98a9df 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2020,6 +2020,7 @@
"ai": {
"examples": "例子",
"text-to-sql-placeholder": "在此输入自然语言后,Bytebase 会马上转换成 SQL 语句",
+ "text-to-sql-disabled-placeholder": "提供 OpenAI API 密钥以开启 ChatSQL 能力。",
"run-automatically": "自动运行",
"conversation": {
"conversations": "会话",
@@ -2041,7 +2042,8 @@
"2": "哪个部门经理的下属最多?",
"3": "各个部门的性别比例如何?"
},
- "statement-copied": "语句已复制到剪贴板"
+ "statement-copied": "语句已复制到剪贴板",
+ "dont-show-again": "不再显示"
}
}
}
diff --git a/frontend/src/plugins/ai/components/AIChatToSQL.vue b/frontend/src/plugins/ai/components/AIChatToSQL.vue
index af1406dbe0..b1d247ec13 100644
--- a/frontend/src/plugins/ai/components/AIChatToSQL.vue
+++ b/frontend/src/plugins/ai/components/AIChatToSQL.vue
@@ -1,5 +1,6 @@
<template>
<ChatPanel v-if="openAIKey" />
+ <MockInputPlaceholder v-else />
</template>
<script lang="ts" setup>
@@ -16,6 +17,7 @@ import {
useSettingByName,
} from "@/store";
import ChatPanel from "./ChatPanel.vue";
+import MockInputPlaceholder from "./MockInputPlaceholder.vue";
import { Connection } from "@/types";
type LocalState = {
diff --git a/frontend/src/plugins/ai/components/MockInputPlaceholder.vue b/frontend/src/plugins/ai/components/MockInputPlaceholder.vue
new file mode 100644
index 0000000000..8b559debce
--- /dev/null
+++ b/frontend/src/plugins/ai/components/MockInputPlaceholder.vue
@@ -0,0 +1,59 @@
+<template>
+ <div v-if="!dismissed" class="w-full px-4 py-2 border-t">
+ <NInputGroup>
+ <NInput
+ class="bb-ai-mock-input !cursor-pointer"
+ :disabled="false"
+ :placeholder="$t('plugin.ai.text-to-sql-disabled-placeholder')"
+ @click.prevent.stop="handleClick"
+ >
+ <template #prefix>
+ <heroicons-outline:sparkles class="w-4 h-4 text-accent" />
+ </template>
+ <template #suffix>
+ <NTooltip>
+ <template #trigger>
+ <NButton
+ :quaternary="true"
+ type="primary"
+ size="small"
+ @click.prevent.stop="handleDismiss"
+ >
+ <heroicons:x-mark />
+ </NButton>
+ </template>
+ <div class="whitespace-nowrap">
+ {{ $t("plugin.ai.dont-show-again") }}
+ </div>
+ </NTooltip>
+ </template>
+ </NInput>
+ </NInputGroup>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { useRouter } from "vue-router";
+import { NInput, NInputGroup, NButton, NTooltip } from "naive-ui";
+import { useLocalStorage } from "@vueuse/core";
+
+const router = useRouter();
+const dismissed = useLocalStorage<boolean>(
+ "bb.plugin.open-ai.dismiss-placeholder",
+ false
+);
+
+const handleClick = () => {
+ router.push({ name: "setting.workspace.general", hash: "#ai-augmentation" });
+};
+
+const handleDismiss = () => {
+ dismissed.value = true;
+};
+</script>
+
+<style lang="postcss">
+.bb-ai-mock-input .n-input__input-el {
+ @apply !ring-0 !cursor-pointer !placeholder-current;
+}
+</style>