Skip to content

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

chore: optimize query result (#16491)

ecmadao708a2b50db93
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 1451322141..7c3a509958 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -132,6 +132,7 @@
"loading": "Loading",
"copy": "Copy",
"copied": "Copied",
+ "click-to-copy": "Click to copy",
"manage": "Manage",
"table": "Table",
"search": "Search",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 69ed88bb05..cab1ebffc6 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -132,6 +132,7 @@
"loading": "Cargando",
"copy": "Copiar",
"copied": "Copiado",
+ "click-to-copy": "Haga clic para copiar",
"manage": "Administrar",
"table": "Tabla",
"search": "Buscar",
@@ -2742,4 +2743,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 6586c52311..7b049cbe04 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -132,6 +132,7 @@
"loading": "読み込み中",
"copy": "コピー",
"copied": "コピーされました",
+ "click-to-copy": "クリックしてコピー",
"manage": "管理",
"table": "テーブル",
"search": "検索",
@@ -2742,4 +2743,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 819e168b6e..759f6abf41 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -132,6 +132,7 @@
"loading": "Đang tải",
"copy": "Sao chép",
"copied": "Đã sao chép",
+ "click-to-copy": "Nhấp để sao chép",
"manage": "Quản lý",
"table": "Bảng",
"search": "Tìm kiếm",
@@ -2742,4 +2743,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 05c303766f..00d32276b1 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -132,6 +132,7 @@
"loading": "加载中",
"copy": "拷贝",
"copied": "已拷贝",
+ "click-to-copy": "点击复制",
"manage": "管理",
"table": "表",
"search": "搜索",
@@ -2742,4 +2743,4 @@
"last-visit": "上次访问",
"changelog-for-version": "{version} 的更新日志"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.ts
index ac5c88eb53..f7784c0523 100644
--- a/frontend/src/store/modules/sqlEditor/tab.ts
+++ b/frontend/src/store/modules/sqlEditor/tab.ts
@@ -12,6 +12,7 @@ import type {
} from "@/types";
import { DEFAULT_SQL_EDITOR_TAB_MODE, isValidDatabaseName } from "@/types";
import { DataSourceType } from "@/types/proto/v1/instance_service";
+import { PlanFeature } from "@/types/proto/v1/subscription_service";
import {
WebStorageHelper,
defaultSQLEditorTab,
@@ -28,7 +29,6 @@ import {
extractUserId,
hasFeature,
} from "../v1";
-import { PlanFeature } from "@/types/proto/v1/subscription_service";
import { useSQLEditorStore } from "./editor";
import {
EXTENDED_TAB_FIELDS,
@@ -285,6 +285,30 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
});
};
+ // removeDatabaseQueryContext remove the context by id, and returns the next context.
+ const removeDatabaseQueryContext = ({
+ database,
+ contextId,
+ }: {
+ database: string;
+ contextId: string;
+ }): SQLEditorDatabaseQueryContext | undefined => {
+ const tab = tabById(currentTabId.value);
+ if (!tab || !tab.databaseQueryContexts) {
+ return;
+ }
+ if (!tab.databaseQueryContexts.has(database)) {
+ return;
+ }
+ const contexts = tab.databaseQueryContexts.get(database)!;
+ const index = contexts.findIndex((context) => context.id === contextId);
+ if (index < 0) {
+ return;
+ }
+ contexts.splice(index, 1);
+ return contexts[index] || contexts[index - 1];
+ };
+
const updateDatabaseQueryContext = ({
database,
contextId,
@@ -448,6 +472,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
updateCurrentTab,
updateBatchQueryContext,
updateDatabaseQueryContext,
+ removeDatabaseQueryContext,
setCurrentTabId,
selectOrAddSimilarNewTab,
maybeInitProject,
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 65950e62b3..95db5a2569 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -144,9 +144,17 @@
<div
class="w-full flex items-center justify-between text-xs mt-1 gap-x-4 text-control-light"
>
- <div class="flex-1 truncate">
- {{ result.statement }}
- </div>
+ <NTooltip :disabled="!isSupported">
+ <template #trigger>
+ <div
+ class="truncate cursor-pointer hover:bg-gray-200"
+ @click="copyStatement"
+ >
+ {{ result.statement }}
+ </div>
+ </template>
+ {{ $t("common.click-to-copy") }}
+ </NTooltip>
<div class="shrink-0 space-x-2">
<NButton
v-if="showVisualizeButton"
@@ -176,6 +184,32 @@
</template>
<script lang="ts" setup>
+import type { ColumnDef } from "@tanstack/vue-table";
+import {
+ getCoreRowModel,
+ getPaginationRowModel,
+ getSortedRowModel,
+ useVueTable,
+} from "@tanstack/vue-table";
+import { useClipboard } from "@vueuse/core";
+import { useDebounceFn, useLocalStorage } from "@vueuse/core";
+import dayjs from "dayjs";
+import { isEmpty } from "lodash-es";
+import { ExternalLinkIcon } from "lucide-vue-next";
+import {
+ NButton,
+ NFormItem,
+ NInput,
+ NPagination,
+ NSelect,
+ NSwitch,
+ NTooltip,
+ type SelectOption,
+} from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
+import { computed, reactive } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
import { BBAttention } from "@/bbkit";
import type {
DownloadContent,
@@ -192,7 +226,8 @@ import {
useSQLEditorStore,
useSQLEditorTabStore,
useSQLStore,
- useStorageStore
+ useStorageStore,
+ pushNotification,
} from "@/store";
import type { ComposedDatabase, SQLEditorQueryParams } from "@/types";
import {
@@ -218,25 +253,6 @@ import {
instanceV1HasStructuredQueryResult,
isNullOrUndefined,
} from "@/utils";
-import type { ColumnDef } from "@tanstack/vue-table";
-import {
- getCoreRowModel,
- getPaginationRowModel,
- getSortedRowModel,
- useVueTable,
-} from "@tanstack/vue-table";
-import { useDebounceFn, useLocalStorage } from "@vueuse/core";
-import dayjs from "dayjs";
-import { isEmpty } from "lodash-es";
-import { ExternalLinkIcon } from "lucide-vue-next";
-import {
- NButton, NFormItem, NInput, NPagination, NSelect, NSwitch, NTooltip,
- type SelectOption
-} from "naive-ui";
-import { v4 as uuidv4 } from "uuid";
-import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
import DataBlock from "./DataBlock.vue";
import DataTable from "./DataTable";
import { provideSelectionContext } from "./DataTable/common/selection-logic";
@@ -269,6 +285,23 @@ const state = reactive<LocalState>({
vertical: false,
});
+const { copy: copyTextToClipboard, isSupported } = useClipboard({
+ legacy: true,
+});
+
+const copyStatement = () => {
+ if (!isSupported.value) {
+ return;
+ }
+ copyTextToClipboard(props.result.statement).then(() => {
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.copied"),
+ });
+ });
+};
+
const { t } = useI18n();
const router = useRouter();
const { dark, keyword } = useSQLResultViewContext();
diff --git a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/ResultPanel.vue b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/ResultPanel.vue
index 4511d478d1..877cb87d8e 100644
--- a/frontend/src/views/sql-editor/EditorPanel/ResultPanel/ResultPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/ResultPanel/ResultPanel.vue
@@ -28,6 +28,11 @@
class="text-red-600 w-4 h-auto"
/>
<BBSpin v-if="context.status === 'EXECUTING'" :size="10" />
+ <XIcon
+ v-if="queryContexts.length > 1"
+ class="text-gray-400 w-4 h-auto hover:text-gray-600"
+ @click.stop="handleCloseTab(context.id)"
+ />
</div>
</template>
{{ context.params.statement }}
@@ -60,7 +65,7 @@
<script lang="ts" setup>
import dayjs from "dayjs";
import { head } from "lodash-es";
-import { CircleAlertIcon } from "lucide-vue-next";
+import { CircleAlertIcon, XIcon } from "lucide-vue-next";
import { NTabs, NTabPane, NTooltip } from "naive-ui";
import { computed, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -131,4 +136,14 @@ watch(
},
{ immediate: true }
);
+
+const handleCloseTab = (id: string) => {
+ const nextContext = tabStore.removeDatabaseQueryContext({
+ database: selectedDatabase.value?.name ?? "",
+ contextId: id,
+ });
+ if (selectedTab.value === id && nextContext) {
+ selectedTab.value = nextContext.id;
+ }
+};
</script>