mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 12:13:57 +00:00
#90 handle native json field in datagrid
This commit is contained in:
parent
c30724c5da
commit
7524b30f50
@ -1,6 +1,19 @@
|
||||
<script lang="ts">
|
||||
import _ from 'lodash';
|
||||
|
||||
export let selection;
|
||||
export let wrap;
|
||||
</script>
|
||||
|
||||
<textarea class="flex1" {wrap} readonly value={selection.map(cell => cell.value).join('\n')} />
|
||||
<textarea
|
||||
class="flex1"
|
||||
{wrap}
|
||||
readonly
|
||||
value={selection
|
||||
.map(cell => {
|
||||
const { value } = cell;
|
||||
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value, undefined, 2);
|
||||
return cell.value;
|
||||
})
|
||||
.join('\n')}
|
||||
/>
|
||||
|
@ -100,7 +100,7 @@
|
||||
{:else if value.type == 'Buffer' && _.isArray(value.data)}
|
||||
<span class="null">({value.data.length} bytes)</span>
|
||||
{:else if _.isPlainObject(value)}
|
||||
<span class="null">(JSON)</span>
|
||||
<span class="null" title={JSON.stringify(value, undefined, 2)}>(JSON)</span>
|
||||
{:else if _.isArray(value)}
|
||||
<span class="null">[{value.length} items]</span>
|
||||
{:else}
|
||||
|
@ -161,6 +161,13 @@
|
||||
if (allRowCount == null) return 'Loading row count...';
|
||||
return `Rows: ${allRowCount.toLocaleString()}`;
|
||||
}
|
||||
|
||||
function getCopiedValue(value) {
|
||||
if (value === null) return '(NULL)';
|
||||
if (value === undefined) return '(NoField)';
|
||||
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
|
||||
return value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
@ -329,7 +336,7 @@
|
||||
if (!rowData) return '';
|
||||
const line = colIndexes
|
||||
.map(col => realColumnUniqueNames[col])
|
||||
.map(col => (rowData[col] == null ? '(NULL)' : rowData[col]))
|
||||
.map(col => getCopiedValue(rowData[col]))
|
||||
.join('\t');
|
||||
return line;
|
||||
});
|
||||
|
@ -1,7 +1,15 @@
|
||||
<script lang="ts" context="module">
|
||||
function getEditedValue(value) {
|
||||
if (_.isPlainObject(value) || _.isArray(value)) return JSON.stringify(value);
|
||||
return value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import keycodes from '../utility/keycodes';
|
||||
import { onMount } from 'svelte';
|
||||
import createRef from '../utility/createRef';
|
||||
import _ from 'lodash';
|
||||
|
||||
export let inplaceEditorState;
|
||||
export let dispatchInsplaceEditor;
|
||||
@ -54,7 +62,7 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
domEditor.value = inplaceEditorState.text || cellValue;
|
||||
domEditor.value = inplaceEditorState.text || getEditedValue(cellValue);
|
||||
domEditor.focus();
|
||||
if (inplaceEditorState.selectAll) {
|
||||
domEditor.select();
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user