diff --git a/app/pages/Profile.jsx b/app/pages/Profile.jsx index a3eb31586..ae56ab505 100644 --- a/app/pages/Profile.jsx +++ b/app/pages/Profile.jsx @@ -27,8 +27,8 @@ class Profile extends Component {

{ this.props.params.id === "040AF00182" ? "Nigeria" : "Ethopia" }

-

Top Crop ID (from "preneed"): { topCrop }

-

{ topCrop } Competitors ("need" using "preneed" in URL): { competitors ? competitors.map(c => c.geo_name).join(", ") : "Loading" }

+

Top Crop ID (from "preneed"): { topCrop.crop }

+

{ topCrop.crop } Competitors ("need" using "preneed" in URL): { competitors ? competitors.map(c => c.geo_name).join(", ") : "Loading" }

Agriculture Climate @@ -44,12 +44,12 @@ class Profile extends Component { const topCropUrl = "https://api.dataafrica.io/api/join/?show=year,crop&sumlevel=latest_by_geo,lowest&required=harvested_area&order=harvested_area&sort=desc&display_names=true&geo=&limit-1"; Profile.preneed = [ - fetchData("topCrop", topCropUrl, res => dataFold(res)[0].crop) + fetchData("topCrop", topCropUrl, res => dataFold(res)[0]) ]; Profile.need = [ Child, Child2, - fetchData("competitors", "api/join/?show=geo&sumlevel=adm0&crop=&required=harvested_area&order=harvested_area&sort=desc&display_names=true"), + fetchData("competitors", "api/join/?show=geo&sumlevel=adm0&crop=&required=harvested_area&order=harvested_area&sort=desc&display_names=true"), fetchData("value_of_production", "api/join/?geo=&show=crop&required=harvested_area,value_of_production&order=value_of_production&sort=desc&display_names=true&limit=5") ]; diff --git a/src/actions/fetchData.js b/src/actions/fetchData.js index 885c59fc6..e91016fe2 100644 --- a/src/actions/fetchData.js +++ b/src/actions/fetchData.js @@ -8,12 +8,12 @@ function fetchData(key, url, format = dataFold, config = {}) { let u = url.indexOf("http") === 0 ? url : `${store.API}${url}`; (url.match(/<[^\&\=\/>]+>/g) || []).forEach(variable => { - let x = variable.slice(1, -1); - if (params[x]) x = params[x]; - else if (store.data && store.data[x]) x = store.data[x]; - else if (store[x]) x = store[x]; + let x = variable.slice(1, -1).split("."); + if (params[x[0]]) x = params[x[0]]; + else if (store.data && store.data[x[0]]) x = x.reduce((o, i) => o[i], store.data); + else if (store[x[0]]) x = x.reduce((o, i) => o[i], store); else x = false; - if (x) u = u.replace(variable, x); + if (x && typeof x !== "object") u = u.replace(variable, x); }); return {