Skip to content

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

feat: move paging control to the top toolbar (#4611)

Liu Ji615b3d774696
diff --git a/frontend/src/views/sql-editor/EditorCommon/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/DataTable.vue
index ef351f4167..8c55f5c8f9 100644
--- a/frontend/src/views/sql-editor/EditorCommon/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/DataTable.vue
@@ -1,8 +1,8 @@
<template>
<div
- class="bb-data-table relative w-full h-full overflow-hidden flex flex-col"
+ class="bb-data-table relative w-full flex-1 overflow-hidden flex flex-col"
>
- <div class="w-full flex-1 overflow-hidden">
+ <div class="w-full flex-1 flex flex-col overflow-hidden">
<div
class="header-track absolute z-0 left-0 top-0 right-0 h-[34px] border border-block-border bg-gray-50 dark:bg-gray-700"
/>
@@ -60,31 +60,12 @@
</div>
</div>
</div>
-
- <div v-if="showPagination" class="flex justify-end pt-2">
- <NPagination
- :item-count="table.getCoreRowModel().rows.length"
- :page="table.getState().pagination.pageIndex + 1"
- :page-size="table.getState().pagination.pageSize"
- :show-quick-jumper="true"
- :show-size-picker="true"
- :page-sizes="[20, 50, 100]"
- @update-page="handleChangePage"
- @update-page-size="(ps) => table.setPageSize(ps)"
- />
- </div>
</div>
</template>
<script lang="ts" setup>
import { computed, nextTick, PropType, ref, watch } from "vue";
-import {
- getCoreRowModel,
- useVueTable,
- getPaginationRowModel,
- ColumnDef,
-} from "@tanstack/vue-table";
-import { NPagination } from "naive-ui";
+import { ColumnDef, Table } from "@tanstack/vue-table";
import useTableColumnWidthLogic from "./useTableResize";
export type DataTableColumn = {
@@ -92,18 +73,19 @@ export type DataTableColumn = {
title: string;
};
-const PAGE_SIZES = [20, 50, 100];
-const DEFAULT_PAGE_SIZE = 50;
-
const props = defineProps({
data: {
type: Array as PropType<string[][]>,
default: () => [],
},
columns: {
- type: Array as PropType<DataTableColumn[]>,
+ type: Array as PropType<ColumnDef<string[]>[]>,
default: () => [],
},
+ table: {
+ type: Object as PropType<Table<string[]>>,
+ required: true,
+ },
});
const scrollerRef = ref<HTMLDivElement>();
@@ -117,42 +99,22 @@ const tableResize = useTableColumnWidthLogic({
});
const data = computed(() => props.data);
-const columns = computed(() =>
- props.columns.map<ColumnDef<string[]>>((col, index) => ({
- id: `${col.key}@${index}`,
- accessorFn: (item) => item[index],
- header: col.title,
- }))
-);
-const table = useVueTable<string[]>({
- get data() {
- return data.value;
- },
- get columns() {
- return columns.value;
- },
- getCoreRowModel: getCoreRowModel(),
- getPaginationRowModel: getPaginationRowModel(),
-});
-
-table.setPageSize(DEFAULT_PAGE_SIZE);
-const showPagination = computed(() => props.data.length > PAGE_SIZES[0]);
-
-const handleChangePage = (page: number) => {
- table.setPageIndex(page - 1);
- scrollerRef.value?.scrollTo(0, 0);
+const scrollTo = (x: number, y: number) => {
+ scrollerRef.value?.scroll(x, y);
};
watch(
- () => props.columns.map((col) => col.title).join("|"),
+ () => props.columns.map((col) => col.header).join("|"),
() => {
nextTick(() => {
// Re-calculate the column widths once the column definition changed.
- scrollerRef.value?.scrollTo(0, 0);
+ scrollTo(0, 0);
tableResize.reset();
});
},
{ immediate: true }
);
+
+defineExpose({ scrollTo });
</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/TableView.vue b/frontend/src/views/sql-editor/EditorCommon/TableView.vue
index 5e1837f8ae..c585e61893 100644
--- a/frontend/src/views/sql-editor/EditorCommon/TableView.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/TableView.vue
@@ -1,7 +1,7 @@
<template>
<NConfigProvider
v-bind="naiveUIConfig"
- class="relative flex flex-col justify-start items-start h-full p-2"
+ class="relative flex flex-col justify-start items-start p-2"
:class="dark && 'dark bg-dark-bg'"
>
<div
@@ -32,6 +32,17 @@
</span>
</div>
<div class="flex justify-between items-center gap-x-3">
+ <NPagination
+ v-if="showPagination"
+ :item-count="table.getCoreRowModel().rows.length"
+ :page="table.getState().pagination.pageIndex + 1"
+ :page-size="table.getState().pagination.pageSize"
+ :show-quick-jumper="true"
+ :show-size-picker="true"
+ :page-sizes="[20, 50, 100]"
+ @update-page="handleChangePage"
+ @update-page-size="(ps) => table.setPageSize(ps)"
+ />
<NButton
v-if="showVisualizeButton"
text
@@ -55,7 +66,15 @@
</div>
</div>
- <DataTable v-show="!showPlaceholder" :columns="columns" :data="data" />
+ <div class="flex-1 w-full flex flex-col overflow-y-auto">
+ <DataTable
+ v-show="!showPlaceholder"
+ ref="dataTable"
+ :table="table"
+ :columns="columns"
+ :data="data"
+ />
+ </div>
<div
v-if="showPlaceholder"
@@ -74,19 +93,25 @@
</template>
<script lang="ts" setup>
-import { computed, PropType, reactive } from "vue";
+import { computed, PropType, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { debouncedRef } from "@vueuse/core";
import { unparse } from "papaparse";
import { isEmpty } from "lodash-es";
import dayjs from "dayjs";
-import { darkTheme, NConfigProvider } from "naive-ui";
+import { darkTheme, NConfigProvider, NPagination } from "naive-ui";
import { darkThemeOverrides } from "@/../naive-ui.config";
import { useTabStore, useInstanceStore } from "@/store";
import { createExplainToken } from "@/utils";
import DataTable from "./DataTable.vue";
import { RESULT_ROWS_LIMIT } from "@/store";
+import {
+ ColumnDef,
+ getCoreRowModel,
+ getPaginationRowModel,
+ useVueTable,
+} from "@tanstack/vue-table";
interface State {
search: string;
@@ -109,6 +134,9 @@ const props = defineProps({
},
});
+const PAGE_SIZES = [20, 50, 100];
+const DEFAULT_PAGE_SIZE = 50;
+
const { t } = useI18n();
const tabStore = useTabStore();
const instanceStore = useInstanceStore();
@@ -117,6 +145,8 @@ const state = reactive<State>({
search: "",
});
+const dataTable = ref<InstanceType<typeof DataTable>>();
+
const showSearchFeature = computed(() => {
const instance = instanceStore.getInstanceById(
tabStore.currentTab.connection.instanceId
@@ -141,14 +171,12 @@ const columns = computed(() => {
if (!props.queryResult) {
return [];
}
-
const columns = props.queryResult[0];
- return columns.map((d) => {
- return {
- title: d,
- key: d,
- };
- });
+ return columns.map<ColumnDef<string[]>>((col, index) => ({
+ id: `${col}@${index}`,
+ accessorFn: (item) => item[index],
+ header: col,
+ }));
});
const data = computed(() => {
@@ -167,6 +195,19 @@ const data = computed(() => {
return temp;
});
+const table = useVueTable<string[]>({
+ get data() {
+ return data.value;
+ },
+ get columns() {
+ return columns.value;
+ },
+ getCoreRowModel: getCoreRowModel(),
+ getPaginationRowModel: getPaginationRowModel(),
+});
+
+table.setPageSize(DEFAULT_PAGE_SIZE);
+
const showPlaceholder = computed(() => {
if (!props.queryResult) return true;
if (props.loading) return true;
@@ -190,7 +231,7 @@ const handleExportBtnClick = (format: "csv" | "json") => {
let rawText = "";
if (format === "csv") {
- const csvFields = columns.value.map((item) => item.key);
+ const csvFields = columns.value.map((col) => col.header as string);
const csvData = data.value.map((d) => {
const temp: any[] = [];
for (const k in d) {
@@ -246,4 +287,11 @@ const visualizeExplain = () => {
// nothing
}
};
+
+const showPagination = computed(() => data.value.length > PAGE_SIZES[0]);
+
+const handleChangePage = (page: number) => {
+ table.setPageIndex(page - 1);
+ dataTable.value?.scrollTo(0, 0);
+};
</script>
diff --git a/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue
index d4f9f9af21..1291e47b4a 100644
--- a/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue
+++ b/frontend/src/views/sql-editor/TerminalPanel/TerminalPanel.vue
@@ -25,8 +25,9 @@
@history="handleHistory"
@clear-screen="handleClearScreen"
/>
- <div v-if="query.queryResult" class="max-h-[20rem] overflow-y-auto">
+ <div v-if="query.queryResult" class="max-h-[20rem] flex flex-col">
<TableView
+ class="flex-1 overflow-hidden"
:query-result="query.queryResult.data"
:loading="query.status === 'RUNNING'"
:dark="true"