Skip to content

Commit

Permalink
Merge pull request #79 from qlik-oss/QB-493/wrongDataDisplay
Browse files Browse the repository at this point in the history
Qb 493/wrong data display
  • Loading branch information
PurwaShrivastava authored Dec 5, 2019
2 parents ce81549 + 8aa8627 commit f17a7b7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
41 changes: 35 additions & 6 deletions src/data-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DataCell from './data-cell.jsx';
import RowHeader from './row-header.jsx';
import { injectSeparators } from '../utilities';

// eslint-disable-next-line react/prefer-stateless-function
class DataTable extends React.PureComponent {
render () {
const {
Expand All @@ -20,6 +21,7 @@ class DataTable extends React.PureComponent {
const {
headers: {
dimension1,
dimension2,
measurements
},
matrix
Expand All @@ -30,6 +32,36 @@ class DataTable extends React.PureComponent {
maxWidth: columnSeparatorWidth
};

const renderMeasurementData = (dimIndex, atEvery) => {
const injectSeparatorsArray = injectSeparators(
matrix[dimIndex],
columnSeparatorWidth,
atEvery
);

if (dimension2.length <= 0) {
return injectSeparatorsArray;
}

let measurementDataRow = [],
index = 0;
dimension2.forEach((dim2) => {
measurements.forEach((measure) => {
for (index = 0; index < injectSeparatorsArray.length; index++) {
if (dimension1[dimIndex].displayValue === injectSeparatorsArray[index].parents.dimension1.header) {
if (dim2.displayValue === injectSeparatorsArray[index].parents.dimension2.header) {
if (measure.name === injectSeparatorsArray[index].parents.measurement.header) {
measurementDataRow.push(injectSeparatorsArray[index]);
break;
}
}
}
}
});
});
return measurementDataRow;
};

return (
<div className="row-wrapper">
<table>
Expand Down Expand Up @@ -65,11 +97,7 @@ class DataTable extends React.PureComponent {
styling={styling}
/> : null
}
{renderData && injectSeparators(
matrix[dimensionIndex],
columnSeparatorWidth,
{ atEvery: measurements.length }
).map((measurementData, index) => {
{renderData && renderMeasurementData(dimensionIndex, { atEvery: measurements.length }).map((measurementData, index) => {
if (measurementData.isSeparator) {
return (
<td
Expand All @@ -80,6 +108,7 @@ class DataTable extends React.PureComponent {
);
}

// eslint-disable-next-line no-shadow
const { dimension1: dimension1Info, dimension2, measurement } = measurementData.parents;
const id = `${dimension1Info.elementNumber}-${dimension2 && dimension2.elementNumber}-${measurement.header}-${measurement.index}`;
return (
Expand Down Expand Up @@ -112,14 +141,14 @@ DataTable.defaultProps = {
DataTable.propTypes = {
cellWidth: PropTypes.string.isRequired,
columnSeparatorWidth: PropTypes.string.isRequired,
component: PropTypes.shape({}).isRequired,
data: PropTypes.shape({
headers: PropTypes.shape({
dimension1: PropTypes.array.isRequired
}).isRequired,
matrix: PropTypes.arrayOf(PropTypes.array.isRequired).isRequired
}).isRequired,
general: PropTypes.shape({}).isRequired,
component: PropTypes.shape({}).isRequired,
renderData: PropTypes.bool,
styling: PropTypes.shape({
hasCustomFileStyle: PropTypes.bool.isRequired
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default {
}
],
qMeasures: [],
qSuppressMissing: true,
qSuppressZero: false
}
},
Expand Down
22 changes: 13 additions & 9 deletions src/initialize-transformed.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function generateMatrixCell ({ cell, dimension1Information, dimension2Informatio

if (dimension2Information) {
matrixCell.parents.dimension2 = {
elementNumber: dimension2Information.qElemNumber
elementNumber: dimension2Information.qElemNumber,
header: dimension2Information.qText
};
}

Expand Down Expand Up @@ -141,7 +142,7 @@ function generateDataSet (
let rowDataIndex = 0;
dimension2.forEach(dim => {
rowDataIndex = appendMissingCells(
row, newRow, rowDataIndex, measurements, rowIndex, dim.elementNumber);
row, newRow, rowDataIndex, measurements, rowIndex, dim, dimension1);
});
} else {
appendMissingCells(row, newRow, 0, measurements, rowIndex);
Expand All @@ -165,14 +166,11 @@ function generateDataSet (
* index of the dimension2 value being processed.
*/
function appendMissingCells (
sourceRow, destRow, sourceIndex, measurements, dim1ElementNumber, dim2ElementNumber = -1) {
sourceRow, destRow, sourceIndex, measurements, matrixIndex, dim2, dim1) {

let index = sourceIndex;
measurements.forEach((measurement, measureIndex) => {
if (index < sourceRow.length
&& (dim2ElementNumber === -1
|| sourceRow[index].parents.dimension2.elementNumber === dim2ElementNumber)
&& sourceRow[index].parents.measurement.header === measurement.name) {
if (index < sourceRow.length) {
// Source contains the expected cell
destRow.push(sourceRow[index]);
index++;
Expand All @@ -181,8 +179,14 @@ function appendMissingCells (
destRow.push({
displayValue: '',
parents: {
dimension1: { elementNumber: dim1ElementNumber },
dimension2: { elementNumber: dim2ElementNumber },
dimension1: {
elementNumber: dim1[matrixIndex].elementNumber,
header: dim1[matrixIndex].displayValue
},
dimension2: {
elementNumber: dim2.elementNumber,
header: dim2.displayValue
},
measurement: {
header: measurement.name,
index: measureIndex
Expand Down

0 comments on commit f17a7b7

Please sign in to comment.