diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index f1ab7ac673..3f852a73b8 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -12057,6 +12057,9 @@ const gridContextMenuItems = computed(() => { + diff --git a/apps/desktop/src/lib/__tests__/dataGrid/cellDetailPresentation.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/cellDetailPresentation.spec.ts new file mode 100644 index 0000000000..88d7ef7854 --- /dev/null +++ b/apps/desktop/src/lib/__tests__/dataGrid/cellDetailPresentation.spec.ts @@ -0,0 +1,18 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; +import { compactJsonText, valueEditorActions } from "@/lib/dataGrid/cellDetailPresentation"; + +const dataGridSource = readFileSync(new URL("../../../components/grid/DataGrid.vue", import.meta.url), "utf8"); + +describe("cellDetailPresentation", () => { + it("offers compact JSON beside format JSON for editable JSON values", () => { + expect(valueEditorActions({ canSetNull: true, canFormatJson: true })).toEqual(["formatJson", "compactJson", "setNull", "restoreOriginal"]); + expect(valueEditorActions({ canSetNull: false, canFormatJson: false })).toEqual(["restoreOriginal"]); + expect(compactJsonText('{\n "name": "DBX",\n "enabled": true\n}')).toBe('{"name":"DBX","enabled":true}'); + }); + + it("wires the value editor compact action to the existing compact handler", () => { + expect(dataGridSource).toContain("activeValueEditorActions.includes('compactJson')"); + expect(dataGridSource).toContain('@click="compactDetailJson"'); + }); +}); diff --git a/apps/desktop/src/lib/dataGrid/cellDetailPresentation.ts b/apps/desktop/src/lib/dataGrid/cellDetailPresentation.ts index f05617c6ce..233d3c9aee 100644 --- a/apps/desktop/src/lib/dataGrid/cellDetailPresentation.ts +++ b/apps/desktop/src/lib/dataGrid/cellDetailPresentation.ts @@ -1,7 +1,7 @@ import { safeJsonFormat } from "@/lib/common/safeJsonFormat"; export type CellDetailTab = "details" | "hexViewer" | "valueEditor"; -export type ValueEditorAction = "formatJson" | "setNull" | "restoreOriginal"; +export type ValueEditorAction = "formatJson" | "compactJson" | "setNull" | "restoreOriginal"; export const CELL_DETAIL_JSON_FORMAT_MAX_LENGTH = 50_000; @@ -49,7 +49,8 @@ function cellDetailRawEditorText(value: unknown): string { export function valueEditorActions(options: { canSetNull: boolean; canFormatJson?: boolean }): ValueEditorAction[] { const actions: ValueEditorAction[] = []; - if (options.canFormatJson) actions.push("formatJson"); + // JSON 校验通过后同时提供格式化和压缩,避免两个入口的编辑能力不一致。 + if (options.canFormatJson) actions.push("formatJson", "compactJson"); if (options.canSetNull) actions.push("setNull"); actions.push("restoreOriginal"); return actions;