Skip to content

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

chore: support vertical display query results (#10417)

ecmadao82c6ffb6948a
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 010c43534b..2b8a035c80 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2207,6 +2207,7 @@
"notify-invalid-sql-statement": "Invalid SQL statement.",
"can-not-execute-query": "Cannot execute query when loading data.",
"rows": "row | rows",
+ "vertical-display": "Vertical display",
"no-history-found": "No history found",
"no-sheet-found": "No sheet found",
"search-history": "Search History",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 29be4da1cd..87b1a8cd83 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2203,6 +2203,7 @@
"notify-invalid-sql-statement": "Declaración SQL inválida.",
"can-not-execute-query": "No se puede ejecutar la consulta al cargar datos.",
"rows": "fila | filas",
+ "vertical-display": "Pantalla vertical",
"no-history-found": "No se encontró historial",
"no-sheet-found": "No se encontró hoja",
"search-history": "Historial de búsqueda",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index dc3c392e4b..08d7591de5 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2205,6 +2205,7 @@
"notify-invalid-sql-statement": "無効なSQLステートメントです",
"can-not-execute-query": "データを読み込んでいるときにクエリを実行できません",
"rows": "行 | 行",
+ "vertical-display": "縦型表示",
"no-history-found": "履歴が見つかりません",
"no-sheet-found": "シートが見つかりません",
"search-history": "履歴を検索",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index e6fd394250..359abc0a4f 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2202,6 +2202,7 @@
"goto-edit-schema-hint": "请从编辑器顶部选择一个数据库连接",
"can-not-execute-query": "加载数据时无法执行查询",
"rows": "条记录",
+ "vertical-display": "竖向展示",
"no-history-found": "暂无历史记录",
"no-sheet-found": "暂无工作表",
"search-history": "搜索历史记录",
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
new file mode 100644
index 0000000000..454fd45de1
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
@@ -0,0 +1,83 @@
+<template>
+ <div class="space-y-5 m-2">
+ <div
+ v-for="(row, rowIndex) of rows"
+ :key="`rows-${rowIndex + offset}`"
+ class="font-mono"
+ >
+ <p
+ class="font-medium text-gray-500 dark:text-gray-300 overflow-hidden whitespace-nowrap"
+ >
+ ******************************** {{ rowIndex + offset + 1 }}. row
+ ********************************
+ </p>
+ <div class="space-y-2 py-2 px-3 bg-gray-50 dark:bg-gray-700 rounded-sm">
+ <div
+ v-for="header in table.getFlatHeaders()"
+ :key="header.index"
+ class="flex items-center text-gray-500 dark:text-gray-300 text-sm"
+ >
+ <div class="w-28 text-left flex items-center font-medium">
+ {{ header.column.columnDef.header }}
+ <SensitiveDataIcon
+ v-if="isSensitiveColumn(header.index)"
+ class="ml-0.5 shrink-0"
+ />
+ <template v-else-if="isColumnMissingSensitive(header.index)">
+ <FeatureBadgeForInstanceLicense
+ v-if="hasSensitiveFeature"
+ :show="true"
+ custom-class="ml-0.5 shrink-0"
+ feature="bb.feature.sensitive-data"
+ />
+ <FeatureBadge
+ v-else
+ feature="bb.feature.sensitive-data"
+ custom-class="ml-0.5 shrink-0"
+ />
+ </template>
+ :
+ </div>
+ <div class="flex-1">
+ <TableCell
+ :value="row.getVisibleCells()[header.index].getValue()"
+ :keyword="keyword"
+ :set-index="setIndex"
+ :row-index="offset + rowIndex"
+ :col-index="header.index"
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div v-if="rows.length === 0" class="text-center w-full my-12 textinfolabel">
+ {{ $t("sql-editor.no-rows-found") }}
+ </div>
+</template>
+
+<script setup lang="ts">
+import { Table } from "@tanstack/vue-table";
+import { computed } from "vue";
+import { useSubscriptionV1Store } from "@/store";
+import SensitiveDataIcon from "./DataTable/SensitiveDataIcon.vue";
+import TableCell from "./DataTable/TableCell.vue";
+import { useSQLResultViewContext } from "./context";
+
+const props = defineProps<{
+ table: Table<string[]>;
+ setIndex: number;
+ offset: number;
+ isSensitiveColumn: (index: number) => boolean;
+ isColumnMissingSensitive: (index: number) => boolean;
+}>();
+
+const { keyword } = useSQLResultViewContext();
+const subscriptionStore = useSubscriptionV1Store();
+
+const rows = computed(() => props.table.getRowModel().rows);
+
+const hasSensitiveFeature = computed(() => {
+ return subscriptionStore.hasFeature("bb.feature.sensitive-data");
+});
+</script>
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 0bbd8a273e..45833d3220 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
@@ -10,7 +10,7 @@
<div
ref="scrollerRef"
class="inner-wrapper max-h-full w-full overflow-auto border-y border-r border-block-border fix-scrollbar-z-index"
- :class="data.length === 0 && 'border-b-0 border-r-0'"
+ :class="rows.length === 0 && 'border-b-0 border-r-0'"
>
<table
ref="tableRef"
@@ -71,7 +71,7 @@
</thead>
<tbody>
<tr
- v-for="(row, rowIndex) of table.getRowModel().rows"
+ v-for="(row, rowIndex) of rows"
:key="rowIndex"
class="group"
:data-row-index="offset + rowIndex"
@@ -94,7 +94,7 @@
</tbody>
</table>
<div
- v-if="data.length === 0"
+ v-if="rows.length === 0"
class="text-center w-full my-12 textinfolabel"
>
{{ $t("sql-editor.no-rows-found") }}
@@ -105,8 +105,8 @@
</template>
<script lang="ts" setup>
-import { ColumnDef, Table } from "@tanstack/vue-table";
-import { computed, nextTick, PropType, ref, watch } from "vue";
+import { Table } from "@tanstack/vue-table";
+import { computed, nextTick, ref, watch } from "vue";
import { useSubscriptionV1Store } from "@/store";
import { useSQLResultViewContext } from "../context";
import ColumnSortedIcon from "./ColumnSortedIcon.vue";
@@ -119,36 +119,13 @@ export type DataTableColumn = {
title: string;
};
-const props = defineProps({
- data: {
- type: Array as PropType<string[][]>,
- default: () => [],
- },
- columns: {
- type: Array as PropType<ColumnDef<string[]>[]>,
- default: () => [],
- },
- sensitive: {
- type: Array as PropType<boolean[]>,
- default: () => [],
- },
- masked: {
- type: Array as PropType<boolean[]>,
- default: () => [],
- },
- table: {
- type: Object as PropType<Table<string[]>>,
- required: true,
- },
- setIndex: {
- type: Number,
- default: 0,
- },
- offset: {
- type: Number,
- default: 0,
- },
-});
+const props = defineProps<{
+ table: Table<string[]>;
+ setIndex: number;
+ offset: number;
+ isSensitiveColumn: (index: number) => boolean;
+ isColumnMissingSensitive: (index: number) => boolean;
+}>();
const scrollerRef = ref<HTMLDivElement>();
const tableRef = ref<HTMLTableElement>();
@@ -161,27 +138,24 @@ const tableResize = useTableColumnWidthLogic({
maxWidth: 640, // 40rem
});
-const data = computed(() => props.data);
const { keyword } = useSQLResultViewContext();
const hasSensitiveFeature = computed(() => {
return subscriptionStore.hasFeature("bb.feature.sensitive-data");
});
-const isSensitiveColumn = (index: number): boolean => {
- return props.masked[index] ?? false;
-};
-
-const isColumnMissingSensitive = (index: number): boolean => {
- return (props.sensitive[index] ?? false) && !isSensitiveColumn(index);
-};
-
const scrollTo = (x: number, y: number) => {
scrollerRef.value?.scroll(x, y);
};
+const rows = computed(() => props.table.getRowModel().rows);
+
watch(
- () => props.columns.map((col) => col.header).join("|"),
+ () =>
+ props.table
+ .getFlatHeaders()
+ .map((header) => String(header.column.columnDef.header))
+ .join("|"),
() => {
nextTick(() => {
// Re-calculate the column widths once the column definition changed.
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index ff4b5a4017..234be90321 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -29,6 +29,12 @@
</span>
</div>
<div class="flex justify-between items-center gap-x-3 overflow-y-hidden">
+ <div class="flex items-center">
+ <NSwitch v-model:value="state.vertical" size="small" />
+ <span class="ml-1 whitespace-nowrap text-sm text-gray-500">
+ {{ $t("sql-editor.vertical-display") }}
+ </span>
+ </div>
<NPagination
v-if="showPagination"
:simple="true"
@@ -87,14 +93,21 @@
</div>
<div class="flex-1 w-full flex flex-col overflow-y-auto">
+ <DataBlock
+ v-if="state.vertical"
+ :table="table"
+ :set-index="setIndex"
+ :offset="pageIndex * pageSize"
+ :is-sensitive-column="isSensitiveColumn"
+ :is-column-missing-sensitive="isColumnMissingSensitive"
+ />
<DataTable
+ v-else
:table="table"
- :columns="columns"
- :data="data"
- :masked="props.result.masked"
- :sensitive="props.result.sensitive"
:set-index="setIndex"
:offset="pageIndex * pageSize"
+ :is-sensitive-column="isSensitiveColumn"
+ :is-column-missing-sensitive="isColumnMissingSensitive"
/>
</div>
@@ -145,7 +158,7 @@ import {
} from "@tanstack/vue-table";
import { useDebounceFn } from "@vueuse/core";
import { isEmpty } from "lodash-es";
-import { NInput, NPagination, NTooltip } from "naive-ui";
+import { NInput, NSwitch, NPagination, NTooltip } from "naive-ui";
import { BinaryLike } from "node:crypto";
import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
@@ -180,6 +193,7 @@ import {
instanceV1HasStructuredQueryResult,
} from "@/utils";
import { customTheme } from "@/utils/customTheme";
+import DataBlock from "./DataBlock.vue";
import DataTable from "./DataTable";
import EmptyView from "./EmptyView.vue";
import ErrorView from "./ErrorView.vue";
@@ -187,6 +201,7 @@ import { useSQLResultViewContext } from "./context";
type LocalState = {
search: string;
+ vertical: boolean;
showRequestExportPanel: boolean;
};
type ViewMode = "RESULT" | "EMPTY" | "AFFECTED-ROWS" | "ERROR";
@@ -207,6 +222,7 @@ const props = defineProps<{
const state = reactive<LocalState>({
search: "",
+ vertical: false,
showRequestExportPanel: false,
});
@@ -311,6 +327,17 @@ const data = computed(() => {
return temp;
});
+const isSensitiveColumn = (columnIndex: number): boolean => {
+ return props.result.masked[columnIndex] ?? false;
+};
+
+const isColumnMissingSensitive = (columnIndex: number): boolean => {
+ return (
+ (props.result.sensitive[columnIndex] ?? false) &&
+ !isSensitiveColumn(columnIndex)
+ );
+};
+
const table = useVueTable<string[]>({
get data() {
return data.value;