From 923e108dd31f3c7f7c441f148432fdc5ab4d9248 Mon Sep 17 00:00:00 2001 From: Jan Siegel Date: Tue, 19 Mar 2024 13:08:50 +0100 Subject: [PATCH] Make the `source` argument for `setDataAtCell` in the Merge Cells plugin more specific. (#10857) * Make the `source` argument for `setDataAtCell` in the Merge Cells plugin more specific. * - Extend the test with `beforeChange` hook - Remove the ObserveChanges entry from the Events and Hooks docs page - Add the Merge Cells entry to the Events and Hooks docs page * Add the changelog entry. --- .changelogs/10857.json | 8 +++++ .../events-and-hooks/events-and-hooks.md | 2 +- .../mergeCells/__tests__/mergeCells.spec.js | 30 +++++++++++++++++++ .../src/plugins/mergeCells/mergeCells.js | 4 ++- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .changelogs/10857.json diff --git a/.changelogs/10857.json b/.changelogs/10857.json new file mode 100644 index 00000000000..f51fda39360 --- /dev/null +++ b/.changelogs/10857.json @@ -0,0 +1,8 @@ +{ + "issuesOrigin": "private", + "title": "Unified the `source` arguments of the `beforeChange`/`afterChange` hooks when being triggered by the Merge Cells plugin.", + "type": "fixed", + "issueOrPR": 10857, + "breaking": false, + "framework": "none" +} diff --git a/docs/content/guides/getting-started/events-and-hooks/events-and-hooks.md b/docs/content/guides/getting-started/events-and-hooks/events-and-hooks.md index 8f10b036151..8a212f1906e 100644 --- a/docs/content/guides/getting-started/events-and-hooks/events-and-hooks.md +++ b/docs/content/guides/getting-started/events-and-hooks/events-and-hooks.md @@ -170,7 +170,7 @@ It's worth mentioning that some Handsontable hooks are triggered from the Handso | [`ContextMenu.rowAbove`](@/api/contextMenu.md) | Action triggered by the ContextMenu plugin after the "Insert row above" has been clicked. | | [`ContextMenu.rowBelow`](@/api/contextMenu.md) | Action triggered by the ContextMenu plugin after the "Insert row below" has been clicked. | | [`CopyPaste.paste`](@/api/copyPaste.md) | Action triggered by the CopyPaste plugin after the value has been pasted. | -| `ObserveChanges.change` | Action triggered by the ObserveChanges plugin after the changes have been detected. | +| `MergeCells` | Action triggered by the MergeCells plugin when clearing the merged cells' underlying cells. | | [`UndoRedo.redo`](@/api/undoRedo.md) | Action triggered by the UndoRedo plugin after the change has been redone. | | [`UndoRedo.undo`](@/api/undoRedo.md) | Action triggered by the UndoRedo plugin after the change has been undone. | | [`ColumnSummary.set`](@/api/columnSummary.md) | Action triggered by the ColumnSummary plugin after the calculation has been done. | diff --git a/handsontable/src/plugins/mergeCells/__tests__/mergeCells.spec.js b/handsontable/src/plugins/mergeCells/__tests__/mergeCells.spec.js index ce8ec577451..05c05662d4b 100644 --- a/handsontable/src/plugins/mergeCells/__tests__/mergeCells.spec.js +++ b/handsontable/src/plugins/mergeCells/__tests__/mergeCells.spec.js @@ -67,6 +67,36 @@ describe('MergeCells', () => { ]); }); + it('should provide information about the source of the change in the `beforeChange` and `afterChange` hooks', () => { + const beforeChange = jasmine.createSpy('beforeChange'); + const afterChange = jasmine.createSpy('afterChange'); + + handsontable({ + data: [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16], + ], + mergeCells: [{ + row: 0, + col: 0, + rowspan: 2, + colspan: 2 + }], + beforeChange, + afterChange, + }); + + expect(beforeChange.calls.mostRecent().args[1]).toEqual('MergeCells'); + expect(afterChange.calls.mostRecent().args[1]).toEqual('MergeCells'); + + getPlugin('mergeCells').merge(2, 2, 3, 3); + + expect(beforeChange.calls.mostRecent().args[1]).toEqual('MergeCells'); + expect(afterChange.calls.mostRecent().args[1]).toEqual('MergeCells'); + }); + it('should merge cells on startup respecting indexes sequence changes', () => { handsontable({ data: [ diff --git a/handsontable/src/plugins/mergeCells/mergeCells.js b/handsontable/src/plugins/mergeCells/mergeCells.js index 19f354b4d86..3a6782fa998 100644 --- a/handsontable/src/plugins/mergeCells/mergeCells.js +++ b/handsontable/src/plugins/mergeCells/mergeCells.js @@ -313,7 +313,8 @@ export class MergeCells extends BasePlugin { return; } - this.hot.setDataAtCell(populatedNulls); + // TODO: Change the `source` argument to a more meaningful value, e.g. `${this.pluginName}.clearCells`. + this.hot.setDataAtCell(populatedNulls, undefined, undefined, this.pluginName); } } @@ -451,6 +452,7 @@ export class MergeCells extends BasePlugin { populationInfo = [mergeParent.row, mergeParent.col, clearedData]; } else { + // TODO: Change the `source` argument to a more meaningful value, e.g. `${this.pluginName}.clearCells`. this.hot.populateFromArray( mergeParent.row, mergeParent.col, clearedData, undefined, undefined, this.pluginName); }