Skip to content

Commit 7cb1b2c

Browse files
authored
Merge pull request #3474 from Vizzuality/fix/redirect-for-non-valid-isos
Fix/redirect for non valid iso's
2 parents 3a4ac95 + e4a104d commit 7cb1b2c

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

app/controllers/dashboards_controller.rb

+3
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ def embed
2525

2626
def set_title
2727
@location = params[:iso] ? Dashboards.find_country_by_iso(params[:iso]) : "#{params[:type] && params[:type].capitalize || 'Global'} Dashboard"
28+
if !@location
29+
redirect_to action: "index", type: 'global'
30+
end
2831
end
2932
end

app/javascript/pages/dashboards/router.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { connectRoutes } from 'redux-first-router';
1+
import { connectRoutes, NOT_FOUND, redirect } from 'redux-first-router';
22
import createHistory from 'history/createBrowserHistory';
33
import queryString from 'query-string';
44
import { setWidgetSettingsStore } from 'components/widgets/actions';
@@ -26,6 +26,11 @@ export const routes = {
2626
},
2727
[EMBED]: {
2828
path: '/embed/dashboards/:type/:country?/:region?/:subRegion?'
29+
},
30+
[NOT_FOUND]: {
31+
path: '/404',
32+
thunk: dispatch =>
33+
dispatch(redirect({ type: COUNTRY, location: { type: 'global' } }))
2934
}
3035
};
3136

app/javascript/providers/country-data-provider/country-data-provider-actions.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,9 @@ export const getCountries = createThunkAction(
3737
.all([getCountriesProvider(), getFAOCountriesProvider()])
3838
.then(
3939
axios.spread((gadm28Countries, faoCountries) => {
40-
const allCountries = uniqBy(
41-
[...gadm28Countries.data.rows, ...faoCountries.data.rows],
42-
'iso'
43-
);
44-
const countries = uniqBy(
45-
allCountries.filter(c => c.iso !== 'XCA'),
46-
'iso'
47-
);
4840
dispatch(setGadmCountries(gadm28Countries.data.rows));
4941
dispatch(setFAOCountries(faoCountries.data.rows));
50-
dispatch(setCountries(countries));
42+
dispatch(setCountries(gadm28Countries.data.rows));
5143
dispatch(setCountriesLoading(false));
5244
})
5345
)

app/javascript/services/country.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const REQUEST_URL = `${process.env.CARTO_API_URL}/sql?q=`;
44

55
const SQL_QUERIES = {
66
getCountries:
7-
'SELECT iso, country as name FROM umd_nat_staging GROUP BY iso, name ORDER BY name',
7+
"SELECT iso, country as name FROM umd_nat_staging WHERE iso != 'TWN' AND iso != 'XCA' GROUP BY iso, name ORDER BY name",
88
getFAOCountries:
99
'SELECT DISTINCT country AS iso, name FROM table_1_forest_area_and_characteristics',
1010
getRegions:

app/models/dashboards.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Dashboards
22
class << self
33
def find_all_countries
4-
url = "#{ENV['CARTO_API_URL']}/sql?q=SELECT%20DISTINCT%20iso,%20name_0%20as%20name%20FROM%20gadm28_adm2"
4+
url = "#{ENV['CARTO_API_URL']}/sql?q=SELECT%20DISTINCT%20iso,%20name_engli%20as%20name%20FROM%20gadm28_countries%20WHERE%20iso%20!=%20'XCA'%20AND%20iso%20!=%20'TWN'"
55
# CACHE: &bust=true if you want to flush the cache
66
response = Typhoeus.get(url, headers: {"Accept" => "application/json"})
77
if response.success? and (response.body.length > 0)
@@ -13,7 +13,7 @@ def find_all_countries
1313

1414
def find_country_by_iso(iso)
1515
return nil unless iso
16-
url = "#{ENV['CARTO_API_URL']}/sql?q=SELECT%20iso,%20name_0%20as%20name%20FROM%20gadm28_adm2%20WHERE%20iso%20=%20'#{iso}'%20LIMIT%201"
16+
url = "#{ENV['CARTO_API_URL']}/sql?q=SELECT%20iso,%20name_engli%20as%20name%20FROM%20gadm28_countries%20WHERE%20iso%20=%20'#{iso}'%20AND%20iso%20!=%20'XCA'%20AND%20iso%20!=%20'TWN'%20LIMIT%201"
1717
# CACHE: &bust=true if you want to flush the cache
1818
response = Typhoeus.get(url, headers: {"Accept" => "application/json"})
1919
if response.success? and (response.body.length > 0)

public/sitemap.xml

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)