Skip to content

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

chore: support select multiple databases to batch query in the connection panel (#16050)

ecmadao3f092909352c
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index f4c04f422a..a49cddfc11 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1725,7 +1725,6 @@
"sql-editor": {
"self": "SQL Editor",
"select-connection": "Please select connections",
- "search-databases": "Search Databases",
"search-results": "Search Results",
"loading-databases": "Loading Databases...",
"show-databases-without-query-permission": "Show databases without query permissions",
@@ -1803,7 +1802,6 @@
},
"batch-query": {
"batch": "Batch",
- "select-database": "Select database below",
"description": "Batch query {count} additional databases under {project}.",
"show-or-hide-empty-query-results": "Show / hide empty query results"
},
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 526192f199..db7ee6374e 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1725,7 +1725,6 @@
"sql-editor": {
"self": "Editor de SQL",
"select-connection": "Por favor seleccione conexiones",
- "search-databases": "Buscar bases de datos",
"search-results": "Resultados de búsqueda",
"loading-databases": "Cargando bases de datos...",
"show-databases-without-query-permission": "Muestra las bases de datos que no tienen permisos de consulta",
@@ -1803,7 +1802,6 @@
},
"batch-query": {
"batch": "Lote",
- "select-database": "Seleccione la base de datos a continuación",
"description": "Consulta por lotes {count} bases de datos adicionales en {project}.",
"show-or-hide-empty-query-results": "Mostrar/ocultar resultados de consulta vacíos"
},
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 4bf8784f24..06de3cf335 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1725,7 +1725,6 @@
"sql-editor": {
"self": "SQLエディタ",
"select-connection": "データ接続を選択してください",
- "search-databases": "データベースを検索する",
"search-results": "の検索結果",
"loading-databases": "データベース情報をロードしています...",
"show-databases-without-query-permission": "クエリ権限のないデータベースを表示します",
@@ -1803,7 +1802,6 @@
},
"batch-query": {
"batch": "バッチ",
- "select-database": "以下のデータベースを選択してください",
"description": "{project} の下にある {count} データベースをバッチクエリします。",
"show-or-hide-empty-query-results": "空のクエリ結果の表示/非表示"
},
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 8670b39a45..9fb8b08a35 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1725,7 +1725,6 @@
"sql-editor": {
"self": "Trình soạn thảo SQL",
"select-connection": "Vui lòng chọn kết nối",
- "search-databases": "Tìm kiếm Cơ sở dữ liệu",
"search-results": "Kết quả tìm kiếm",
"loading-databases": "Đang tải Cơ sở dữ liệu...",
"show-databases-without-query-permission": "Hiển thị cơ sở dữ liệu không có quyền truy vấn",
@@ -1803,7 +1802,6 @@
},
"batch-query": {
"batch": "Hàng loạt",
- "select-database": "Chọn cơ sở dữ liệu bên dưới",
"description": "Truy vấn hàng loạt {count} cơ sở dữ liệu bổ sung trong {project}.",
"show-or-hide-empty-query-results": "Hiển thị / ẩn kết quả truy vấn trống"
},
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index bee99eb04f..45f08afb78 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1725,7 +1725,6 @@
"sql-editor": {
"self": "SQL 编辑器",
"select-connection": "请选择数据连接",
- "search-databases": "搜索数据库",
"search-results": "搜索结果",
"loading-databases": "加载数据库信息...",
"show-databases-without-query-permission": "显示没有查询权限的数据库",
@@ -1803,7 +1802,6 @@
},
"batch-query": {
"batch": "批量",
- "select-database": "选择下面的数据库",
"description": "批量查询 {project} 下的 {count} 个数据库。",
"show-or-hide-empty-query-results": "显示/隐藏空查询结果"
},
diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.ts
index 3d4c8fe8c1..46a10d3f5c 100644
--- a/frontend/src/store/modules/sqlEditor/editor.ts
+++ b/frontend/src/store/modules/sqlEditor/editor.ts
@@ -1,7 +1,7 @@
import { useLocalStorage, useDebounceFn } from "@vueuse/core";
import { defineStore } from "pinia";
import { computed, ref, watch, watchEffect } from "vue";
-import { useDatabaseV1Store } from "@/store";
+import { useDatabaseV1Store, type DatabaseFilter } from "@/store";
import { type ComposedDatabase, isValidProjectName } from "@/types";
import { QueryOption_RedisRunCommandsOn } from "@/types/proto/v1/sql_service";
import { hasWorkspacePermissionV2, getDefaultPagination } from "@/utils";
@@ -43,7 +43,7 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
loading: false,
});
- const fetchDatabases = useDebounceFn(async (name?: string) => {
+ const fetchDatabases = useDebounceFn(async (filter?: DatabaseFilter) => {
fetchDataState.value.loading = true;
const pageToken = fetchDataState.value.nextPageToken;
@@ -52,9 +52,7 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
parent: project.value,
pageToken,
pageSize: getDefaultPagination(),
- filter: {
- query: name,
- },
+ filter,
});
if (pageToken) {
@@ -70,9 +68,9 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
}
}, 500);
- const prepareDatabases = async (name?: string) => {
+ const prepareDatabases = async (filter?: DatabaseFilter) => {
fetchDataState.value.nextPageToken = "";
- await fetchDatabases(name);
+ await fetchDatabases(filter);
};
watchEffect(async () => {
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index 360d44ab0d..3b3b05dbd3 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -1,10 +1,39 @@
<template>
<div class="sql-editor-tree gap-y-1 h-full flex flex-col relative">
+ <div class="w-full px-4 mt-4">
+ <div
+ class="textinfolabel mb-2 w-full leading-4 flex items-center gap-x-1"
+ >
+ <FeatureBadge feature="bb.feature.batch-query" />
+ {{
+ $t("sql-editor.batch-query.description", {
+ count: state.selectedDatabases.size,
+ project: editorStore.project,
+ })
+ }}
+ </div>
+ <div
+ class="w-full mt-1 flex flex-row justify-start items-start flex-wrap gap-2"
+ >
+ <NTag
+ v-for="database in state.selectedDatabases"
+ :key="database"
+ closable
+ @close="() => handleUncheckDatabase(database)"
+ >
+ <RichDatabaseName
+ :database="databaseStore.getDatabaseByName(database)"
+ />
+ </NTag>
+ </div>
+ </div>
+ <NDivider class="!my-3" />
<div class="flex flex-row gap-x-0.5 px-1 items-center">
- <SearchBox
- :loading="editorStore.loading"
- v-model:search-pattern="searchPattern"
- class="flex-1"
+ <AdvancedSearch
+ v-model:params="state.params"
+ :autofocus="false"
+ :placeholder="$t('database.filter-database')"
+ :scope-options="scopeOptions"
/>
<GroupingBar :disabled="editorStore.loading" class="shrink-0" />
</div>
@@ -36,7 +65,7 @@
:data="treeStore.tree"
:show-irrelevant-nodes="false"
:selected-keys="selectedKeys"
- :pattern="mounted ? searchPattern : ''"
+ :pattern="mounted ? state.params.query : ''"
:default-expand-all="true"
:expand-on-click="true"
:node-props="nodeProps"
@@ -54,7 +83,7 @@
@click="
() =>
editorStore
- .fetchDatabases(searchPattern)
+ .fetchDatabases(filter)
.then(() => treeStore.buildTree())
"
>
@@ -84,23 +113,36 @@
}}</span>
</MaskSpinner>
</div>
+
+ <FeatureModal
+ feature="bb.feature.batch-query"
+ :open="state.showFeatureModal"
+ @cancel="state.showFeatureModal = false"
+ />
</template>
<script lang="ts" setup>
import { useElementSize, useMounted } from "@vueuse/core";
import { head } from "lodash-es";
import {
+ NTag,
NButton,
NTree,
NDropdown,
NCheckbox,
+ NDivider,
type TreeOption,
} from "naive-ui";
import { storeToRefs } from "pinia";
-import { ref, nextTick, watch, h, computed } from "vue";
+import { ref, nextTick, watch, h, computed, reactive } from "vue";
+import AdvancedSearch from "@/components/AdvancedSearch";
+import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
+import { FeatureBadge, FeatureModal } from "@/components/FeatureGuard";
import MaskSpinner from "@/components/misc/MaskSpinner.vue";
+import { RichDatabaseName } from "@/components/v2";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
+ hasFeature,
useDatabaseV1Store,
useSQLEditorTabStore,
resolveOpeningDatabaseListFromSQLEditorTabList,
@@ -109,28 +151,111 @@ import {
idForSQLEditorTreeNodeTarget,
useInstanceResourceByName,
} from "@/store";
-import type { ComposedDatabase, SQLEditorTreeNode } from "@/types";
+import {
+ instanceNamePrefix,
+ environmentNamePrefix,
+} from "@/store/modules/v1/common";
+import type {
+ ComposedDatabase,
+ SQLEditorTreeNode,
+ CoreSQLEditorTab,
+} from "@/types";
import { DEFAULT_SQL_EDITOR_TAB_MODE } from "@/types";
-import { findAncestor, isDescendantOf, isDatabaseV1Queryable } from "@/utils";
+import { engineFromJSON } from "@/types/proto/v1/common";
+import {
+ findAncestor,
+ isDescendantOf,
+ isDatabaseV1Queryable,
+ CommonFilterScopeIdList,
+ extractProjectResourceName,
+ emptySQLEditorConnection,
+ tryConnectToCoreSQLEditorTab,
+} from "@/utils";
+import type { SearchParams } from "@/utils";
import { useSQLEditorContext } from "../../context";
import {
DatabaseHoverPanel,
provideHoverStateContext,
} from "./DatabaseHoverPanel";
import GroupingBar from "./GroupingBar";
-import SearchBox from "./SearchBox/index.vue";
-import useSearchHistory from "./SearchBox/useSearchHistory";
import { Label } from "./TreeNode";
import { setConnection, useDropdown } from "./actions";
+interface LocalState {
+ selectedDatabases: Set<string>;
+ params: SearchParams;
+ showFeatureModal: boolean;
+}
+
const treeStore = useSQLEditorTreeStore();
const tabStore = useSQLEditorTabStore();
const editorStore = useSQLEditorStore();
const databaseStore = useDatabaseV1Store();
+const hasBatchQueryFeature = computed(() =>
+ hasFeature("bb.feature.batch-query")
+);
+
+const state = reactive<LocalState>({
+ selectedDatabases: new Set(),
+ params: {
+ query: "",
+ scopes: [],
+ },
+ showFeatureModal: false,
+});
+
+watch(
+ () => tabStore.currentTab?.id,
+ () => {
+ if (!tabStore.currentTab) {
+ return;
+ }
+ const databases = tabStore.currentTab.batchQueryContext?.databases ?? [];
+ databases.push(tabStore.currentTab.connection.database);
+ state.selectedDatabases = new Set(databases);
+ },
+ {
+ immediate: true,
+ }
+);
+
+watch(
+ () => [...state.selectedDatabases],
+ (selectedDatabases) => {
+ if (!tabStore.currentTab && selectedDatabases.length > 0) {
+ const database = databaseStore.getDatabaseByName(selectedDatabases[0]);
+ const coreTab: CoreSQLEditorTab = {
+ connection: {
+ ...emptySQLEditorConnection(),
+ instance: database.instance,
+ database: database.name,
+ },
+ worksheet: "",
+ mode: DEFAULT_SQL_EDITOR_TAB_MODE,
+ };
+ tryConnectToCoreSQLEditorTab(coreTab);
+ }
+ tabStore.updateCurrentTab({
+ batchQueryContext: {
+ databases: selectedDatabases,
+ },
+ });
+ }
+);
+
+const handleUncheckDatabase = (database: string) => {
+ state.selectedDatabases.delete(database);
+};
+
+const scopeOptions = useCommonSearchScopeOptions([
+ ...CommonFilterScopeIdList,
+ "database-label",
+ "engine",
+]);
+
const editorContext = useSQLEditorContext();
const { events: editorEvents, showConnectionPanel } = editorContext;
-const searchHistory = useSearchHistory();
const {
state: hoverState,
position: hoverPosition,
@@ -155,7 +280,6 @@ const { height: treeContainerHeight } = useElementSize(
}
);
const treeRef = ref<InstanceType<typeof NTree>>();
-const searchPattern = ref("");
const selectedKeys = ref<string[]>([]);
// Highlight the current tab's connection node.
@@ -189,12 +313,34 @@ const { hasMissingQueryDatabases, showMissingQueryDatabases } =
// dynamic render the highlight keywords
const renderLabel = ({ option }: { option: TreeOption }) => {
- const node = option as any as SQLEditorTreeNode;
+ const node = option as SQLEditorTreeNode;
+ let checked = false;
+ if (node.meta.type === "database") {
+ checked = state.selectedDatabases.has(
+ (node as SQLEditorTreeNode<"database">).meta.target.name
+ );
+ }
return h(Label, {
node,
+ checked,
factors: treeStore.filteredFactorList,
- keyword: searchPattern.value ?? "",
+ keyword: state.params.query,
connectedDatabases: connectedDatabases.value,
+ "onUpdate:checked": (checked: boolean) => {
+ if (node.meta.type !== "database") {
+ return;
+ }
+ const dbName = (node as SQLEditorTreeNode<"database">).meta.target.name;
+ if (checked) {
+ if (!hasBatchQueryFeature.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+ state.selectedDatabases.add(dbName);
+ } else {
+ state.selectedDatabases.delete(dbName);
+ }
+ },
});
};
@@ -217,18 +363,14 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
},
context: editorContext,
});
+ tabStore.updateCurrentTab({
+ batchQueryContext: {
+ databases: [],
+ },
+ });
showConnectionPanel.value = false;
}
}
-
- // If the search pattern is not empty, append the selected database name to
- // the search history.
- if (searchPattern.value) {
- if (type === "database") {
- const database = node.meta.target as ComposedDatabase;
- searchHistory.appendSearchResult(database.name);
- }
- }
}
},
onContextmenu(e: MouseEvent) {
@@ -294,23 +436,77 @@ useEmitteryEventListener(editorEvents, "tree-ready", async () => {
selectedKeys.value = await getSelectedKeys();
});
+const selectedLabels = computed(() => {
+ return state.params.scopes
+ .filter((scope) => scope.id === "database-label")
+ .map((scope) => scope.value);
+});
+
+const selectedInstance = computed(() => {
+ const instanceId = state.params.scopes.find(
+ (scope) => scope.id === "instance"
+ )?.value;
+ if (!instanceId) {
+ return;
+ }
+ return `${instanceNamePrefix}${instanceId}`;
+});
+
+const selectedEnvironment = computed(() => {
+ const environmentId = state.params.scopes.find(
+ (scope) => scope.id === "environment"
+ )?.value;
+ if (!environmentId) {
+ return;
+ }
+ return `${environmentNamePrefix}${environmentId}`;
+});
+
+const selectedEngines = computed(() => {
+ return state.params.scopes
+ .filter((scope) => scope.id === "engine")
+ .map((scope) => engineFromJSON(scope.value));
+});
+
+const filter = computed(() => ({
+ instance: selectedInstance.value,
+ environment: selectedEnvironment.value,
+ query: state.params.query,
+ labels: selectedLabels.value,
+ engines: selectedEngines.value,
+}));
+
+watch(
+ () => editorStore.project,
+ (project) => {
+ state.params.scopes = [
+ {
+ id: "project",
+ readonly: true,
+ value: extractProjectResourceName(project),
+ },
+ ];
+ },
+ { immediate: true }
+);
+
watch(
[
() => editorStore.project,
() => editorStore.projectContextReady,
- () => searchPattern.value,
+ () => filter.value,
],
- async ([, ready, search]) => {
+ async ([_, ready, filter]) => {
if (!ready) {
treeStore.state = "LOADING";
} else {
- await editorStore.prepareDatabases(search);
+ await editorStore.prepareDatabases(filter);
treeStore.buildTree();
treeStore.state = "READY";
editorEvents.emit("tree-ready");
}
},
- { immediate: true }
+ { immediate: true, deep: true }
);
</script>
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/index.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/index.vue
deleted file mode 100644
index d26713313b..0000000000
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/index.vue
+++ /dev/null
@@ -1,152 +0,0 @@
-<template>
- <NAutoComplete
- ref="autoCompleteRef"
- size="small"
- clear-after-select
- blur-after-select
- :clearable="true"
- :value="searchPattern"
- :placeholder="$t('sql-editor.search-databases')"
- :options="autoCompleteOptions"
- :render-label="renderLabel"
- :get-show="getOptionShow"
- @update:value="$emit('update:search-pattern', $event || '')"
- @select="handleDatabaseSelect"
- @compositionstart="isIMECompositing = true"
- @compositionend="isIMECompositing = false"
- @keydown.esc="handleEscapeKey"
- >
- <template #prefix>
- <SearchIcon class="w-4 h-auto text-gray-300" />
- </template>
- </NAutoComplete>
-</template>
-
-<script lang="ts" setup>
-import { SearchIcon } from "lucide-vue-next";
-import type { AutoCompleteInst, SelectOption } from "naive-ui";
-import { NAutoComplete } from "naive-ui";
-import { computed, watchEffect, h, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
-import { useDatabaseV1Store, batchGetOrFetchDatabases } from "@/store";
-import type { CoreSQLEditorTab } from "@/types";
-import { DEFAULT_SQL_EDITOR_TAB_MODE, isValidDatabaseName } from "@/types";
-import {
- emptySQLEditorConnection,
- tryConnectToCoreSQLEditorTab,
-} from "@/utils";
-import useSearchHistory from "./useSearchHistory";
-
-defineOptions({
- name: "SearchBox",
-});
-
-const props = defineProps<{
- searchPattern: string;
-}>();
-
-defineEmits<{
- (event: "update:search-pattern", keyword: string): void;
-}>();
-
-const { t } = useI18n();
-const databaseStore = useDatabaseV1Store();
-const { searchHistory } = useSearchHistory();
-const isIMECompositing = ref(false);
-const autoCompleteRef = ref<AutoCompleteInst>();
-
-const getOptionShow = () => {
- if (autoCompleteOptions.value[0].children.length === 0) {
- return false;
- }
- return true;
-};
-
-const autoCompleteOptions = computed(() => {
- const databaseNames = searchHistory.value;
- return [
- {
- type: "group",
- key: "recent",
- label: t("common.recent"),
- children: databaseNames
- .filter((databaseName) => {
- const database = databaseStore.getDatabaseByName(databaseName);
- return (
- database &&
- isValidDatabaseName(database.name) &&
- database.name
- .toLowerCase()
- .includes((props.searchPattern || "").toLowerCase())
- );
- })
- .slice(0, 5) // Only show 5 recent databases.
- .map<SelectOption>((databaseName) => {
- return {
- label: databaseName,
- value: databaseName,
- };
- }),
- },
- ];
-});
-
-const renderLabel = (option: SelectOption) => {
- if (option.type === "group") {
- return h(
- "div",
- { class: "w-full text-sm text-gray-400" },
- String(option.label)
- );
- }
-
- const database = databaseStore.getDatabaseByName(option.value as string);
- return h(
- "div",
- {
- class: "w-full flex items-center gap-x-1",
- },
- [
- h(InstanceV1EngineIcon, {
- instance: database.instanceResource,
- }),
- h(EnvironmentV1Name, {
- environment: database.effectiveEnvironmentEntity,
- link: false,
- class: "text-control-light",
- }),
- h(
- "span",
- {
- class: "truncate",
- },
- database.databaseName
- ),
- ]
- );
-};
-
-const handleDatabaseSelect = async (databaseName: string) => {
- const database = await databaseStore.getOrFetchDatabaseByName(databaseName);
- const coreTab: CoreSQLEditorTab = {
- connection: {
- ...emptySQLEditorConnection(),
- instance: database.instance,
- database: database.name,
- },
- worksheet: "",
- mode: DEFAULT_SQL_EDITOR_TAB_MODE,
- };
- tryConnectToCoreSQLEditorTab(coreTab);
-};
-
-const handleEscapeKey = (_e: KeyboardEvent) => {
- if (isIMECompositing.value) return;
- autoCompleteRef.value?.blur();
-};
-
-watchEffect(async () => {
- await batchGetOrFetchDatabases(searchHistory.value);
-});
-</script>
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/useSearchHistory.ts b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/useSearchHistory.ts
deleted file mode 100644
index ebbfbe6cf6..0000000000
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/SearchBox/useSearchHistory.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { useLocalStorage } from "@vueuse/core";
-import { uniq } from "lodash-es";
-
-const useSearchHistory = () => {
- const searchHistory = useLocalStorage<string[]>(
- "sql-editor-search-result-history",
- []
- );
-
- const appendSearchResult = (databaseName: string) => {
- if (!databaseName) {
- return;
- }
- searchHistory.value = uniq([databaseName, ...searchHistory.value]);
- };
-
- return {
- searchHistory,
- appendSearchResult,
- };
-};
-
-export default useSearchHistory;
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
index 3465728343..09083b6eab 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
@@ -1,5 +1,13 @@
<template>
<div class="flex items-center max-w-full overflow-hidden gap-x-1">
+ <NCheckbox
+ v-if="!disallowBatchQuery"
+ :checked="checked"
+ :disabled="tabStore.currentTab?.connection.database === database.name"
+ @click.stop.prevent=""
+ @update:checked="$emit('update:checked', $event)"
+ />
+
<InstanceV1EngineIcon
v-if="!hasInstanceContext"
:instance="database.instanceResource"
@@ -14,16 +22,14 @@
<DatabaseIcon />
- <span class="text-control-light">
- {{ extractProjectResourceName(database.projectEntity.name) }}
- </span>
-
<span class="flex-1 truncate">
<HighlightLabelText :text="database.databaseName" :keyword="keyword" />
<span v-if="!hasInstanceContext" class="text-control-light">
({{ database.instanceResource.title }})
</span>
- <span v-if="connected"> ({{ $t("sql-editor.connected") }}) </span>
+ <span v-if="connected" class="textinfolabel">
+ ({{ $t("sql-editor.connected") }})
+ </span>
</span>
<RequestQueryButton
v-if="showRequestQueryButton"
@@ -36,15 +42,16 @@
</template>
<script setup lang="ts">
+import { NCheckbox } from "naive-ui";
import { computed } from "vue";
import DatabaseIcon from "~icons/heroicons-outline/circle-stack";
import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
-import { hasFeature, useAppFeature } from "@/store";
+import { hasFeature, useAppFeature, useSQLEditorTabStore } from "@/store";
import type {
SQLEditorTreeNode as TreeNode,
SQLEditorTreeFactor as Factor,
} from "@/types";
-import { extractProjectResourceName, isDatabaseV1Queryable } from "@/utils";
+import { isDatabaseV1Queryable } from "@/utils";
import RequestQueryButton from "../../../EditorCommon/ResultView/RequestQueryButton.vue";
import HighlightLabelText from "./HighlightLabelText.vue";
@@ -53,8 +60,19 @@ const props = defineProps<{
factors: Factor[];
keyword: string;
connected: boolean;
+ checked?: boolean;
}>();
+defineEmits<{
+ (event: "update:checked", checked: boolean): void;
+}>();
+
+const tabStore = useSQLEditorTabStore();
+
+const disallowBatchQuery = useAppFeature(
+ "bb.feature.sql-editor.disallow-batch-query"
+);
+
const disallowRequestQuery = useAppFeature(
"bb.feature.sql-editor.disallow-request-query"
);
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
index dec6cecac1..0a332195bf 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
@@ -7,6 +7,7 @@
</template>
<template v-if="type === 'database'">
<DatabaseNode
+ v-bind="$attrs"
:node="node"
:factors="factors"
:keyword="keyword"
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPanel.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPanel.vue
index 4440e0a964..917b7443c4 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPanel.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPanel.vue
@@ -9,6 +9,7 @@
<DrawerContent
:style="{
width: contentWidth,
+ maxWidth: '800px',
}"
class="connection-panel-content"
>
@@ -60,10 +61,10 @@ defineEmits<{
const { width: winWidth } = useWindowSize();
const { itemList: settingItemList } = useSettingItems();
const contentWidth = computed(() => {
- if (winWidth.value >= 640) {
- return "480px";
+ if (winWidth.value >= 800) {
+ return "50vw";
}
- return "calc(100vw - 2rem)";
+ return "calc(100vw - 4rem)";
});
const allowManageInstance = computed(() => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue b/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue
deleted file mode 100644
index 6fafca99b1..0000000000
--- a/frontend/src/views/sql-editor/EditorCommon/BatchQueryDatabasesSelector.vue
+++ /dev/null
@@ -1,189 +0,0 @@
-<template>
- <NPopover
- v-if="showBatchQuerySelector"
- placement="bottom"
- :disabled="!hasBatchQueryFeature"
- trigger="click"
- >
- <template #trigger>
- <NPopover placement="bottom">
- <template #trigger>
- <NButton
- size="small"
- :type="
- state.selectedDatabaseNames.length > 0 && hasBatchQueryFeature
- ? 'primary'
- : 'default'
- "
- style="--n-padding: 0 5px"
- @click="handleTriggerClick"
- >
- <template #icon>
- <SquareStackIcon class="w-4 h-4" />
- </template>
- </NButton>
- </template>
- <template #default>
- {{ $t("sql-editor.batch-query.batch") }}
- <FeatureBadge feature="bb.feature.batch-query" />
- </template>
- </NPopover>
- </template>
- <div
- class="max-w-[calc(100vw-10rem)] w-192 max-h-128 overflow-y-auto p-1 pb-2"
- >
- <p class="text-gray-500 mb-1 w-full leading-4">
- {{
- $t("sql-editor.batch-query.description", {
- count: state.selectedDatabaseNames.length,
- project: project.title,
- })
- }}
- </p>
- <div class="w-full flex flex-col justify-start items-start">
- <div
- class="w-full mt-1 flex flex-row justify-start items-start flex-wrap gap-2"
- >
- <p v-if="state.selectedDatabaseNames.length === 0">
- {{ $t("sql-editor.batch-query.select-database") }}
- </p>
- <NTag
- v-for="databaseName in state.selectedDatabaseNames"
- :key="databaseName"
- closable
- @close="() => handleUncheckDatabaseRow(databaseName)"
- >
- <div class="flex flex-row justify-center items-center">
- <InstanceV1EngineIcon
- :instance="
- databaseStore.getDatabaseByName(databaseName).instanceResource
- "
- />
- <span class="text-sm text-control-light mx-1">
- {{
- databaseStore.getDatabaseByName(databaseName)
- .effectiveEnvironmentEntity.title
- }}
- </span>
- {{ databaseStore.getDatabaseByName(databaseName).databaseName }}
- </div>
- </NTag>
- </div>
- <NDivider class="!my-3" />
- <div class="w-full flex flex-row justify-end items-center mb-3">
- <SearchBox
- v-model:value="state.keyword"
- :placeholder="$t('sql-editor.search-databases')"
- />
- </div>
- <PagedDatabaseTable
- mode="PROJECT_SHORT"
- :show-selection="true"
- :filter="filter"
- :parent="project.name"
- :schemaless="true"
- :custom-click="true"
- v-model:selected-database-names="state.selectedDatabaseNames"
- />
- </div>
- </div>
- </NPopover>
-
- <FeatureModal
- feature="bb.feature.batch-query"
- :open="state.showFeatureModal"
- @cancel="state.showFeatureModal = false"
- />
-</template>
-
-<script lang="ts" setup>
-import { SquareStackIcon } from "lucide-vue-next";
-import { NPopover, NDivider, NTag, NButton } from "naive-ui";
-import { computed, reactive, watch } from "vue";
-import { FeatureBadge, FeatureModal } from "@/components/FeatureGuard";
-import { InstanceV1EngineIcon, SearchBox } from "@/components/v2";
-import { PagedDatabaseTable } from "@/components/v2/Model/DatabaseV1Table";
-import {
- hasFeature,
- useAppFeature,
- useConnectionOfCurrentSQLEditorTab,
- useDatabaseV1Store,
- useSQLEditorTabStore,
-} from "@/store/modules";
-import { isValidDatabaseName } from "@/types";
-
-interface LocalState {
- keyword: string;
- showFeatureModal: boolean;
- selectedDatabaseNames: string[];
-}
-
-const databaseStore = useDatabaseV1Store();
-const tabStore = useSQLEditorTabStore();
-const state = reactive<LocalState>({
- keyword: "",
- showFeatureModal: false,
- selectedDatabaseNames: [],
-});
-// Save the stringified label key-value pairs.
-const currentTab = computed(() => tabStore.currentTab);
-const { database: selectedDatabase } = useConnectionOfCurrentSQLEditorTab();
-const hasBatchQueryFeature = hasFeature("bb.feature.batch-query");
-const disallowBatchQuery = useAppFeature(
- "bb.feature.sql-editor.disallow-batch-query"
-);
-const { database } = useConnectionOfCurrentSQLEditorTab();
-
-const project = computed(() => selectedDatabase.value.projectEntity);
-
-const filter = computed(() => ({
- query: state.keyword,
-}));
-
-const showBatchQuerySelector = computed(() => {
- if (disallowBatchQuery.value) {
- return false;
- }
-
- const tab = currentTab.value;
- return (
- tab &&
- // Only show entry when user selected a database.
- isValidDatabaseName(database.value.name) &&
- tab.mode !== "ADMIN"
- );
-});
-
-const handleUncheckDatabaseRow = (databaseName: string) => {
- state.selectedDatabaseNames = state.selectedDatabaseNames.filter(
- (name) => name !== databaseName
- );
-};
-
-const handleTriggerClick = () => {
- if (!hasBatchQueryFeature) {
- state.showFeatureModal = true;
- }
-};
-
-watch(
- () => state.selectedDatabaseNames,
- () => {
- tabStore.updateCurrentTab({
- batchQueryContext: {
- databases: state.selectedDatabaseNames,
- },
- });
- }
-);
-
-watch(
- () => currentTab.value?.batchQueryContext?.databases,
- (databases) => {
- state.selectedDatabaseNames = databases ?? [];
- },
- {
- immediate: true,
- }
-);
-</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue b/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
index da8e98d48a..3b32a15873 100644
--- a/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
@@ -21,6 +21,17 @@
"
class="flex flex-row items-center text-main"
>
+ <NPopover
+ v-if="(currentTab.batchQueryContext?.databases.length ?? 0) > 1"
+ placement="bottom"
+ >
+ <template #trigger>
+ <SquareStackIcon class="w-4 h-4 mr-1 text-accent" />
+ </template>
+ <template #default>
+ {{ $t("sql-editor.batch-query.batch") }}
+ </template>
+ </NPopover>
<EnvironmentV1Name
:environment="database.effectiveEnvironmentEntity"
:link="false"
@@ -47,8 +58,8 @@
</template>
<script lang="ts" setup>
-import { ChevronRightIcon } from "lucide-vue-next";
-import { NButton } from "naive-ui";
+import { ChevronRightIcon, SquareStackIcon } from "lucide-vue-next";
+import { NButton, NPopover } from "naive-ui";
import { storeToRefs } from "pinia";
import { DatabaseIcon } from "@/components/Icon";
import { InstanceV1EngineIcon, EnvironmentV1Name } from "@/components/v2";
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index 9af5cf210a..8db28a1ee9 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -125,7 +125,6 @@
<div
class="action-right gap-x-2 flex overflow-x-auto sm:overflow-x-hidden sm:justify-end items-center"
>
- <BatchQueryDatabasesSelector />
<NButtonGroup>
<DatabaseChooser />
<SchemaChooser />
@@ -176,7 +175,6 @@ import { Engine } from "@/types/proto/v1/common";
import { keyboardShortcutStr, isWorksheetWritableV1 } from "@/utils";
import { useSQLEditorContext } from "../context";
import AdminModeButton from "./AdminModeButton.vue";
-import BatchQueryDatabasesSelector from "./BatchQueryDatabasesSelector.vue";
import ContainerChooser from "./ContainerChooser.vue";
import DatabaseChooser from "./DatabaseChooser.vue";
import OpenAIButton from "./OpenAIButton";