From 383bba947eade19fbb05c326041b369cf7b8eca2 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Tue, 14 Dec 2021 11:54:36 +0200 Subject: [PATCH] Restore map tab when removing region filter --- assets/js/dashboard/stats/locations/index.js | 13 +++++++----- assets/js/dashboard/stats/locations/map.js | 21 ++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/assets/js/dashboard/stats/locations/index.js b/assets/js/dashboard/stats/locations/index.js index 4f9fc621c..216cf37e4 100644 --- a/assets/js/dashboard/stats/locations/index.js +++ b/assets/js/dashboard/stats/locations/index.js @@ -106,7 +106,7 @@ export default class Locations extends React.Component { } if (this.state.mode === 'regions' && isRemovingFilter('country')) { - this.setMode('countries')() + this.setMode(this.countriesRestoreMode || 'countries')() } } @@ -117,8 +117,11 @@ export default class Locations extends React.Component { } } - onCountryFilter() { - this.setMode('regions')() + onCountryFilter(mode) { + return () => { + this.countriesRestoreMode = mode + this.setMode('regions')() + } } onRegionFilter() { @@ -132,10 +135,10 @@ export default class Locations extends React.Component { case "regions": return case "countries": - return + return case "map": default: - return + return } } diff --git a/assets/js/dashboard/stats/locations/map.js b/assets/js/dashboard/stats/locations/map.js index 55c84dea4..c9de680b0 100644 --- a/assets/js/dashboard/stats/locations/map.js +++ b/assets/js/dashboard/stats/locations/map.js @@ -109,14 +109,19 @@ class Countries extends React.Component { datamap.svg.selectAll('.datamaps-subunit').on('click', (geography) => { const country = this.state.countries.find(c => c.alpha_3 === geography.id) - navigateToQuery( - this.props.history, - this.props.query, - { - country: country.code, - country_name: country.name - } - ) + if (country) { + this.props.onClick() + + navigateToQuery( + this.props.history, + this.props.query, + { + country: country.code, + country_name: country.name + } + ) + } + }) } });