Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLAG-997] GADM country list #4891

Open
wants to merge 19 commits into
base: epic/gadm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
69311d3
feat(metadata): add new geostore query for admin level 0
willian-viana Oct 1, 2024
4b23e0d
feat(countries): migrate queries from gadm 3.6 to 4.1
willian-viana Nov 15, 2024
ad60535
chore(comments): remove old comments
willian-viana Nov 15, 2024
753745f
chore(gadm): replace parseGadm36Id method name to parseGadmId
willian-viana Jan 9, 2025
064456c
fix(countryProvider): fix country provider implementation
willian-viana Jan 23, 2025
cf83268
feat(location-service): migrate countryConfig request from Carto to D…
willian-viana Jan 23, 2025
bcb2ddb
chore(comments): remove comment
willian-viana Jan 23, 2025
010305b
chore(location-service): extract search by Iso and ID logic
willian-viana Jan 23, 2025
0b2fdf7
feat(location-service): add location tests
willian-viana Jan 23, 2025
a413cf1
feat(country-service): add tests for country service
willian-viana Jan 23, 2025
35e2282
fix(gadm): fix setSubRegions actions
willian-viana Jan 24, 2025
6303c0b
chore(gadm): remove 3.6 from GADM methods name
willian-viana Jan 24, 2025
e446c34
feat(gadm): add tests for gadm utils
willian-viana Jan 24, 2025
de4e603
chore(fao): remove WHERE 1 = 1
willian-viana Jan 27, 2025
95a00f9
chore(location-service): refact countryConfig to avoid providers dupl…
willian-viana Jan 27, 2025
375936d
chore(country-service): improve tests adding SQL queries directly
willian-viana Jan 27, 2025
289b850
fix(gadm): fix adm level validation
willian-viana Jan 30, 2025
86c76b5
fix(gadm): add name_0 as a fallback for country name
willian-viana Jan 30, 2025
bb349eb
fix(gadm): remove conflicted areas from country list
willian-viana Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/map-menu/components/sections/search/selectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector, createStructuredSelector } from 'reselect';
import { deburrUpper } from 'utils/strings';
import { getGadm36Id } from 'utils/gadm';
import { getGadmId } from 'utils/gadm';
import sortBy from 'lodash/sortBy';
import { translateText, selectActiveLang } from 'utils/lang';

