diff --git a/packages/datalib/src/ChangeSet.ts b/packages/datalib/src/ChangeSet.ts
index ea25708ff..f983349f8 100644
--- a/packages/datalib/src/ChangeSet.ts
+++ b/packages/datalib/src/ChangeSet.ts
@@ -165,22 +165,26 @@ export function batchUpdateChangeSet(
return changeSet;
}
-function extractFields(item: ChangeSetItem): UpdateField[] {
- return _.keys(item.fields).map((targetColumn) => ({
- targetColumn,
- exprType: 'value',
- value: item.fields[targetColumn],
- }));
+function extractFields(item: ChangeSetItem, allowNulls = true): UpdateField[] {
+ return _.keys(item.fields)
+ .filter((targetColumn) => allowNulls || item.fields[targetColumn] != null)
+ .map((targetColumn) => ({
+ targetColumn,
+ exprType: 'value',
+ value: item.fields[targetColumn],
+ }));
}
function insertToSql(item: ChangeSetItem): Insert {
+ const fields = extractFields(item, false);
+ if (fields.length == 0) return null;
return {
targetTable: {
pureName: item.pureName,
schemaName: item.schemaName,
},
commandType: 'insert',
- fields: extractFields(item),
+ fields,
};
}
@@ -236,17 +240,19 @@ function deleteToSql(item: ChangeSetItem): Delete {
}
export function changeSetToSql(changeSet: ChangeSet): Command[] {
- return [
+ return _.compact([
...changeSet.inserts.map(insertToSql),
...changeSet.updates.map(updateToSql),
...changeSet.deletes.map(deleteToSql),
- ];
+ ]);
}
export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
- console.log('definition', definition);
+ // console.log('definition', definition);
const [field, item] = findExistingChangeSetItem(changeSet, definition);
- console.log('field, item', field, item);
+ // console.log('field, item', field, item);
+ // console.log('changeSet[field]', changeSet[field]);
+ // console.log('changeSet[field] filtered', changeSet[field].filter((x) => x != item);
if (item)
return {
...changeSet,
diff --git a/packages/web/src/datagrid/DataGridCore.js b/packages/web/src/datagrid/DataGridCore.js
index 46a7bac93..8a0ac12ec 100644
--- a/packages/web/src/datagrid/DataGridCore.js
+++ b/packages/web/src/datagrid/DataGridCore.js
@@ -379,6 +379,7 @@ export default function DataGridCore(props) {
};
const insertedRows = getChangeSetInsertedRows(changeSet, display.baseTable);
+
const rowCountNewIncluded = loadedRows.length + insertedRows.length;
React.useEffect(() => {
@@ -618,29 +619,29 @@ export default function DataGridCore(props) {
let allRows = loadedAndInsertedRows;
if (selectedCells.length <= 1) {
- if (isRegularCell(currentCell)) {
- let rowIndex = currentCell[0];
- for (const rowData of pasteRows) {
- if (rowIndex >= allRows.length) {
- chs = changeSetInsertNewRow(chs, display.baseTable);
- allRows = [...loadedRows, ...getChangeSetInsertedRows(chs, display.baseTable)];
- }
- let colIndex = currentCell[1];
- const row = allRows[rowIndex];
- for (const cell of rowData) {
- chs = setChangeSetValue(
- chs,
- display.getChangeSetField(
- row,
- realColumnUniqueNames[colIndex],
- rowIndex >= loadedRows.length ? rowIndex - loadedRows.length : null
- ),
- cell
- );
- colIndex += 1;
- }
- rowIndex += 1;
+ const startRow = isRegularCell(currentCell) ? currentCell[0] : loadedAndInsertedRows.length;
+ const startCol = isRegularCell(currentCell) ? currentCell[1] : 0;
+ let rowIndex = startRow;
+ for (const rowData of pasteRows) {
+ if (rowIndex >= allRows.length) {
+ chs = changeSetInsertNewRow(chs, display.baseTable);
+ allRows = [...loadedRows, ...getChangeSetInsertedRows(chs, display.baseTable)];
}
+ let colIndex = startCol;
+ const row = allRows[rowIndex];
+ for (const cell of rowData) {
+ chs = setChangeSetValue(
+ chs,
+ display.getChangeSetField(
+ row,
+ realColumnUniqueNames[colIndex],
+ rowIndex >= loadedRows.length ? rowIndex - loadedRows.length : null
+ ),
+ cell == '(NULL)' ? null : cell
+ );
+ colIndex += 1;
+ }
+ rowIndex += 1;
}
}
if (selectedCells.length > 1) {
@@ -671,14 +672,17 @@ export default function DataGridCore(props) {
function copyToClipboard() {
const rowIndexes = _.uniq(selectedCells.map((x) => x[0])).sort();
const lines = rowIndexes.map((rowIndex) => {
- const colIndexes = selectedCells
+ let colIndexes = selectedCells
.filter((x) => x[0] == rowIndex)
.map((x) => x[1])
.sort();
+ if (colIndexes.includes('header')) {
+ colIndexes = _.range(0, columnSizes.count);
+ }
const rowData = loadedAndInsertedRows[rowIndex];
const line = colIndexes
.map((col) => realColumnUniqueNames[col])
- .map((col) => (rowData[col] == null ? '' : rowData[col]))
+ .map((col) => (rowData[col] == null ? '(NULL)' : rowData[col]))
.join('\t');
return line;
});
@@ -831,7 +835,9 @@ export default function DataGridCore(props) {
const { errorMessage } = resp.data || {};
if (errorMessage) {
- showModal((modalState) => );
+ showModal((modalState) => (
+
+ ));
} else {
dispatchChangeSet({ type: 'reset', value: createChangeSet() });
setConfirmSql(null);
@@ -1017,6 +1023,7 @@ export default function DataGridCore(props) {
if (row != null) {
let newRow = null;
const rowCount = rowCountNewIncluded;
+ if (rowCount == 0) return;
if (row < firstVisibleRowScrollIndex) newRow = row;
else if (row + 1 >= firstVisibleRowScrollIndex + visibleRowCountLowerBound)
diff --git a/packages/web/src/sqleditor/SqlEditor.js b/packages/web/src/sqleditor/SqlEditor.js
index cd7ffb8a0..923e6b1e9 100644
--- a/packages/web/src/sqleditor/SqlEditor.js
+++ b/packages/web/src/sqleditor/SqlEditor.js
@@ -46,6 +46,13 @@ export default function SqlEditor({
};
}, [onKeyDown]);
+ // React.useEffect(() => {
+ // if (currentEditorRef.current.editor)
+ // currentEditorRef.current.editor.setOptions({
+ // showGutter: false,
+ // });
+ // }, []);
+
return (