Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROU-4519: Issue with dropdown column with dependency triggering OnCellValueChange event twice #375

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 62 additions & 48 deletions src/Providers/DataGrid/Wijmo/Columns/DropdownColumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,66 +160,80 @@ namespace Providers.DataGrid.Wijmo.Column {
this.provider.index,
false
) ?? '';
const cellRange = new wijmo.grid.CellRange(
rowNumber,
this.provider.index
);
const currentSel = this.grid.provider.selection;

// check if the first selected parent cell has an undo action on undo stack
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const existingUndoAction: any =
this.grid.features.undoStack.stack._stack.find(
(data: GridEditAction) =>
data.col === currentSel.leftCol &&
data.row === currentSel.topRow
// if the child dropdown value is already empty, we don't want register the undo action and trigger cell value change event again
if (column && currentValue !== '') {
// get original value of the child cell
const originalValue = this.grid.features.dirtyMark.getOldValue(
rowNumber,
this.grid.getColumnByIndex(this.provider.index).config
.binding
);

if (existingUndoAction) {
// check if current child cell has an undo action on undo stack
const existingEditActionForColRow =
existingUndoAction?._actions?.find(
(action: GridEditAction) =>
action.col === this.provider.index &&
action.row === rowNumber
) ?? false;

// only add child undo action if it doesn't already exist. we don't want duplicated actions
if (existingEditActionForColRow === false) {
// add new child action into existing parent action in order
existingUndoAction.addChildAction(
new GridEditAction(
this.grid,
new wijmo.grid.CellRangeEventArgs(
this.grid.provider.cells,
cellRange
)
)
const cellRange = new wijmo.grid.CellRange(
rowNumber,
this.provider.index
);
const currentSel = this.grid.provider.selection;

// filter the parent cell has an undo actions on undo stack
const filteredUndoAction: wijmo.undo.UndoableAction[] =
this.grid.features.undoStack.stack._stack.filter(
(data: GridEditAction) =>
data.col === currentSel.leftCol &&
data.row === currentSel.topRow
);

// get the lastest undo action filtered if any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const existingUndoAction: any =
OS-giulianasilva marked this conversation as resolved.
Show resolved Hide resolved
filteredUndoAction.length > 0
? filteredUndoAction[filteredUndoAction.length - 1]
: undefined;

if (existingUndoAction) {
// check if current child cell has an undo action on undo stack
const existingEditActionForColRow =
existingUndoAction?._actions?.find(
(action: GridEditAction) =>
action.col === this.provider.index &&
action.row === rowNumber
) ?? false;

// only add child undo action if it doesn't already exist. we don't want duplicated actions
if (existingEditActionForColRow === false) {
// add new child action into existing parent action in order
existingUndoAction.addChildAction(
new GridEditAction(
this.grid,
new wijmo.grid.CellRangeEventArgs(
this.grid.provider.cells,
cellRange
)
)
);
}
}
}

// always clear the child cell when the parent changes
this.grid.provider.setCellData(
rowNumber,
this.provider.index,
'',
true
);
// always clear the child cell when the parent changes
this.grid.provider.setCellData(
rowNumber,
this.provider.index,
'',
true
);

this.grid.features.validationMark.validateCell(
rowNumber,
this,
true
);
this.grid.features.validationMark.validateCell(
rowNumber,
this,
false
);

// trigger cell value change event
if (column) {
this.columnEvents.trigger(
OSFramework.DataGrid.Event.Column.ColumnEventType
.OnCellValueChange,
'',
currentValue,
originalValue,
rowNumber
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Providers/DataGrid/Wijmo/Features/ValidationMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ namespace Providers.DataGrid.Wijmo.Feature {
currValue,
currValue
);
} else {
this._setCellStatus(column, rowNumber, currValue);
}
}

Expand Down
Loading