diff --git a/src/components/DataDimension/Info/DataElementInfo.js b/src/components/DataDimension/Info/DataElementInfo.js index c3c72512c..4a1754bdd 100644 --- a/src/components/DataDimension/Info/DataElementInfo.js +++ b/src/components/DataDimension/Info/DataElementInfo.js @@ -3,7 +3,13 @@ import PropTypes from 'prop-types' import React from 'react' import i18n from '../../../locales/index.js' import { valueTypeDisplayNames } from '../../../modules/valueTypes.js' -import { getCommonFields, InfoTable } from './InfoTable.js' +import { + getCommonFields, + renderDataSets, + renderLegendSets, + renderGroupMemberships, + InfoTable, +} from './InfoTable.js' import styles from './styles/InfoPopover.style.js' const dataElementQuery = { @@ -29,20 +35,12 @@ export const DataElementInfo = ({ id, displayNameProp }) => { {i18n.t('Data set(s)')} - {data?.dataElement.dataSetElements.length === 1 ? ( - data.dataElement.dataSetElements[0].dataSet - .displayName - ) : ( - - )} + {data?.dataElement.dataSetElements && + renderDataSets( + data.dataElement.dataSetElements.map( + ({ dataSet }) => dataSet + ) + )} @@ -66,18 +64,26 @@ export const DataElementInfo = ({ id, displayNameProp }) => { {i18n.t('Category combo')} -
- - {data?.dataElement.categoryCombo.displayName} - - -
+ {data?.dataElement.categoryCombo.displayName === + 'default' ? ( + {i18n.t('None')} + ) : ( +
+ + { + data?.dataElement.categoryCombo + .displayName + } + + +
+ )} {data?.dataElement.optionSet && ( @@ -89,35 +95,16 @@ export const DataElementInfo = ({ id, displayNameProp }) => { {i18n.t('Group membership')} - {data?.dataElement.dataElementGroups.length === 1 ? ( - data.dataElement.dataElementGroups[0].displayName - ) : ( - - )} + {data?.dataElement.dataElementGroups && + renderGroupMemberships( + data.dataElement.dataElementGroups + )} {Boolean(data?.dataElement.legendSets.length) && ( {i18n.t('Legend set(s)')} - - {data.dataElement.legendSets.length === 1 ? ( - data.dataElement.legendSets[0].displayName - ) : ( - - )} - + {renderLegendSets(data.dataElement.legendSets)} )} diff --git a/src/components/DataDimension/Info/DataElementOperandInfo.js b/src/components/DataDimension/Info/DataElementOperandInfo.js index fa8ed6da5..622a899ff 100644 --- a/src/components/DataDimension/Info/DataElementOperandInfo.js +++ b/src/components/DataDimension/Info/DataElementOperandInfo.js @@ -3,7 +3,13 @@ import PropTypes from 'prop-types' import React, { useCallback, useEffect, useState } from 'react' import i18n from '../../../locales/index.js' import { valueTypeDisplayNames } from '../../../modules/valueTypes.js' -import { getCommonFields, InfoTable } from './InfoTable.js' +import { + getCommonFields, + renderDataSets, + renderGroupMemberships, + renderLegendSets, + InfoTable, +} from './InfoTable.js' import styles from './styles/InfoPopover.style.js' const dataElementOperandsQuery = { @@ -81,21 +87,12 @@ export const DataElementOperandInfo = ({ id, displayNameProp }) => { {i18n.t('Data set(s)')} - {data?.dataElementOperand.dataElement.dataSetElements - .length === 1 ? ( - data.dataElementOperand.dataElement - .dataSetElements[0].dataSet.displayName - ) : ( - - )} + {data?.dataElementOperand.dataElement.dataSetElements && + renderDataSets( + data.dataElementOperand.dataElement.dataSetElements.map( + ({ dataSet }) => dataSet + ) + )} @@ -125,21 +122,26 @@ export const DataElementOperandInfo = ({ id, displayNameProp }) => { {i18n.t('Category combo')} -
- - { - data?.dataElementOperand.dataElement - .categoryCombo.displayName - } - - -
+ {data?.dataElementOperand.dataElement.categoryCombo + .displayName === 'default' ? ( + {i18n.t('None')} + ) : ( +
+ + { + data?.dataElementOperand.dataElement + .categoryCombo.displayName + } + + +
+ )} {data?.dataElementOperand.dataElement.optionSet && ( @@ -156,19 +158,12 @@ export const DataElementOperandInfo = ({ id, displayNameProp }) => { {i18n.t('Group membership')} - {data?.dataElementOperand.dataElement.dataElementGroups - .length === 1 ? ( - data.dataElementOperand.dataElement - .dataElementGroups[0].displayName - ) : ( - - )} + {data?.dataElementOperand.dataElement + .dataElementGroups && + renderGroupMemberships( + data.dataElementOperand.dataElement + .dataElementGroups + )} {Boolean( @@ -177,18 +172,8 @@ export const DataElementOperandInfo = ({ id, displayNameProp }) => { {i18n.t('Legend set(s)')} - {data.dataElementOperand.dataElement.legendSets - .length === 1 ? ( - data.dataElementOperand.dataElement - .legendSets[0].displayName - ) : ( - + {renderLegendSets( + data.dataElementOperand.dataElement.legendSets )} diff --git a/src/components/DataDimension/Info/EventDataItemInfo.js b/src/components/DataDimension/Info/EventDataItemInfo.js index 8b5b867ed..5074580ab 100644 --- a/src/components/DataDimension/Info/EventDataItemInfo.js +++ b/src/components/DataDimension/Info/EventDataItemInfo.js @@ -4,7 +4,7 @@ import React from 'react' import i18n from '../../../locales/index.js' import { DIMENSION_TYPE_PROGRAM_DATA_ELEMENT } from '../../../modules/dataTypes.js' import { valueTypeDisplayNames } from '../../../modules/valueTypes.js' -import { getCommonFields, InfoTable } from './InfoTable.js' +import { getCommonFields, renderLegendSets, InfoTable } from './InfoTable.js' import styles from './styles/InfoPopover.style.js' const programDataElementQuery = { @@ -66,19 +66,7 @@ export const EventDataItemInfo = ({ type, id, displayNameProp }) => { {Boolean(data?.legendSets.length) && ( {i18n.t('Legend set(s)')} - - {data.legendSets.length === 1 ? ( - data.legendSets[0].displayName - ) : ( - - )} - + {renderLegendSets(data.legendSets)} )} diff --git a/src/components/DataDimension/Info/IndicatorInfo.js b/src/components/DataDimension/Info/IndicatorInfo.js index 690e28dfa..9af68cd20 100644 --- a/src/components/DataDimension/Info/IndicatorInfo.js +++ b/src/components/DataDimension/Info/IndicatorInfo.js @@ -5,7 +5,9 @@ import { validateIndicatorExpressionMutation } from '../../../api/expression.js' import i18n from '../../../locales/index.js' import { getCommonFields, + renderGroupMemberships, renderHumanReadableExpression, + renderLegendSets, InfoTable, } from './InfoTable.js' import styles from './styles/InfoPopover.style.js' @@ -156,39 +158,16 @@ export const IndicatorInfo = ({ id, displayNameProp }) => { {i18n.t('Group membership')} - {data?.indicator.indicatorGroups.length === 1 ? ( - data.indicator.indicatorGroups[0].displayName - ) : ( -
- -
- )} + {data?.indicator.indicatorGroups && + renderGroupMemberships( + data.indicator.indicatorGroups + )} {Boolean(data?.indicator.legendSets.length) && ( {i18n.t('Legend set(s)')} - - {data.indicator.legendSets.length === 1 ? ( - data.indicator.legendSets[0].displayName - ) : ( -
- -
- )} - + {renderLegendSets(data.indicator.legendSets)} )} diff --git a/src/components/DataDimension/Info/InfoTable.js b/src/components/DataDimension/Info/InfoTable.js index 9d7b457c1..ccb9875df 100644 --- a/src/components/DataDimension/Info/InfoTable.js +++ b/src/components/DataDimension/Info/InfoTable.js @@ -15,6 +15,58 @@ export const capitalizeText = (text) => export const sentenceCaseText = (text) => text && capitalizeText(text.replaceAll('_', ' ').toLowerCase()) +export const renderDataSets = (dataSets) => { + if (dataSets.length === 0) { + return ( + <> + {i18n.t('None')} + + + ) + } else if (dataSets.length === 1) { + return dataSets[0].displayName + } else { + return ( + <> +
+ +
+ + + ) + } +} + +export const renderGroupMemberships = (groups) => { + if (groups.length === 0) { + return ( + <> + {i18n.t('None')} + + + ) + } else if (groups.length === 1) { + return groups[0].displayName + } else { + return ( + <> +
+ +
+ + + ) + } +} + export const renderHumanReadableExpression = (expressionData) => ( <> {expressionData.status === 'ERROR' ? ( @@ -26,6 +78,23 @@ export const renderHumanReadableExpression = (expressionData) => ( ) +export const renderLegendSets = (legendSets) => { + return legendSets.length === 1 ? ( + legendSets[0].displayName + ) : ( + <> +
+ +
+ + + ) +} + export const InfoTable = ({ data, error, loading, children }) => { const { fromServerDate } = useTimeZoneConversion() diff --git a/src/components/DataDimension/Info/ProgramIndicatorInfo.js b/src/components/DataDimension/Info/ProgramIndicatorInfo.js index f07dee1a6..8d45c13ad 100644 --- a/src/components/DataDimension/Info/ProgramIndicatorInfo.js +++ b/src/components/DataDimension/Info/ProgramIndicatorInfo.js @@ -6,6 +6,7 @@ import i18n from '../../../locales/index.js' import { getCommonFields, renderHumanReadableExpression, + renderLegendSets, sentenceCaseText, InfoTable, } from './InfoTable.js' @@ -198,19 +199,7 @@ export const ProgramIndicatorInfo = ({ id, displayNameProp }) => { {i18n.t('Legend set(s)')} - {data.programIndicator.legendSets.length === 1 ? ( - data.programIndicator.legendSets[0].displayName - ) : ( -
- -
- )} + {renderLegendSets(data.programIndicator.legendSets)} )}