Skip to content

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

chore: add tips to copy query result (#14899)

boojack415ad8db61ee
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 56c902f08d..55b81d49f2 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2602,7 +2602,8 @@
"go-to-create": "Go to create",
"contact-the-admin-to-grant-access": "Contact to the admin to grant access."
},
- "upload-file": "Upload file"
+ "upload-file": "Upload file",
+ "copy-selected-results": "Copy selected data by {action} or {button}"
},
"schema-editor": {
"self": "Schema Editor",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 19d7b981cb..8dc22e4f3d 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2602,7 +2602,8 @@
"go-to-create": "ir a crear",
"contact-the-admin-to-grant-access": "Póngase en contacto con el administrador para otorgar acceso."
},
- "upload-file": "Subir archivo"
+ "upload-file": "Subir archivo",
+ "copy-selected-results": "Copiar datos seleccionados por {action} o {button}"
},
"schema-editor": {
"self": "Editor de esquema",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 9c51ce9075..ed3d516fbf 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2602,7 +2602,8 @@
"go-to-create": "作成に行く",
"contact-the-admin-to-grant-access": "管理者に連絡してアクセスを許可してください。"
},
- "upload-file": "ファイルをアップロードする"
+ "upload-file": "ファイルをアップロードする",
+ "copy-selected-results": "選択したデータを{action}または{button}でコピーします"
},
"schema-editor": {
"self": "スキーマエディタ",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 2cf7720932..b344d4df32 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2602,7 +2602,8 @@
"go-to-create": "去创建",
"contact-the-admin-to-grant-access": "联系管理员以授予访问权限。"
},
- "upload-file": "上传文件"
+ "upload-file": "上传文件",
+ "copy-selected-results": "通过 {action} 或 {button} 来快速复制选定的数据"
},
"schema-editor": {
"self": "Schema 编辑器",
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
index 6371b95ae8..8932c370fb 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
@@ -137,7 +137,7 @@
import type { Table } from "@tanstack/vue-table";
import { useElementSize } from "@vueuse/core";
import { NEmpty, NScrollbar } from "naive-ui";
-import { computed, nextTick, ref, toRef, watch } from "vue";
+import { computed, nextTick, ref, watch } from "vue";
import {
FeatureBadge,
FeatureBadgeForInstanceLicense,
@@ -148,7 +148,7 @@ import { usePreventBackAndForward } from "@/utils";
import { useSQLResultViewContext } from "../../context";
import ColumnSortedIcon from "../common/ColumnSortedIcon.vue";
import SensitiveDataIcon from "../common/SensitiveDataIcon.vue";
-import { provideSelectionContext } from "../common/selection-logic";
+import { useSelectionContext } from "../common/selection-logic";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
@@ -170,7 +170,7 @@ const {
state: selectionState,
disabled: selectionDisabled,
selectColumn,
-} = provideSelectionContext(toRef(props, "table"));
+} = useSelectionContext();
const containerRef = ref<HTMLDivElement>();
const scrollbarRef = ref<InstanceType<typeof NScrollbar>>();
const tableRef = ref<HTMLTableElement>();
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
index a40b037cb1..158d7b19bc 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
@@ -57,7 +57,6 @@ import { computed, h, nextTick, ref, toRef, watch, type StyleValue } from "vue";
import { QueryRow, type RowValue } from "@/types/proto/v1/sql_service";
import { nextAnimationFrame, usePreventBackAndForward } from "@/utils";
import { useSQLResultViewContext } from "../../context";
-import { provideSelectionContext } from "../common/selection-logic";
import ColumnHeader from "./ColumnHeader.vue";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
@@ -82,7 +81,6 @@ const props = defineProps<{
const { keyword } = useSQLResultViewContext();
-provideSelectionContext(toRef(props, "table"));
const headers = computed(() => {
return props.table.getFlatHeaders() as Header<QueryRow, RowValue>[];
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
index 17bc4a38bd..484c69a124 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
@@ -30,7 +30,7 @@ export type SelectionContext = {
selectRow: (row: number) => void;
selectColumn: (column: number) => void;
deselect: () => void;
- copy: () => void;
+ copy: () => boolean;
};
export const KEY = Symbol(
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue
new file mode 100644
index 0000000000..0b25d83eeb
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue
@@ -0,0 +1,70 @@
+<template>
+ <div
+ v-if="shouldShow"
+ class="w-full absolute h-full bg-white dark:bg-dark-bg flex flex-row justify-start items-center text-control dark:text-control-light"
+ @click.prevent.stop
+ >
+ <InfoIcon :size="16" class="mr-2 text-control" />
+ <i18n-t
+ keypath="sql-editor.copy-selected-results"
+ tag="p"
+ class="text-sm flex flex-row justify-start items-center gap-1"
+ >
+ <template #action>
+ <kbd
+ class="w-auto h-5 flex items-center justify-center bg-black dark:bg-zinc-700 dark:text-zinc-300 bg-opacity-10 rounded px-1.5 text-control overflow-y-hidden"
+ >
+ <span v-if="isMac" class="text-base leading-none">⌘</span>
+ <span
+ v-else
+ class="tracking-tighter text-xs transform scale-x-90 leading-none"
+ >
+ Ctrl
+ </span>
+ <span class="pl-1 text-xs leading-none">C</span>
+ </kbd>
+ </template>
+ <template #button>
+ <NButton size="tiny" @click="copySelection" type="primary" secondary>
+ <template #icon>
+ <CopyIcon />
+ </template>
+ {{ $t("common.copy") }}
+ </NButton>
+ </template>
+ </i18n-t>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { CopyIcon, InfoIcon } from "lucide-vue-next";
+import { NButton } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { pushNotification } from "@/store";
+import { useSelectionContext } from "./DataTable/common/selection-logic";
+
+const { t } = useI18n();
+const { state: selectionState, copy, deselect } = useSelectionContext();
+
+const shouldShow = computed(
+ () =>
+ selectionState.value.rows.length > 0 ||
+ selectionState.value.columns.length > 0
+);
+
+const isMac = navigator.platform.match(/mac/i);
+
+const copySelection = () => {
+ const copied = copy();
+ if (!copied) {
+ return;
+ }
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.copied"),
+ });
+ deselect();
+};
+</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index c89daa730d..21104adb0e 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -4,7 +4,7 @@
<ErrorView :error="result.error" />
</BBAttention>
<div
- class="w-full shrink-0 flex flex-row justify-between items-center mb-2 overflow-x-auto hide-scrollbar"
+ class="relative w-full shrink-0 flex flex-row justify-between items-center mb-2 overflow-x-auto hide-scrollbar"
>
<div class="flex flex-row justify-start items-center mr-2 shrink-0">
<NInput
@@ -113,6 +113,7 @@
</NButton>
</template>
</div>
+ <SelectionCopyTooltips />
</div>
<div class="flex-1 w-full flex flex-col overflow-y-auto">
@@ -248,8 +249,10 @@ import {
} from "@/utils";
import DataBlock from "./DataBlock.vue";
import { DataTable, DataTableLite } from "./DataTable";
+import { provideSelectionContext } from "./DataTable/common/selection-logic";
import EmptyView from "./EmptyView.vue";
import ErrorView from "./ErrorView";
+import SelectionCopyTooltips from "./SelectionCopyTooltips.vue";
import { useSQLResultViewContext } from "./context";
type LocalState = {
@@ -444,6 +447,8 @@ const table = useVueTable<QueryRow>({
table.setPageSize(storedPageSize.value);
+provideSelectionContext(computed(() => table));
+
const pageIndex = computed(() => {
return table.getState().pagination.pageIndex;
});