JSONL data editor supports data types

This commit is contained in:
Jan Prochazka 2024-08-26 14:26:38 +02:00
parent 32ebd86171
commit 2232a7bab1
12 changed files with 67 additions and 20 deletions

View File

@ -61,10 +61,13 @@ class ParseStream extends stream.Transform {
if (update.document) {
obj = update.document;
} else {
obj = {
...obj,
...update.fields,
};
obj = _.omitBy(
{
...obj,
...update.fields,
},
(v, k) => v.$$undefined$$
);
}
}

View File

@ -457,6 +457,8 @@
export const activator = createActivator('DataGridCore', false);
export let dataEditorTypesBehaviourOverride = null;
const wheelRowCount = 5;
const tabVisible: any = getContext('tabVisible');
@ -829,13 +831,13 @@
showModal(EditCellDataModal, {
value: cellData,
dataEditorTypesBehaviour: display?.driver?.dataEditorTypesBehaviour,
dataEditorTypesBehaviour: getEditorTypes(),
onSave: value => grider.setCellValue(currentCell[0], realColumnUniqueNames[currentCell[1]], value),
});
}
export function getEditorTypes() {
return display?.driver?.dataEditorTypesBehaviour;
return dataEditorTypesBehaviourOverride ?? display?.driver?.dataEditorTypesBehaviour;
}
export function addJsonDocumentEnabled() {
@ -1268,7 +1270,7 @@
const cellData = rowData[realColumnUniqueNames[cell[1]]];
if (shouldOpenMultilineDialog(cellData)) {
showModal(EditCellDataModal, {
dataEditorTypesBehaviour: display?.driver?.dataEditorTypesBehaviour,
dataEditorTypesBehaviour: getEditorTypes(),
value: cellData,
onSave: value => grider.setCellValue(cell[0], realColumnUniqueNames[cell[1]], value),
});
@ -1580,7 +1582,7 @@
}
let colIndex = startCol;
for (const cell of rowData) {
setCellValue([rowIndex, colIndex], parseCellValue(cell, display?.driver?.dataEditorTypesBehaviour));
setCellValue([rowIndex, colIndex], parseCellValue(cell, getEditorTypes()));
colIndex += 1;
}
rowIndex += 1;
@ -1965,6 +1967,7 @@
{dispatchInsplaceEditor}
{frameSelection}
onSetFormView={formViewAvailable && display?.baseTable?.primaryKey ? handleSetFormView : null}
{dataEditorTypesBehaviourOverride}
/>
{/each}
</tbody>

View File

@ -27,6 +27,8 @@
export let database;
export let driver;
export let dataEditorTypesBehaviourOverride = null;
$: rowData = grider.getRowData(rowIndex);
$: rowStatus = grider.getRowStatus(rowIndex);
@ -59,11 +61,12 @@
{inplaceEditorState}
{dispatchInsplaceEditor}
cellValue={rowData[col.uniqueName]}
options="{col.options}"
canSelectMultipleOptions="{col.canSelectMultipleOptions}"
options={col.options}
canSelectMultipleOptions={col.canSelectMultipleOptions}
onSetValue={value => grider.setCellValue(rowIndex, col.uniqueName, value)}
{driver}
/>
{dataEditorTypesBehaviourOverride}
/>
{:else}
<DataGridCell
{rowIndex}
@ -71,7 +74,7 @@
{col}
{conid}
{database}
editorTypes={driver?.dataEditorTypesBehaviour}
editorTypes={dataEditorTypesBehaviourOverride ?? driver?.dataEditorTypesBehaviour}
allowHintField={hintFieldsAllowed?.includes(col.uniqueName)}
isSelected={frameSelection ? false : cellIsSelected(rowIndex, col.colIndex, selectedCells)}
isCurrentCell={col.colIndex == currentCellColumn}

View File

@ -10,6 +10,7 @@
export let options;
export let canSelectMultipleOptions;
export let driver;
export let dataEditorTypesBehaviourOverride = null;
</script>
<td class="editor">
@ -23,6 +24,7 @@
{options}
{canSelectMultipleOptions}
{driver}
{dataEditorTypesBehaviourOverride}
/>
{:else}
<InplaceInput
@ -32,6 +34,7 @@
{cellValue}
{onSetValue}
{driver}
{dataEditorTypesBehaviourOverride}
/>
{/if}
</div>

View File

@ -16,6 +16,8 @@
export let cellValue;
export let driver;
export let dataEditorTypesBehaviourOverride = null;
let domEditor;
let showEditorButton = true;
@ -23,7 +25,7 @@
const isChangedRef = createRef(!!inplaceEditorState.text);
$: editorTypes = driver?.dataEditorTypesBehaviour;
$: editorTypes = dataEditorTypesBehaviourOverride ?? driver?.dataEditorTypesBehaviour;
function handleKeyDown(event) {
showEditorButton = false;

View File

@ -13,6 +13,8 @@
export let canSelectMultipleOptions;
export let driver;
export let dataEditorTypesBehaviourOverride = null;
let value;
let valueInit;
let optionsData;
@ -20,7 +22,12 @@
onMount(() => {
value =
inplaceEditorState.text || stringifyCellValue(cellValue, 'inlineEditorIntent', driver?.dataEditorTypesBehaviour).value;
inplaceEditorState.text ||
stringifyCellValue(
cellValue,
'inlineEditorIntent',
dataEditorTypesBehaviourOverride ?? driver?.dataEditorTypesBehaviour
).value;
valueInit = value;
const optionsSelected = value.split(',');

View File

@ -99,5 +99,22 @@
preprocessLoadedRow={changeSetState?.value?.dataUpdateCommands
? row => processJsonDataUpdateCommands(row, changeSetState?.value?.dataUpdateCommands)
: null}
dataEditorTypesBehaviourOverride={{
parseJsonNull: true,
parseJsonBoolean: true,
parseNumber: true,
parseJsonArray: true,
parseJsonObject: true,
explicitDataType: true,
supportNumberType: true,
supportStringType: true,
supportBooleanType: true,
supportNullType: true,
supportJsonType: true,
supportFieldRemoval: true,
}}
/>
{/key}

View File

@ -69,7 +69,7 @@
export let macroPreview;
export let macroValues;
export let onPublishedCellsChanged
export let onPublishedCellsChanged;
export const activator = createActivator('JslDataGridCore', false);
export let setLoadedRows;
@ -201,7 +201,7 @@
bind:this={domGrid}
{...$$props}
setLoadedRows={handleSetLoadedRows}
onPublishedCellsChanged={value => {
onPublishedCellsChanged={value => {
publishedCells = value;
if (onPublishedCellsChanged) {
onPublishedCellsChanged(value);

View File

@ -210,6 +210,7 @@
export let rowCountNotAvailable;
// export let formDisplay;
export let onNavigate;
export let dataEditorTypesBehaviourOverride = null;
let wrapperHeight = 1;
let wrapperWidth = 1;
@ -652,6 +653,7 @@
driver={display?.driver}
inplaceEditorState={$inplaceEditorState}
{dispatchInsplaceEditor}
{dataEditorTypesBehaviourOverride}
cellValue={rowData[col.uniqueName]}
options={col.options}
canSelectMultipleOptions={col.canSelectMultipleOptions}

View File

@ -30,6 +30,7 @@
import { changeSetContainsChanges, createChangeSet } from 'dbgate-datalib';
import localforage from 'localforage';
import { onMount, tick } from 'svelte';
import _ from 'lodash';
import ToolStripCommandButton from '../buttons/ToolStripCommandButton.svelte';
import ToolStripCommandSplitButton from '../buttons/ToolStripCommandSplitButton.svelte';
@ -129,7 +130,13 @@
await apiCall('archive/modify-file', {
folder: archiveFolder,
file: archiveFile,
changeSet: $changeSetStore.value,
changeSet: {
...$changeSetStore.value,
updates: $changeSetStore.value.updates.map(update => ({
...update,
fields: _.mapValues(update.fields, (v, k) => (v === undefined ? { $$undefined$$: true } : v)),
})),
},
});
await afterSaveChangeSet();
}

View File

@ -125,7 +125,7 @@
...changeSet,
updates: changeSet.updates.map(update => ({
...update,
fields: _.mapValues(update.fields, (v, k) => (v === undefined ? { $undefined: true } : v)),
fields: _.mapValues(update.fields, (v, k) => (v === undefined ? { $$undefined$$: true } : v)),
})),
},
});

View File

@ -330,10 +330,10 @@ const driver = {
}
} else {
const resdoc = await collection.updateOne(convertObjectId(update.condition), {
$set: convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$undefined)),
$set: convertObjectId(_.pickBy(update.fields, (v, k) => !v?.$$undefined$$)),
$unset: _.fromPairs(
Object.keys(update.fields)
.filter((k) => update.fields[k]?.$undefined)
.filter((k) => update.fields[k]?.$$undefined$$)
.map((k) => [k, ''])
),