From c4de3738fca5c6f235d51da4561a5f95dab402f2 Mon Sep 17 00:00:00 2001 From: zipg Date: Tue, 30 Jun 2026 22:38:45 +0800 Subject: [PATCH] =?UTF-8?q?Improve:=20=E8=AE=B0=E4=BD=8F=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=A0=BC=E8=AF=A6=E6=83=85=20JSON=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E7=8A=B6=E6=80=81=20(#2252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: staff --- apps/desktop/src/components/grid/DataGrid.vue | 29 +++++++++++-------- apps/desktop/src/i18n/locales/en.ts | 2 +- apps/desktop/src/i18n/locales/es.ts | 1 + apps/desktop/src/i18n/locales/it.ts | 1 + apps/desktop/src/i18n/locales/ja.ts | 1 + apps/desktop/src/i18n/locales/pt-BR.ts | 1 + apps/desktop/src/i18n/locales/zh-CN.ts | 2 +- apps/desktop/src/i18n/locales/zh-TW.ts | 2 +- apps/desktop/src/stores/settingsStore.ts | 4 +++ packages/app-tests/settingsStore.test.ts | 4 +++ 10 files changed, 32 insertions(+), 15 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index c2da9b777..a2214bd2f 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -158,7 +158,8 @@ import { formatShortcut } from "@/lib/shortcutRegistry"; import { SearchableSelect } from "@/components/ui/searchable-select"; const SqlPreviewPanel = defineAsyncComponent(() => import("@/components/editor/SqlPreviewPanel.vue")); -const FORMATTED_JSON_EDIT_WARNING_STORAGE_KEY = "dbx-cell-detail-formatted-json-edit-warning-shown"; +const FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY = "dbx-cell-detail-formatted-json-edit-warning-count"; +const FORMATTED_JSON_EDIT_WARNING_MAX_COUNT = 10; const { t } = useI18n(); const slots = useSlots(); @@ -448,8 +449,6 @@ const rowDetailDialogOpen = ref(false); const rowDetailDialogRowId = ref(null); const columnDetailDialogOpen = ref(false); const columnDetailDialogColumnIndex = ref(null); -const cellDetailJsonView = ref(false); -const sideDetailJsonView = ref(false); const rowDetailSearch = ref(""); const columnDetailSearch = ref(""); const isResizingDetail = ref(false); @@ -3810,6 +3809,10 @@ const dialogCellDetail = computed(() => { return target ? cellDetailFor(target.rowIndex, target.col) : null; }); +const cellDetailJsonFormatted = computed(() => settingsStore.editorSettings.cellDetailJsonFormatted); +const sideDetailJsonView = computed(() => cellDetailJsonFormatted.value && !!activeCellDetail.value?.formattedJson); +const cellDetailJsonView = computed(() => cellDetailJsonFormatted.value && !!dialogCellDetail.value?.formattedJson); + const rowDetail = computed(() => { if (rowDetailDialogRowId.value === null) return null; const item = getRowItem(rowDetailDialogRowId.value); @@ -3854,8 +3857,7 @@ const filteredRowDetailFields = computed(() => (rowDetail.value ? filterDataGrid const filteredColumnDetailFields = computed(() => (columnDetail.value ? filterDataGridDetailFields(columnDetail.value.fields, columnDetailSearch.value) : [])); watch(cellDetailDialogOpen, (open) => { - if (open) cellDetailJsonView.value = false; - else cellDetailDialogTarget.value = null; + if (!open) cellDetailDialogTarget.value = null; }); watch(rowDetailDialogOpen, (open) => { @@ -4014,7 +4016,6 @@ async function prefetchDetailSqlCondition() { watch(activeCellDetail, (detail) => { void prefetchDetailSqlCondition(); - sideDetailJsonView.value = false; if (activeCellDetailTab.value !== "valueEditor") return; if (!detail?.isEditable) { resetDetailEdit(); @@ -4174,9 +4175,14 @@ function cellDetailEditText(detail: DataGridCellDetail): string { function warnFormattedJsonEditIfNeeded(detail: DataGridCellDetail, force = false) { if (!force && (!sideDetailJsonView.value || !detail.formattedJson)) return; - if (safeLocalStorageGet(FORMATTED_JSON_EDIT_WARNING_STORAGE_KEY) === "1") return; + const count = Number(safeLocalStorageGet(FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY)) || 0; + if (count >= FORMATTED_JSON_EDIT_WARNING_MAX_COUNT) return; toast(t("grid.formattedJsonEditWarning"), 10000); - safeLocalStorageSet(FORMATTED_JSON_EDIT_WARNING_STORAGE_KEY, "1"); + safeLocalStorageSet(FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY, String(count + 1)); +} + +function toggleCellDetailJsonFormatted() { + settingsStore.updateEditorSettings({ cellDetailJsonFormatted: !cellDetailJsonFormatted.value }); } function startDetailEdit() { @@ -6038,7 +6044,6 @@ async function openDialogCellInSidePanel() { showCellDetails(detail.rowNumber - 1, detail.colIndex); cellDetailDialogOpen.value = false; await nextTick(); - sideDetailJsonView.value = cellDetailJsonView.value && !!detail.formattedJson; if (detail.isEditable) startDetailEdit(); } @@ -8917,7 +8922,7 @@ const gridContextMenuItems = computed(() => {
{{ t("grid.cellValue") }}
- @@ -8959,7 +8964,7 @@ const gridContextMenuItems = computed(() => {