Skip to content

Commit

Permalink
fix: apply legend to all numeric and boolean types (DHIS2-17611) (#1683)
Browse files Browse the repository at this point in the history
* fix: apply to all numeric and boolean types

* chore: remove obsolete comment, remove test file

* chore: add back i18n, weird issue
  • Loading branch information
janhenrikoverland authored Jun 26, 2024
1 parent e1ef741 commit e93b106
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions src/components/PivotTable/PivotTableValueCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/modules/renderValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+$/, '')

Expand Down Expand Up @@ -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]+/, ' ')
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/valueTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit e93b106

Please sign in to comment.