Skip to content

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

chore(sql-editor): update data table select actions (#15044)

boojacke3927d5d9d1e
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
index 2d2607bd71..23daba7ce8 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
@@ -20,21 +20,18 @@
:key="header.index"
class="group relative px-2 py-2 min-w-[2rem] text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-x border-block-border dark:border-zinc-500"
:class="{
+ 'cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800':
+ !selectionDisabled,
'!bg-accent/10 dark:!bg-accent/40':
selectionState.rows.length === 0 &&
selectionState.columns.includes(header.index),
+ 'pl-3': header.index === 0,
}"
v-bind="tableResize.getColumnProps(header.index)"
+ @click.stop="selectColumn(header.index)"
>
<div class="flex items-center overflow-hidden">
- <span
- class="flex flex-row items-center select-none"
- :class="{
- 'cursor-pointer hover:text-accent dark:hover:text-gray-500':
- !selectionDisabled,
- }"
- @click.stop="selectColumn(header.index)"
- >
+ <span class="flex flex-row items-center select-none">
<template
v-if="String(header.column.columnDef.header).length > 0"
>
@@ -101,11 +98,9 @@
:allow-select="true"
/>
<div
- v-if="cellIndex === 0"
- class="absolute inset-y-0 left-0 w-2"
+ v-if="cellIndex === 0 && !selectionDisabled"
+ class="absolute inset-y-0 left-0 w-3 cursor-pointer hover:bg-accent/10 dark:hover:bg-accent/40"
: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),
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 35e9e3dc13..6b6e24e6a2 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
@@ -29,8 +29,9 @@
<script setup lang="ts">
import { type Table } from "@tanstack/vue-table";
import { useResizeObserver } from "@vueuse/core";
-import { escape, uniq } from "lodash-es";
+import { escape } from "lodash-es";
import { NButton } from "naive-ui";
+import { twMerge } from "tailwind-merge";
import { computed, ref } from "vue";
import { useConnectionOfCurrentSQLEditorTab } from "@/store";
import { Engine } from "@/types/proto/v1/common";
@@ -48,12 +49,13 @@ const props = defineProps<{
allowSelect?: boolean;
}>();
-const { dark, detail, keyword } = useSQLResultViewContext();
+const { detail, keyword } = useSQLResultViewContext();
const {
state: selectionState,
disabled: selectionDisabled,
selectCell,
+ selectRow,
} = useSelectionContext();
const wrapperRef = ref<HTMLDivElement>();
const truncated = ref(false);
@@ -91,7 +93,10 @@ const classes = computed(() => {
const classes: string[] = [];
if (allowSelect.value) {
classes.push("cursor-pointer");
- classes.push(dark.value ? "hover:bg-white/20" : "hover:bg-black/5");
+ classes.push("hover:bg-white/20 dark:hover:bg-black/5");
+ if (props.colIndex === 0) {
+ classes.push("pl-3");
+ }
if (
selectionState.value.columns.length === 1 &&
selectionState.value.rows.length === 1
@@ -112,7 +117,7 @@ const classes = computed(() => {
} else {
classes.push("select-none");
}
- return uniq(classes);
+ return twMerge(classes);
});
const html = computed(() => {
@@ -144,7 +149,12 @@ const handleClick = (e: MouseEvent) => {
if (!allowSelect.value) {
return;
}
- selectCell(props.rowIndex, props.colIndex);
+ // If the user is holding the ctrl/cmd key, select the row.
+ if (e.ctrlKey || e.metaKey) {
+ selectRow(props.rowIndex);
+ } else {
+ selectCell(props.rowIndex, props.colIndex);
+ }
e.stopPropagation();
};
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 3bbf45e868..65511c8512 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
@@ -219,6 +219,11 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {
if (disabled.value) return;
if (state.value.columns.length === 0 && state.value.rows.length === 0)
return;
+ // Deselect all when escape is pressed.
+ if (e.key === "Escape") {
+ deselect();
+ }
+ // Copy when Cmd/Ctrl + C is pressed.
if ((e.key === "c" || e.key === "C") && (e.metaKey || e.ctrlKey)) {
const copied = copy();
if (copied) {
@@ -229,7 +234,6 @@ export const provideSelectionContext = (table: Ref<Table<QueryRow>>) => {
style: "SUCCESS",
title: t("common.copied"),
});
- deselect();
}
}
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue
index 0b25d83eeb..dc879e29f5 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SelectionCopyTooltips.vue
@@ -45,7 +45,7 @@ import { pushNotification } from "@/store";
import { useSelectionContext } from "./DataTable/common/selection-logic";
const { t } = useI18n();
-const { state: selectionState, copy, deselect } = useSelectionContext();
+const { state: selectionState, copy } = useSelectionContext();
const shouldShow = computed(
() =>
@@ -65,6 +65,5 @@ const copySelection = () => {
style: "SUCCESS",
title: t("common.copied"),
});
- deselect();
};
</script>