mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 12:16:01 +00:00
changeset - delete
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user