mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
macro - previre modified cells
This commit is contained in:
@@ -27,7 +27,7 @@ export function runMacro(
|
|||||||
const rows = data.rows.map((row, rowIndex) => {
|
const rows = data.rows.map((row, rowIndex) => {
|
||||||
const selectedRow = selectedRows[rowIndex];
|
const selectedRow = selectedRows[rowIndex];
|
||||||
if (selectedRow) {
|
if (selectedRow) {
|
||||||
const changedValues = [];
|
const modifiedFields = [];
|
||||||
let res = null;
|
let res = null;
|
||||||
for (const cell of selectedRow) {
|
for (const cell of selectedRow) {
|
||||||
const { column } = cell;
|
const { column } = cell;
|
||||||
@@ -38,14 +38,14 @@ export function runMacro(
|
|||||||
res = { ...row };
|
res = { ...row };
|
||||||
}
|
}
|
||||||
res[column] = newValue;
|
res[column] = newValue;
|
||||||
if (preview) changedValues.push(column);
|
if (preview) modifiedFields.push(column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res) {
|
if (res) {
|
||||||
if (changedValues.length > 0) {
|
if (modifiedFields.length > 0) {
|
||||||
return {
|
return {
|
||||||
...res,
|
...res,
|
||||||
__changedValues: new Set(changedValues),
|
__modifiedFields: new Set(modifiedFields),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -56,9 +56,8 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
if (insertedRowIndex != null) status = 'inserted';
|
if (insertedRowIndex != null) status = 'inserted';
|
||||||
const rowStatus = {
|
const rowStatus = {
|
||||||
status,
|
status,
|
||||||
modifiedFields: new Set(
|
modifiedFields:
|
||||||
matchedChangeSetItem && matchedChangeSetItem.fields ? Object.keys(matchedChangeSetItem.fields) : []
|
matchedChangeSetItem && matchedChangeSetItem.fields ? new Set(Object.keys(matchedChangeSetItem.fields)) : null,
|
||||||
),
|
|
||||||
};
|
};
|
||||||
this.rowDataCache[index] = rowUpdated;
|
this.rowDataCache[index] = rowUpdated;
|
||||||
this.rowStatusCache[index] = rowStatus;
|
this.rowStatusCache[index] = rowStatus;
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export default function DataGridCore(props) {
|
|||||||
isLoading,
|
isLoading,
|
||||||
grider,
|
grider,
|
||||||
onSelectionChanged,
|
onSelectionChanged,
|
||||||
|
frameSelection,
|
||||||
} = props;
|
} = props;
|
||||||
// console.log('RENDER GRID', display.baseTable.pureName);
|
// console.log('RENDER GRID', display.baseTable.pureName);
|
||||||
const columns = React.useMemo(() => display.allColumns, [display]);
|
const columns = React.useMemo(() => display.allColumns, [display]);
|
||||||
@@ -997,6 +998,7 @@ export default function DataGridCore(props) {
|
|||||||
autofillMarkerCell={filterCellForRow(autofillMarkerCell, rowIndex)}
|
autofillMarkerCell={filterCellForRow(autofillMarkerCell, rowIndex)}
|
||||||
display={display}
|
display={display}
|
||||||
focusedColumn={display.focusedColumn}
|
focusedColumn={display.focusedColumn}
|
||||||
|
frameSelection={frameSelection}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ const TableBodyCell = styled.td`
|
|||||||
background-color: deepskyblue;
|
background-color: deepskyblue;
|
||||||
color: white;`}
|
color: white;`}
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.isFrameSelected &&
|
||||||
|
`
|
||||||
|
outline: 3px solid cyan;
|
||||||
|
outline-offset: -3px;`}
|
||||||
|
|
||||||
${(props) =>
|
${(props) =>
|
||||||
props.isAutofillSelected &&
|
props.isAutofillSelected &&
|
||||||
!props.isFocusedColumn &&
|
!props.isFocusedColumn &&
|
||||||
@@ -59,7 +65,7 @@ const TableBodyCell = styled.td`
|
|||||||
`
|
`
|
||||||
background-color: #DBFFDB;`}
|
background-color: #DBFFDB;`}
|
||||||
|
|
||||||
${(props) =>
|
${(props) =>
|
||||||
!props.isSelected &&
|
!props.isSelected &&
|
||||||
!props.isAutofillSelected &&
|
!props.isAutofillSelected &&
|
||||||
!props.isFocusedColumn &&
|
!props.isFocusedColumn &&
|
||||||
@@ -175,6 +181,7 @@ function DataGridRow(props) {
|
|||||||
autofillSelectedCells,
|
autofillSelectedCells,
|
||||||
focusedColumn,
|
focusedColumn,
|
||||||
grider,
|
grider,
|
||||||
|
frameSelection,
|
||||||
} = props;
|
} = props;
|
||||||
// usePropsCompare({
|
// usePropsCompare({
|
||||||
// rowHeight,
|
// rowHeight,
|
||||||
@@ -200,7 +207,7 @@ function DataGridRow(props) {
|
|||||||
const hintFieldsAllowed = visibleRealColumns
|
const hintFieldsAllowed = visibleRealColumns
|
||||||
.filter((col) => {
|
.filter((col) => {
|
||||||
if (!col.hintColumnName) return false;
|
if (!col.hintColumnName) return false;
|
||||||
if (rowStatus.status == 'updated' && rowStatus.modifiedFields.has(col.uniqueName)) return false;
|
if (rowStatus.modifiedFields && rowStatus.modifiedFields.has(col.uniqueName)) return false;
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map((col) => col.uniqueName);
|
.map((col) => col.uniqueName);
|
||||||
@@ -222,13 +229,18 @@ function DataGridRow(props) {
|
|||||||
}}
|
}}
|
||||||
data-row={rowIndex}
|
data-row={rowIndex}
|
||||||
data-col={col.colIndex}
|
data-col={col.colIndex}
|
||||||
isSelected={cellIsSelected(rowIndex, col.colIndex, selectedCells)}
|
isSelected={frameSelection ? false : cellIsSelected(rowIndex, col.colIndex, selectedCells)}
|
||||||
|
isFrameSelected={frameSelection ? cellIsSelected(rowIndex, col.colIndex, selectedCells) : false}
|
||||||
isAutofillSelected={cellIsSelected(rowIndex, col.colIndex, autofillSelectedCells)}
|
isAutofillSelected={cellIsSelected(rowIndex, col.colIndex, autofillSelectedCells)}
|
||||||
isModifiedRow={rowStatus.status == 'updated'}
|
isModifiedRow={rowStatus.status == 'updated'}
|
||||||
isFocusedColumn={col.uniqueName == focusedColumn}
|
isFocusedColumn={col.uniqueName == focusedColumn}
|
||||||
isModifiedCell={rowStatus.status == 'updated' && rowStatus.modifiedFields.has(col.uniqueName)}
|
isModifiedCell={rowStatus.modifiedFields && rowStatus.modifiedFields.has(col.uniqueName)}
|
||||||
isInsertedRow={rowStatus.status == 'inserted'}
|
isInsertedRow={
|
||||||
isDeletedRow={rowStatus.status == 'deleted'}
|
rowStatus.status == 'inserted' || (rowStatus.insertedFields && rowStatus.insertedFields.has(col.uniqueName))
|
||||||
|
}
|
||||||
|
isDeletedRow={
|
||||||
|
rowStatus.status == 'deleted' || (rowStatus.deletedFields && rowStatus.deletedFields.has(col.uniqueName))
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{inplaceEditorState.cell &&
|
{inplaceEditorState.cell &&
|
||||||
rowIndex == inplaceEditorState.cell[0] &&
|
rowIndex == inplaceEditorState.cell[0] &&
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export interface GriderRowStatus {
|
export interface GriderRowStatus {
|
||||||
status: 'regular' | 'updated' | 'deleted' | 'inserted';
|
status: 'regular' | 'updated' | 'deleted' | 'inserted';
|
||||||
modifiedFields: Set<string>;
|
modifiedFields?: Set<string>;
|
||||||
|
insertedFields?: Set<string>;
|
||||||
|
deletedFields?: Set<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default abstract class Grider {
|
export default abstract class Grider {
|
||||||
@@ -10,7 +12,6 @@ export default abstract class Grider {
|
|||||||
getRowStatus(index): GriderRowStatus {
|
getRowStatus(index): GriderRowStatus {
|
||||||
const res: GriderRowStatus = {
|
const res: GriderRowStatus = {
|
||||||
status: 'regular',
|
status: 'regular',
|
||||||
modifiedFields: new Set(),
|
|
||||||
};
|
};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export default function FreeTableGridCore(props) {
|
|||||||
grider={grider}
|
grider={grider}
|
||||||
display={display}
|
display={display}
|
||||||
onSelectionChanged={macroPreview ? handleSelectionChanged : null}
|
onSelectionChanged={macroPreview ? handleSelectionChanged : null}
|
||||||
|
frameSelection={!!macroPreview}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { FreeTableModel, MacroDefinition, MacroSelectedCell, runMacro } from '@dbgate/datalib';
|
import { FreeTableModel, MacroDefinition, MacroSelectedCell, runMacro } from '@dbgate/datalib';
|
||||||
import Grider from '../datagrid/Grider';
|
import Grider, { GriderRowStatus } from '../datagrid/Grider';
|
||||||
|
|
||||||
export default class MacroPreviewGrider extends Grider {
|
export default class MacroPreviewGrider extends Grider {
|
||||||
model: FreeTableModel;
|
model: FreeTableModel;
|
||||||
@@ -8,6 +8,14 @@ export default class MacroPreviewGrider extends Grider {
|
|||||||
this.model = runMacro(macro, macroArgs, model, true, selectedCells);
|
this.model = runMacro(macro, macroArgs, model, true, selectedCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRowStatus(index): GriderRowStatus {
|
||||||
|
const row = this.model.rows[index];
|
||||||
|
return {
|
||||||
|
status: 'regular',
|
||||||
|
modifiedFields: row ? row.__modifiedFields : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
getRowData(index: any) {
|
getRowData(index: any) {
|
||||||
return this.model.rows[index];
|
return this.model.rows[index];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user