copy & paste fixes

This commit is contained in:
Jan Prochazka
2020-05-20 18:29:41 +02:00
parent 2bf47dac80
commit 6df7743b4c
3 changed files with 56 additions and 36 deletions

View File

@@ -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,

View File

@@ -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) => <ErrorMessageModal modalState={modalState} message={errorMessage} title='Error when saving' />);
showModal((modalState) => (
<ErrorMessageModal modalState={modalState} message={errorMessage} title="Error when saving" />
));
} 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)

View File

@@ -46,6 +46,13 @@ export default function SqlEditor({
};
}, [onKeyDown]);
// React.useEffect(() => {
// if (currentEditorRef.current.editor)
// currentEditorRef.current.editor.setOptions({
// showGutter: false,
// });
// }, []);
return (
<Wrapper ref={containerRef}>
<AceEditor