Expand Down Expand Up @@ -49,7 +49,7 @@ const getLocations = createSelector(
(locations, location) => {
if (!locations) return null;
const { adm0, adm1, adm2 } = location;
const gadmId = getGadm36Id(adm0, adm1, adm2);
const gadmId = getGadmId(adm0, adm1, adm2);

return locations
.map((l) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const getInteractionData = (state, { data }) => data;

/**
* Returns an object with the selected location name, its area and a sentence do be displayed.
* @param {method} createSelector - return a memoized outut selector.
* @param {method} createSelector - return a memoized output selector.
* @see https://reselect.js.org/introduction/getting-started/#output-selector for implementation details
* @param {selector} getInteractionData - data from the area clicked by user
* @return {object} sentence, location name and area.
*/
export const getSentence = createSelector(
[getInteractionData],
({ data } = {}) => {
const { adm_level, gid_0, name_1, country } = data;
let name = adm_level > 0 ? data[`name_${adm_level}`] : country;
const { adm_level, gid_0, name_1, name_0, country } = data;
let name = adm_level > 0 ? data[`name_${adm_level}`] : country || name_0;

if (!gid_0) {
name = data[Object.keys(data).find((k) => k.includes('name'))];
Expand All @@ -30,12 +30,15 @@ export const getSentence = createSelector(
locationNames = [
locationNameTranslated,
translateText(name_1),
translateText(country),
translateText(country || name_0),
];
}

if (Number(adm_level) === '1') {
locationNames = [locationNameTranslated, translateText(country)];
if (Number(adm_level) === 1) {
locationNames = [
locationNameTranslated,
translateText(country || name_0),
];
}

const locationName = locationNames.join(', ');
Expand Down
17 changes: 9 additions & 8 deletions components/widgets/climate/soil-organic/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getSortedData = createSelector(
[getData, getSettings, getAdm1, getAdm2],
(data, settings, adm1, adm2) => {
if (isEmpty(data)) return null;
// console.log('soil-organic', { data, settings })

let regionKey = 'iso';
if (adm1) regionKey = 'adm1';
if (adm2) regionKey = 'adm2';
Expand Down Expand Up @@ -121,10 +121,10 @@ export const parseSentence = createSelector(
settings.unit === 'totalBiomass'
? formatNumber({ num: percent, unit: '%' })
: formatNumber({
num: avgBiomDensity,
unit: 'tC/ha',
spaceUnit: true,
});
num: avgBiomDensity,
unit: 'tC/ha',
spaceUnit: true,
});

const labels = {
globalDensity: 'soil organic carbon density',
Expand All @@ -134,9 +134,10 @@ export const parseSentence = createSelector(
// Properties defined for labels and sentences are named in a way that relates with the display
// but the units are somewhat fixed, due to their dependency on the whitelists for settings dropdowns.
// We map them here.
const sentenceLabelProperty = settings.unit === 'totalBiomass' ? 'globalBiomass' : 'globalDensity';
const sentenceLabelProperty =
settings.unit === 'totalBiomass' ? 'globalBiomass' : 'globalDensity';
const sentence = sentences[sentenceLabelProperty];
const label = labels[sentenceLabelProperty]
const label = labels[sentenceLabelProperty];

return {
sentence,
Expand All @@ -145,7 +146,7 @@ export const parseSentence = createSelector(
value,
},
};
};
}

// Standard processing for adm1 and adm2 areas, same sentence, same formatting.
const location_id = location && location.value;
Expand Down
2 changes: 1 addition & 1 deletion pages/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getStaticProps = async () => {
props: {
impactProjects,
sgfProjects,
countries: countries?.data?.rows,
countries: countries?.data,
notifications: notifications || [],
},
revalidate: 10,
Expand Down
17 changes: 8 additions & 9 deletions pages/dashboards/[[...location]].js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import uniqBy from 'lodash/uniqBy';

import useRouter from 'utils/router';
import { decodeQueryParams } from 'utils/url';
import { parseGadm36Id } from 'utils/gadm';
import { parseGadmId } from 'utils/gadm';
import { parseStringWithVars } from 'utils/strings';

import { getLocationData } from 'services/location';
import { getPublishedNotifications } from 'services/notifications';
import {
// getCountriesProvider,
getRegionsProvider,
getSubRegionsProvider,
getCategorisedCountries,
Expand Down Expand Up @@ -183,9 +182,9 @@ export const getServerSideProps = async ({ params, query, req }) => {
const countryLinks = await getCountryLinksSerialized();
countryData = {
...countryData,
regions: uniqBy(regions.data.rows).map((row) => ({
id: parseGadm36Id(row.id).adm1,
value: parseGadm36Id(row.id).adm1,
regions: uniqBy(regions.data).map((row) => ({
id: parseGadmId(row.id).adm1,
value: parseGadmId(row.id).adm1,
label: row.name,
name: row.name,
})),
Expand All @@ -194,12 +193,12 @@ export const getServerSideProps = async ({ params, query, req }) => {
}

if (adm1) {
const subRegions = await getSubRegionsProvider(adm0, adm1);
const subRegions = await getSubRegionsProvider({ adm0, adm1 });
countryData = {
...countryData,
subRegions: uniqBy(subRegions.data.rows).map((row) => ({
id: parseGadm36Id(row.id).adm2,
value: parseGadm36Id(row.id).adm2,
subRegions: uniqBy(subRegions.data).map((row) => ({
id: parseGadmId(row.id).adm2,
value: parseGadmId(row.id).adm2,
label: row.name,
name: row.name,
})),
Expand Down
32 changes: 8 additions & 24 deletions pages/embed/sentence/[[...location]].js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import uniqBy from 'lodash/uniqBy';

import { parseGadm36Id } from 'utils/gadm';
import { parseGadmId } from 'utils/gadm';

import { getLocationData } from 'services/location';
import {
// getCountriesProvider,
getRegionsProvider,
getSubRegionsProvider,
getCategorisedCountries,
Expand Down Expand Up @@ -91,9 +90,9 @@ export const getServerSideProps = async ({ params }) => {
const countryLinks = await getCountryLinksSerialized();
countryData = {
...countryData,
regions: uniqBy(regions.data.rows).map((row) => ({
id: parseGadm36Id(row.id).adm1,
value: parseGadm36Id(row.id).adm1,
regions: uniqBy(regions.data).map((row) => ({
id: parseGadmId(row.id).adm1,
value: parseGadmId(row.id).adm1,
label: row.name,
name: row.name,
})),
Expand All @@ -102,12 +101,12 @@ export const getServerSideProps = async ({ params }) => {
}

if (adm1) {
const subRegions = await getSubRegionsProvider(adm0, adm1);
const subRegions = await getSubRegionsProvider({ adm0, adm1 });
countryData = {
...countryData,
subRegions: uniqBy(subRegions.data.rows).map((row) => ({
id: parseGadm36Id(row.id).adm2,
value: parseGadm36Id(row.id).adm2,
subRegions: uniqBy(subRegions.data).map((row) => ({
id: parseGadmId(row.id).adm2,
value: parseGadmId(row.id).adm2,
label: row.name,
name: row.name,
})),
Expand Down Expand Up @@ -151,21 +150,6 @@ export const getServerSideProps = async ({ params }) => {
};
}
};
//
gtempus marked this conversation as resolved.
Show resolved Hide resolved
// export const getStaticPaths = async () => {
// const countryData = await getCountriesProvider();
// const { rows: countries } = countryData?.data || {};
// const countryPaths = countries.map((c) => ({
// params: {
// location: ['country', c.iso],
// },
// }));
//
// return {
// paths: ['/embed/sentence/', ...countryPaths] || [],
// fallback: true,
// };
// };

const getSentenceClientSide = async (
locationNames = null,
Expand Down
2 changes: 1 addition & 1 deletion pages/grants-and-fellowships/[section].js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getServerSideProps = async ({ query }) => {
title: 'Projects | Grants & Fellowships | Global Forest Watch',
section: query?.section,
projects: parsedProjects || [],
allCountries: allCountries?.data?.rows || [],
allCountries: allCountries?.data || [],
projectCountries: uniqCountries || [],
country: query?.country || '',
projectsTexts: pageTexts?.[0]?.acf,
Expand Down
17 changes: 8 additions & 9 deletions providers/country-data-provider/actions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAction, createThunkAction } from 'redux/actions';
import { parseGadm36Id } from 'utils/gadm';
import { parseGadmId } from 'utils/gadm';
import uniqBy from 'lodash/uniqBy';

import {
Expand Down Expand Up @@ -47,10 +47,10 @@ export const getRegions = createThunkAction(
getRegionsProvider(country)
.then((response) => {
const parsedResponse = [];
uniqBy(response.data.rows).forEach((row) => {
uniqBy(response.data).forEach((region) => {
parsedResponse.push({
id: parseGadm36Id(row.id).adm1,
name: row.name,
id: parseGadmId(region.id).adm1,
name: region.name,
});
});
dispatch(setRegions(parsedResponse, 'id'));
Expand All @@ -67,14 +67,13 @@ export const getSubRegions = createThunkAction(
({ adm0, adm1, token }) =>
(dispatch) => {
dispatch(setSubRegionsLoading(true));
getSubRegionsProvider(adm0, adm1, token)
getSubRegionsProvider({ adm0, adm1, token })
.then((subRegions) => {
const { rows } = subRegions.data;
const parsedResponse = [];
uniqBy(rows).forEach((row) => {
uniqBy(subRegions?.data).forEach((subRegion) => {
parsedResponse.push({
id: parseGadm36Id(row.id).adm2,
name: row.name,
id: parseGadmId(subRegion.id).adm2,
name: subRegion.name,
});
});
dispatch(setSubRegions(uniqBy(parsedResponse, 'id')));
Expand Down
Loading