Skip to content

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

chore: optimize result selection/copy (#17378)

ecmadao3f509e0c3e71
diff --git a/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue b/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
index ea1cfa60a8..7d31c82269 100644
--- a/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/cells/UserNameCell.vue
@@ -49,6 +49,7 @@
class="ml-3 text-xs"
>
<CopyButton
+ v-if="user.serviceKey"
quaternary
size="small"
:text="false"
@@ -58,7 +59,7 @@
{{ $t("settings.members.copy-service-key") }}
</CopyButton>
<NButton
- v-if="!user.serviceKey"
+ v-else
tertiary
size="small"
@click.prevent="$emit('reset-service-key', user)"
diff --git a/frontend/src/components/v2/Button/CopyButton.vue b/frontend/src/components/v2/Button/CopyButton.vue
index e4e945f2dc..28bbd34f33 100644
--- a/frontend/src/components/v2/Button/CopyButton.vue
+++ b/frontend/src/components/v2/Button/CopyButton.vue
@@ -1,6 +1,6 @@
<template>
<NButton
- v-if="isSupported && content"
+ v-if="isSupported && !isEmpty"
v-bind="$attrs"
:text="text"
:size="size"
@@ -18,12 +18,13 @@
import { useClipboard } from "@vueuse/core";
import { CopyIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
+import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { pushNotification } from "@/store";
const props = withDefaults(
defineProps<{
- content: string;
+ content: string | (() => string);
text?: boolean;
disabled?: boolean;
size?: "tiny" | "small" | "medium" | "large";
@@ -40,11 +41,24 @@ const { copy: copyTextToClipboard, isSupported } = useClipboard({
});
const { t } = useI18n();
+const isEmpty = computed(() => {
+ if (typeof props.content === "function") {
+ return false;
+ }
+ return !props.content;
+});
+
const handleCopy = () => {
if (!isSupported.value) {
return;
}
- copyTextToClipboard(props.content).then(() => {
+ let value = "";
+ if (typeof props.content === "function") {
+ value = props.content();
+ } else {
+ value = props.content;
+ }
+ copyTextToClipboard(value).then(() => {
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/v2/Form/ResourceIdField.vue b/frontend/src/components/v2/Form/ResourceIdField.vue
index 54e92c83b3..f43a5183ea 100644
--- a/frontend/src/components/v2/Form/ResourceIdField.vue
+++ b/frontend/src/components/v2/Form/ResourceIdField.vue
@@ -11,7 +11,7 @@
class="text-gray-600 font-medium mr-1 flex items-center gap-x-1"
>
{{ state.resourceId }}
- <CopyButton v-if="readonly" :content="value" />
+ <CopyButton v-if="readonly && value" :content="value" />
</div>
<span v-else class="text-control-placeholder italic">
&lt;EMPTY&gt;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
index 69042b8536..2fcf2cca32 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
@@ -9,7 +9,7 @@
>
<div
ref="wrapperRef"
- class="whitespace-nowrap font-mono text-start line-clamp-1"
+ class="font-mono text-start break-words line-clamp-3"
v-html="html"
></div>
<div
@@ -135,9 +135,11 @@ watchEffect(() => {
useResizeObserver(wrapperRef, (entries) => {
const div = entries[0].target as HTMLDivElement;
- const contentWidth = div.scrollWidth;
- const visibleWidth = div.offsetWidth;
- if (contentWidth > visibleWidth) {
+ const contentHeight = div.scrollHeight;
+ const visibleHeight = div.offsetHeight;
+ // Check if content is truncated vertically (due to line-clamp)
+ if (contentHeight > visibleHeight + 2) {
+ // +2 for minor pixel differences
truncated.value = true;
} else {
truncated.value = false;
@@ -224,9 +226,17 @@ const formattedValue = computed(() => {
};
});
+const plainValue = computed(() => {
+ const value = extractSQLRowValuePlain(formattedValue.value);
+ if (value === undefined || value === null) {
+ return value;
+ }
+ return String(value);
+});
+
const html = computed(() => {
// Extract the display value
- const value = extractSQLRowValuePlain(formattedValue.value);
+ const value = plainValue.value;
if (value === undefined) {
return `<span class="text-gray-400 italic">UNSET</span>`;
@@ -234,18 +244,17 @@ const html = computed(() => {
if (value === null) {
return `<span class="text-gray-400 italic">NULL</span>`;
}
- const str = String(value);
- if (str.length === 0) {
+ if (value.length === 0) {
return `<br style="min-width: 1rem; display: inline-flex;" />`;
}
const kw = keyword.value.trim();
if (!kw) {
- return escape(str);
+ return escape(value);
}
return getHighlightHTMLByRegExp(
- escape(str),
+ escape(value),
escape(kw),
false /* !caseSensitive */
);
@@ -272,4 +281,8 @@ const showDetail = () => {
table: props.table,
};
};
+
+defineExpose({
+ plainValue,
+});
</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/VirtualDataBlock.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/VirtualDataBlock.vue
index ee569f8ff0..6d51b19a34 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/VirtualDataBlock.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/VirtualDataBlock.vue
@@ -13,7 +13,7 @@
}"
>
<div
- v-for="virtualRow in virtualItems"
+ v-for="(virtualRow, i) in virtualItems"
:key="`row-${offset + virtualRow.index}`"
class="font-mono mb-5 mx-2"
:style="{
@@ -27,13 +27,22 @@
{{ offset + virtualRow.index + 1 }}. row
********************************
</p>
- <div class="py-2 px-3 bg-gray-50 dark:bg-gray-700 rounded-sm">
+ <div
+ class="py-2 px-3 bg-gray-50 dark:bg-gray-700 rounded-sm relative"
+ >
+ <div
+ class="absolute right-2 top-2 z-50 opacity-70 hover:opacity-100"
+ >
+ <CopyButton size="small" :content="() => getContent(i)" />
+ </div>
<div
v-for="header in columnHeaders"
:key="`${virtualRow.index}-${header.index}`"
- class="flex items-center text-gray-500 dark:text-gray-300 text-sm"
+ class="flex items-start text-gray-500 dark:text-gray-300 text-sm"
>
- <div class="min-w-[7rem] text-left flex items-center font-medium">
+ <div
+ class="min-w-[7rem] text-left flex items-start font-medium pt-1"
+ >
{{ header.column.columnDef.header }}
<MaskingReasonPopover
v-if="getMaskingReason && getMaskingReason(header.index)"
@@ -48,6 +57,7 @@
</div>
<div class="flex-1">
<TableCell
+ ref="cellRefs"
:table="table"
:value="
rows[virtualRow.index]
@@ -59,6 +69,7 @@
:row-index="offset + virtualRow.index"
:col-index="header.index"
:column-type="getColumnType(header)"
+ :allow-select="true"
/>
</div>
</div>
@@ -79,6 +90,7 @@
import type { Table } from "@tanstack/vue-table";
import { useVirtualizer } from "@tanstack/vue-virtual";
import { computed, ref, watch } from "vue";
+import { CopyButton } from "@/components/v2";
import type { QueryRow, RowValue } from "@/types/proto-es/v1/sql_service_pb";
import TableCell from "./DataTable/TableCell.vue";
import MaskingReasonPopover from "./DataTable/common/MaskingReasonPopover.vue";
@@ -96,6 +108,7 @@ const props = defineProps<{
const { keyword } = useSQLResultViewContext();
const containerRef = ref<HTMLDivElement>();
+const cellRefs = ref<InstanceType<typeof TableCell>[]>([]);
const rows = computed(() => props.table.getRowModel().rows);
@@ -130,4 +143,20 @@ watch(
virtualizer.value.scrollToOffset(0);
}
);
+
+const getContent = (index: number): string => {
+ const object = columnHeaders.value.reduce(
+ (obj, header, j) => {
+ if (!header.column.columnDef.header) {
+ return obj;
+ }
+ obj[`${header.column.columnDef.header}`] =
+ cellRefs.value[index * columnHeaders.value.length + j]?.plainValue;
+ return obj;
+ },
+ {} as Record<string, any>
+ );
+
+ return JSON.stringify(object, null, 4);
+};
</script>