This commit is contained in:
Jan Prochazka
2024-08-26 09:32:28 +02:00
parent eaa943a39d
commit 4cbfa7c937
5 changed files with 33 additions and 29 deletions

View File

@@ -167,28 +167,26 @@ export function stringifyCellValue(
} }
} }
} }
if (editorTypes?.parseJsonArray) {
if (_isArray(value)) { if (_isArray(value)) {
switch (intent) { switch (intent) {
case 'gridCellIntent': case 'gridCellIntent':
return stringifyJsonToGrid(value); return stringifyJsonToGrid(value);
case 'multilineEditorIntent': case 'multilineEditorIntent':
return { value: JSON.stringify(value) }; return { value: JSON.stringify(value, null, 2) };
default: default:
return { value: JSON.stringify(value, null, 2), gridStyle: 'valueCellStyle' }; return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
} }
} }
}
if (editorTypes?.parseJsonObject) {
if (_isPlainObject(value)) { if (_isPlainObject(value)) {
switch (intent) { switch (intent) {
case 'gridCellIntent': case 'gridCellIntent':
return stringifyJsonToGrid(value); return stringifyJsonToGrid(value);
case 'multilineEditorIntent': case 'multilineEditorIntent':
return { value: JSON.stringify(value) }; return { value: JSON.stringify(value, null, 2) };
default: default:
return { value: JSON.stringify(value, null, 2), gridStyle: 'valueCellStyle' }; return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
}
} }
} }

View File

@@ -3,10 +3,7 @@
import ShowFormButton from '../formview/ShowFormButton.svelte'; import ShowFormButton from '../formview/ShowFormButton.svelte';
import { detectTypeIcon, getConvertValueMenu, isJsonLikeLongString, safeJsonParse } from 'dbgate-tools'; import { detectTypeIcon, getConvertValueMenu, isJsonLikeLongString, safeJsonParse } from 'dbgate-tools';
import { openJsonDocument } from '../tabs/JsonTab.svelte'; import { openJsonDocument } from '../tabs/JsonTab.svelte';
import openNewTab from '../utility/openNewTab';
import CellValue from './CellValue.svelte'; import CellValue from './CellValue.svelte';
import { showModal } from '../modals/modalTools';
import EditCellDataModal from '../modals/EditCellDataModal.svelte';
import { openJsonLinesData } from '../utility/openJsonLinesData'; import { openJsonLinesData } from '../utility/openJsonLinesData';
import ShowFormDropDownButton from '../formview/ShowFormDropDownButton.svelte'; import ShowFormDropDownButton from '../formview/ShowFormDropDownButton.svelte';

View File

@@ -343,7 +343,7 @@
<script lang="ts"> <script lang="ts">
import { GridDisplay } from 'dbgate-datalib'; import { GridDisplay } from 'dbgate-datalib';
import { driverBase, parseCellValue, detectSqlFilterBehaviour } from 'dbgate-tools'; import { driverBase, parseCellValue, detectSqlFilterBehaviour, stringifyCellValue } from 'dbgate-tools';
import { getContext, onDestroy } from 'svelte'; import { getContext, onDestroy } from 'svelte';
import _, { map } from 'lodash'; import _, { map } from 'lodash';
import registerCommand from '../commands/registerCommand'; import registerCommand from '../commands/registerCommand';
@@ -811,7 +811,7 @@
const cellData = rowData[realColumnUniqueNames[currentCell[1]]]; const cellData = rowData[realColumnUniqueNames[currentCell[1]]];
showModal(EditCellDataModal, { showModal(EditCellDataModal, {
value: cellData?.toString() || '', value: stringifyCellValue(cellData, 'multilineEditorIntent').value,
onSave: value => grider.setCellValue(currentCell[0], realColumnUniqueNames[currentCell[1]], value), onSave: value => grider.setCellValue(currentCell[0], realColumnUniqueNames[currentCell[1]], value),
}); });
} }
@@ -1246,7 +1246,7 @@
const cellData = rowData[realColumnUniqueNames[cell[1]]]; const cellData = rowData[realColumnUniqueNames[cell[1]]];
if (shouldOpenMultilineDialog(cellData)) { if (shouldOpenMultilineDialog(cellData)) {
showModal(EditCellDataModal, { showModal(EditCellDataModal, {
value: cellData, value: stringifyCellValue(cellData, 'multilineEditorIntent').value,
onSave: value => grider.setCellValue(cell[0], realColumnUniqueNames[cell[1]], value), onSave: value => grider.setCellValue(cell[0], realColumnUniqueNames[cell[1]], value),
}); });
return true; return true;

View File

@@ -157,7 +157,7 @@
<script lang="ts"> <script lang="ts">
import { getFilterValueExpression } from 'dbgate-filterparser'; import { getFilterValueExpression } from 'dbgate-filterparser';
import { filterName } from 'dbgate-tools'; import { filterName, stringifyCellValue } from 'dbgate-tools';
import _ from 'lodash'; import _ from 'lodash';
@@ -490,7 +490,7 @@
const cellData = rowData[column.uniqueName]; const cellData = rowData[column.uniqueName];
if (shouldOpenMultilineDialog(cellData)) { if (shouldOpenMultilineDialog(cellData)) {
showModal(EditCellDataModal, { showModal(EditCellDataModal, {
value: cellData, value: stringifyCellValue(cellData, 'multilineEditorIntent').value,
onSave: value => grider.setCellValue(0, column.uniqueName, value), onSave: value => grider.setCellValue(0, column.uniqueName, value),
}); });
return true; return true;

View File

@@ -9,6 +9,15 @@
return true; return true;
} }
} }
if (value?.$oid) {
return false;
}
if (value?.$date) {
return false;
}
if (_.isPlainObject(value) || _.isArray(value)) {
return true;
}
return false; return false;
} }
</script> </script>