@@ -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-
3044export const createDataChunks = ( dxs , pe , ou , chunkSize , layout ) => {
3145 const chunks = [ ]
3246
0 commit comments