From 3370c6aa4bc5347b1af3396660ac1dcb5c8122a9 Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Tue, 9 Apr 2024 13:59:41 +0200 Subject: [PATCH] fix: fetch repetition data for LL to show in plugin (#2946) (cherry picked from commit 25378ce65effdf6e0670f95a927d97aa7164643a) Co-authored-by: Jen Jones Arnesen --- .github/pull_request_template.md | 33 ++++++++++++++++++++++++++++++++ src/api/fetchVisualization.js | 7 ++++++- src/api/metadata.js | 21 +++++++++++++------- 3 files changed, 53 insertions(+), 8 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 15baaecf1..0515b811b 100644 --- a/src/api/fetchVisualization.js +++ b/src/api/fetchVisualization.js @@ -1,6 +1,10 @@ import { getInstance } from 'd2' import { getVisualizationId } from '../modules/item.js' -import { getEndPointName, MAP } from '../modules/itemTypes.js' +import { + getEndPointName, + MAP, + EVENT_VISUALIZATION, +} from '../modules/itemTypes.js' import { getMapFields, getFavoriteFields } from './metadata.js' export const apiFetchVisualization = async (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 4f524a107..fa652bd21 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 ? [ '*',