Skip to content

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

chore: use table model (#10514)

Liu Jid70895176815
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
index 454fd45de1..2373adb599 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
@@ -40,6 +40,7 @@
</div>
<div class="flex-1">
<TableCell
+ :table="table"
:value="row.getVisibleCells()[header.index].getValue()"
:keyword="keyword"
:set-index="setIndex"
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 45833d3220..a4c896e3d3 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
@@ -83,6 +83,7 @@
:data-col-index="cellIndex"
>
<TableCell
+ :table="table"
:value="cell.getValue()"
:keyword="keyword"
:set-index="setIndex"
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 cd6eee5767..06daf4d727 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
@@ -22,6 +22,7 @@
</template>
<script setup lang="ts">
+import { type Table } from "@tanstack/vue-table";
import { useResizeObserver } from "@vueuse/core";
import { escape } from "lodash-es";
import { NButton } from "naive-ui";
@@ -32,6 +33,7 @@ import { getHighlightHTMLByRegExp } from "@/utils";
import { useSQLResultViewContext } from "../context";
const props = defineProps<{
+ table: Table<string[]>;
value: unknown;
setIndex: number;
rowIndex: number;
@@ -116,6 +118,7 @@ const showDetail = () => {
set: props.setIndex,
row: props.rowIndex,
col: props.colIndex,
+ table: props.table,
};
};
</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue
index d67e628332..38732a5816 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue
@@ -76,44 +76,38 @@
<script setup lang="ts">
import { onKeyStroke, useClipboard } from "@vueuse/core";
-import { escape, get } from "lodash-es";
+import { escape } from "lodash-es";
import { ChevronDownIcon, ChevronUpIcon, ClipboardIcon } from "lucide-vue-next";
import { NButton, NTooltip } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { DrawerContent } from "@/components/v2";
import { pushNotification } from "@/store";
-import { SQLResultSetV1 } from "@/types";
-import { QueryResult, RowValue } from "@/types/proto/v1/sql_service";
-import { extractSQLRowValue } from "@/utils";
import { useSQLResultViewContext } from "./context";
-const props = defineProps<{
- resultSet?: SQLResultSetV1;
-}>();
-
const { t } = useI18n();
const { dark, detail, disallowCopyingData } = useSQLResultViewContext();
-const value = computed(() => {
- const { resultSet } = props;
- const { set, row, col } = detail.value;
- const cell: RowValue =
- get(resultSet, `results.${set}.rows.${row}.values.${col}`) ??
- RowValue.fromJSON({});
- return extractSQLRowValue(cell);
+const detailValue = computed(() => {
+ const { row, col, table } = detail.value;
+ if (!table) return undefined;
+
+ const value = table
+ .getPrePaginationRowModel()
+ .rows[row]?.getVisibleCells()
+ [col]?.getValue<string>();
+ return value;
});
const totalCount = computed(() => {
- const result: QueryResult =
- get(props.resultSet, `results.${detail.value.set}`) ??
- QueryResult.fromJSON({});
- return result.rows.length;
+ const { table } = detail.value;
+ if (!table) return 0;
+ return table.getPrePaginationRowModel().rows.length;
});
const html = computed(() => {
- const str = String(value.value);
- if (str.length === 0) {
+ const str = detailValue.value;
+ if (!str || str.length === 0) {
return `<br style="min-width: 1rem; display: inline-flex;" />`;
}
@@ -122,7 +116,7 @@ const html = computed(() => {
const { copy, copied } = useClipboard({
source: computed(() => {
- return String(value.value);
+ return detailValue.value ?? "";
}),
});
const handleCopy = () => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index 157dda9c0d..76ded22af3 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -71,7 +71,7 @@
</div>
<Drawer v-model:show="detail.show" @close="detail.show = false">
- <DetailPanel v-if="detail.show" :result-set="resultSet" />
+ <DetailPanel v-if="detail.show" />
</Drawer>
</NConfigProvider>
</template>
@@ -139,6 +139,7 @@ const detail: SQLResultViewContext["detail"] = ref({
set: 0,
row: 0,
col: 0,
+ table: undefined,
});
const viewMode = computed((): ViewMode => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/context.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/context.ts
index 4228694a21..a543a5a43f 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/context.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/context.ts
@@ -1,3 +1,4 @@
+import { type Table } from "@tanstack/vue-table";
import { type Ref, type InjectionKey, provide, inject } from "vue";
export type SQLResultViewContext = {
@@ -9,6 +10,7 @@ export type SQLResultViewContext = {
set: number; // The index of selected result set.
row: number; // The row index of selected record.
col: number; // The column index of selected cell.
+ table: Table<string[]> | undefined;
}>;
};