From e705ba2db27cfdd37044158bfb18805760842e48 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Thu, 23 Mar 2023 15:25:11 +0100 Subject: [PATCH] fix: fetch repetition data for LL to show in plugin (cherry picked from commit 25378ce65effdf6e0670f95a927d97aa7164643a) --- .github/pull_request_template.md | 33 ++++++++++++++++++++++++++++++++ src/api/fetchVisualization.js | 11 ++++++++--- src/api/metadata.js | 21 +++++++++++++------- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..bbd787803 --- /dev/null +++ b/.github/pull_request_template.md @@ -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_ diff --git a/src/api/fetchVisualization.js b/src/api/fetchVisualization.js index 42aa609be..983d6221e 100644 --- a/src/api/fetchVisualization.js +++ b/src/api/fetchVisualization.js @@ -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) @@ -11,6 +15,7 @@ export const apiFetchVisualization = async item => { : getFavoriteFields({ withDimensions: true, withOptions: true, + withRepetition: item.type === EVENT_VISUALIZATION, }) const d2 = await getInstance() diff --git a/src/api/metadata.js b/src/api/metadata.js index 0d2f3269f..c7144f74a 100644 --- a/src/api/metadata.js +++ b/src/api/metadata.js @@ -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 ? [ '*',