Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(sql-editor): allow select table cell to copy (#14988)
boojack04d91ac9c511
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vueindex 1ae9f1d6ad..54558343ad 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue@@ -20,26 +20,21 @@class="relative border-collapse table-fixed z-[1]"v-bind="tableResize.getTableProps()">- <thead class="sticky top-0 z-[1] drop-shadow-sm">+ <thead class="bg-white sticky top-0 z-[1] drop-shadow-sm"><tr><thv-for="header of table.getFlatHeaders()":key="header.index"class="group relative px-2 py-2 min-w-[2rem] text-left bg-gray-50 dark:bg-gray-700 text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border border-t-0 border-block-border border-b-0":class="{- 'cursor-pointer': !selectionDisabled,+ 'cursor-pointer hover:bg-accent/5': !selectionDisabled,+ '!bg-accent/10':+ selectionState.rows.length === 0 &&+ selectionState.columns.includes(header.index),}"@click.stop="selectColumn(header.index)"v-bind="tableResize.getColumnProps(header.index)">- <div- v-if="!selectionDisabled"- class="absolute inset-0 group-hover:bg-accent/10 pointer-events-none"- :class="- selectionState.columns.includes(header.index) &&- 'bg-accent/10'- "- /><div class="flex items-center overflow-hidden"><span class="flex flex-row items-center select-none"><template@@ -108,6 +103,17 @@:col-index="cellIndex":allow-select="true"/>+ <div+ v-if="cellIndex === 0"+ class="absolute inset-y-0 left-0 w-2"+ :class="{+ 'cursor-pointer hover:bg-accent/10': !selectionDisabled,+ 'bg-accent/10':+ selectionState.columns.length === 0 &&+ selectionState.rows.includes(offset + rowIndex),+ }"+ @click.prevent.stop="selectRow(offset + rowIndex)"+ ></div></td></tr></tbody>@@ -165,6 +171,7 @@ const {state: selectionState,disabled: selectionDisabled,selectColumn,+ selectRow,} = useSelectionContext();const containerRef = ref<HTMLDivElement>();const scrollbarRef = ref<InstanceType<typeof NScrollbar>>();diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite.vueindex ed70ea2055..729d624b01 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite.vue@@ -15,12 +15,15 @@v-for="header of table.getFlatHeaders()":key="header.index"class="relative min-w-[2rem] max-w-[50vw] text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-l first:border-l-0 border-block-border dark:border-zinc-500"- :class="{- 'cursor-pointer': !selectionDisabled,- 'bg-accent/10 dark:bg-accent/40': selectionState.columns.includes(- header.index- ),- }"+ :class="+ twMerge(+ !selectionDisabled &&+ 'cursor-pointer hover:bg-accent/5 dark:hover:bg-accent/20',+ selectionState.rows.length === 0 &&+ selectionState.columns.includes(header.index) &&+ '!bg-accent/10 dark:!bg-accent/40'+ )+ "@click.stop="selectColumn(header.index)"><div class="px-2 py-2 flex items-center overflow-hidden">@@ -83,6 +86,18 @@:col-index="cellIndex":allow-select="true"/>+ <div+ v-if="cellIndex === 0"+ class="absolute inset-y-0 left-0 w-2"+ :class="{+ 'cursor-pointer hover:bg-accent/10 dark:hover:bg-accent/40':+ !selectionDisabled,+ 'bg-accent/10 dark:bg-accent/40':+ selectionState.columns.length === 0 &&+ selectionState.rows.includes(offset + rowIndex),+ }"+ @click.prevent.stop="selectRow(offset + rowIndex)"+ ></div></td></tr></tbody>@@ -92,6 +107,7 @@<script lang="ts" setup>import type { Table } from "@tanstack/vue-table";+import { twMerge } from "tailwind-merge";import { computed, nextTick, ref, watch } from "vue";import {FeatureBadge,@@ -118,6 +134,7 @@ const {state: selectionState,disabled: selectionDisabled,selectColumn,+ selectRow,} = useSelectionContext();const containerRef = ref<HTMLDivElement>();const subscriptionStore = useSubscriptionV1Store();diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vueindex ee051984f1..35e9e3dc13 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue@@ -48,13 +48,12 @@ const props = defineProps<{allowSelect?: boolean;}>();-const { dark, disallowCopyingData, detail, keyword } =- useSQLResultViewContext();+const { dark, detail, keyword } = useSQLResultViewContext();const {state: selectionState,disabled: selectionDisabled,- selectRow,+ selectCell,} = useSelectionContext();const wrapperRef = ref<HTMLDivElement>();const truncated = ref(false);@@ -90,24 +89,28 @@ const clickable = computed(() => {const classes = computed(() => {const classes: string[] = [];- if (disallowCopyingData.value) {- classes.push("select-none");- }if (allowSelect.value) {- if (props.colIndex === 0) {- classes.push("cursor-pointer");- classes.push("hover:bg-accent/10 hover:dark:bg-accent/40");- }+ classes.push("cursor-pointer");+ classes.push(dark.value ? "hover:bg-white/20" : "hover:bg-black/5");if (+ selectionState.value.columns.length === 1 &&+ selectionState.value.rows.length === 1+ ) {+ if (+ selectionState.value.columns[0] === props.colIndex &&+ selectionState.value.rows[0] === props.rowIndex+ ) {+ classes.push("!bg-accent/10 dark:!bg-accent/40");+ }+ } else if (selectionState.value.columns.includes(props.colIndex) ||selectionState.value.rows.includes(props.rowIndex)) {- classes.push("bg-accent/10 dark:bg-accent/40");+ classes.push("!bg-accent/10 dark:!bg-accent/40");+ } else {}- }- if (clickable.value) {- classes.push("cursor-pointer");- classes.push(dark.value ? "hover:!bg-white/20" : "hover:!bg-black/5");+ } else {+ classes.push("select-none");}return uniq(classes);});@@ -138,13 +141,11 @@ const html = computed(() => {});const handleClick = (e: MouseEvent) => {- if (props.colIndex === 0 && allowSelect.value) {- selectRow(props.rowIndex);- e.stopPropagation();+ if (!allowSelect.value) {+ return;}-- if (!clickable.value) return;- showDetail();+ selectCell(props.rowIndex, props.colIndex);+ e.stopPropagation();};const showDetail = () => {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.tsindex 1c62dc32eb..3bbf45e868 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@@ -29,6 +29,7 @@ export type SelectionContext = {disabled: Ref<boolean>;selectRow: (row: number) => void;selectColumn: (column: number) => void;+ selectCell: (row: number, column: number) => void;deselect: () => void;copy: () => boolean;};@@ -49,8 +50,18 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {const disabled = computed(() => {return resultViewContext.disallowCopyingData.value;});+ const isCellSelected = computed(+ () => state.value.rows.length === 1 && state.value.columns.length === 1+ );const selectRow = (row: number) => {if (disabled.value) return;+ if (isCellSelected.value) {+ state.value = {+ rows: [row],+ columns: [],+ };+ return;+ }state.value = {rows: sortBy(state.value.rows.includes(row)@@ -62,6 +73,13 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {};const selectColumn = (column: number) => {if (disabled.value) return;+ if (isCellSelected.value) {+ state.value = {+ rows: [],+ columns: [column],+ };+ return;+ }state.value = {rows: [],columns: sortBy(@@ -71,6 +89,20 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {),};};+ const selectCell = (row: number, column: number) => {+ if (disabled.value) return;+ if (+ state.value.rows.includes(row) &&+ state.value.columns.includes(column)+ ) {+ deselect();+ return;+ }+ state.value = {+ rows: [row],+ columns: [column],+ };+ };const deselect = () => {state.value = {rows: [],@@ -92,7 +124,18 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {});const getValues = () => {- if (state.value.rows.length > 0) {+ if (state.value.rows.length === 1 && state.value.columns.length === 1) {+ const row =+ table.value.getPrePaginationRowModel().rows[state.value.rows[0]];+ if (!row) {+ return "";+ }+ const cell = row.getVisibleCells()[state.value.columns[0]];+ if (!cell) {+ return "";+ }+ return String(extractSQLRowValuePlain(cell.getValue() as RowValue));+ } else if (state.value.rows.length > 0) {const rows: Row<QueryRow>[] = [];for (const row of state.value.rows) {const d = table.value.getPrePaginationRowModel().rows[row];@@ -196,6 +239,7 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {disabled,selectRow,selectColumn,+ selectCell,deselect,copy,};diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 75f5d4f587..6528f6e0a4 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -240,7 +240,6 @@ import {extractSQLRowValuePlain,generateIssueTitle,hasPermissionToCreateRequestGrantIssue,- hasWorkspacePermissionV2,instanceV1HasStructuredQueryResult,isNullOrUndefined,} from "@/utils";@@ -326,10 +325,6 @@ const showSearchFeature = computed(() => {});const allowToExportData = computed(() => {- if (hasWorkspacePermissionV2("bb.policies.update")) {- return true;- }-return props.sqlResultSet?.allowExport || false;});