diff --git a/package.json b/package.json index 59cd11d8..0854e3a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d2-dataset-configuration", - "version": "2.4.0", + "version": "2.6.0", "description": "Dataset Configuration User Interface", "main": "src/index.html", "scripts": { diff --git a/src/models/DataSetStore.js b/src/models/DataSetStore.js index 24d31232..3e0ac7e8 100644 --- a/src/models/DataSetStore.js +++ b/src/models/DataSetStore.js @@ -330,9 +330,7 @@ export default class DataSetStore { async _getCustomForm(saving, categoryCombos_) { const { richSections, dataset } = saving; const periodDates = this.getPeriodDates(); - const categoryCombos = - categoryCombos_ || - (await getCategoryCombos(this.d2, { cocFields: "id,categoryOptions[id]" })); + const categoryCombos = categoryCombos_ || (await this.getCategoryCombos(dataset)); const id = (dataset.dataEntryForm ? dataset.dataEntryForm.id : null) || generateUid(); return getCustomForm(this.d2, dataset, periodDates, richSections, categoryCombos).then( @@ -544,6 +542,22 @@ export default class DataSetStore { return collectionToArray(this.dataset.sections).length > 0; } + getCategoryCombos(dataset) { + const categoryComboIds = _(dataset.dataSetElements) + .flatMap(dse => [ + _.get(dse, "dataElement.categoryCombo.id"), + _.get(dse, "categoryCombo.id"), + ]) + .compact() + .uniq() + .value(); + + return getCategoryCombos(this.d2, { + cocFields: "id,categoryOptions[id]", + filterIds: categoryComboIds, + }); + } + /* Save */ _getInitialSaving() { @@ -552,7 +566,8 @@ export default class DataSetStore { const project$ = project ? this.d2.models.categoryOption.get(project.id) : Promise.resolve(null); - const categoryCombos$ = getCategoryCombos(this.d2, { cocFields: "id,categoryOptions[id]" }); + const categoryCombos$ = this.getCategoryCombos(this.dataset); + const countryCodes = _(countries) .map(getCountryCode) .compact() diff --git a/src/utils/Dhis2Helpers.js b/src/utils/Dhis2Helpers.js index 5548e82a..0646f9f4 100644 --- a/src/utils/Dhis2Helpers.js +++ b/src/utils/Dhis2Helpers.js @@ -40,7 +40,7 @@ function redirectToLogin(baseUrl) { function getCategoryCombos(d2, { cocFields, filterIds } = {}) { return d2.models.categoryCombos.list({ fields: _([ - "id,name,displayName,dataDimensionType,isDefault", + "id,name,displayName,isDefault", "categories[id,name,displayName,categoryOptions[id,name,displayName]]", cocFields ? `categoryOptionCombos[${cocFields}]` : null, ])