Skip to content

Commit

Permalink
#7174 - Adds support for new index-translation mechanism in legacy co…
Browse files Browse the repository at this point in the history
…de of ColumnSummary - it is no more possible to read the visual index of non-existing column/row
  • Loading branch information
mrpiotr-dev committed Sep 7, 2020
1 parent 92aa8d4 commit 1b40234
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
://github.com/handsontable/handsontable/pull/7162)
- Fixed an issue where the column headers were cut off after hiding and then showing columns using the Hidden Columns
plugin. [#6395](https://github.com/handsontable/handsontable/issues/6395)
- Fixed an issue where after column or row alteration, Handsontable threw an error if ColumnSummary was enabled without defined rows ranges [#7174](https://github.com/handsontable/handsontable/pull/7174)

### Changed
- Updated dependencies to meet security requirements [#7222](https://github.com/handsontable/handsontable/pull/7222)
Expand Down
28 changes: 17 additions & 11 deletions src/plugins/columnSummary/endpoints.js
Expand Up @@ -497,10 +497,12 @@ class Endpoints {
this.hot.toVisualColumn(endpoint.destinationColumn)
];

// Clear the meta on the "old" indexes
const cellMeta = this.hot.getCellMeta(visualRowIndex, visualColumnIndex);
cellMeta.readOnly = false;
cellMeta.className = '';
if (visualColumnIndex !== null && visualRowIndex !== null) {
// Clear the meta on the "old" indexes
const cellMeta = this.hot.getCellMeta(visualRowIndex, visualColumnIndex);
cellMeta.readOnly = false;
cellMeta.className = '';
}

this.cellsToSetCache.push([
this.hot.toVisualRow(endpoint.destinationRow + (useOffset ? alterRowOffset : 0)),
Expand All @@ -527,14 +529,18 @@ class Endpoints {
return;
}

const cellMeta = this.hot.getCellMeta(
this.hot.toVisualRow(endpoint.destinationRow + reverseRowOffset),
endpoint.destinationColumn + reverseColOffset
);
const destinationVisualRow = this.hot.toVisualRow(endpoint.destinationRow + reverseRowOffset);

if (destinationVisualRow !== null) {
const cellMeta = this.hot.getCellMeta(
destinationVisualRow,
endpoint.destinationColumn + reverseColOffset
);

if (source === 'init' || cellMeta.readOnly !== endpoint.readOnly) {
cellMeta.readOnly = endpoint.readOnly;
cellMeta.className = 'columnSummaryResult';
if (source === 'init' || cellMeta.readOnly !== endpoint.readOnly) {
cellMeta.readOnly = endpoint.readOnly;
cellMeta.className = 'columnSummaryResult';
}
}

if (endpoint.roundFloat && !isNaN(endpoint.result)) {
Expand Down
36 changes: 36 additions & 0 deletions src/plugins/columnSummary/test/columnSummary.e2e.js
Expand Up @@ -474,6 +474,42 @@ describe('ColumnSummarySpec', () => {
expect(getCellMeta(0, 2).readOnly).toEqual(true);
});

describe('if range is undefined', () => {
it('should not throw an error if removing column', () => {
const hot = handsontable({
data: createNumericData(3, 3),
height: 200,
width: 200,
columnSummary: [{
destinationRow: 2,
destinationColumn: 2,
type: 'sum'
}],
});

expect(() => {
hot.alter('remove_col', 0, 1);
}).not.toThrow();
});

it('should not throw an error if removing row', () => {
const hot = handsontable({
data: createNumericData(3, 3),
height: 200,
width: 200,
columnSummary: [{
destinationRow: 2,
destinationColumn: 2,
type: 'sum'
}],
});

expect(() => {
hot.alter('remove_row', 0, 1);
}).not.toThrow();
});
});

it('should modify the calculation row range when a row was moved outside the range', () => {
const hot = handsontable({
data: createNumericData(40, 40),
Expand Down

0 comments on commit 1b40234

Please sign in to comment.