From be6ea56d1c733aba497d669184668f96e8ae344b Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Mon, 6 May 2024 13:21:16 +0200 Subject: [PATCH] fix: fix a crash when row totals is enabled (DHIS2-17297) (#1660) --- src/modules/pivotTable/PivotTableEngine.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modules/pivotTable/PivotTableEngine.js b/src/modules/pivotTable/PivotTableEngine.js index b5788fee1..7b90e0935 100644 --- a/src/modules/pivotTable/PivotTableEngine.js +++ b/src/modules/pivotTable/PivotTableEngine.js @@ -515,9 +515,19 @@ export class PivotTableEngine { if (!this.data[row]) { return undefined } + const cellValue = this.data[row][column] - if (cellValue && !Array.isArray(cellValue)) { + if (!cellValue) { + // Empty cell + // The cell still needs to get the valueType to render correctly 0 and cumulative values + return { + valueType: VALUE_TYPE_NUMBER, + totalAggregationType: AGGREGATE_TYPE_SUM, + } + } + + if (!Array.isArray(cellValue)) { // This is a total cell return { valueType: cellValue.valueType, @@ -532,6 +542,7 @@ export class PivotTableEngine { const dxRowIndex = this.dimensionLookup.rows.findIndex( (dim) => dim.isDxDimension ) + if (rowHeaders.length && dxRowIndex !== -1) { return { valueType: rowHeaders[dxRowIndex].valueType, @@ -553,11 +564,6 @@ export class PivotTableEngine { } } - // Empty cell - // The cell still needs to get the valueType to render correctly 0 and cumulative values - // - // OR - // // Data is in Filter // TODO : This assumes the server ignores text types, we should confirm this is the case return {