Skip to content

Commit cb3ff7a

Browse files
committed
Fix disaggregated download bugs
1 parent dec4a26 commit cb3ff7a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dhis2-downloader",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"description": "DHIS2 Downloader",
55
"main": "./out/main/index.js",
66
"author": "globalfinancingfacility.org",

src/renderer/src/utils/downloadUtils.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const generateDownloadingUrl = (
55
pe,
66
co,
77
format = 'json',
8-
layout = { rows: ['ou', 'pe', 'dx'], columns: [] }) => {
8+
layout = null
9+
) => {
910
// Base dimension URL parts
1011
let parameters = `api/analytics.${format}?dimension=ou:${ou}&dimension=pe:${pe}&dimension=dx:${dx}`
1112

@@ -18,15 +19,28 @@ export const generateDownloadingUrl = (
1819
let layoutParams =
1920
'&displayProperty=NAME&ignoreLimit=TRUE&hierarchyMeta=TRUE&hideEmptyRows=TRUE&showHierarchy=TRUE'
2021

21-
const rows = layout?.rows || ['ou', 'pe', 'dx']
22-
const columns = layout?.columns || []
22+
let rows = ['ou', 'pe', 'dx']
23+
let columns = []
24+
25+
if (layout && typeof layout === 'object') {
26+
rows = layout.rows || rows
27+
columns = layout.columns || columns
28+
}
29+
30+
// If co is present, add it to rows if not already included
31+
if (co && co.length > 0) {
32+
for (const cat of co) {
33+
if (!rows.includes(cat) && !columns.includes(cat)) {
34+
rows.push(cat) // You may customize this to push to `columns` instead if preferred
35+
}
36+
}
37+
}
2338

2439
if (rows.length > 0) layoutParams += `&rows=${rows.join(';')}`
2540
if (columns.length > 0) layoutParams += `&columns=${columns.join(';')}`
2641

2742
return `${dhis2Url}/${parameters}${layoutParams}`
2843
}
29-
3044
export const createDataChunks = (dxs, pe, ou, chunkSize, layout) => {
3145
const chunks = []
3246

0 commit comments

Comments
 (0)