Skip to content

Commit

Permalink
fix: avoid DV plugin crash if no ou levels are returned (#1442)
Browse files Browse the repository at this point in the history
This happened on test.e2e.dhis2.org/analytics-dev, I'm not sure it's
possible for an instance to not have any ou levels, but this fix prevents
the plugin from crashing and the app from showing a blank visualization.

Co-authored-by: Martin <martin@moid.se>
  • Loading branch information
edoardo and martinkrulltott authored Jun 20, 2023
1 parent cb51518 commit 5296bd7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/modules/ouLevelUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const replaceNumericOuLevelWithUid = (ouLevels) => (item) => {
}

const ouIntId = parseInt(ouIdHelper.removePrefix(item.id), 10)
const ouUid = ouLevels.find((l) => parseInt(l.level, 10) === ouIntId).id
const ouUid = ouLevels.find((l) => parseInt(l.level, 10) === ouIntId)?.id

return Object.assign({}, item, { id: ouIdHelper.addLevelPrefix(ouUid) })
return ouUid
? Object.assign({}, item, { id: ouIdHelper.addLevelPrefix(ouUid) })
: item
}

export const convertOuLevelsToUids = (ouLevels, layout) => {
Expand Down

0 comments on commit 5296bd7

Please sign in to comment.