Skip to content

Commit

Permalink
fix: fetch repetition data for LL to show in plugin
Browse files Browse the repository at this point in the history
(cherry picked from commit 25378ce)
  • Loading branch information
edoardo committed Apr 9, 2024
1 parent e83ef75 commit e705ba2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
33 changes: 33 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Implements [DHIS2-XXXX](https://dhis2.atlassian.net/browse/DHIS2-XXXX)

**Requires https://github.com/dhis2/analytics/pull/XXX**

---

### Key features

1. _feature_

---

### Description

_text_

---

### TODO

- [ ] _task_

---

### Known issues

- [ ] _issue_

---

### Screenshots

_supporting text_
11 changes: 8 additions & 3 deletions src/api/fetchVisualization.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { getInstance } from 'd2'
import { getVisualizationId } from '../modules/item'
import { getEndPointName, MAP } from '../modules/itemTypes'
import { getMapFields, getFavoriteFields } from './metadata'
import { getVisualizationId } from '../modules/item.js'
import {
getEndPointName,
MAP,
EVENT_VISUALIZATION,
} from '../modules/itemTypes.js'
import { getMapFields, getFavoriteFields } from './metadata.js'

export const apiFetchVisualization = async item => {
const id = getVisualizationId(item)
Expand All @@ -11,6 +15,7 @@ export const apiFetchVisualization = async item => {
: getFavoriteFields({
withDimensions: true,
withOptions: true,
withRepetition: item.type === EVENT_VISUALIZATION,
})

const d2 = await getInstance()
Expand Down
21 changes: 14 additions & 7 deletions src/api/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,36 @@ export const getItemFields = () => [
]

// Dimension
export const getDimensionFields = ({ withItems }) =>
export const getDimensionFields = ({ withItems, withRepetition }) =>
arrayClean([
'dimension',
'legendSet[id]',
'filter',
'programStage',
withItems ? `items[${getItemFields().join(',')}]` : ``,
withRepetition ? 'repetition' : '',
])

// Axis
export const getAxesFields = ({ withItems }) => [
`columns[${getDimensionFields({ withItems }).join(',')}]`,
`rows[${getDimensionFields({ withItems }).join(',')}]`,
`filters[${getDimensionFields({ withItems }).join(',')}]`,
export const getAxesFields = ({ withItems, withRepetition }) => [
`columns[${getDimensionFields({ withItems, withRepetition }).join(',')}]`,
`rows[${getDimensionFields({ withItems, withRepetition }).join(',')}]`,
`filters[${getDimensionFields({ withItems, withRepetition }).join(',')}]`,
]

// Favorite
export const getFavoriteFields = ({ withDimensions, withOptions }) => {
export const getFavoriteFields = ({
withDimensions,
withOptions,
withRepetition,
}) => {
return arrayClean([
`${getIdNameFields({ rename: true }).join(',')}`,
'type',
'displayDescription~rename(description)',
withDimensions ? `${getAxesFields({ withItems: true }).join(',')}` : ``,
withDimensions
? `${getAxesFields({ withItems: true, withRepetition }).join(',')}`
: ``,
withOptions
? [
'*',
Expand Down

0 comments on commit e705ba2

Please sign in to comment.