diff --git a/pages/api/metadata/[...params].js b/pages/api/metadata/[...params].js index f9e4816f09..92ce9c4962 100644 --- a/pages/api/metadata/[...params].js +++ b/pages/api/metadata/[...params].js @@ -1,7 +1,7 @@ import { GFW_METADATA_API, GFW_STAGING_METADATA_API } from 'utils/apis'; import axios from 'axios'; -const ENVIRONMENT = process.env.NEXT_PUBLIC_FEATURE_ENV; +const ENVIRONMENT = process.env.NEXT_PUBLIC_RW_FEATURE_ENV; const GFW_METADATA_API_URL = ENVIRONMENT === 'staging' ? GFW_STAGING_METADATA_API : GFW_METADATA_API; diff --git a/pages/dashboards/[[...location]].js b/pages/dashboards/[[...location]].js index fb817a9911..4a4f3013dd 100644 --- a/pages/dashboards/[[...location]].js +++ b/pages/dashboards/[[...location]].js @@ -13,7 +13,6 @@ import { parseStringWithVars } from 'utils/strings'; import { getLocationData } from 'services/location'; import { getPublishedNotifications } from 'services/notifications'; import { - // getCountriesProvider, getRegionsProvider, getSubRegionsProvider, getCategorisedCountries, @@ -183,7 +182,7 @@ export const getServerSideProps = async ({ params, query, req }) => { const countryLinks = await getCountryLinksSerialized(); countryData = { ...countryData, - regions: uniqBy(regions.data.rows).map((row) => ({ + regions: uniqBy(regions.data).map((row) => ({ id: parseGadm36Id(row.id).adm1, value: parseGadm36Id(row.id).adm1, label: row.name, @@ -197,7 +196,7 @@ export const getServerSideProps = async ({ params, query, req }) => { const subRegions = await getSubRegionsProvider(adm0, adm1); countryData = { ...countryData, - subRegions: uniqBy(subRegions.data.rows).map((row) => ({ + subRegions: uniqBy(subRegions.data).map((row) => ({ id: parseGadm36Id(row.id).adm2, value: parseGadm36Id(row.id).adm2, label: row.name, diff --git a/pages/embed/sentence/[[...location]].js b/pages/embed/sentence/[[...location]].js index 611b2d5f77..72c21d4165 100644 --- a/pages/embed/sentence/[[...location]].js +++ b/pages/embed/sentence/[[...location]].js @@ -6,7 +6,6 @@ import { parseGadm36Id } from 'utils/gadm'; import { getLocationData } from 'services/location'; import { - // getCountriesProvider, getRegionsProvider, getSubRegionsProvider, getCategorisedCountries, @@ -91,7 +90,7 @@ export const getServerSideProps = async ({ params }) => { const countryLinks = await getCountryLinksSerialized(); countryData = { ...countryData, - regions: uniqBy(regions.data.rows).map((row) => ({ + regions: uniqBy(regions.data).map((row) => ({ id: parseGadm36Id(row.id).adm1, value: parseGadm36Id(row.id).adm1, label: row.name, @@ -105,7 +104,7 @@ export const getServerSideProps = async ({ params }) => { const subRegions = await getSubRegionsProvider(adm0, adm1); countryData = { ...countryData, - subRegions: uniqBy(subRegions.data.rows).map((row) => ({ + subRegions: uniqBy(subRegions.data).map((row) => ({ id: parseGadm36Id(row.id).adm2, value: parseGadm36Id(row.id).adm2, label: row.name, @@ -151,21 +150,6 @@ export const getServerSideProps = async ({ params }) => { }; } }; -// -// 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, diff --git a/providers/country-data-provider/actions.js b/providers/country-data-provider/actions.js index a34d4607ac..0207890b4e 100644 --- a/providers/country-data-provider/actions.js +++ b/providers/country-data-provider/actions.js @@ -47,7 +47,7 @@ export const getRegions = createThunkAction( getRegionsProvider(country) .then((response) => { const parsedResponse = []; - uniqBy(response.data.rows).forEach((row) => { + uniqBy(response.data).forEach((row) => { parsedResponse.push({ id: parseGadm36Id(row.id).adm1, name: row.name, @@ -64,25 +64,26 @@ export const getRegions = createThunkAction( export const getSubRegions = createThunkAction( 'getSubRegions', - ({ adm0, adm1, token }) => (dispatch) => { - dispatch(setSubRegionsLoading(true)); - getSubRegionsProvider(adm0, adm1, token) - .then((subRegions) => { - const { rows } = subRegions.data; - const parsedResponse = []; - uniqBy(rows).forEach((row) => { - parsedResponse.push({ - id: parseGadm36Id(row.id).adm2, - name: row.name, + ({ adm0, adm1, token }) => + (dispatch) => { + dispatch(setSubRegionsLoading(true)); + getSubRegionsProvider(adm0, adm1, token) + .then((subRegions) => { + const { rows } = subRegions.data; + const parsedResponse = []; + uniqBy(rows).forEach((row) => { + parsedResponse.push({ + id: parseGadm36Id(row.id).adm2, + name: row.name, + }); }); + dispatch(setSubRegions(uniqBy(parsedResponse, 'id'))); + dispatch(setSubRegionsLoading(false)); + }) + .catch(() => { + dispatch(setSubRegionsLoading(false)); }); - dispatch(setSubRegions(uniqBy(parsedResponse, 'id'))); - dispatch(setSubRegionsLoading(false)); - }) - .catch(() => { - dispatch(setSubRegionsLoading(false)); - }); - } + } ); export const getCountryLinks = createThunkAction( diff --git a/providers/datasets-provider/actions.js b/providers/datasets-provider/actions.js index 18fa932203..cb0784831b 100644 --- a/providers/datasets-provider/actions.js +++ b/providers/datasets-provider/actions.js @@ -14,7 +14,7 @@ export const setDatasets = createAction('setDatasets'); export const setDatasetsWithMetadata = createAction('setDatasetsWithMetadata'); const handleFeatureEnvLock = (env) => { - const currEnv = process.env.NEXT_PUBLIC_FEATURE_ENV; + const currEnv = process.env.NEXT_PUBLIC_RW_FEATURE_ENV; const MIXED_ENV = 'preproduction-staging'; if (env === MIXED_ENV && currEnv !== 'production') { return true; diff --git a/services/country.js b/services/country.js index 214b28df89..cad5cd9227 100644 --- a/services/country.js +++ b/services/country.js @@ -1,17 +1,19 @@ import { all, spread } from 'axios'; -import { cartoRequest } from 'utils/request'; +import { cartoRequest, dataRequest } from 'utils/request'; import { getGadm36Id } from 'utils/gadm'; +const GADM_DATASET = '/dataset/gadm_administrative_boundaries/v4.1/query'; + const SQL_QUERIES = { - getCountries: - "SELECT iso, name_engli as name FROM gadm36_countries WHERE iso != 'TWN' AND iso != 'XCA' ORDER BY name", + getGADMCountries: + "SELECT country AS name, gid_0 AS iso FROM gadm_administrative_boundaries WHERE adm_level = '0' ORDER BY country", + getGADMRegions: + "SELECT name_1 AS name, gid_1 AS id FROM gadm_administrative_boundaries WHERE adm_level='1' AND gid_0 = '{iso}' ORDER BY name ", + getGADMSubRegions: + "SELECT gid_2 as id, name_2 as name FROM gadm_administrative_boundaries WHERE gid_0 = '{iso}' AND gid_1 = '{adm1}' AND adm_level='2' AND type_2 NOT IN ('Waterbody', 'Water body', 'Water Body') ORDER BY name", getFAOCountries: 'SELECT DISTINCT country AS iso, name FROM table_1_forest_area_and_characteristics', - getRegions: - "SELECT gid_1 as id, name_1 as name FROM gadm36_adm1 WHERE iso = '{iso}' ORDER BY name ", - getSubRegions: - "SELECT gid_2 as id, name_2 as name FROM gadm36_adm2 WHERE iso = '{iso}' AND gid_1 = '{adm1}' AND type_2 NOT IN ('Waterbody', 'Water body', 'Water Body') ORDER BY name", getCountryLinks: 'SELECT iso, external_links FROM external_links_gfw WHERE forest_atlas is true', getRanking: @@ -22,8 +24,9 @@ const convertToOptions = (countries) => countries.map((c) => ({ label: c.name, value: c.iso })); export const getCountriesProvider = () => { - const url = `/sql?q=${SQL_QUERIES.getCountries}`; - return cartoRequest.get(url); + const url = `${GADM_DATASET}?sql=${SQL_QUERIES.getGADMCountries}`; + + return dataRequest.get(url); }; export const getFAOCountriesProvider = () => { @@ -32,15 +35,20 @@ export const getFAOCountriesProvider = () => { }; export const getRegionsProvider = ({ adm0, token }) => { - const url = `/sql?q=${SQL_QUERIES.getRegions}`.replace('{iso}', adm0); - return cartoRequest.get(url, { cancelToken: token }); + const url = `${GADM_DATASET}?sql=${SQL_QUERIES.getGADMRegions}`.replace( + '{iso}', + adm0 + ); + + return dataRequest.get(url, { cancelToken: token }); }; export const getSubRegionsProvider = (adm0, adm1, token) => { - const url = `/sql?q=${SQL_QUERIES.getSubRegions}` + const url = `${GADM_DATASET}?sql=${SQL_QUERIES.getGADMSubRegions}` .replace('{iso}', adm0) .replace('{adm1}', getGadm36Id(adm0, adm1)); - return cartoRequest.get(url, { cancelToken: token }); + + return dataRequest.get(url, { cancelToken: token }); }; export const getCountryLinksProvider = (token) => { @@ -67,17 +75,17 @@ export const getCountryLinksSerialized = async () => { export const getCategorisedCountries = (asOptions = false) => all([getCountriesProvider(), getFAOCountriesProvider()]).then( - spread((gadm36Countries, faoCountries) => { + spread((gadm41Countries, faoCountries) => { return { gadmCountries: asOptions - ? convertToOptions(gadm36Countries.data.rows) - : gadm36Countries.data.rows, + ? convertToOptions(gadm41Countries.data) + : gadm41Countries.data, faoCountries: asOptions ? convertToOptions(faoCountries.data.rows) : faoCountries.data.rows, countries: asOptions - ? convertToOptions(gadm36Countries.data.rows) - : gadm36Countries.data.rows, + ? convertToOptions(gadm41Countries.data) + : gadm41Countries.data, }; }) ); diff --git a/services/datasets.js b/services/datasets.js index 4d1b819d71..a7ff3012f6 100644 --- a/services/datasets.js +++ b/services/datasets.js @@ -1,7 +1,7 @@ import { rwRequest, dataRequest } from 'utils/request'; const environmentString = () => { - const env = process.env.NEXT_PUBLIC_FEATURE_ENV; + const env = process.env.NEXT_PUBLIC_RW_FEATURE_ENV; let envString = 'production'; if (env === 'preproduction') { envString += ',preproduction'; diff --git a/services/shape.js b/services/shape.js index 003208f9c7..d859860ac8 100644 --- a/services/shape.js +++ b/services/shape.js @@ -3,7 +3,9 @@ import request from 'utils/request'; import { GFW_API, GFW_STAGING_API } from 'utils/apis'; const GFW_API_URL = - process.env.NEXT_PUBLIC_FEATURE_ENV === 'staging' ? GFW_STAGING_API : GFW_API; + process.env.NEXT_PUBLIC_RW_FEATURE_ENV === 'staging' + ? GFW_STAGING_API + : GFW_API; const QUERIES = { ogrConvert: '/v2/ogr/convert',