Skip to content

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

chore: optimize database connection panel (#19250)

ecmadaoa9e945640ab9
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
index e3bcd4dd2a..d9c86429d0 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
@@ -38,12 +38,12 @@ const props = withDefaults(
databaseGroupList: DatabaseGroup[];
bordered?: boolean;
loading?: boolean;
- customClick?: boolean;
showSelection?: boolean;
showExternalLink?: boolean;
showActions?: boolean;
singleSelection?: boolean;
pageSize?: number;
+ onRowClick?: (e: MouseEvent, databaseGroup: DatabaseGroup) => void;
selectedDatabaseGroupNames?: string[];
}>(),
{
@@ -54,7 +54,6 @@ const props = withDefaults(
);
const emit = defineEmits<{
- (event: "row-click", e: MouseEvent, databaseGroup: DatabaseGroup): void;
(event: "update:selected-database-group-names", val: string[]): void;
(event: "delete", databaseGroup: DatabaseGroup): void;
}>();
@@ -188,8 +187,8 @@ const rowProps = (databaseGroup: DatabaseGroup) => {
return {
style: "cursor: pointer;",
onClick: (e: MouseEvent) => {
- if (props.customClick) {
- emit("row-click", e, databaseGroup);
+ if (props.onRowClick) {
+ props.onRowClick(e, databaseGroup);
return;
}
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index ad4693426c..e83878fd52 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -1,10 +1,9 @@
<template>
<DatabaseGroupDataTable
:database-group-list="filteredDbGroupList"
- :custom-click="true"
:loading="!ready"
:show-actions="allowDelete"
- @row-click="handleDatabaseGroupClick"
+ :on-row-click="handleDatabaseGroupClick"
@delete="handleDelete"
/>
</template>
diff --git a/frontend/src/components/v2/Model/RichDatabaseName.vue b/frontend/src/components/v2/Model/RichDatabaseName.vue
index 06861dc886..3c96990e92 100644
--- a/frontend/src/components/v2/Model/RichDatabaseName.vue
+++ b/frontend/src/components/v2/Model/RichDatabaseName.vue
@@ -1,7 +1,7 @@
<template>
<NPopover :disabled="!tooltip">
<template #trigger>
- <div class="flex flex-row justify-start items-center gap-x-1">
+ <div v-bind="$attrs" class="flex flex-row justify-start items-center gap-x-1">
<ProjectV1Name
v-if="showProject"
:project="getDatabaseProject(database)"
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 258e15be0e..3a085a4334 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1998,6 +1998,8 @@
"invalid-database": "Invalid database {database}",
"request-aborted": "User aborted the request",
"no-data-source": "No queriable data source. Please check the data source query policy on environment or project.",
+ "database-not-queriable": "Database is not queriable",
+ "no-queriable-database": "No queriable database",
"rows": "row | rows",
"vertical-display": "Vertical display",
"no-history-found": "No history found",
@@ -2033,7 +2035,6 @@
"rows-upper-limit": "reached the limit of query results",
"close-sheet": "Close sheet",
"connect": "Connect",
- "connected": "Connected",
"connect-in-admin-mode": "Connect in admin mode",
"admin-mode": {
"self": "Admin mode",
@@ -2089,7 +2090,6 @@
"click-to-sync-now": "Click to sync now",
"sync-in-progress": "Sync in progress",
"select-a-database-to-start": "Select a database to start",
- "show-empty-environments": "Show empty environments",
"select-encoding": "Select encoding",
"current-connection": "Current connection",
"matched-in-group": "Matched in the database group: {title}",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 5005b01013..af6e612a4c 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1998,6 +1998,8 @@
"invalid-database": "Base de datos no válida {database}",
"request-aborted": "El usuario abortó la solicitud",
"no-data-source": "No se puede consultar ninguna fuente de datos. Consulte la política de consulta de fuentes de datos del entorno o proyecto.",
+ "database-not-queriable": "La base de datos no se puede consultar",
+ "no-queriable-database": "No hay base de datos consultable",
"rows": "fila | filas",
"vertical-display": "Pantalla vertical",
"no-history-found": "No se encontró historial",
@@ -2033,7 +2035,6 @@
"rows-upper-limit": "se ha alcanzado el límite de resultados de la consulta",
"close-sheet": "Cerrar hoja",
"connect": "Conectar",
- "connected": "Conectado",
"connect-in-admin-mode": "Conectar en modo administrador",
"admin-mode": {
"self": "Modo administrador",
@@ -2089,7 +2090,6 @@
"click-to-sync-now": "Haga clic para sincronizar ahora",
"sync-in-progress": "Sincronización en progreso",
"select-a-database-to-start": "Seleccione una base de datos para comenzar",
- "show-empty-environments": "Mostrar entornos vacíos",
"select-encoding": "Seleccionar codificación",
"current-connection": "Conexión actual",
"matched-in-group": "Coincidido en el grupo de base de datos: {title}",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index e9f516a476..33b26a59d8 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1998,6 +1998,8 @@
"invalid-database": "無効なデータベース {database}",
"request-aborted": "ユーザーがリクエストを中止しました",
"no-data-source": "クエリ可能なデータソースがありません。環境またはプロジェクトのデータソースクエリポリシーを確認してください。",
+ "database-not-queriable": "データベースはクエリできません",
+ "no-queriable-database": "クエリ可能なデータベースがありません",
"rows": "記録",
"vertical-display": "縦型表示",
"no-history-found": "まだ履歴がありません",
@@ -2033,7 +2035,6 @@
"rows-upper-limit": "クエリ結果の数が上限に達しました",
"close-sheet": "ワークシートを閉じる",
"connect": "接続する",
- "connected": "接続",
"connect-in-admin-mode": "管理者モードで接続する",
"admin-mode": {
"self": "管理者モード",
@@ -2089,7 +2090,6 @@
"click-to-sync-now": "クリックして今すぐ同期します",
"sync-in-progress": "同期中",
"select-a-database-to-start": "開始するにはデータベースを選択してください",
- "show-empty-environments": "空の環境を表示",
"select-encoding": "エンコーディングの選択",
"current-connection": "現在の接続",
"matched-in-group": "データベース グループ {title} に一致しました",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 072db9771d..2bf89f6c87 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1998,6 +1998,8 @@
"invalid-database": "Cơ sở dữ liệu không hợp lệ {database}",
"request-aborted": "Người dùng đã hủy yêu cầu",
"no-data-source": "Không có nguồn dữ liệu có thể truy vấn. Vui lòng kiểm tra chính sách truy vấn nguồn dữ liệu trên môi trường hoặc dự án.",
+ "database-not-queriable": "Cơ sở dữ liệu không thể truy vấn",
+ "no-queriable-database": "Không có cơ sở dữ liệu có thể truy vấn",
"rows": "dòng | dòng",
"vertical-display": "Hiển thị dọc",
"no-history-found": "Không tìm thấy lịch sử",
@@ -2033,7 +2035,6 @@
"rows-upper-limit": "đã đạt đến giới hạn kết quả truy vấn",
"close-sheet": "Đóng trang tính",
"connect": "Kết nối",
- "connected": "Đã kết nối",
"connect-in-admin-mode": "Kết nối ở chế độ quản trị",
"admin-mode": {
"self": "Chế độ quản trị",
@@ -2089,7 +2090,6 @@
"click-to-sync-now": "Nhấp để đồng bộ ngay",
"sync-in-progress": "Đang đồng bộ",
"select-a-database-to-start": "Chọn một cơ sở dữ liệu để bắt đầu",
- "show-empty-environments": "Hiển thị môi trường trống",
"select-encoding": "Chọn mã hóa",
"current-connection": "Kết nối hiện tại",
"matched-in-group": "Phù hợp trong nhóm cơ sở dữ liệu: {title}",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 52fe100870..1686a906e2 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1998,6 +1998,8 @@
"invalid-database": "数据库 {database} 无效",
"request-aborted": "用户中止了请求",
"no-data-source": "没有可查询的数据源。请检查环境或项目的数据源查询策略。",
+ "database-not-queriable": "数据库不可查询",
+ "no-queriable-database": "没有可查询的数据库",
"rows": "条记录",
"vertical-display": "竖向展示",
"no-history-found": "暂无历史记录",
@@ -2033,7 +2035,6 @@
"rows-upper-limit": "到达查询结果条数上限",
"close-sheet": "关闭工作表",
"connect": "连接",
- "connected": "已连接",
"connect-in-admin-mode": "以管理员模式连接",
"admin-mode": {
"self": "管理员模式",
@@ -2089,7 +2090,6 @@
"click-to-sync-now": "点击立即同步",
"sync-in-progress": "正在同步",
"select-a-database-to-start": "选择数据库以开始",
- "show-empty-environments": "显示空环境",
"select-encoding": "选择编码",
"current-connection": "当前连接",
"matched-in-group": "在数据库组 {title} 中匹配",
diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.ts
index d43a096254..d7da1a772c 100644
--- a/frontend/src/store/modules/sqlEditor/tab.ts
+++ b/frontend/src/store/modules/sqlEditor/tab.ts
@@ -26,7 +26,6 @@ import {
import {
hasFeature,
useDatabaseV1ByName,
- useDatabaseV1Store,
useEnvironmentV1Store,
useWorkSheetStore,
} from "../v1";
@@ -475,18 +474,3 @@ export const useConnectionOfCurrentSQLEditorTab = () => {
return { connection, instance, database, environment };
};
-
-export const resolveOpeningDatabaseListFromSQLEditorTabList = () => {
- const { openTabList } = useSQLEditorTabStore();
- const databaseStore = useDatabaseV1Store();
- const databaseSet = new Set<string>();
-
- for (const tab of openTabList) {
- const { database } = tab.connection;
- if (database) {
- const db = databaseStore.getDatabaseByName(database);
- databaseSet.add(db.name);
- }
- }
- return databaseSet;
-};
diff --git a/frontend/src/utils/storage-keys.ts b/frontend/src/utils/storage-keys.ts
index 50556b0e2e..2452e9b7da 100644
--- a/frontend/src/utils/storage-keys.ts
+++ b/frontend/src/utils/storage-keys.ts
@@ -53,8 +53,8 @@ export const storageKeySqlEditorCurrentTab = (project: string, email: string) =>
`bb.sql-editor.current-tab.${project}.${email}`;
export const storageKeySqlEditorConnExpanded = (env: string, email: string) =>
`bb.sql-editor.conn-expanded.${env}.${email}`;
-export const storageKeySqlEditorConnExpandedKeys = (email: string) =>
- `bb.sql-editor.conn-expanded-keys.${email}`;
+export const storageKeySqlEditorShowMissingQueryDb = (email: string) =>
+ `bb.sql-editor.show-missing-query-db.${email}`;
export const storageKeySqlEditorWorksheetFilter = (
project: string,
email: string
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index d64c1f7bf6..ca17ad0e85 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -87,21 +87,15 @@
>
<template v-if="treeStore.state === 'READY'">
<NCheckbox
- v-if="existEmptyEnvironment"
- v-model:checked="state.showEmptyEnvironment"
+ v-model:checked="showMissingQueryDatabases"
>
- {{ $t("sql-editor.show-empty-environments") }}
+ {{ $t("sql-editor.show-databases-without-query-permission") }}
</NCheckbox>
<div
v-for="[environment, treeState] of treeByEnvironment.entries()"
:key="environment"
>
<div
- v-if="
- !treeIsEmpty(treeState) ||
- (state.showEmptyEnvironment &&
- environment !== UNKNOWN_ENVIRONMENT_NAME)
- "
class="flex flex-col gap-y-2 pt-2 pb-2"
>
<NTree
@@ -122,7 +116,7 @@
environment
) &&
(!treeIsEmpty(treeState) ||
- treeState.showMissingQueryDatabases.value)
+ showMissingQueryDatabases)
"
class="w-full flex items-center justify-start pl-4"
>
@@ -134,7 +128,7 @@
() =>
treeState
.fetchDatabases(filter)
- .then(() => treeState.buildTree())
+ .then(() => treeState.buildTree(showMissingQueryDatabases))
"
>
{{ $t("common.load-more") }}
@@ -157,6 +151,7 @@
</template>
<DatabaseGroupTable
:database-group-names="selectedDatabaseGroupNames"
+ @select="handleSelectDatabaseGroup"
@update:database-group-names="onDatabaseGroupSelectionUpdate"
/>
</NTabPane>
@@ -221,7 +216,7 @@ import {
type DatabaseFilter,
featureToRef,
idForSQLEditorTreeNodeTarget,
- resolveOpeningDatabaseListFromSQLEditorTabList,
+ pushNotification,
useCurrentUserV1,
useDatabaseV1Store,
useDBGroupStore,
@@ -243,7 +238,6 @@ import {
isValidDatabaseGroupName,
isValidDatabaseName,
isValidProjectName,
- UNKNOWN_ENVIRONMENT_NAME,
unknownEnvironment,
} from "@/types";
import { Engine } from "@/types/proto-es/v1/common_pb";
@@ -259,8 +253,7 @@ import {
getValueFromSearchParams,
getValuesFromSearchParams,
isDatabaseV1Queryable,
- isDescendantOf,
- storageKeySqlEditorConnExpandedKeys,
+ storageKeySqlEditorShowMissingQueryDb,
useDynamicLocalStorage,
} from "@/utils";
import { useSQLEditorContext } from "../../context";
@@ -277,7 +270,6 @@ import { type TreeByEnvironment, useSQLEditorTreeByEnvironment } from "./tree";
interface LocalState {
params: SearchParams;
missingFeature?: PlanFeature;
- showEmptyEnvironment: boolean;
batchQueryDataSourceType?: QueryDataSourceType;
selectionMode: "DATABASE" | "DATABASE-GROUP";
switchingConnection: boolean;
@@ -298,23 +290,20 @@ const { t } = useI18n();
const environmentList = computed(() => useEnvironmentV1Store().environmentList);
-const expandedState = useDynamicLocalStorage<{
- initialized: boolean;
- expandedKeys: string[];
-}>(
- computed(() => storageKeySqlEditorConnExpandedKeys(currentUser.value.email)),
- {
- initialized: false,
- expandedKeys: [],
- }
+const showMissingQueryDatabases = useDynamicLocalStorage<boolean>(
+ computed(() =>
+ storageKeySqlEditorShowMissingQueryDb(currentUser.value.email)
+ ),
+ true
);
watch(
- () => expandedState.value.expandedKeys,
- () => {
- expandedState.value.initialized = true;
- },
- { deep: true }
+ () => showMissingQueryDatabases.value,
+ (showMissingQueryDatabases) => {
+ for (const treeState of treeByEnvironment.value.values()) {
+ treeState.buildTree(showMissingQueryDatabases);
+ }
+ }
);
const hasBatchQueryFeature = featureToRef(PlanFeature.FEATURE_BATCH_QUERY);
@@ -327,7 +316,6 @@ const state = reactive<LocalState>({
query: "",
scopes: [],
},
- showEmptyEnvironment: false,
batchQueryDataSourceType: DataSourceType.READ_ONLY,
selectionMode: "DATABASE",
switchingConnection: false,
@@ -364,9 +352,11 @@ watch(
{ immediate: true }
);
+// onBatchQueryContextChange changes the batchQueryContext and connect to the 1st queryable database.
+// return boolean true if exists any queryable database in the batchQueryContext.
const onBatchQueryContextChange = async (
batchQueryContext: BatchQueryContext
-) => {
+): Promise<boolean> => {
state.switchingConnection = true;
try {
@@ -392,6 +382,7 @@ const onBatchQueryContextChange = async (
} else {
tabStore.updateBatchQueryContext(batchQueryContext);
}
+ return !!queryableDatabase;
} finally {
state.switchingConnection = false;
}
@@ -443,7 +434,32 @@ const onDatabaseGroupSelectionUpdate = async (databaseGroups: string[]) => {
...(tabStore.currentTab?.batchQueryContext ?? { databases: [] }),
databaseGroups,
});
- await onBatchQueryContextChange(batchQueryContext);
+ const success = await onBatchQueryContextChange(batchQueryContext);
+
+ if (databaseGroups.length > 0 && !success) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("sql-editor.no-queriable-database"),
+ });
+ }
+};
+
+const handleSelectDatabaseGroup = async (name: string) => {
+ const batchQueryContext: BatchQueryContext = cloneDeep({
+ ...(tabStore.currentTab?.batchQueryContext ?? { databases: [] }),
+ databaseGroups: [name],
+ });
+ const success = await onBatchQueryContextChange(batchQueryContext);
+ if (success) {
+ showConnectionPanel.value = false;
+ } else {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: t("sql-editor.no-queriable-database"),
+ });
+ }
};
const flattenSelectedDatabasesFromGroup = computed(() => {
@@ -468,15 +484,6 @@ const treeByEnvironment = shallowRef<
Map<string /* environment full name */, TreeByEnvironment>
>(new Map());
-const existEmptyEnvironment = computed(() => {
- for (const [_, value] of treeByEnvironment.value.entries()) {
- if (treeIsEmpty(value)) {
- return true;
- }
- }
- return false;
-});
-
const treeIsEmpty = (value: TreeByEnvironment) => {
if (value.tree.value.length === 0) {
return true;
@@ -590,10 +597,6 @@ const getSelectedKeys = async () => {
return [];
};
-const connectedDatabases = computed(() =>
- resolveOpeningDatabaseListFromSQLEditorTabList()
-);
-
// The connection panel should:
// - change the connection for the current tab
// - connect to a new tab, this will create a new worksheet
@@ -637,6 +640,11 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
checkTooltip = t("sql-editor.matched-in-group", { title: checkedByGroup });
} else if (tabStore.currentTab?.connection.database === databaseName) {
checkTooltip = t("sql-editor.current-connection");
+ } else if (databaseName) {
+ const database = (node as SQLEditorTreeNode<"database">).meta.target;
+ if (!isDatabaseV1Queryable(database)) {
+ checkTooltip = t("sql-editor.database-not-queriable");
+ }
}
return h(Label, {
@@ -646,7 +654,14 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
checkDisabled: !!checkedByGroup || state.switchingConnection,
checkTooltip,
keyword: state.params.query,
- connected: connectedDatabases.value.has(databaseName),
+ onClick: () => {
+ if (node.disabled) {
+ return;
+ }
+ if (node.meta.type === "database") {
+ connect(node);
+ }
+ },
"onUpdate:checked": (checked: boolean) => {
if (node.meta.type !== "database") {
return;
@@ -663,18 +678,6 @@ const renderLabel = ({ option }: { option: TreeOption }) => {
const nodeProps = ({ option }: { option: TreeOption }) => {
const node = option as SQLEditorTreeNode;
return {
- onClick(e: MouseEvent) {
- if (node.disabled) return;
-
- if (isDescendantOf(e.target as Element, ".n-tree-node-content")) {
- const { type } = node.meta;
- // Check if clicked on the content part.
- // And ignore the fold/unfold arrow.
- if (type === "database") {
- connect(node);
- }
- }
- },
onContextmenu(e: MouseEvent) {
e.preventDefault();
showDropdown.value = false;
@@ -786,7 +789,9 @@ const prepareDatabases = async () => {
await treeByEnvironment.value
.get(environment.name)
?.prepareDatabases(filter.value);
- treeByEnvironment.value.get(environment.name)?.buildTree();
+ treeByEnvironment.value
+ .get(environment.name)
+ ?.buildTree(showMissingQueryDatabases.value);
}
)
);
@@ -822,6 +827,7 @@ watch(
padding-left: 0 !important;
font-size: 0.875rem;
line-height: 1.25rem;
+ cursor: default !important;
}
.sql-editor-tree :deep(.n-tree-node-wrapper) {
padding: 0;
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseGroupTable.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseGroupTable.vue
index da14d97de1..6fb4d240ab 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseGroupTable.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseGroupTable.vue
@@ -18,6 +18,7 @@
:show-external-link="true"
:page-size="100"
:loading="!ready"
+ :on-row-click="handleDatabaseGroupClick"
:selected-database-group-names="databaseGroupNames"
@update:selected-database-group-names="(groups) => $emit('update:databaseGroupNames', groups)"
/>
@@ -29,13 +30,15 @@ import { computed, ref } from "vue";
import DatabaseGroupDataTable from "@/components/DatabaseGroup/DatabaseGroupDataTable.vue";
import { SearchBox } from "@/components/v2";
import { useDBGroupListByProject, useSQLEditorStore } from "@/store/modules";
+import type { DatabaseGroup } from "@/types/proto-es/v1/database_group_service_pb";
import { DatabaseGroupView } from "@/types/proto-es/v1/database_group_service_pb";
defineProps<{
databaseGroupNames: string[];
}>();
-defineEmits<{
+const emit = defineEmits<{
+ (event: "select", databaseGroupName: string): Promise<void>;
(
event: "update:databaseGroupNames",
databaseGroupNames: string[]
@@ -63,4 +66,11 @@ const filteredDbGroupList = computed(() => {
);
});
});
+
+const handleDatabaseGroupClick = (
+ _: MouseEvent,
+ databaseGroup: DatabaseGroup
+) => {
+ emit("select", databaseGroup.name);
+};
</script>
\ No newline at end of file
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 b71f19add6..6cfedac354 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
@@ -3,6 +3,7 @@
<NTooltip v-if="tabStore.supportBatchMode" :disabled="!checkTooltip" :placement="'bottom-start'">
<template #trigger>
<NCheckbox
+ class="mr-2"
:checked="checked"
:disabled="checkDisabled || !canQuery"
@click.stop.prevent=""
@@ -13,19 +14,19 @@
</NTooltip>
<RichDatabaseName
+ class="cursor-pointer tree-node-database"
:database="database"
:show-instance="true"
:show-engine-icon="true"
:show-environment="false"
:show-arrow="true"
:keyword="keyword"
+ @click.stop.prevent="$emit('click')"
/>
- <span v-if="connected" class="truncate textinfolabel">
- ({{ $t("sql-editor.connected") }})
- </span>
<RequestQueryButton
v-if="showRequestQueryButton"
+ class="ml-auto"
:text="true"
:permission-denied-detail="create(PermissionDeniedDetailSchema, {
resources: [database.name],
@@ -50,13 +51,13 @@ import RequestQueryButton from "../../../EditorCommon/ResultView/RequestQueryBut
const props = defineProps<{
node: TreeNode;
keyword: string;
- connected?: boolean;
checked?: boolean;
checkDisabled?: boolean;
checkTooltip?: string;
}>();
defineEmits<{
+ (event: "click"): void;
(event: "update:checked", checked: boolean): void;
}>();
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 dd1a05ef44..bba20782c2 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/Label.vue
@@ -17,7 +17,8 @@
:checked="checked"
:check-disabled="checkDisabled"
:check-tooltip="checkTooltip"
- :connected="connected"
+ @click="$emit('click')"
+ @update:checked="event => $emit('update:checked', event)"
/>
</template>
<template v-if="type === 'label'">
@@ -39,7 +40,11 @@ const props = defineProps<{
checked: boolean;
checkDisabled?: boolean;
checkTooltip?: string;
- connected: boolean;
+}>();
+
+defineEmits<{
+ (event: "click"): void;
+ (event: "update:checked", checked: boolean): void;
}>();
const type = computed(() => props.node.meta.type);
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/tree.ts b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/tree.ts
index 230bb09a13..4ed4707663 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/tree.ts
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/tree.ts
@@ -1,9 +1,7 @@
import { useDebounceFn } from "@vueuse/core";
-import { NCheckbox } from "naive-ui";
import { storeToRefs } from "pinia";
import type { ComputedRef, Ref } from "vue";
-import { computed, h, ref, watch } from "vue";
-import { t } from "@/plugins/i18n";
+import { computed, ref, watch } from "vue";
import {
buildTreeImpl,
type DatabaseFilter,
@@ -37,14 +35,13 @@ export type TreeByEnvironment = {
initialized: boolean;
expandedKeys: string[];
}>;
- buildTree: () => void;
+ buildTree: (showMissingQueryDatabases: boolean) => void;
prepareDatabases: (filter?: DatabaseFilter) => Promise<void>;
fetchDatabases: (filter?: DatabaseFilter) => Promise<void>;
fetchDataState: ComputedRef<{
loading: boolean;
nextPageToken?: string;
}>;
- showMissingQueryDatabases: ComputedRef<boolean>;
};
export const useSQLEditorTreeByEnvironment = (
@@ -56,7 +53,6 @@ export const useSQLEditorTreeByEnvironment = (
const environmentStore = useEnvironmentV1Store();
const tree = ref<TreeNode[]>([]);
- const showMissingQueryDatabases = ref<boolean>(false);
const databaseList = ref<Database[]>([]);
const fetchDataState = ref<{
loading: boolean;
@@ -116,21 +112,12 @@ export const useSQLEditorTreeByEnvironment = (
await fetchDatabases(filter);
};
- const hasMissingQueryDatabases = computed(() => {
- return databaseList.value.some((db) => !isDatabaseV1Queryable(db));
- });
-
- const filteredDatabaseList = computed(() => {
- if (!showMissingQueryDatabases.value) {
- return databaseList.value.filter((db) => isDatabaseV1Queryable(db));
+ const buildTree = (showMissingQueryDatabases: boolean) => {
+ let list = [...databaseList.value];
+ if (!showMissingQueryDatabases) {
+ list = list.filter((db) => isDatabaseV1Queryable(db));
}
- return databaseList.value;
- });
-
- const buildTree = () => {
- tree.value = buildTreeImpl(filteredDatabaseList.value, [
- defaultEnvironmentFactor.factor,
- ]);
+ tree.value = buildTreeImpl(list, [defaultEnvironmentFactor.factor]);
if (tree.value.length === 0) {
const env = environmentStore.getEnvironmentByName(environment);
@@ -138,46 +125,14 @@ export const useSQLEditorTreeByEnvironment = (
rootNode.children = [];
tree.value = [rootNode];
}
-
- if (hasMissingQueryDatabases.value) {
- for (const node of tree.value) {
- node.suffix = () => {
- return h(
- NCheckbox,
- {
- checked: showMissingQueryDatabases.value,
- onUpdateChecked: (checked) =>
- (showMissingQueryDatabases.value = checked),
- onClick: (e: MouseEvent) => {
- e.preventDefault();
- e.stopPropagation();
- },
- },
- h(
- "span",
- { class: "textinfolabel text-sm" },
- t("sql-editor.show-databases-without-query-permission")
- )
- );
- };
- }
- }
};
- watch(
- () => showMissingQueryDatabases.value,
- () => {
- buildTree();
- }
- );
-
return {
tree: computed(() => tree.value),
expandedState,
buildTree,
prepareDatabases,
fetchDatabases,
- showMissingQueryDatabases: computed(() => showMissingQueryDatabases.value),
fetchDataState: computed(() => fetchDataState.value),
};
};