Skip to content

Commit

Permalink
Merge pull request #452 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
adrianq authored Dec 3, 2023
2 parents e1fe0f2 + e8b7c62 commit 8c2c9ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
23 changes: 19 additions & 4 deletions src/models/DataSetStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Dhis2Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
Expand Down

0 comments on commit 8c2c9ba

Please sign in to comment.