Skip to content

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

chore(sql-editor): prevent accidentally triggering the browsers go back gesture in SQL editor's result data table (#13625)

Liu Jia334dd6d1551
diff --git a/frontend/src/utils/dom.ts b/frontend/src/utils/dom.ts
index ceb6817ef2..5f0184bcf1 100644
--- a/frontend/src/utils/dom.ts
+++ b/frontend/src/utils/dom.ts
@@ -1,3 +1,5 @@
+import { onBeforeUnmount, onMounted, unref, type Ref } from "vue";
+
export const isDescendantOf = (
node: Element | null | undefined,
selector: string
@@ -41,3 +43,36 @@ export const getScrollParent = (
export const nextAnimationFrame = () => {
return new Promise<number>((resolve) => requestAnimationFrame(resolve));
};
+
+export const usePreventBackAndForward = (
+ elemRef: Ref<HTMLElement | null | undefined> | HTMLElement = document.body
+) => {
+ const preventBackForward = (elem: HTMLElement) => {
+ function handleWheel(e: WheelEvent) {
+ const maxX = elem.scrollWidth - elem.clientWidth;
+ const scrollTarget = elem.scrollLeft + e.deltaX;
+ if (scrollTarget < 0 || scrollTarget > maxX) {
+ e.preventDefault();
+ }
+ }
+
+ elem.addEventListener("wheel", handleWheel, {
+ passive: false,
+ });
+
+ return () => {
+ elem.removeEventListener("wheel", handleWheel);
+ };
+ };
+
+ let unregister: () => void;
+ onMounted(() => {
+ const elem = unref(elemRef);
+ if (!elem) return;
+ unregister = preventBackForward(elem);
+ });
+
+ onBeforeUnmount(() => {
+ unregister && unregister();
+ });
+};
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 4da0726bf1..45e4aa0ec8 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
@@ -107,14 +107,18 @@
<script lang="ts" setup>
import type { Table } from "@tanstack/vue-table";
import { computed, nextTick, ref, watch } from "vue";
+import {
+ FeatureBadge,
+ FeatureBadgeForInstanceLicense,
+} from "@/components/FeatureGuard";
import { useSubscriptionV1Store } from "@/store";
import type { QueryRow, RowValue } from "@/types/proto/v1/sql_service";
+import { usePreventBackAndForward } from "@/utils";
import { useSQLResultViewContext } from "../context";
import ColumnSortedIcon from "./ColumnSortedIcon.vue";
import SensitiveDataIcon from "./SensitiveDataIcon.vue";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
-import { FeatureBadge, FeatureBadgeForInstanceLicense } from "@/components/FeatureGuard";
export type DataTableColumn = {
key: string;
@@ -133,6 +137,8 @@ const scrollerRef = ref<HTMLDivElement>();
const tableRef = ref<HTMLTableElement>();
const subscriptionStore = useSubscriptionV1Store();
+usePreventBackAndForward(scrollerRef);
+
const tableResize = useTableColumnWidthLogic({
tableRef,
scrollerRef,
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 72525b8f82..c317e30ea6 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"
+ class="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
@@ -34,7 +34,9 @@
<span class="ml-2">{{ $t("sql-editor.rows-upper-limit") }}</span>
</span>
</div>
- <div class="flex justify-between items-center gap-x-3 overflow-y-hidden">
+ <div
+ class="flex justify-between items-center shrink-0 gap-x-3 overflow-y-hidden hide-scrollbar"
+ >
<div class="flex items-center">
<NSwitch v-model:value="state.vertical" size="small" />
<span class="ml-1 whitespace-nowrap text-sm text-gray-500">
@@ -47,7 +49,7 @@
:item-count="table.getCoreRowModel().rows.length"
:page="pageIndex + 1"
:page-size="pageSize"
- class="pagination"
+ class="pagination whitespace-nowrap"
style="--n-input-width: 2.5rem"
@update-page="handleChangePage"
>