Skip to content

Commit

Permalink
chore: use level uuids rather than level numbers (#26)
Browse files Browse the repository at this point in the history
Part of fix for [DHIS2-6990]

The api has supported use of uid since 2.31 [DHIS2- 4889]
  • Loading branch information
jenniferarnesen authored May 22, 2019
1 parent e1f19b0 commit 9fb17b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/OrgUnitDimension/OrgUnitDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class OrgUnitDimension extends Component {

return {
...levelOu,
id: `${LEVEL_ID_PREFIX}-${levelOu.level}`,
id: `${LEVEL_ID_PREFIX}-${levelOu.id}`,
}
}),
],
Expand Down
15 changes: 15 additions & 0 deletions src/modules/__tests__/orgUnitDimension.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getLevelsFromIds } from '../orgUnitDimensions'

const levelOptions = [{ id: 'fluttershy' }, { id: 'rarity' }]

describe('orgUnitDimension module', () => {
it('returns array with id when level-id received', () => {
expect(getLevelsFromIds(['abc', 'LEVEL-rarity'], levelOptions)).toEqual(
['rarity']
)
})

it('returns empty array when level-id not received', () => {
expect(getLevelsFromIds(['abc', 'rarity'], levelOptions)).toEqual([])
})
})
8 changes: 2 additions & 6 deletions src/modules/orgUnitDimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,8 @@ export const getLevelsFromIds = (ids, levelOptions) => {
return ids
.filter(isLevelId)
.map(id => id.substr(LEVEL_ID_PREFIX.length + 1))
.map(
level =>
levelOptions.find(
option => Number(option.level) === Number(level)
).id
)
.map(id => levelOptions.find(option => option.id === id))
.map(level => level.id)
}

/**
Expand Down

0 comments on commit 9fb17b9

Please sign in to comment.