mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 17:53:59 +00:00
changeset - delete
This commit is contained in:
@@ -51,15 +51,23 @@ export function findExistingChangeSetItem(
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [
|
const inUpdates = changeSet.updates.find(
|
||||||
'updates',
|
|
||||||
changeSet.updates.find(
|
|
||||||
x =>
|
x =>
|
||||||
x.pureName == definition.pureName &&
|
x.pureName == definition.pureName &&
|
||||||
x.schemaName == definition.schemaName &&
|
x.schemaName == definition.schemaName &&
|
||||||
_.isEqual(x.condition, definition.condition)
|
_.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,
|
definition: ChangeSetFieldDefinition,
|
||||||
value: string
|
value: string
|
||||||
): ChangeSet {
|
): 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) {
|
if (existingItem) {
|
||||||
return {
|
return {
|
||||||
...changeSet,
|
...changeSet,
|
||||||
@@ -191,6 +203,30 @@ export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: Chan
|
|||||||
return changeSet;
|
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) {
|
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
||||||
if (!name) return [];
|
if (!name) return [];
|
||||||
if (!changeSet) return [];
|
if (!changeSet) return [];
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import {
|
|||||||
revertChangeSetRowChanges,
|
revertChangeSetRowChanges,
|
||||||
getChangeSetInsertedRows,
|
getChangeSetInsertedRows,
|
||||||
changeSetInsertNewRow,
|
changeSetInsertNewRow,
|
||||||
|
deleteChangeSetRows,
|
||||||
} from '@dbgate/datalib';
|
} from '@dbgate/datalib';
|
||||||
import { scriptToSql } from '@dbgate/sqltree';
|
import { scriptToSql } from '@dbgate/sqltree';
|
||||||
import { sleep } from '../utility/common';
|
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) {
|
function handleGridWheel(event) {
|
||||||
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
|
let newFirstVisibleRowScrollIndex = firstVisibleRowScrollIndex;
|
||||||
if (event.deltaY > 0) {
|
if (event.deltaY > 0) {
|
||||||
@@ -409,10 +416,15 @@ export default function DataGridCore(props) {
|
|||||||
if (event.keyCode == keycodes.r && event.ctrlKey) {
|
if (event.keyCode == keycodes.r && event.ctrlKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
revertRowChanges();
|
revertRowChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.keyCode == keycodes.delete && event.ctrlKey) {
|
||||||
|
event.preventDefault();
|
||||||
|
deleteCurrentRow();
|
||||||
// this.saveAndFocus();
|
// this.saveAndFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.keyCode == keycodes.insert) {
|
if (event.keyCode == keycodes.insert && !event.ctrlKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (display.baseTable) {
|
if (display.baseTable) {
|
||||||
setChangeSet(changeSetInsertNewRow(changeSet, display.baseTable));
|
setChangeSet(changeSetInsertNewRow(changeSet, display.baseTable));
|
||||||
|
|||||||
@@ -49,7 +49,18 @@ const TableBodyCell = styled.td`
|
|||||||
`
|
`
|
||||||
background-color: #DBFFDB;`}
|
background-color: #DBFFDB;`}
|
||||||
|
|
||||||
|
${props =>
|
||||||
|
!props.isSelected &&
|
||||||
|
props.isDeletedRow &&
|
||||||
|
`
|
||||||
|
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`
|
const HintSpan = styled.span`
|
||||||
color: gray;
|
color: gray;
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
@@ -99,8 +110,16 @@ export default function DataGridRow({
|
|||||||
}) {
|
}) {
|
||||||
// console.log('RENDER ROW', rowIndex);
|
// console.log('RENDER ROW', rowIndex);
|
||||||
const rowDefinition = display.getChangeSetRow(row);
|
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 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 (
|
return (
|
||||||
<TableBodyRow style={{ height: `${rowHeight}px` }}>
|
<TableBodyRow style={{ height: `${rowHeight}px` }}>
|
||||||
<TableHeaderCell data-row={rowIndex} data-col="header">
|
<TableHeaderCell data-row={rowIndex} data-col="header">
|
||||||
@@ -119,8 +138,11 @@ export default function DataGridRow({
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
isSelected={cellIsSelected(rowIndex, col.colIndex)}
|
isSelected={cellIsSelected(rowIndex, col.colIndex)}
|
||||||
isModifiedRow={!!matchedChangeSetItem}
|
isModifiedRow={!!matchedChangeSetItem}
|
||||||
isModifiedCell={matchedChangeSetItem && col.uniqueName in matchedChangeSetItem.fields}
|
isModifiedCell={
|
||||||
|
matchedChangeSetItem && matchedField == 'updates' && col.uniqueName in matchedChangeSetItem.fields
|
||||||
|
}
|
||||||
isInsertedRow={insertedRowIndex != null}
|
isInsertedRow={insertedRowIndex != null}
|
||||||
|
isDeletedRow={matchedField == 'deletes'}
|
||||||
>
|
>
|
||||||
{inplaceEditorState.cell &&
|
{inplaceEditorState.cell &&
|
||||||
rowIndex == inplaceEditorState.cell[0] &&
|
rowIndex == inplaceEditorState.cell[0] &&
|
||||||
@@ -138,9 +160,7 @@ export default function DataGridRow({
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<CellFormattedValue value={rowUpdated[col.uniqueName]} />
|
<CellFormattedValue value={rowUpdated[col.uniqueName]} />
|
||||||
{(!matchedChangeSetItem || !(col.uniqueName in matchedChangeSetItem.fields)) && col.hintColumnName && (
|
{hintFieldsAllowed.includes(col.uniqueName) && <HintSpan>{row[col.hintColumnName]}</HintSpan>}
|
||||||
<HintSpan>{row[col.hintColumnName]}</HintSpan>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</TableBodyCell>
|
</TableBodyCell>
|
||||||
|
|||||||
Reference in New Issue
Block a user