Skip to content

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

feat(sql-editor): formatted view for JSON fields (#14525)

Liu Jiace397250bb9
diff --git a/frontend/package.json b/frontend/package.json
index e1dfb487ba..98b476c573 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -63,6 +63,7 @@
"pinia": "2.1.7",
"pouchdb": "^9.0.0",
"pouchdb-find": "^9.0.0",
+ "pretty-print-json": "^3.0.3",
"qrcode": "^1.5.4",
"qs": "6.13.0",
"rxjs": "^7.8.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 45d352439e..ebc7b99794 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -139,6 +139,9 @@ importers:
pouchdb-find:
specifier: ^9.0.0
version: 9.0.0
+ pretty-print-json:
+ specifier: ^3.0.3
+ version: 3.0.3
qrcode:
specifier: ^1.5.4
version: 1.5.4
@@ -3378,6 +3381,9 @@ packages:
engines: {node: '>=14'}
hasBin: true
+ resolution: {integrity: sha512-uIL9/fr5dGV80BDrbN9HWBegwyuN0hCOHA+3EsysnusuQDlhBu6w7dPNm+hBCRiL7Up0jwfGgPX3Ngu/iQ0a8A==}
+
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
@@ -7585,6 +7591,8 @@ snapshots:
+
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index e25d3f8148..cfacac37af 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -295,7 +295,8 @@
"encoding": "Encoding",
"finish": "Finish",
"title": "Title",
- "hide": "Hide"
+ "hide": "Hide",
+ "text-wrap": "Text wrap"
},
"error-page": {
"go-back-home": "Go back home"
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 8e0cab0879..ee6b4f2536 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -295,7 +295,8 @@
"encoding": "Codificación",
"finish": "Finalizar",
"title": "Título",
- "hide": "Esconder"
+ "hide": "Esconder",
+ "text-wrap": "Ajuste de texto"
},
"error-page": {
"go-back-home": "Volver al inicio"
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index fcd8027aea..4757e02c61 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -295,7 +295,8 @@
"encoding": "エンコーディング",
"finish": "仕上げる",
"title": "タイトル",
- "hide": "隠れる"
+ "hide": "隠れる",
+ "text-wrap": "テキストの折り返し"
},
"error-page": {
"go-back-home": "ホームページに戻る"
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index ec7fe3e220..fc565ec196 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -295,7 +295,8 @@
"encoding": "编码",
"finish": "完成",
"title": "标题",
- "hide": "隐藏"
+ "hide": "隐藏",
+ "text-wrap": "文本折行"
},
"error-page": {
"go-back-home": "回到主页"
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
index f30b0bc992..2b0ae4cbbd 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataBlock.vue
@@ -68,8 +68,8 @@ import {
} from "@/components/FeatureGuard";
import { useSubscriptionV1Store } from "@/store";
import type { QueryRow, RowValue } from "@/types/proto/v1/sql_service";
-import SensitiveDataIcon from "./DataTable/SensitiveDataIcon.vue";
-import TableCell from "./DataTable/TableCell.vue";
+import TableCell from "./DataTable/DataTable/TableCell.vue";
+import SensitiveDataIcon from "./DataTable/common/SensitiveDataIcon.vue";
import { useSQLResultViewContext } from "./context";
const props = defineProps<{
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/ColumnSortedIcon.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/ColumnSortedIcon.vue
deleted file mode 100644
index 8b6dece5d9..0000000000
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/ColumnSortedIcon.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-<template>
- <span class="w-4 h-auto opacity-80 ml-1">
- <ArrowDownWideNarrow
- v-if="!isSorted || isSorted === 'desc'"
- class="w-full h-auto"
- :class="[isSorted ? 'text-accent' : 'text-gray-300']"
- />
- <ArrowUpWideNarrow v-else class="w-full h-auto text-accent" />
- </span>
-</template>
-
-<script lang="ts" setup>
-import type { SortDirection } from "@tanstack/vue-table";
-import { ArrowUpWideNarrow, ArrowDownWideNarrow } from "lucide-vue-next";
-
-defineProps<{
- isSorted: false | SortDirection;
-}>();
-</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
similarity index 97%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
index f46045b4ad..a719858fe6 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/DataTable.vue
@@ -133,9 +133,9 @@ import {
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 { useSQLResultViewContext } from "../../context";
+import ColumnSortedIcon from "../common/ColumnSortedIcon.vue";
+import SensitiveDataIcon from "../common/SensitiveDataIcon.vue";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/TableCell.vue
similarity index 98%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/TableCell.vue
index 5ec3a1ac75..2f626fbcb2 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/TableCell.vue
@@ -31,7 +31,7 @@ import { useConnectionOfCurrentSQLEditorTab } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import type { QueryRow, RowValue } from "@/types/proto/v1/sql_service";
import { extractSQLRowValue, getHighlightHTMLByRegExp } from "@/utils";
-import { useSQLResultViewContext } from "../context";
+import { useSQLResultViewContext } from "../../context";
const props = defineProps<{
table: Table<QueryRow>;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/index.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/index.ts
new file mode 100644
index 0000000000..5e544303ab
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/index.ts
@@ -0,0 +1,3 @@
+import DataTable from "./DataTable.vue";
+
+export default DataTable;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/useTableResize.ts
similarity index 100%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/useTableResize.ts
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable/useTableResize.ts
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/ColumnHeader.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/ColumnHeader.vue
similarity index 94%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/ColumnHeader.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/ColumnHeader.vue
index 54aa1608da..aa29e0f582 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/ColumnHeader.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/ColumnHeader.vue
@@ -53,8 +53,8 @@ import FeatureBadge from "@/components/FeatureGuard/FeatureBadge.vue";
import FeatureBadgeForInstanceLicense from "@/components/FeatureGuard/FeatureBadgeForInstanceLicense.vue";
import { featureToRef } from "@/store";
import type { QueryRow } from "@/types/proto/v1/sql_service";
-import ColumnSortedIcon from "./ColumnSortedIcon.vue";
-import SensitiveDataIcon from "./SensitiveDataIcon.vue";
+import ColumnSortedIcon from "../common/ColumnSortedIcon.vue";
+import SensitiveDataIcon from "../common/SensitiveDataIcon.vue";
defineProps<{
header: Header<QueryRow, any>;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/DataTableLite.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
similarity index 99%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/DataTableLite.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
index c5b698ee02..9360e86b2a 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/DataTableLite.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/DataTableLite.vue
@@ -56,7 +56,7 @@ import { type DataTableColumn, type DataTableInst, NDataTable } from "naive-ui";
import { computed, h, nextTick, ref, toRef, watch, type StyleValue } from "vue";
import { QueryRow, type RowValue } from "@/types/proto/v1/sql_service";
import { nextAnimationFrame, usePreventBackAndForward } from "@/utils";
-import { useSQLResultViewContext } from "../context";
+import { useSQLResultViewContext } from "../../context";
import ColumnHeader from "./ColumnHeader.vue";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/TableCell.vue
similarity index 98%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/TableCell.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/TableCell.vue
index 145d72e9a8..5c865c49b0 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/TableCell.vue
@@ -35,7 +35,7 @@ import { useConnectionOfCurrentSQLEditorTab } from "@/store";
import { Engine } from "@/types/proto/v1/common";
import type { QueryRow, RowValue } from "@/types/proto/v1/sql_service";
import { extractSQLRowValue, getHighlightHTMLByRegExp } from "@/utils";
-import { useSQLResultViewContext } from "../context";
+import { useSQLResultViewContext } from "../../context";
const props = defineProps<{
table: Table<QueryRow>;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/index.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/index.ts
similarity index 100%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/index.ts
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/index.ts
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/useTableResize.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/useTableResize.ts
similarity index 100%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/useTableResize.ts
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTableLite/useTableResize.ts
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/ColumnSortedIcon.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/ColumnSortedIcon.vue
similarity index 100%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/ColumnSortedIcon.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/ColumnSortedIcon.vue
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/SensitiveDataIcon.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/SensitiveDataIcon.vue
similarity index 100%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/SensitiveDataIcon.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/SensitiveDataIcon.vue
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/index.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/index.ts
index 5e544303ab..ab54e4f8eb 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/index.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/index.ts
@@ -1,3 +1,4 @@
-import DataTable from "./DataTable.vue";
+import DataTable from "./DataTable";
+import DataTableLite from "./DataTableLite";
-export default DataTable;
+export { DataTable, DataTableLite };
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/SensitiveDataIcon.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/SensitiveDataIcon.vue
deleted file mode 100644
index fb6b648d38..0000000000
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTableLite/SensitiveDataIcon.vue
+++ /dev/null
@@ -1,41 +0,0 @@
-<template>
- <NTooltip :animated="false" :delay="250">
- <template #trigger>
- <heroicons-outline:eye-slash
- class="w-[12px] h-[12px] -mb-[2px]"
- :class="[clickable && 'cursor-pointer']"
- v-bind="$attrs"
- @click="handleClick"
- />
- </template>
-
- <span class="whitespace-nowrap">
- {{ $t("sensitive-data.self") }}
- </span>
- </NTooltip>
-</template>
-
-<script lang="ts" setup>
-import { NTooltip } from "naive-ui";
-import { computed } from "vue";
-import { useRouter } from "vue-router";
-import { WORKSPACE_ROUTE_DATA_MASKING } from "@/router/dashboard/workspaceRoutes";
-import { hasWorkspacePermissionV2 } from "@/utils";
-
-const router = useRouter();
-
-const clickable = computed(() => {
- return hasWorkspacePermissionV2("bb.policies.update");
-});
-
-const handleClick = () => {
- if (!clickable.value) {
- return;
- }
- const url = router.resolve({
- name: WORKSPACE_ROUTE_DATA_MASKING,
- hash: "#sensitive-column-list",
- });
- window.open(url.href, "_BLANK");
-};
-</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/DetailPanel.vue
similarity index 53%
rename from frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue
rename to frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/DetailPanel.vue
index 9e82d05ff8..03af0e450d 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/DetailPanel.vue
@@ -55,7 +55,25 @@
</div>
</div>
- <div>
+ <div class="flex items-center gap-1">
+ <NPopover v-if="guessedIsJSON">
+ <template #trigger>
+ <NButton
+ size="small"
+ style="--n-padding: 0 5px"
+ :type="format ? 'primary' : 'default'"
+ :secondary="format"
+ @click="format = !format"
+ >
+ <template #icon>
+ <BracesIcon class="w-4 h-4" />
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ {{ $t("sql-editor.format") }}
+ </template>
+ </NPopover>
<NButton v-if="!disallowCopyingData" size="small" @click="handleCopy">
<template #icon>
<ClipboardIcon class="w-4 h-4" />
@@ -64,33 +82,80 @@
</NButton>
</div>
</div>
- <!-- eslint-disable vue/no-v-html -->
- <div
- class="flex-1 overflow-auto whitespace-pre-wrap text-sm font-mono border p-2"
- :class="disallowCopyingData && 'select-none'"
- v-html="html"
- ></div>
+ <NScrollbar
+ class="flex-1 overflow-hidden text-sm font-mono border p-2 relative"
+ :content-class="contentClass"
+ :x-scrollable="true"
+ trigger="none"
+ >
+ <template v-if="guessedIsJSON && format">
+ <div
+ class="absolute right-2 top-2 flex justify-end items-center gap-1"
+ >
+ <NPopover>
+ <template #trigger>
+ <NButton
+ size="tiny"
+ style="--n-padding: 0 4px"
+ :type="wrap ? 'primary' : 'default'"
+ :secondary="wrap"
+ @click="wrap = !wrap"
+ >
+ <template #icon>
+ <WrapTextIcon class="w-3 h-3" />
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ {{ $t("common.text-wrap") }}
+ </template>
+ </NPopover>
+ </div>
+ <PrettyJSON :content="content ?? ''" />
+ </template>
+ <template v-else>
+ <template v-if="content && content.length > 0">
+ {{ content }}
+ </template>
+ <br v-else style="min-width: 1rem; display: inline-flex" />
+ </template>
+ </NScrollbar>
</div>
</DrawerContent>
</template>
<script setup lang="ts">
-import { onKeyStroke, useClipboard } from "@vueuse/core";
-import { escape } from "lodash-es";
-import { ChevronDownIcon, ChevronUpIcon, ClipboardIcon } from "lucide-vue-next";
-import { NButton, NTooltip } from "naive-ui";
+import { onKeyStroke, useClipboard, useLocalStorage } from "@vueuse/core";
+import {
+ ChevronDownIcon,
+ ChevronUpIcon,
+ ClipboardIcon,
+ BracesIcon,
+ WrapTextIcon,
+} from "lucide-vue-next";
+import { NButton, NPopover, NScrollbar, NTooltip } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { DrawerContent } from "@/components/v2";
import { pushNotification } from "@/store";
import type { RowValue } from "@/types/proto/v1/sql_service";
import { extractSQLRowValue } from "@/utils";
-import { useSQLResultViewContext } from "./context";
+import { useSQLResultViewContext } from "../context";
+import PrettyJSON from "./PrettyJSON.vue";
const { t } = useI18n();
const { dark, detail, disallowCopyingData } = useSQLResultViewContext();
-const detailValueString = computed(() => {
+const format = useLocalStorage<boolean>(
+ "bb.sql-editor.detail-panel.format",
+ false
+);
+const wrap = useLocalStorage<boolean>(
+ "bb.sql-editor.detail-panel.line-wrap",
+ true
+);
+
+const content = computed(() => {
const { row, col, table } = detail.value;
if (!table) return undefined;
@@ -102,24 +167,38 @@ const detailValueString = computed(() => {
return String(extractSQLRowValue(value).plain);
});
+const guessedIsJSON = computed(() => {
+ if (!content.value || content.value.length === 0) return false;
+ const maybeJSON = content.value.trim();
+ return (
+ (maybeJSON.startsWith("{") && maybeJSON.endsWith("}")) ||
+ (maybeJSON.startsWith("[") && maybeJSON.endsWith("]"))
+ );
+});
+
const totalCount = computed(() => {
const { table } = detail.value;
if (!table) return 0;
return table.getPrePaginationRowModel().rows.length;
});
-const html = computed(() => {
- const str = detailValueString.value;
- if (!str || str.length === 0) {
- return `<br style="min-width: 1rem; display: inline-flex;" />`;
- }
+const contentClass = computed(() => {
+ const classes: string[] = [];
- return escape(str);
+ if (disallowCopyingData.value) {
+ classes.push("select-none");
+ }
+ if (guessedIsJSON.value && format.value && !wrap.value) {
+ classes.push("whitespace-pre");
+ } else {
+ classes.push("whitespace-pre-wrap");
+ }
+ return classes.join(" ");
});
const { copy, copied } = useClipboard({
source: computed(() => {
- return detailValueString.value ?? "";
+ return content.value ?? "";
}),
legacy: true,
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/PrettyJSON.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/PrettyJSON.vue
new file mode 100644
index 0000000000..74dc95a116
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/PrettyJSON.vue
@@ -0,0 +1,53 @@
+<template>
+ <!-- eslint-disable-next-line vue/no-v-html -->
+ <div v-html="state.html" />
+</template>
+
+<script setup lang="ts">
+import { escape } from "lodash-es";
+import { shallowReactive, watch } from "vue";
+
+const props = defineProps<{
+ content: string;
+}>();
+
+const state = shallowReactive({
+ html: "",
+ controller: new AbortController(),
+});
+
+watch(
+ () => props.content,
+ async (content) => {
+ if (state.controller) {
+ state.controller.abort();
+ state.controller = new AbortController();
+ }
+ const controller = state.controller;
+ const finish = (html: string) => {
+ if (controller.signal.aborted) {
+ return;
+ }
+ state.html = html;
+ };
+
+ try {
+ const { prettyPrintJson } = await import("pretty-print-json");
+ await import("./pretty-print-json.css");
+ const obj = JSON.parse(content);
+ const html = prettyPrintJson.toHtml(obj, {
+ quoteKeys: true,
+ trailingCommas: false,
+ });
+ finish(html);
+ } catch (err) {
+ console.warn("[PrettyJSON]", err);
+
+ finish(escape(props.content));
+ }
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/index.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/index.ts
new file mode 100644
index 0000000000..4740165dc9
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/index.ts
@@ -0,0 +1,3 @@
+import DetailPanel from "./DetailPanel.vue";
+
+export default DetailPanel;
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/pretty-print-json.css b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/pretty-print-json.css
new file mode 100644
index 0000000000..d378f77f3e
--- /dev/null
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DetailPanel/pretty-print-json.css
@@ -0,0 +1,146 @@
+/*! pretty-print-json v3.0.3 ~~ https://pretty-print-json.js.org ~~ MIT License */
+
+/* Layout */
+.json-container {
+ font-family: menlo, consolas, monospace;
+ font-style: normal;
+ font-weight: bold;
+ line-height: 1.4em;
+ font-size: 0.9rem;
+ transition: background-color 400ms;
+}
+a.json-link {
+ text-decoration: none;
+ border-bottom: 1px solid;
+ outline: none;
+}
+a.json-link:hover {
+ background-color: transparent;
+ outline: none;
+}
+ol.json-lines {
+ white-space: normal;
+ padding-inline-start: 3em;
+ margin: 0px;
+}
+ol.json-lines > li {
+ white-space: pre;
+ text-indent: 0.7em;
+ line-height: 1.5em;
+ padding: 0px;
+}
+ol.json-lines > li::marker {
+ font-family: system-ui, sans-serif;
+ font-weight: normal;
+}
+.json-key,
+.json-string,
+.json-number,
+.json-boolean,
+.json-null,
+.json-mark,
+a.json-link,
+ol.json-lines > li {
+ transition: all 400ms;
+}
+
+/* Custom Colors */
+ol.json-lines {
+ --colorGraphite: #303030;
+ --colorCharcoal: #222222;
+ --colorTar: #161616;
+}
+
+/* Colors */
+.json-container {
+ background-color: white;
+}
+.json-key {
+ color: brown;
+}
+.json-string {
+ color: olive;
+}
+.json-number {
+ color: navy;
+}
+.json-boolean {
+ color: teal;
+}
+.json-null {
+ color: dimgray;
+}
+.json-mark {
+ color: black;
+}
+a.json-link {
+ color: purple;
+}
+a.json-link:visited {
+ color: slategray;
+}
+a.json-link:hover {
+ color: blueviolet;
+}
+a.json-link:active {
+ color: slategray;
+}
+ol.json-lines > li::marker {
+ color: dimgray;
+}
+ol.json-lines > li:nth-child(odd) {
+ background-color: gainsboro;
+}
+ol.json-lines > li:nth-child(even) {
+ background-color: whitesmoke;
+}
+ol.json-lines > li:hover {
+ background-color: lemonchiffon;
+}
+
+/* Dark Mode */
+.dark-mode .json-container {
+ background-color: black;
+}
+.dark-mode .json-key {
+ color: indianred;
+}
+.dark-mode .json-string {
+ color: khaki;
+}
+.dark-mode .json-number {
+ color: deepskyblue;
+}
+.dark-mode .json-boolean {
+ color: mediumseagreen;
+}
+.dark-mode .json-null {
+ color: darkorange;
+}
+.dark-mode .json-mark {
+ color: silver;
+}
+.dark-mode a.json-link {
+ color: mediumorchid;
+}
+.dark-mode a.json-link:visited {
+ color: slategray;
+}
+.dark-mode a.json-link:hover {
+ color: violet;
+}
+.dark-mode a.json-link:active {
+ color: slategray;
+}
+.dark-mode ol.json-lines > li::marker {
+ color: silver;
+}
+.dark-mode ol.json-lines > li:nth-child(odd) {
+ background-color: var(--colorCharcoal);
+}
+.dark-mode ol.json-lines > li:nth-child(even) {
+ background-color: var(--colorTar);
+}
+.dark-mode ol.json-lines > li:hover {
+ background-color: dimgray;
+}
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index a0d1cac259..8919597517 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -119,7 +119,7 @@ import type {
import { PolicyType } from "@/types/proto/v1/org_policy_service";
import type { QueryResult } from "@/types/proto/v1/sql_service";
import { hasWorkspacePermissionV2 } from "@/utils";
-import DetailPanel from "./DetailPanel.vue";
+import DetailPanel from "./DetailPanel";
import EmptyView from "./EmptyView.vue";
import ErrorView from "./ErrorView";
import RequestQueryButton from "./RequestQueryButton.vue";
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index a46b6d5f04..9835a32710 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -245,8 +245,7 @@ import {
isNullOrUndefined,
} from "@/utils";
import DataBlock from "./DataBlock.vue";
-import DataTable from "./DataTable";
-import DataTableLite from "./DataTableLite";
+import { DataTable, DataTableLite } from "./DataTable";
import EmptyView from "./EmptyView.vue";
import ErrorView from "./ErrorView";
import { useSQLResultViewContext } from "./context";