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

@ -150,7 +150,7 @@ export function stringifyCellValue(
if (value === true) return { value: 'true', gridStyle: 'valueCellStyle' };
if (value === false) return { value: 'false', gridStyle: 'valueCellStyle' };
if (editorTypes?.parseHexAsBuffer) {
if (value?.type == 'Buffer' && _isArray(value.data)) {
return { value: '0x' + arrayToHexString(value.data), gridStyle: 'valueCellStyle' };
@ -167,28 +167,26 @@ export function stringifyCellValue(
}
}
}
if (editorTypes?.parseJsonArray) {
if (_isArray(value)) {
switch (intent) {
case 'gridCellIntent':
return stringifyJsonToGrid(value);
case 'multilineEditorIntent':
return { value: JSON.stringify(value) };
default:
return { value: JSON.stringify(value, null, 2), gridStyle: 'valueCellStyle' };
}
if (_isArray(value)) {
switch (intent) {
case 'gridCellIntent':
return stringifyJsonToGrid(value);
case 'multilineEditorIntent':
return { value: JSON.stringify(value, null, 2) };
default:
return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
}
}
if (editorTypes?.parseJsonObject) {
if (_isPlainObject(value)) {
switch (intent) {
case 'gridCellIntent':
return stringifyJsonToGrid(value);
case 'multilineEditorIntent':
return { value: JSON.stringify(value) };
default:
return { value: JSON.stringify(value, null, 2), gridStyle: 'valueCellStyle' };
}
if (_isPlainObject(value)) {
switch (intent) {
case 'gridCellIntent':
return stringifyJsonToGrid(value);
case 'multilineEditorIntent':
return { value: JSON.stringify(value, null, 2) };
default:
return { value: JSON.stringify(value), gridStyle: 'valueCellStyle' };
}
}

View File

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

View File

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

View File

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

View File

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