mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 11:56:00 +00:00
changeset - delete
This commit is contained in:
@@ -51,15 +51,23 @@ export function findExistingChangeSetItem(
|
||||
),
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'updates',
|
||||
changeSet.updates.find(
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
_.isEqual(x.condition, definition.condition)
|
||||
),
|
||||
];
|
||||
const inUpdates = changeSet.updates.find(
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
_.isEqual(x.condition, definition.condition)
|
||||
);
|
||||
if (inUpdates) return ['updates', inUpdates];
|
||||
|
||||
const inDeletes = changeSet.deletes.find(
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
_.isEqual(x.condition, definition.condition)
|
||||
);
|
||||
if (inDeletes) return ['deletes', inDeletes];
|
||||
|
||||
return ['updates', null];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +76,11 @@ export function setChangeSetValue(
|
||||
definition: ChangeSetFieldDefinition,
|
||||
value: string
|
||||
): ChangeSet {
|
||||
const [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||
if (fieldName == 'deletes') {
|
||||
changeSet = revertChangeSetRowChanges(changeSet, definition);
|
||||
[fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||
}
|
||||
if (existingItem) {
|
||||
return {
|
||||
...changeSet,
|
||||
@@ -191,6 +203,30 @@ export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: Chan
|
||||
return changeSet;
|
||||
}
|
||||
|
||||
export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetRowDefinition): ChangeSet {
|
||||
let [fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||
if (fieldName == 'updates') {
|
||||
changeSet = revertChangeSetRowChanges(changeSet, definition);
|
||||
[fieldName, existingItem] = findExistingChangeSetItem(changeSet, definition);
|
||||
}
|
||||
if (fieldName == 'inserts') {
|
||||
return revertChangeSetRowChanges(changeSet, definition);
|
||||
} else {
|
||||
if (existingItem && fieldName == 'deletes') return changeSet;
|
||||
return {
|
||||
...changeSet,
|
||||
deletes: [
|
||||
...changeSet.deletes,
|
||||
{
|
||||
pureName: definition.pureName,
|
||||
schemaName: definition.schemaName,
|
||||
condition: definition.condition,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
||||
if (!name) return [];
|
||||
if (!changeSet) return [];
|
||||
|
||||
@@ -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