Skip to content

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

feat(sql-editor): improve SQL Editor layout (#8040)

Liu Ji974d2212afd6
diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.css
index 792adcc24a..2854903d3d 100644
--- a/frontend/src/assets/css/tailwind.css
+++ b/frontend/src/assets/css/tailwind.css
@@ -308,6 +308,13 @@
.fix-scrollbar-z-index {
transform: translate3d(0, 0, 0);
}
+
+ .writing-vertical-rl {
+ writing-mode: vertical-rl;
+ }
+ .writing-vertical-lr {
+ writing-mode: vertical-lr;
+ }
}
.fade-enter-active,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index b037a86898..e5bca8e6fe 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1977,7 +1977,8 @@
"rename": "Rename"
}
}
- }
+ },
+ "filter-by-name": "Filter by name"
},
"schema-editor": {
"self": "Schema Editor",
@@ -2596,7 +2597,9 @@
},
"statement-copied": "Statement copied to clipboard",
"dont-show-again": "Don't show again",
- "chat-sql": "ChatSQL"
+ "chat-sql": "ChatSQL",
+ "disable-chat-sql": "Disable Chat SQL",
+ "enable-chat-sql": "Enable Chat SQL"
}
},
"custom-approval": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e651cff7ef..79aceb4225 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1973,7 +1973,8 @@
"rename": "Rebautizar"
}
}
- }
+ },
+ "filter-by-name": "Filtrar por nombre"
},
"schema-editor": {
"self": "Editor de esquema",
@@ -2593,7 +2594,9 @@
},
"statement-copied": "Declaración copiada al portapapeles",
"dont-show-again": "No mostrar de nuevo",
- "chat-sql": "ChatSQL"
+ "chat-sql": "ChatSQL",
+ "disable-chat-sql": "Deshabilitar Chat SQL",
+ "enable-chat-sql": "Habilitar Chat SQL"
}
},
"custom-approval": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 09d3ebdcb7..9c74f4939b 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1972,7 +1972,8 @@
"rename": "重命名"
}
}
- }
+ },
+ "filter-by-name": "根据名称过滤"
},
"schema-editor": {
"self": "Schema 编辑器",
@@ -2590,7 +2591,9 @@
},
"statement-copied": "语句已复制到剪贴板",
"dont-show-again": "不再显示",
- "chat-sql": "ChatSQL"
+ "chat-sql": "ChatSQL",
+ "disable-chat-sql": "关闭 Chat SQL",
+ "enable-chat-sql": "开启 Chat SQL"
}
},
"custom-approval": {
diff --git a/frontend/src/plugins/ai/components/AIChatToSQL.vue b/frontend/src/plugins/ai/components/AIChatToSQL.vue
index 59cdbfc0a0..080097dd4c 100644
--- a/frontend/src/plugins/ai/components/AIChatToSQL.vue
+++ b/frontend/src/plugins/ai/components/AIChatToSQL.vue
@@ -1,6 +1,5 @@
<template>
<ChatPanel v-if="openAIKey" />
- <MockInputPlaceholder v-else-if="allowConfig" />
</template>
<script lang="ts" setup>
@@ -18,7 +17,6 @@ import { Connection } from "@/types";
import { useChatByTab, provideAIContext } from "../logic";
import type { AIContextEvents } from "../types";
import ChatPanel from "./ChatPanel.vue";
-import MockInputPlaceholder from "./MockInputPlaceholder.vue";
type LocalState = {
showHistoryDialog: boolean;
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index 758c6c397d..00147e68b7 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -11,7 +11,7 @@
</template>
<AIChatToSQL
- v-if="!tabStore.isDisconnected"
+ v-if="!tabStore.isDisconnected && showAIChatBox"
:allow-config="sqlEditorStore.mode === 'BUNDLED'"
@apply-statement="handleApplyStatement"
/>
@@ -40,6 +40,7 @@ import {
ExecutingHintModal,
SaveSheetModal,
} from "../EditorCommon";
+import { useSQLEditorContext } from "../context";
import SQLEditor from "./SQLEditor.vue";
import SheetForIssueTipsBar from "./SheetForIssueTipsBar.vue";
@@ -47,6 +48,7 @@ const tabStore = useTabStore();
const saveSheetModal = ref<InstanceType<typeof SaveSheetModal>>();
const tab = useCurrentTab();
const sqlEditorStore = useSQLEditorStore();
+const { showAIChatBox } = useSQLEditorContext();
const { executeReadonly } = useExecuteSQL();
diff --git a/frontend/src/views/sql-editor/ProfileDropdown/ProfileDropdown.vue b/frontend/src/views/sql-editor/ProfileDropdown/ProfileDropdown.vue
new file mode 100644
index 0000000000..80859f0e3a
--- /dev/null
+++ b/frontend/src/views/sql-editor/ProfileDropdown/ProfileDropdown.vue
@@ -0,0 +1,216 @@
+<template>
+ <div class="relative">
+ <button
+ id="user-menu"
+ type="button"
+ class="flex text-sm text-white focus:outline-none focus:shadow-solid"
+ aria-label="User menu"
+ aria-haspopup="true"
+ @click.prevent="menu.toggle()"
+ @contextmenu.capture.prevent="menu.toggle()"
+ >
+ <UserAvatar :size="'SMALL'" :user="currentUserV1" />
+ </button>
+ <BBContextMenu ref="menu" class="origin-top-left mt-2 w-48">
+ <router-link
+ class="px-4 py-3 menu-item"
+ to="/setting/profile"
+ role="menuitem"
+ target="_blank"
+ >
+ <p class="text-sm flex justify-between">
+ <span class="text-main font-medium truncate">
+ {{ currentUserV1.title }}
+ </span>
+ <span class="text-control">
+ {{ roleNameV1(currentUserV1.userRole) }}
+ </span>
+ </p>
+ <p class="text-sm text-control truncate">
+ {{ currentUserV1.email }}
+ </p>
+ </router-link>
+ <div class="border-t border-gray-100"></div>
+ <div
+ v-if="!isRelease"
+ class="py-1 menu-item"
+ role="menuitem"
+ @click.prevent="ping"
+ >
+ Ping
+ </div>
+ <div class="border-t border-gray-100"></div>
+ <div class="py-1">
+ <router-link
+ to="/setting"
+ class="menu-item"
+ role="menuitem"
+ target="_blank"
+ >{{ $t("settings.sidebar.profile") }}</router-link
+ >
+ <div
+ class="menu-item relative"
+ @mouseenter="languageMenu.toggle()"
+ @mouseleave="languageMenu.toggle()"
+ @click.capture.prevent="languageMenu.toggle()"
+ >
+ <span>{{ $t("common.language") }}</span>
+ <BBContextMenu
+ ref="languageMenu"
+ class="origin-left absolute left-0 -top-1 -translate-x-48 transform"
+ >
+ <div
+ class="menu-item px-3 py-1 hover:bg-gray-100"
+ :class="{ 'bg-gray-100': locale === 'en-US' }"
+ @click.prevent="toggleLocale('en-US')"
+ >
+ <div class="radio text-sm">
+ <input type="radio" class="btn" :checked="locale === 'en-US'" />
+ <label class="ml-2">English</label>
+ </div>
+ </div>
+ <div
+ class="menu-item px-3 py-1 hover:bg-gray-100"
+ :class="{ 'bg-gray-100': locale === 'zh-CN' }"
+ @click.prevent="toggleLocale('zh-CN')"
+ >
+ <div class="radio text-sm">
+ <input type="radio" class="btn" :checked="locale === 'zh-CN'" />
+ <label class="ml-2">简体中文</label>
+ </div>
+ </div>
+ <div
+ class="menu-item px-3 py-1 hover:bg-gray-100"
+ :class="{ 'bg-gray-100': locale === 'es-ES' }"
+ @click.prevent="toggleLocale('es-ES')"
+ >
+ <div class="radio text-sm">
+ <input type="radio" class="btn" :checked="locale === 'es-ES'" />
+ <label class="ml-2">Español</label>
+ </div>
+ </div>
+ </BBContextMenu>
+ </div>
+ <a
+ v-if="showQuickstart"
+ class="menu-item"
+ role="menuitem"
+ @click.prevent="resetQuickstart"
+ >{{ $t("quick-start.self") }}</a
+ >
+ <a
+ href="https://bytebase.com/docs?source=console"
+ target="_blank"
+ class="menu-item"
+ >
+ {{ $t("common.help") }}
+ </a>
+ </div>
+ <div class="border-t border-gray-100"></div>
+ <div v-if="allowToggleDebug" class="py-1 menu-item">
+ <div class="flex flex-row items-center space-x-2 justify-between">
+ <span>Debug</span>
+ <BBSwitch :value="isDebug" @toggle="switchDebug" />
+ </div>
+ </div>
+ <div class="border-t border-gray-100"></div>
+ <div class="py-1">
+ <a class="menu-item" role="menuitem" @click.prevent="logout">{{
+ $t("common.logout")
+ }}</a>
+ </div>
+ </BBContextMenu>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { storeToRefs } from "pinia";
+import { computed, ref } from "vue";
+import { useRouter } from "vue-router";
+import { BBContextMenu, BBSwitch } from "@/bbkit";
+import UserAvatar from "@/components/User/UserAvatar.vue";
+import { useLanguage } from "@/composables/useLanguage";
+import {
+ pushNotification,
+ useActuatorV1Store,
+ useAuthStore,
+ useCurrentUserV1,
+ useUIStateStore,
+} from "@/store";
+import { hasWorkspacePermissionV1, roleNameV1 } from "@/utils";
+
+const actuatorStore = useActuatorV1Store();
+const authStore = useAuthStore();
+const uiStateStore = useUIStateStore();
+const router = useRouter();
+const { setLocale, locale } = useLanguage();
+const menu = ref();
+const languageMenu = ref();
+const currentUserV1 = useCurrentUserV1();
+
+// For now, debug mode is a global setting and will affect all users.
+// So we only allow DBA and Owner to toggle it.
+const allowToggleDebug = computed(() => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.debug",
+ currentUserV1.value.userRole
+ );
+});
+
+const showQuickstart = computed(() => !actuatorStore.isDemo);
+
+const logout = () => {
+ authStore.logout().then(() => {
+ router.push({ name: "auth.signin" });
+ });
+};
+
+const resetQuickstart = () => {
+ const keys = [
+ "hidden",
+ "issue.visit",
+ "project.visit",
+ "environment.visit",
+ "instance.visit",
+ "database.visit",
+ "member.addOrInvite",
+ "kbar.open",
+ "data.query",
+ "help.issue.detail",
+ "help.project",
+ "help.environment",
+ "help.instance",
+ "help.database",
+ "help.member",
+ ];
+ keys.forEach((key) => {
+ uiStateStore.saveIntroStateByKey({
+ key,
+ newState: false,
+ });
+ });
+};
+
+const { isDebug } = storeToRefs(actuatorStore);
+
+const switchDebug = () => {
+ actuatorStore.patchDebug({
+ debug: !isDebug.value,
+ });
+};
+
+const ping = () => {
+ actuatorStore.fetchServerInfo().then((info) => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: JSON.stringify(info, null, 4),
+ });
+ });
+};
+
+const toggleLocale = (lang: string) => {
+ setLocale(lang);
+ languageMenu.value.toggle();
+};
+</script>
diff --git a/frontend/src/views/sql-editor/ProfileDropdown/index.ts b/frontend/src/views/sql-editor/ProfileDropdown/index.ts
new file mode 100644
index 0000000000..ff77d8eb81
--- /dev/null
+++ b/frontend/src/views/sql-editor/ProfileDropdown/index.ts
@@ -0,0 +1,3 @@
+import ProfileDropdown from "./ProfileDropdown.vue";
+
+export default ProfileDropdown;
diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
index 01070cc4d9..a6e4d0ca4c 100644
--- a/frontend/src/views/sql-editor/SQLEditorPage.vue
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -1,117 +1,129 @@
<template>
<div class="sqleditor--wrapper">
- <Splitpanes
- class="default-theme flex flex-col flex-1 overflow-hidden"
- :dbl-click-splitter="false"
- >
- <Pane v-if="windowWidth >= 800" size="20">
- <AsidePanel @alter-schema="handleAlterSchema" />
- </Pane>
- <template v-else>
- <teleport to="body">
- <div
- id="fff"
- class="fixed rounded-full border border-control-border shadow-lg w-10 h-10 bottom-[4rem] flex items-center justify-center bg-white hover:bg-control-bg cursor-pointer z-[99999999] transition-all"
- :class="[
- state.sidebarExpanded
- ? 'left-[80%] -translate-x-5'
- : 'left-[1rem]',
- ]"
- style="
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
- transition-duration: 300ms;
- "
- @click="state.sidebarExpanded = !state.sidebarExpanded"
- >
- <heroicons-outline:chevron-left
- class="w-6 h-6 transition-transform"
- :class="[state.sidebarExpanded ? '' : '-scale-100']"
- />
- </div>
- <NDrawer
- v-model:show="state.sidebarExpanded"
- width="80vw"
- placement="left"
- >
- <AsidePanel @alter-schema="handleAlterSchema" />
- </NDrawer>
- </teleport>
- </template>
- <Pane class="relative">
- <TabList />
-
- <template v-if="allowAccess">
- <template v-if="tabStore.currentTab.mode === TabMode.ReadOnly">
- <Splitpanes
- v-if="allowReadOnlyMode"
- horizontal
- class="default-theme"
- :dbl-click-splitter="false"
+ <div class="flex-1 flex flex-row h-full">
+ <Splitpanes
+ class="default-theme flex flex-col flex-1 overflow-hidden"
+ :dbl-click-splitter="false"
+ >
+ <Pane v-if="windowWidth >= 800" size="20">
+ <AsidePanel @alter-schema="handleAlterSchema" />
+ </Pane>
+ <template v-else>
+ <teleport to="body">
+ <div
+ id="fff"
+ class="fixed rounded-full border border-control-border shadow-lg w-10 h-10 bottom-[4rem] flex items-center justify-center bg-white hover:bg-control-bg cursor-pointer z-[99999999] transition-all"
+ :class="[
+ state.sidebarExpanded
+ ? 'left-[80%] -translate-x-5'
+ : 'left-[1rem]',
+ ]"
+ style="
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
+ transition-duration: 300ms;
+ "
+ @click="state.sidebarExpanded = !state.sidebarExpanded"
>
- <Pane>
+ <heroicons-outline:chevron-left
+ class="w-6 h-6 transition-transform"
+ :class="[state.sidebarExpanded ? '' : '-scale-100']"
+ />
+ </div>
+ <NDrawer
+ v-model:show="state.sidebarExpanded"
+ width="80vw"
+ placement="left"
+ >
+ <AsidePanel @alter-schema="handleAlterSchema" />
+ </NDrawer>
+ </teleport>
+ </template>
+ <Pane class="relative">
+ <TabList />
+
+ <div class="w-full h-full overflow-hidden">
+ <template v-if="allowAccess">
+ <template v-if="tabStore.currentTab.mode === TabMode.ReadOnly">
<Splitpanes
- vertical
+ v-if="allowReadOnlyMode"
+ horizontal
class="default-theme"
:dbl-click-splitter="false"
>
<Pane>
- <EditorPanel />
+ <Splitpanes
+ vertical
+ class="default-theme"
+ :dbl-click-splitter="false"
+ >
+ <Pane>
+ <EditorPanel />
+ </Pane>
+ <Pane
+ v-if="showSecondarySidebar && windowWidth >= 1024"
+ :size="25"
+ >
+ <SecondarySidebar @alter-schema="handleAlterSchema" />
+ </Pane>
+ </Splitpanes>
</Pane>
- <Pane
- v-if="showSecondarySidebar && windowWidth >= 1024"
- :size="25"
- >
- <SecondarySidebar @alter-schema="handleAlterSchema" />
+ <Pane v-if="!isDisconnected" :size="40">
+ <ResultPanel />
</Pane>
</Splitpanes>
- </Pane>
- <Pane v-if="!isDisconnected" :size="40">
- <ResultPanel />
- </Pane>
- </Splitpanes>
+ <div
+ v-else
+ class="w-full h-full flex flex-col items-center justify-center gap-y-2"
+ >
+ <img
+ src="../../assets/illustration/403.webp"
+ class="max-h-[40%]"
+ />
+ <i18n-t
+ class="textinfolabel flex items-center"
+ keypath="sql-editor.allow-admin-mode-only"
+ tag="div"
+ >
+ <template #instance>
+ <InstanceV1Name :instance="instance" :link="false" />
+ </template>
+ </i18n-t>
+ <AdminModeButton />
+ </div>
+ </template>
+
+ <TerminalPanelV1
+ v-if="tabStore.currentTab.mode === TabMode.Admin"
+ />
+ </template>
<div
v-else
- class="w-full h-full flex flex-col items-center justify-center gap-y-2"
+ class="w-full h-full flex flex-col items-center justify-center"
>
<img
src="../../assets/illustration/403.webp"
class="max-h-[40%]"
/>
- <i18n-t
- class="textinfolabel flex items-center"
- keypath="sql-editor.allow-admin-mode-only"
- tag="div"
- >
- <template #instance>
- <InstanceV1Name :instance="instance" :link="false" />
- </template>
- </i18n-t>
- <AdminModeButton />
+ <div class="textinfolabel">
+ {{ $t("database.access-denied") }}
+ </div>
</div>
- </template>
-
- <TerminalPanelV1 v-if="tabStore.currentTab.mode === TabMode.Admin" />
- </template>
- <div
- v-else
- class="w-full h-full flex flex-col items-center justify-center"
- >
- <img src="../../assets/illustration/403.webp" class="max-h-[40%]" />
- <div class="textinfolabel">
- {{ $t("database.access-denied") }}
</div>
- </div>
- <div
- v-if="isFetchingSheet"
- class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"
- >
- <BBSpin />
- </div>
- </Pane>
- </Splitpanes>
+ <div
+ v-if="isFetchingSheet"
+ class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"
+ >
+ <BBSpin />
+ </div>
+ </Pane>
+ </Splitpanes>
+ <div v-if="windowWidth >= 1024" class="h-full border-l shrink-0">
+ <SecondaryGutterBar />
+ </div>
+ </div>
<Quickstart />
<Drawer v-model:show="showSheetPanel">
@@ -159,10 +171,12 @@ import {
provideSecondarySidebarContext,
default as SecondarySidebar,
} from "./SecondarySidebar";
+import { SecondaryGutterBar } from "./SecondarySidebar";
import { provideSheetContext } from "./Sheet";
import SheetPanel from "./SheetPanel";
import TabList from "./TabList";
import TerminalPanelV1 from "./TerminalPanel/TerminalPanelV1.vue";
+import { provideSQLEditorContext } from "./context";
type LocalState = {
sidebarExpanded: boolean;
@@ -181,6 +195,8 @@ const tabStore = useTabStore();
const databaseStore = useDatabaseV1Store();
const sqlEditorStore = useSQLEditorStore();
const currentUserV1 = useCurrentUserV1();
+// provide context for SQL Editor
+provideSQLEditorContext();
// provide context for sheets
const { showPanel: showSheetPanel } = provideSheetContext();
const { show: showSecondarySidebar } = provideSecondarySidebarContext();
@@ -278,6 +294,10 @@ const handleAlterSchema = async (params: {
.splitpanes.default-theme .splitpanes__splitter:hover::after {
@apply bg-white opacity-100;
}
+
+.secondary-sidebar-gutter .n-tabs-wrapper {
+ @apply pt-0;
+}
</style>
<style scoped>
@@ -288,6 +308,6 @@ const handleAlterSchema = async (params: {
--color-branding: #4f46e5;
--border-color: rgba(200, 200, 200, 0.2);
- @apply flex-1 overflow-hidden flex flex-col;
+ @apply w-full flex-1 overflow-hidden flex flex-col;
}
</style>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/ColumnList.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/ColumnList.vue
index b2d64f518e..0866c35160 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/ColumnList.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/ColumnList.vue
@@ -1,18 +1,18 @@
<template>
<div class="overflow-hidden">
<VirtualList
- :items="table.columns"
+ :items="filteredColumnList"
:key-field="`name`"
:item-resizable="true"
:item-size="24"
>
<template #default="{ item: column }: VirtualListItem">
<div class="flex items-start px-4">
+ <!-- eslint-disable vue/no-v-html -->
<div
class="text-sm leading-6 text-gray-600whitespace-pre-wrap break-words flex-2 min-w-[4rem]"
- >
- {{ column.name }}
- </div>
+ v-html="renderColumnName(column)"
+ />
<div
class="shrink-0 text-right text-sm leading-6 text-gray-400 overflow-x-hidden whitespace-nowrap flex-1 min-w-[4rem]"
>
@@ -25,18 +25,45 @@
</template>
<script setup lang="ts">
+import { escape } from "lodash-es";
+import { computed } from "vue";
import { VirtualList } from "vueuc";
import {
ColumnMetadata,
TableMetadata,
} from "@/types/proto/v1/database_service";
+import { getHighlightHTMLByRegExp } from "@/utils";
+import { useSchemaPanelContext } from "./context";
export type VirtualListItem = {
item: ColumnMetadata;
index: number;
};
-defineProps<{
+const props = defineProps<{
table: TableMetadata;
}>();
+
+const { keyword } = useSchemaPanelContext();
+const filteredColumnList = computed(() => {
+ const kw = keyword.value.toLowerCase().trim();
+ if (!kw) {
+ return props.table.columns;
+ }
+ return props.table.columns.filter((column) => {
+ return column.name.toLowerCase().includes(kw);
+ });
+});
+
+const renderColumnName = (column: ColumnMetadata) => {
+ if (!keyword.value.trim()) {
+ return column.name;
+ }
+
+ return getHighlightHTMLByRegExp(
+ escape(column.name),
+ escape(keyword.value.trim()),
+ false /* !caseSensitive */
+ );
+};
</script>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
index 8698ed7faa..eef97f6c38 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
@@ -1,33 +1,48 @@
<template>
- <div class="w-full h-full relative overflow-hidden">
- <template v-if="databaseMetadata">
- <DatabaseSchema
- :database="database"
- :database-metadata="databaseMetadata"
- :header-clickable="state.selected !== undefined"
- @click-header="state.selected = undefined"
- @select-table="handleSelectTable"
- @alter-schema="emit('alter-schema', $event)"
- />
- <Transition name="slide-up" appear>
- <TableSchema
- v-if="state.selected"
- class="absolute bottom-0 w-full h-[calc(100%-41px)] bg-white"
+ <div class="flex flex-col h-full py-0.5">
+ <div class="flex items-center gap-x-1 px-0.5">
+ <NInput
+ v-model:value="keyword"
+ size="small"
+ :placeholder="$t('sql-editor.filter-by-name')"
+ :clearable="true"
+ >
+ <template #prefix>
+ <heroicons-outline:search class="h-5 w-5 text-gray-300" />
+ </template>
+ </NInput>
+ </div>
+
+ <div class="w-full h-full relative overflow-hidden">
+ <template v-if="databaseMetadata">
+ <DatabaseSchema
:database="database"
:database-metadata="databaseMetadata"
- :schema="state.selected.schema"
- :table="state.selected.table"
- @close="state.selected = undefined"
+ :header-clickable="state.selected !== undefined"
+ @click-header="state.selected = undefined"
+ @select-table="handleSelectTable"
@alter-schema="emit('alter-schema', $event)"
/>
- </Transition>
- </template>
+ <Transition name="slide-up" appear>
+ <TableSchema
+ v-if="state.selected"
+ class="absolute bottom-0 w-full h-[calc(100%-41px)] bg-white"
+ :database="database"
+ :database-metadata="databaseMetadata"
+ :schema="state.selected.schema"
+ :table="state.selected.table"
+ @close="state.selected = undefined"
+ @alter-schema="emit('alter-schema', $event)"
+ />
+ </Transition>
+ </template>
- <div
- v-else
- class="absolute inset-0 bg-white/50 flex flex-col items-center justify-center"
- >
- <BBSpin />
+ <div
+ v-else
+ class="absolute inset-0 bg-white/50 flex flex-col items-center justify-center"
+ >
+ <BBSpin />
+ </div>
</div>
</div>
</template>
@@ -43,6 +58,7 @@ import {
} from "@/types/proto/v1/database_service";
import DatabaseSchema from "./DatabaseSchema.vue";
import TableSchema from "./TableSchema.vue";
+import { provideSchemaPanelContext } from "./context";
type LocalState = {
selected?: { schema: SchemaMetadata; table: TableMetadata };
@@ -62,6 +78,7 @@ const state = reactive<LocalState>({
const dbSchemaStore = useDBSchemaV1Store();
const { currentTab } = storeToRefs(useTabStore());
const conn = computed(() => currentTab.value.connection);
+const { keyword } = provideSchemaPanelContext();
const { database } = useDatabaseV1ByUID(computed(() => conn.value.databaseId));
const databaseMetadata = ref<DatabaseMetadata>();
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableList.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableList.vue
index 68e8c08dfd..b488dbcdf2 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableList.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/TableList.vue
@@ -1,7 +1,7 @@
<template>
<div class="flex flex-col overflow-hidden">
<VirtualList
- :items="flattenTableList"
+ :items="filteredTableList"
:key-field="`key`"
:item-resizable="true"
:item-size="24"
@@ -18,8 +18,8 @@
@click="handleClickTable(schema, table)"
>
<heroicons-outline:table class="h-4 w-4 mr-1 shrink-0" />
- <span v-if="schema.name">{{ schema.name }}.</span>
- <span>{{ table.name }}</span>
+ <!-- eslint-disable-next-line vue/no-v-html -->
+ <div v-html="renderTableName(schema, table)" />
</div>
</div>
</template>
@@ -28,12 +28,15 @@
</template>
<script setup lang="ts">
+import { escape } from "lodash-es";
import { computed } from "vue";
import { VirtualList } from "vueuc";
import {
SchemaMetadata,
TableMetadata,
} from "@/types/proto/v1/database_service";
+import { getHighlightHTMLByRegExp } from "@/utils";
+import { useSchemaPanelContext } from "./context";
export type SchemaAndTable = {
key: string;
@@ -55,6 +58,8 @@ const emit = defineEmits<{
(e: "select-table", schema: SchemaMetadata, table: TableMetadata): void;
}>();
+const { keyword } = useSchemaPanelContext();
+
const flattenTableList = computed(() => {
return props.schemaList.flatMap((schema) => {
return schema.tables.map<SchemaAndTable>((table) => ({
@@ -65,10 +70,40 @@ const flattenTableList = computed(() => {
});
});
+const filteredTableList = computed(() => {
+ const kw = keyword.value.toLowerCase().trim();
+ if (!kw) {
+ return flattenTableList.value;
+ }
+ return flattenTableList.value.filter(({ schema, table }) => {
+ return (
+ schema.name.toLowerCase().includes(kw) ||
+ table.name.toLowerCase().includes(kw)
+ );
+ });
+});
+
const handleClickTable = (schema: SchemaMetadata, table: TableMetadata) => {
if (!props.rowClickable) {
return;
}
emit("select-table", schema, table);
};
+
+const renderTableName = (schema: SchemaMetadata, table: TableMetadata) => {
+ const parts: string[] = [];
+ if (schema.name) {
+ parts.push(`${schema.name}.`);
+ }
+ parts.push(table.name);
+ if (!keyword.value.trim()) {
+ return parts.join("");
+ }
+
+ return getHighlightHTMLByRegExp(
+ escape(parts.join("")),
+ escape(keyword.value.trim()),
+ false /* !caseSensitive */
+ );
+};
</script>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/context.ts b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/context.ts
new file mode 100644
index 0000000000..2b7d5b6b5b
--- /dev/null
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/context.ts
@@ -0,0 +1,23 @@
+import { InjectionKey, inject, provide, Ref, ref } from "vue";
+
+export type SchemaPanelContext = {
+ keyword: Ref<string>;
+};
+
+export const KEY = Symbol(
+ "bb.sql-editor.schema-panel"
+) as InjectionKey<SchemaPanelContext>;
+
+export const useSchemaPanelContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideSchemaPanelContext = () => {
+ const context: SchemaPanelContext = {
+ keyword: ref(""),
+ };
+
+ provide(KEY, context);
+
+ return context;
+};
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/OpenAIButton.vue b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/OpenAIButton.vue
new file mode 100644
index 0000000000..33e8500846
--- /dev/null
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/OpenAIButton.vue
@@ -0,0 +1,68 @@
+<template>
+ <NTooltip v-if="showButton">
+ <template #trigger>
+ <NButton
+ tag="div"
+ size="small"
+ style="--n-height: 24px; --n-padding: 0 4px"
+ class="self-center"
+ v-bind="buttonProps"
+ @click="showAIChatBox = !showAIChatBox"
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 320 320"
+ fill="currentColor"
+ stroke="none"
+ class="w-4 h-4"
+ >
+ <path
+ xmlns="http://www.w3.org/2000/svg"
+ d="m297.06 130.97c7.26-21.79 4.76-45.66-6.85-65.48-17.46-30.4-52.56-46.04-86.84-38.68-15.25-17.18-37.16-26.95-60.13-26.81-35.04-.08-66.13 22.48-76.91 55.82-22.51 4.61-41.94 18.7-53.31 38.67-17.59 30.32-13.58 68.54 9.92 94.54-7.26 21.79-4.76 45.66 6.85 65.48 17.46 30.4 52.56 46.04 86.84 38.68 15.24 17.18 37.16 26.95 60.13 26.8 35.06.09 66.16-22.49 76.94-55.86 22.51-4.61 41.94-18.7 53.31-38.67 17.57-30.32 13.55-68.51-9.94-94.51zm-120.28 168.11c-14.03.02-27.62-4.89-38.39-13.88.49-.26 1.34-.73 1.89-1.07l63.72-36.8c3.26-1.85 5.26-5.32 5.24-9.07v-89.83l26.93 15.55c.29.14.48.42.52.74v74.39c-.04 33.08-26.83 59.9-59.91 59.97zm-128.84-55.03c-7.03-12.14-9.56-26.37-7.15-40.18.47.28 1.3.79 1.89 1.13l63.72 36.8c3.23 1.89 7.23 1.89 10.47 0l77.79-44.92v31.1c.02.32-.13.63-.38.83l-64.41 37.19c-28.69 16.52-65.33 6.7-81.92-21.95zm-16.77-139.09c7-12.16 18.05-21.46 31.21-26.29 0 .55-.03 1.52-.03 2.2v73.61c-.02 3.74 1.98 7.21 5.23 9.06l77.79 44.91-26.93 15.55c-.27.18-.61.21-.91.08l-64.42-37.22c-28.63-16.58-38.45-53.21-21.95-81.89zm221.26 51.49-77.79-44.92 26.93-15.54c.27-.18.61-.21.91-.08l64.42 37.19c28.68 16.57 38.51 53.26 21.94 81.94-7.01 12.14-18.05 21.44-31.2 26.28v-75.81c.03-3.74-1.96-7.2-5.2-9.06zm26.8-40.34c-.47-.29-1.3-.79-1.89-1.13l-63.72-36.8c-3.23-1.89-7.23-1.89-10.47 0l-77.79 44.92v-31.1c-.02-.32.13-.63.38-.83l64.41-37.16c28.69-16.55 65.37-6.7 81.91 22 6.99 12.12 9.52 26.31 7.15 40.1zm-168.51 55.43-26.94-15.55c-.29-.14-.48-.42-.52-.74v-74.39c.02-33.12 26.89-59.96 60.01-59.94 14.01 0 27.57 4.92 38.34 13.88-.49.26-1.33.73-1.89 1.07l-63.72 36.8c-3.26 1.85-5.26 5.31-5.24 9.06l-.04 89.79zm14.63-31.54 34.65-20.01 34.65 20v40.01l-34.65 20-34.65-20z"
+ />
+ </svg>
+ </NButton>
+ </template>
+ <template #default>
+ {{
+ showAIChatBox
+ ? $t("plugin.ai.disable-chat-sql")
+ : $t("plugin.ai.enable-chat-sql")
+ }}
+ </template>
+ </NTooltip>
+</template>
+
+<script setup lang="ts">
+import { ButtonProps, NButton, NTooltip } from "naive-ui";
+import { computed } from "vue";
+import { useSettingV1Store, useTabStore } from "@/store";
+import { useSQLEditorContext } from "../../context";
+
+const tabStore = useTabStore();
+const settingV1Store = useSettingV1Store();
+const openAIKeySetting = computed(() =>
+ settingV1Store.getSettingByName("bb.plugin.openai.key")
+);
+const openAIKey = computed(
+ () => openAIKeySetting.value?.value?.stringValue ?? ""
+);
+
+const { showAIChatBox } = useSQLEditorContext();
+
+const showButton = computed(() => {
+ return openAIKey.value && !tabStore.isDisconnected;
+});
+
+const buttonProps = computed(() => {
+ const props: ButtonProps = {};
+ if (showAIChatBox.value) {
+ props.secondary = true;
+ props.type = "primary";
+ } else {
+ props.quaternary = true;
+ props.type = "default";
+ }
+ return props;
+});
+</script>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue
new file mode 100644
index 0000000000..fe1a51a57d
--- /dev/null
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue
@@ -0,0 +1,124 @@
+<template>
+ <div class="flex flex-col items-stretch justify-start text-sm gap-y-1">
+ <div
+ v-if="showInfoPane"
+ class="gutter-bar--tab"
+ :class="[activeTab === 'INFO' && 'gutter-bar--tab-active']"
+ @click="handleClickTab('INFO')"
+ >
+ {{ $t("common.info") }}
+ </div>
+ <div
+ class="gutter-bar--tab"
+ :class="[activeTab === 'SHEET' && 'gutter-bar--tab-active']"
+ @click="handleClickTab('SHEET')"
+ >
+ {{ $t("sheet.sheet") }}
+ </div>
+ <div
+ class="gutter-bar--tab"
+ :class="[activeTab === 'HISTORY' && 'gutter-bar--tab-active']"
+ @click="handleClickTab('HISTORY')"
+ >
+ {{ $t("common.history") }}
+ </div>
+
+ <OpenAIButton class="self-center" />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed, watch } from "vue";
+import { useInstanceV1Store, useTabStore } from "@/store";
+import { UNKNOWN_ID } from "@/types";
+import { instanceV1HasAlterSchema, isDisconnectedTab } from "@/utils";
+import { TabView, useSecondarySidebarContext } from "../context";
+import OpenAIButton from "./OpenAIButton.vue";
+
+const { show, tab } = useSecondarySidebarContext();
+
+const activeTab = computed(() => {
+ if (!show.value) {
+ return undefined;
+ }
+ return tab.value;
+});
+
+const tabStore = useTabStore();
+
+const isDisconnected = computed(() => {
+ return isDisconnectedTab(tabStore.currentTab);
+});
+
+const isSchemalessInstance = computed(() => {
+ if (isDisconnected.value) {
+ return false;
+ }
+ const { instanceId } = tabStore.currentTab.connection;
+
+ if (instanceId === String(UNKNOWN_ID)) {
+ return false;
+ }
+
+ const instance = useInstanceV1Store().getInstanceByUID(instanceId);
+
+ return !instanceV1HasAlterSchema(instance);
+});
+
+const showInfoPane = computed(() => {
+ if (isDisconnected.value) {
+ return false;
+ }
+
+ const conn = tabStore.currentTab.connection;
+ if (conn.databaseId === String(UNKNOWN_ID)) {
+ return false;
+ }
+
+ return !isSchemalessInstance.value;
+});
+
+const handleClickTab = (target: TabView) => {
+ if (target === activeTab.value) {
+ show.value = false;
+ return;
+ }
+
+ tab.value = target;
+ show.value = true;
+};
+
+watch(
+ showInfoPane,
+ (show) => {
+ if (!show && tab.value === "INFO") {
+ tab.value = "SHEET";
+ }
+ },
+ { immediate: true }
+);
+
+watch(
+ [
+ () => tabStore.currentTab.id,
+ () => tabStore.currentTab.connection.databaseId,
+ ],
+ () => {
+ if (showInfoPane.value) {
+ tab.value = "INFO";
+ }
+ }
+);
+</script>
+
+<style lang="postcss" scoped>
+.gutter-bar--tab {
+ @apply writing-vertical-rl px-1 py-4 border-y bg-gray-50 cursor-pointer select-none;
+}
+.gutter-bar--tab:first-child {
+ @apply border-t-0;
+}
+.gutter-bar--tab.gutter-bar--tab-active {
+ @apply text-accent bg-white;
+}
+</style>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/index.ts b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/index.ts
new file mode 100644
index 0000000000..106d8c9b16
--- /dev/null
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/index.ts
@@ -0,0 +1,3 @@
+import SecondaryGutterBar from "./SecondaryGutterBar.vue";
+
+export default SecondaryGutterBar;
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue b/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue
index af8c5e6bce..21ff6a31c6 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondarySidebar.vue
@@ -1,29 +1,15 @@
<template>
- <NTabs
- v-model:value="tab"
- type="segment"
- size="small"
- class="h-full"
- pane-style="height: calc(100% - 35px); padding: 0;"
- >
- <NTabPane v-if="showInfoPane" name="INFO" :tab="$t('common.info')">
- <InfoTabPane @alter-schema="$emit('alter-schema', $event)" />
- </NTabPane>
- <NTabPane name="SHEET" :tab="$t('sheet.sheet')">
- <SheetTabPane />
- </NTabPane>
- <NTabPane name="HISTORY" :tab="$t('common.history')">
- <HistoryTabPane />
- </NTabPane>
- </NTabs>
+ <div class="h-full">
+ <InfoTabPane
+ v-if="tab === 'INFO'"
+ @alter-schema="$emit('alter-schema', $event)"
+ />
+ <SheetTabPane v-if="tab === 'SHEET'" />
+ <HistoryTabPane v-if="tab === 'HISTORY'" />
+ </div>
</template>
<script setup lang="ts">
-import { NTabs, NTabPane } from "naive-ui";
-import { computed, watch } from "vue";
-import { useInstanceV1Store, useTabStore } from "@/store";
-import { UNKNOWN_ID } from "@/types";
-import { instanceV1HasAlterSchema, isDisconnectedTab } from "@/utils";
import HistoryTabPane from "./HistoryTabPane";
import InfoTabPane from "./InfoTabPane";
import SheetTabPane from "./SheetTabPane";
@@ -37,57 +23,4 @@ defineEmits<{
}>();
const { tab } = useSecondarySidebarContext();
-
-const tabStore = useTabStore();
-
-const isDisconnected = computed(() => {
- return isDisconnectedTab(tabStore.currentTab);
-});
-
-const isSchemalessInstance = computed(() => {
- if (isDisconnected.value) {
- return false;
- }
- const { instanceId } = tabStore.currentTab.connection;
-
- if (instanceId === String(UNKNOWN_ID)) {
- return false;
- }
-
- const instance = useInstanceV1Store().getInstanceByUID(instanceId);
-
- return !instanceV1HasAlterSchema(instance);
-});
-
-const showInfoPane = computed(() => {
- if (isDisconnected.value) {
- return false;
- }
-
- const conn = tabStore.currentTab.connection;
- if (conn.databaseId === String(UNKNOWN_ID)) {
- return false;
- }
-
- return !isSchemalessInstance.value;
-});
-
-watch(
- showInfoPane,
- (show) => {
- if (!show && tab.value === "INFO") {
- tab.value = "SHEET";
- }
- },
- { immediate: true }
-);
-
-watch(
- () => tabStore.currentTab.id,
- () => {
- if (showInfoPane.value) {
- tab.value = "INFO";
- }
- }
-);
</script>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/index.ts b/frontend/src/views/sql-editor/SecondarySidebar/index.ts
index a569c0d9b8..81c106e85a 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/index.ts
+++ b/frontend/src/views/sql-editor/SecondarySidebar/index.ts
@@ -1,6 +1,7 @@
+import SecondaryGutterBar from "./SecondaryGutterBar";
import SecondarySidebar from "./SecondarySidebar.vue";
import ToggleSecondarySidebarButton from "./ToggleSecondarySidebarButton.vue";
export * from "./context";
-export { ToggleSecondarySidebarButton };
+export { ToggleSecondarySidebarButton, SecondaryGutterBar };
export default SecondarySidebar;
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index 81bab0275b..2101087b9b 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -43,7 +43,7 @@
</div>
<div class="hidden lg:block">
- <ToggleSecondarySidebarButton />
+ <ProfileDropdown v-if="showProfileDropdown" />
</div>
<ContextMenu ref="contextMenuRef" />
@@ -58,11 +58,11 @@ import { ref, reactive, nextTick, computed, onMounted, watch } from "vue";
import { useI18n } from "vue-i18n";
import Draggable from "vuedraggable";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
-import { useTabStore } from "@/store";
+import { useSQLEditorStore, useTabStore } from "@/store";
import type { TabInfo } from "@/types";
import { TabMode } from "@/types";
import { defer, getSuggestedTabNameFromConnection } from "@/utils";
-import { ToggleSecondarySidebarButton } from "../SecondarySidebar";
+import ProfileDropdown from "../ProfileDropdown";
import { useSheetContext } from "../Sheet";
import ContextMenu from "./ContextMenu.vue";
import TabItem from "./TabItem";
@@ -92,6 +92,10 @@ const scrollState = reactive({
moreRight: false,
});
+const showProfileDropdown = computed(() => {
+ return useSQLEditorStore().mode === "BUNDLED";
+});
+
const handleSelectTab = async (tab: TabInfo) => {
tabStore.setCurrentTabId(tab.id);
};
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
new file mode 100644
index 0000000000..b45d9b1a43
--- /dev/null
+++ b/frontend/src/views/sql-editor/context.ts
@@ -0,0 +1,31 @@
+import Emittery from "emittery";
+import { InjectionKey, inject, provide, Ref, ref } from "vue";
+
+type SQLEditorEvents = Emittery<{
+ // nothing by now
+}>;
+
+export type SQLEditorContext = {
+ showAIChatBox: Ref<boolean>;
+
+ events: SQLEditorEvents;
+};
+
+export const KEY = Symbol(
+ "bb.sql-editor.context"
+) as InjectionKey<SQLEditorContext>;
+
+export const useSQLEditorContext = () => {
+ return inject(KEY)!;
+};
+
+export const provideSQLEditorContext = () => {
+ const context: SQLEditorContext = {
+ showAIChatBox: ref(false),
+ events: new Emittery(),
+ };
+
+ provide(KEY, context);
+
+ return context;
+};