From e93b106f7e0b3ab9ebae8a21a07d5cebee3d48d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Henrik=20=C3=98verland?= Date: Wed, 26 Jun 2024 16:26:18 +0200 Subject: [PATCH] fix: apply legend to all numeric and boolean types (DHIS2-17611) (#1683) * fix: apply to all numeric and boolean types * chore: remove obsolete comment, remove test file * chore: add back i18n, weird issue --- i18n/en.pot | 4 ++-- src/components/PivotTable/PivotTableValueCell.js | 9 ++++++--- src/modules/renderValue.js | 7 +++++-- src/modules/valueTypes.js | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 936f74c49..7aea739a6 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-01-25T12:05:03.360Z\n" -"PO-Revision-Date: 2024-01-25T12:05:03.360Z\n" +"POT-Creation-Date: 2024-06-26T14:09:30.876Z\n" +"PO-Revision-Date: 2024-06-26T14:09:30.876Z\n" msgid "view only" msgstr "view only" diff --git a/src/components/PivotTable/PivotTableValueCell.js b/src/components/PivotTable/PivotTableValueCell.js index 9013a0a83..78d204f2c 100644 --- a/src/components/PivotTable/PivotTableValueCell.js +++ b/src/components/PivotTable/PivotTableValueCell.js @@ -2,7 +2,10 @@ import PropTypes from 'prop-types' import React, { useRef } from 'react' import { applyLegendSet } from '../../modules/pivotTable/applyLegendSet.js' import { CELL_TYPE_VALUE } from '../../modules/pivotTable/pivotTableConstants.js' -import { VALUE_TYPE_NUMBER } from '../../modules/valueTypes.js' +import { + isNumericValueType, + isBooleanValueType, +} from '../../modules/valueTypes.js' import { PivotTableCell } from './PivotTableCell.js' import { PivotTableEmptyCell } from './PivotTableEmptyCell.js' import { usePivotTableEngine } from './PivotTableEngineContext.js' @@ -43,10 +46,10 @@ export const PivotTableValueCell = ({ ) } - // TODO: Add support for 'INTEGER' type (requires server changes) const legendStyle = cellContent.cellType === CELL_TYPE_VALUE && - cellContent.valueType === VALUE_TYPE_NUMBER + (isNumericValueType(cellContent.valueType) || + isBooleanValueType(cellContent.valueType)) ? applyLegendSet( cellContent.rawValue, cellContent.dxDimension, diff --git a/src/modules/renderValue.js b/src/modules/renderValue.js index a65d8a6d8..5e87629f1 100644 --- a/src/modules/renderValue.js +++ b/src/modules/renderValue.js @@ -2,7 +2,7 @@ import { NUMBER_TYPE_ROW_PERCENTAGE, NUMBER_TYPE_COLUMN_PERCENTAGE, } from './pivotTable/pivotTableConstants.js' -import { isNumericValueType } from './valueTypes.js' +import { isNumericValueType, isBooleanValueType } from './valueTypes.js' const trimTrailingZeros = (stringValue) => stringValue.replace(/\.?0+$/, '') @@ -53,7 +53,10 @@ const toFixedPrecisionString = (value, skipRounding) => { } export const renderValue = (value, valueType, visualization) => { - if (!isNumericValueType(valueType) || value === undefined) { + if ( + !(isNumericValueType(valueType) || isBooleanValueType(valueType)) || + value === undefined + ) { return String(value).replace(/[^\S\n]+/, ' ') } diff --git a/src/modules/valueTypes.js b/src/modules/valueTypes.js index cf5dc01f0..89462b5c6 100644 --- a/src/modules/valueTypes.js +++ b/src/modules/valueTypes.js @@ -34,4 +34,7 @@ const NUMERIC_VALUE_TYPES = [ VALUE_TYPE_INTEGER_ZERO_OR_POSITIVE, ] +const BOOLEAN_VALUE_TYPES = [VALUE_TYPE_BOOLEAN, VALUE_TYPE_TRUE_ONLY] + export const isNumericValueType = (type) => NUMERIC_VALUE_TYPES.includes(type) +export const isBooleanValueType = (type) => BOOLEAN_VALUE_TYPES.includes(type)