Skip to content

Commit

Permalink
Merge branch 'rdl-0.2' of https://github.com/GFDRR/rdl-jkan into rdl-0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
matamadio committed Jun 14, 2024
2 parents 40eae6a + dcda626 commit 4ccaf60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion scripts/dist/bundle.js

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions scripts/src/components/rdl-country-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ export default class {
}

_countriesWithCount (datasets, params) {
return chain(datasets)
.groupBy('geo_coverage')
.flatMap(function (datasetsForCountry, country) {
var countries = country.split(",")
var collated = countries.map(c => prep_country(c, params, datasetsForCountry))

return collated
const datasetsByCountry = datasets.reduce((result, dataset) => {
dataset.geo_coverage.forEach(country => {
if (Array.isArray(result[country])) {
result[country].push(dataset)
} else {
result[country] = [dataset]
}
})
.orderBy('unfilteredCount', 'desc')
.value()
return result;
}, {})

return Object.entries(datasetsByCountry).map((datasetsEntryForOneCountry) => {
const country = datasetsEntryForOneCountry[0];
const datasetsForOneCountry = datasetsEntryForOneCountry[1];
return prep_country(country, params, datasetsForOneCountry)
}, []).sort((a,b) => a.unfilteredCount - b.unfilteredCount)
}
}
12 changes: 11 additions & 1 deletion scripts/src/components/rdl-geographical-scale-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import {chain, omit, defaults} from 'lodash'
import TmplListGroupItem from '../templates/list-group-item'
import {setContent, slugify, collapseListGroup} from '../util'

const ORDER = [
'Global',
'Regional',
'National',
'Sub-national',
]

function prep_geographical_scale(geographicalScale, params, datasetsForGeographicalScales) {
const geographicalScaleSlug = slugify(geographicalScale)
Expand Down Expand Up @@ -32,7 +38,11 @@ export default class {
}
})

const geographicalScalesMarkup = consolidated.map(TmplListGroupItem)
const geographicalScalesMarkup = consolidated.sort((a,b) => {
const aIndex = ORDER.findIndex((title) => title === a.title);
const bIndex = ORDER.findIndex((title) => title === b.title);
return aIndex - bIndex;
}).map(TmplListGroupItem)
setContent(opts.el, geographicalScalesMarkup)
collapseListGroup(opts.el)
}
Expand Down

0 comments on commit 4ccaf60

Please sign in to comment.