Skip to content

Commit

Permalink
fix: filter out non data element items (DHIS2-16857)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Feb 21, 2024
1 parent 4a47db8 commit 49d1860
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 20 deletions.
11 changes: 9 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-02-16T10:12:05.207Z\n"
"PO-Revision-Date: 2024-02-16T10:12:05.207Z\n"
"POT-Creation-Date: 2024-02-20T11:20:56.384Z\n"
"PO-Revision-Date: 2024-02-20T11:20:56.384Z\n"

msgid "All items"
msgstr "All items"
Expand Down Expand Up @@ -63,6 +63,13 @@ msgstr ""
"'Scatter' is intended to show a single data item per axis. Only the first "
"item will be used and saved."

msgid ""
"'Outlier table' can only use data elements. Only data elements will be used "
"and saved."
msgstr ""
"'Outlier table' can only use data elements. Only data elements will be used "
"and saved."

msgid "Vertical"
msgstr "Vertical"

Expand Down
19 changes: 19 additions & 0 deletions src/components/DimensionsPanel/Dialogs/DialogManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export class DialogManager extends Component {
item.isActive = index < 1
})
}

let content = null
if (
dialogId === DIMENSION_ID_DATA ||
Expand Down Expand Up @@ -353,6 +354,24 @@ export class DialogManager extends Component {
},
})
}

if (visType === VIS_TYPE_OUTLIER_TABLE) {
let showInfo = false

selectedItems.forEach((item) => {
if (item.type !== DIMENSION_TYPE_DATA_ELEMENT) {
item.isActive = false
showInfo = true
}
})

if (showInfo) {
infoBoxMessage = i18n.t(
`'Outlier table' can only use data elements. Only data elements will be used and saved.`
)
}
}

const dimensionSelector = (
<DataDimension
enabledDataTypes={dataTypes}
Expand Down
32 changes: 23 additions & 9 deletions src/components/Layout/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
getLayoutTypeByVisType,
DIMENSION_ID_ASSIGNED_CATEGORIES,
DIMENSION_PROP_NO_ITEMS,
DIMENSION_TYPE_DATA_ELEMENT,
VIS_TYPE_OUTLIER_TABLE,
VIS_TYPE_SCATTER,
DIMENSION_ID_DATA,
ALL_DYNAMIC_DIMENSION_ITEMS,
Expand Down Expand Up @@ -61,13 +63,30 @@ const Chip = ({
</div>
)

const isSplitAxis =
type === VIS_TYPE_SCATTER && dimensionId === DIMENSION_ID_DATA

const getMaxNumberOfItems = () =>
getAxisMaxNumberOfItems(type, axisId) ||
getDimensionMaxNumberOfItems(type, dimensionId)

let activeItemIds = getMaxNumberOfItems()
? items.slice(0, getMaxNumberOfItems())
: items

// filter out non DATA_ELEMENT types for Outlier table vis type
if (type === VIS_TYPE_OUTLIER_TABLE && dimensionId === DIMENSION_ID_DATA) {
activeItemIds = activeItemIds.filter(
(id) =>
metadata[id]?.dimensionItemType === DIMENSION_TYPE_DATA_ELEMENT
)
}

const hasWarning =
hasAxisTooManyItems(type, axisId, items.length) ||
hasDimensionTooManyItems(type, dimensionId, items.length) ||
items.length > activeItemIds.length

const isSplitAxis =
type === VIS_TYPE_SCATTER && dimensionId === DIMENSION_ID_DATA

const handleClick = () => {
if (!getPredefinedDimensionProp(dimensionId, DIMENSION_PROP_NO_ITEMS)) {
onClick()
Expand Down Expand Up @@ -124,9 +143,6 @@ const Chip = ({
}

const renderTooltipContent = () => {
const activeItemIds = getMaxNumberOfItems()
? items.slice(0, getMaxNumberOfItems())
: items
const lockedLabel = isLocked
? i18n.t(
`{{dimensionName}} is locked to {{axisName}} for {{visTypeName}}`,
Expand Down Expand Up @@ -162,9 +178,7 @@ const Chip = ({
<span style={isSplitAxis ? styles.label : {}}>
{renderChipLabelSuffix()}
</span>
{(hasAxisTooManyItems(type, axisId, items.length) ||
hasDimensionTooManyItems(type, dimensionId, items.length)) &&
WarningIconWrapper}
{hasWarning && WarningIconWrapper}
{isLocked && LockIconWrapper}
</>
)
Expand Down
5 changes: 4 additions & 1 deletion src/components/Layout/TooltipContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { styles } from './styles/Tooltip.style.js'

const labels = {
noneSelected: () => i18n.t('None selected'),
noneInUse: () => i18n.t('None in use'),
onlyOneInUse: (name) => i18n.t("Only '{{- name}}' in use", { name }),
onlyLimitedNumberInUse: (number) =>
i18n.t("Only '{{number}}' in use", { number }),
Expand All @@ -25,7 +26,9 @@ export const TooltipContent = ({
const hasAllItemsSelected = itemIds.includes(ALL_DYNAMIC_DIMENSION_ITEMS)
const getWarningLabel = () => {
const warningLabel =
itemIds.length === 1
itemIds.length === 0
? labels.noneInUse()
: itemIds.length === 1
? labels.onlyOneInUse(
metadata[itemIds[0]]
? metadata[itemIds[0]].name
Expand Down
27 changes: 20 additions & 7 deletions src/modules/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AXIS_ID_FILTERS,
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
DIMENSION_TYPE_DATA_ELEMENT,
VIS_TYPE_OUTLIER_TABLE,
VIS_TYPE_SINGLE_VALUE,
VIS_TYPE_PIE,
Expand Down Expand Up @@ -139,7 +140,7 @@ export const getItemsByDimensionFromUi = (ui) => {
return result
}

export const getOutlierTableCurrentFromUi = (state, value) => {
export const getOutlierTableCurrentFromUi = (state, value, metadata) => {
const ui = {
...value,
layout: {
Expand All @@ -150,13 +151,25 @@ export const getOutlierTableCurrentFromUi = (state, value) => {

const axesFromUi = getAxesFromUi(ui)

// only save the first pe item
const peItems = layoutGetDimensionItems(axesFromUi, DIMENSION_ID_PERIOD)
const outlierTableAxesFromUi = layoutReplaceDimension(
axesFromUi,
DIMENSION_ID_PERIOD,
[peItems[0]]
)
const dxItems = layoutGetDimensionItems(axesFromUi, DIMENSION_ID_DATA)

const outlierTableAxesFromUi =
// only save the first pe item
layoutReplaceDimension(
// only save data elements dx items
layoutReplaceDimension(
axesFromUi,
DIMENSION_ID_DATA,
dxItems.filter(
({ id }) =>
metadata[id]?.dimensionItemType ===
DIMENSION_TYPE_DATA_ELEMENT
)
),
DIMENSION_ID_PERIOD,
[peItems[0]]
)

return {
...state,
Expand Down
6 changes: 5 additions & 1 deletion src/reducers/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export default (state = DEFAULT_CURRENT, action) => {
case VIS_TYPE_SCATTER:
return getScatterCurrentFromUi(state, action.value.ui)
case VIS_TYPE_OUTLIER_TABLE:
return getOutlierTableCurrentFromUi(state, action.value.ui)
return getOutlierTableCurrentFromUi(
state,
action.value.ui,
action.value.metadata
)
default: {
return getDefaultFromUi(
state,
Expand Down

0 comments on commit 49d1860

Please sign in to comment.