changeset - delete

This commit is contained in:
Jan Prochazka
2020-03-29 12:29:02 +02:00
parent 2107daf0f0
commit 50bf392e4a
3 changed files with 95 additions and 27 deletions

View File

@@ -32,6 +32,7 @@ import {
revertChangeSetRowChanges,
getChangeSetInsertedRows,
changeSetInsertNewRow,
deleteChangeSetRows,
} from '@dbgate/datalib';
import { scriptToSql } from '@dbgate/sqltree';
import { sleep } from '../utility/common';
@@ -344,6 +345,12 @@ export default function DataGridCore(props) {
}
}
function deleteCurrentRow() {
if (loadedRows && currentCell && loadedRows[currentCell[0]]) {
setChangeSet(deleteChangeSetRows(changeSet, display.getChangeSetRow(loadedRows[currentCell[0]])));
}
}
function handleGridWheel(event) {
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
if (event.deltaY > 0) {
@@ -409,10 +416,15 @@ export default function DataGridCore(props) {
if (event.keyCode == keycodes.r && event.ctrlKey) {
event.preventDefault();
revertRowChanges();
}
if (event.keyCode == keycodes.delete && event.ctrlKey) {
event.preventDefault();
deleteCurrentRow();
// this.saveAndFocus();
}
if (event.keyCode == keycodes.insert) {
if (event.keyCode == keycodes.insert && !event.ctrlKey) {
event.preventDefault();
if (display.baseTable) {
setChangeSet(changeSetInsertNewRow(changeSet, display.baseTable));

View File

@@ -35,21 +35,32 @@ const TableBodyCell = styled.td`
!props.isSelected &&
!props.isModifiedCell &&
`
background-color: #FFFFDB;`}
${props =>
!props.isSelected &&
!props.isInsertedRow &&
props.isModifiedCell &&
`
background-color: bisque;`}
background-color: #FFFFDB;`}
${props =>
!props.isSelected &&
!props.isInsertedRow &&
props.isModifiedCell &&
`
background-color: bisque;`}
${props =>
!props.isSelected &&
props.isInsertedRow &&
`
background-color: #DBFFDB;`}
${props =>
!props.isSelected &&
props.isInsertedRow &&
props.isDeletedRow &&
`
background-color: #DBFFDB;`}
`;
background-color: #FFDBFF;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAEElEQVQImWNgIAX8x4KJBAD+agT8INXz9wAAAABJRU5ErkJggg==');
// from http://www.patternify.com/
background-repeat: repeat-x;
background-position: 50% 50%;`}
`;
const HintSpan = styled.span`
color: gray;
margin-left: 5px;
@@ -99,8 +110,16 @@ export default function DataGridRow({
}) {
// console.log('RENDER ROW', rowIndex);
const rowDefinition = display.getChangeSetRow(row);
const [_fld, matchedChangeSetItem] = findExistingChangeSetItem(changeSet, rowDefinition);
const [matchedField, matchedChangeSetItem] = findExistingChangeSetItem(changeSet, rowDefinition);
const rowUpdated = matchedChangeSetItem ? { ...row, ...matchedChangeSetItem.fields } : row;
const hintFieldsAllowed = visibleRealColumns
.filter(col => {
if (!col.hintColumnName) return false;
if (matchedChangeSetItem && matchedField == 'updates' && col.uniqueName in matchedChangeSetItem.fields)
return false;
return true;
})
.map(col => col.uniqueName);
return (
<TableBodyRow style={{ height: `${rowHeight}px` }}>
<TableHeaderCell data-row={rowIndex} data-col="header">
@@ -119,8 +138,11 @@ export default function DataGridRow({
// @ts-ignore
isSelected={cellIsSelected(rowIndex, col.colIndex)}
isModifiedRow={!!matchedChangeSetItem}
isModifiedCell={matchedChangeSetItem && col.uniqueName in matchedChangeSetItem.fields}
isModifiedCell={
matchedChangeSetItem && matchedField == 'updates' && col.uniqueName in matchedChangeSetItem.fields
}
isInsertedRow={insertedRowIndex != null}
isDeletedRow={matchedField == 'deletes'}
>
{inplaceEditorState.cell &&
rowIndex == inplaceEditorState.cell[0] &&
@@ -138,9 +160,7 @@ export default function DataGridRow({
) : (
<>
<CellFormattedValue value={rowUpdated[col.uniqueName]} />
{(!matchedChangeSetItem || !(col.uniqueName in matchedChangeSetItem.fields)) && col.hintColumnName && (
<HintSpan>{row[col.hintColumnName]}</HintSpan>
)}
{hintFieldsAllowed.includes(col.uniqueName) && <HintSpan>{row[col.hintColumnName]}</HintSpan>}
</>
)}
</TableBodyCell>