25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(grid): keep JSON formatting manual
t8y2d02a12efe7d2
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 102005da66..11a036d765 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -101,10 +101,10 @@ import { matchesRowStatusFilter, type RowStatus, type RowStatusFilter } from "@/import { displayCellValue, type CellValue } from "@/lib/cellValue";import { cellImagePreviewUrl } from "@/lib/cellImageUrl";import {+ canFormatCellDetailJson,cellDetailEditorText,defaultCellDetailTab,formatJsonText,- isJsonColumnType,valueEditorActions,visibleCellDetailTabs,type CellDetailTab,@@ -1791,7 +1791,7 @@ const activeValueEditorActions = computed(() => {const detail = activeCellDetail.value;return valueEditorActions({canSetNull: !!detail?.isEditable && detail.value !== null,- canFormatJson: !!detail?.isEditable && isJsonColumnType(detail?.type),+ canFormatJson: !!detail?.isEditable && canFormatCellDetailJson(detail.value, detail.type),});});@@ -1904,7 +1904,7 @@ function setValueEditorNull() {function formatValueEditorJson() {const detail = activeCellDetail.value;- if (!detail || !isJsonColumnType(detail.type)) return;+ if (!detail || !canFormatCellDetailJson(detailEditValue.value, detail.type)) return;detailEditValue.value = formatJsonText(detailEditValue.value) ?? detailEditValue.value;}diff --git a/apps/desktop/src/lib/cellDetailPresentation.ts b/apps/desktop/src/lib/cellDetailPresentation.tsindex 962ea62f47..a0f3e2e93c 100644--- a/apps/desktop/src/lib/cellDetailPresentation.ts+++ b/apps/desktop/src/lib/cellDetailPresentation.ts@@ -17,12 +17,12 @@ export function visibleCellDetailTabs(options: CellDetailPresentationOptions): Creturn tabs;}-export function cellDetailEditorText(value: unknown, columnType?: string): string {+export function cellDetailEditorText(value: unknown, _columnType?: string): string {if (value === null) return "";- if (isJsonColumnType(columnType)) {- const text = typeof value === "object" ? JSON.stringify(value) : String(value);- return formatJsonText(text) ?? text;- }+ return cellDetailRawEditorText(value);+}++function cellDetailRawEditorText(value: unknown): string {if (typeof value === "object") return JSON.stringify(value);return String(value);}@@ -43,6 +43,13 @@ export function isJsonColumnType(columnType: string | undefined): boolean {return base === "json" || base === "jsonb";}+export function canFormatCellDetailJson(value: unknown, columnType?: string): boolean {+ if (value === null || value === undefined) return false;+ const text = cellDetailRawEditorText(value);+ if (isJsonColumnType(columnType)) return !!formatJsonText(text);+ return typeof value === "string" && looksLikeJsonContainer(text) && !!formatJsonText(text);+}+export function formatJsonText(text: string): string | undefined {const trimmed = text.trim();if (!trimmed) return undefined;@@ -52,3 +59,8 @@ export function formatJsonText(text: string): string | undefined {return undefined;}}++function looksLikeJsonContainer(text: string): boolean {+ const trimmed = text.trim();+ return trimmed.startsWith("{") || trimmed.startsWith("[");+}diff --git a/packages/app-tests/cellDetailPresentation.test.ts b/packages/app-tests/cellDetailPresentation.test.tsindex b2e6a8b148..7914cb14c0 100644--- a/packages/app-tests/cellDetailPresentation.test.ts+++ b/packages/app-tests/cellDetailPresentation.test.ts@@ -1,6 +1,7 @@import { strict as assert } from "node:assert";import test from "node:test";import {+ canFormatCellDetailJson,cellDetailEditorText,defaultCellDetailTab,visibleCellDetailTabs,@@ -33,15 +34,18 @@ test("cell detail value editor restores the original value text on cancel", () =assert.equal(cellDetailEditorText("already text"), "already text");});-test("cell detail value editor formats json typed string values", () => {- assert.equal(- cellDetailEditorText('{"nested":true,"items":[1,2]}', "jsonb"),- '{\n "nested": true,\n "items": [\n 1,\n 2\n ]\n}',- );+test("cell detail value editor keeps json text unchanged until formatting is requested", () => {+ assert.equal(cellDetailEditorText('{"nested":true,"items":[1,2]}', "jsonb"), '{"nested":true,"items":[1,2]}');assert.equal(cellDetailEditorText('{"nested":true}', "varchar"), '{"nested":true}');assert.equal(cellDetailEditorText("{invalid", "json"), "{invalid");});+test("cell detail value editor allows json-like string values to be manually formatted", () => {+ assert.equal(cellDetailEditorText('{"name":"示例","value":123}'), '{"name":"示例","value":123}');+ assert.equal(canFormatCellDetailJson('{"name":"示例","value":123}'), true);+ assert.equal(canFormatCellDetailJson("plain text"), false);+});+test("cell detail value editor uses cell actions instead of confirm and cancel", () => {assert.deepEqual(valueEditorActions({ canSetNull: true, canFormatJson: true }), ["formatJson",