renders unchanged 1`] = `
Search for a location
Date: Fri, 8 Nov 2024 10:32:40 +0300
Subject: [PATCH 16/73] Use Set API
---
.../src/lib/data/blockify/hero.js | 6 +++++-
.../src/lib/data/common/index.js | 3 ++-
.../src/lib/hurumap/index.js | 8 +++----
.../src/pages/api/hurumap/profiles/[id].js | 3 ++-
.../src/pages/api/hurumap/profiles/index.js | 3 ++-
.../src/payload/fields/HURUMapURL/index.js | 10 ++++-----
.../src/payload/fields/LocationSelect.js | 11 ++--------
.../src/payload/fields/ProfileSelect.js | 21 ++++++++++++++-----
.../payload/globals/HURUMap/RootGeography.js | 3 +--
.../src/payload/globals/HURUMap/index.js | 4 ++--
10 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/apps/climatemappedafrica/src/lib/data/blockify/hero.js b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
index 5cdfc331d..e9d2fa12a 100644
--- a/apps/climatemappedafrica/src/lib/data/blockify/hero.js
+++ b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
@@ -10,6 +10,7 @@ import {
*/
export default async function hero(block, _api, _context, { hurumap }) {
const {
+ hurumapAPIURL,
profileId,
profilePage,
rootGeography: { center, code, hasData: pinRootGeography },
@@ -21,7 +22,10 @@ export default async function hero(block, _api, _context, { hurumap }) {
country: "region",
};
const childLevel = childLevelMaps[level];
- const { locations, preferredChildren } = await fetchProfile(profileId);
+ const { locations, preferredChildren } = await fetchProfile(
+ hurumapAPIURL,
+ profileId,
+ );
const preferredChildrenPerLevel = preferredChildren[level];
const { children } = geometries;
const preferredLevel =
diff --git a/apps/climatemappedafrica/src/lib/data/common/index.js b/apps/climatemappedafrica/src/lib/data/common/index.js
index 2fd23ad29..93e641d5d 100644
--- a/apps/climatemappedafrica/src/lib/data/common/index.js
+++ b/apps/climatemappedafrica/src/lib/data/common/index.js
@@ -122,11 +122,12 @@ export async function getPageProps(api, context) {
if (hurumapSettings?.enabled) {
// TODO(koech): Handle cases when fetching profile fails?
const {
+ hurumapAPIURL,
page: hurumapPage,
profile: profileId,
...otherHurumapSettings
} = hurumapSettings;
- const profile = await fetchProfile(profileId);
+ const profile = await fetchProfile(hurumapAPIURL, profileId);
const { value: profilePage } = hurumapPage;
if (slug === profilePage.slug) {
variant = "explore";
diff --git a/apps/climatemappedafrica/src/lib/hurumap/index.js b/apps/climatemappedafrica/src/lib/hurumap/index.js
index 822398f8d..b814414be 100644
--- a/apps/climatemappedafrica/src/lib/hurumap/index.js
+++ b/apps/climatemappedafrica/src/lib/hurumap/index.js
@@ -5,9 +5,9 @@ import formatNumericalValue from "@/climatemappedafrica/utils/formatNumericalVal
const apiUrl = process.env.HURUMAP_API_URL || hurumap?.api?.url;
-export async function fetchProfile(id) {
+export async function fetchProfile(BASE_URL, id) {
const { configuration } = await fetchJson(
- new URL(`/api/v1/profiles/${id}/?format=json`, apiUrl),
+ new URL(`/api/v1/profiles/${id}/?format=json`, BASE_URL),
);
const locations = configuration?.featured_locations?.map(
@@ -24,8 +24,8 @@ export async function fetchProfile(id) {
};
}
-export async function fetchProfiles() {
- const { results } = await fetchJson(new URL("/api/v1/profiles", apiUrl));
+export async function fetchProfiles(BASE_URL) {
+ const { results } = await fetchJson(new URL("/api/v1/profiles", BASE_URL));
const profiles = results.map(({ name, id }) => ({ name, id }));
return profiles;
}
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
index def3e9b0d..cc294e77f 100644
--- a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
@@ -5,6 +5,7 @@ let cacheExpiry = 0;
export default async function handler(req, res) {
const { id } = req.query;
+ const { BASE_URL } = req.query;
if (req.method === "GET") {
const now = Date.now();
@@ -13,7 +14,7 @@ export default async function handler(req, res) {
}
try {
- const result = await fetchProfile(id);
+ const result = await fetchProfile(BASE_URL, id);
cache = result;
cacheExpiry = now + 5 * 60 * 1000;
return res.status(200).json(result);
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/index.js b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/index.js
index f985eabca..8c360be85 100644
--- a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/index.js
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/index.js
@@ -4,6 +4,7 @@ let cache = null;
let cacheExpiry = 0;
export default async function handler(req, res) {
+ const { BASE_URL } = req.query;
if (req.method === "GET") {
const now = Date.now();
@@ -12,7 +13,7 @@ export default async function handler(req, res) {
}
try {
- const result = await fetchProfiles();
+ const result = await fetchProfiles(BASE_URL);
cache = result;
cacheExpiry = now + 5 * 60 * 1000;
return res.status(200).json(result);
diff --git a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
index 148141579..a41986c5c 100644
--- a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
+++ b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
@@ -18,7 +18,7 @@ function HURUMapURL(props) {
const [loading, setLoading] = useState(false);
const [isButtonDisabled, setIsButtonDisabled] = useState(true);
// eslint-disable-next-line no-unused-vars
- const isHURUMapAPIURLValid = useFormFields(([_, dispatch]) => dispatch);
+ const HURUMapAPIURLValid = useFormFields(([_, dispatch]) => dispatch);
const validateURL = async () => {
if (!value) return;
@@ -28,16 +28,16 @@ function HURUMapURL(props) {
// Ideally we should have a dedicated endpoint for this
const response = await fetch(`${value}/profiles`);
setIsValid(response.ok);
- isHURUMapAPIURLValid({
+ HURUMapAPIURLValid({
type: "UPDATE",
- path: "isHURUMapAPIURLValid",
+ path: "HURUMapAPIURLValid",
value: response.ok,
});
} catch (error) {
setIsValid(false);
- isHURUMapAPIURLValid({
+ HURUMapAPIURLValid({
type: "UPDATE",
- path: "isHURUMapAPIURLValid",
+ path: "HURUMapAPIURLValid",
value: false,
});
} finally {
diff --git a/apps/climatemappedafrica/src/payload/fields/LocationSelect.js b/apps/climatemappedafrica/src/payload/fields/LocationSelect.js
index b5917beea..9dcb4ae06 100644
--- a/apps/climatemappedafrica/src/payload/fields/LocationSelect.js
+++ b/apps/climatemappedafrica/src/payload/fields/LocationSelect.js
@@ -3,7 +3,6 @@ import {
useAllFormFields,
reduceFieldsToValues,
} from "payload/components/forms";
-import { select } from "payload/dist/fields/validations";
import { createElement, useMemo } from "react";
import useSWR from "swr";
@@ -18,18 +17,12 @@ const getOptions = (locations) =>
value: location.code,
})) || [];
-export async function validateLocation(value, { data, hasMany, required, t }) {
- const { profile } = data;
- const res = await fetcher(`${apiUrl}/api/hurumap/profiles/${profile}`);
- const options = getOptions(res.locations);
- return select(value, { hasMany, options, required, t });
-}
-
function LocationSelect(props) {
const [fields] = useAllFormFields();
const formData = reduceFieldsToValues(fields, true);
+ const BASE_URL = formData.hurumapAPIURL;
const { data } = useSWR(
- `${apiUrl}/api/hurumap/profiles/${formData.profile}`,
+ `${apiUrl}/api/hurumap/profiles/${formData.profile}?BASE_URL=${BASE_URL}`,
fetcher,
{
dedupingInterval: 60000,
diff --git a/apps/climatemappedafrica/src/payload/fields/ProfileSelect.js b/apps/climatemappedafrica/src/payload/fields/ProfileSelect.js
index de8928c83..d3a652c95 100644
--- a/apps/climatemappedafrica/src/payload/fields/ProfileSelect.js
+++ b/apps/climatemappedafrica/src/payload/fields/ProfileSelect.js
@@ -1,4 +1,8 @@
-import { Select } from "payload/components/forms";
+import {
+ Select,
+ useAllFormFields,
+ reduceFieldsToValues,
+} from "payload/components/forms";
import { createElement, useMemo } from "react";
import useSWR from "swr";
@@ -6,10 +10,17 @@ const apiUrl = process.env.PAYLOAD_PUBLIC_APP_URL;
const fetcher = (url) => fetch(url).then((res) => res.json());
function ProfileSelect(props) {
- const { data } = useSWR(`${apiUrl}/api/hurumap/profiles`, fetcher, {
- dedupingInterval: 60000,
- revalidateOnFocus: false,
- });
+ const [fields] = useAllFormFields();
+ const formData = reduceFieldsToValues(fields, true);
+ const BASE_URL = formData.hurumapAPIURL;
+ const { data } = useSWR(
+ `${apiUrl}/api/hurumap/profiles?BASE_URL=${BASE_URL}`,
+ fetcher,
+ {
+ dedupingInterval: 60000,
+ revalidateOnFocus: false,
+ },
+ );
const options = useMemo(
() => data?.map(({ name, id }) => ({ label: name, value: id })) || [],
diff --git a/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js b/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
index 9c993d787..3dd7abfe2 100644
--- a/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
+++ b/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
@@ -1,4 +1,4 @@
-import LocationSelect, { validateLocation } from "../../fields/LocationSelect";
+import LocationSelect from "../../fields/LocationSelect";
const RootGeography = {
label: "Root Geography",
@@ -22,7 +22,6 @@ const RootGeography = {
required: true,
hasMany: false,
defaultValue: "af",
- validate: validateLocation,
admin: {
components: {
Field: LocationSelect,
diff --git a/apps/climatemappedafrica/src/payload/globals/HURUMap/index.js b/apps/climatemappedafrica/src/payload/globals/HURUMap/index.js
index 74d66226d..2a81ba311 100644
--- a/apps/climatemappedafrica/src/payload/globals/HURUMap/index.js
+++ b/apps/climatemappedafrica/src/payload/globals/HURUMap/index.js
@@ -38,7 +38,7 @@ const HURUMap = {
required: true,
},
{
- name: "isHURUMapAPIURLValid",
+ name: "HURUMapAPIURLValid",
type: "checkbox",
admin: {
hidden: true,
@@ -51,7 +51,7 @@ const HURUMap = {
tabs: [Profile, DataPanels, RootGeography, Tutorial],
admin: {
condition: (_, siblingData) =>
- !!siblingData?.enableHURUMap && !!siblingData?.isHURUMapAPIURLValid,
+ !!siblingData?.enableHURUMap && !!siblingData?.HURUMapAPIURLValid,
},
},
],
From 16ff009fefbe0db060d6fa65973994ea4e74db03 Mon Sep 17 00:00:00 2001
From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com>
Date: Fri, 8 Nov 2024 10:56:52 +0300
Subject: [PATCH 17/73] Use named params
---
.../src/lib/data/blockify/hero.js | 6 +++---
.../src/lib/data/common/index.js | 2 +-
apps/climatemappedafrica/src/lib/hurumap/index.js | 4 ++--
.../src/pages/api/hurumap/index.js | 14 --------------
.../src/pages/api/hurumap/profiles/[id].js | 2 +-
.../src/payload/fields/HURUMapURL/index.js | 4 ++--
.../src/payload/globals/HURUMap/DataPanels.js | 5 +++++
7 files changed, 14 insertions(+), 23 deletions(-)
delete mode 100644 apps/climatemappedafrica/src/pages/api/hurumap/index.js
diff --git a/apps/climatemappedafrica/src/lib/data/blockify/hero.js b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
index e9d2fa12a..21d2140da 100644
--- a/apps/climatemappedafrica/src/lib/data/blockify/hero.js
+++ b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
@@ -22,10 +22,10 @@ export default async function hero(block, _api, _context, { hurumap }) {
country: "region",
};
const childLevel = childLevelMaps[level];
- const { locations, preferredChildren } = await fetchProfile(
- hurumapAPIURL,
+ const { locations, preferredChildren } = await fetchProfile({
+ BASE_URL: hurumapAPIURL,
profileId,
- );
+ });
const preferredChildrenPerLevel = preferredChildren[level];
const { children } = geometries;
const preferredLevel =
diff --git a/apps/climatemappedafrica/src/lib/data/common/index.js b/apps/climatemappedafrica/src/lib/data/common/index.js
index 93e641d5d..571f7f973 100644
--- a/apps/climatemappedafrica/src/lib/data/common/index.js
+++ b/apps/climatemappedafrica/src/lib/data/common/index.js
@@ -127,7 +127,7 @@ export async function getPageProps(api, context) {
profile: profileId,
...otherHurumapSettings
} = hurumapSettings;
- const profile = await fetchProfile(hurumapAPIURL, profileId);
+ const profile = await fetchProfile({ BASE_URL: hurumapAPIURL, profileId });
const { value: profilePage } = hurumapPage;
if (slug === profilePage.slug) {
variant = "explore";
diff --git a/apps/climatemappedafrica/src/lib/hurumap/index.js b/apps/climatemappedafrica/src/lib/hurumap/index.js
index b814414be..1d1c78660 100644
--- a/apps/climatemappedafrica/src/lib/hurumap/index.js
+++ b/apps/climatemappedafrica/src/lib/hurumap/index.js
@@ -5,9 +5,9 @@ import formatNumericalValue from "@/climatemappedafrica/utils/formatNumericalVal
const apiUrl = process.env.HURUMAP_API_URL || hurumap?.api?.url;
-export async function fetchProfile(BASE_URL, id) {
+export async function fetchProfile({ BASE_URL, profileId }) {
const { configuration } = await fetchJson(
- new URL(`/api/v1/profiles/${id}/?format=json`, BASE_URL),
+ new URL(`/api/v1/profiles/${profileId}/?format=json`, BASE_URL),
);
const locations = configuration?.featured_locations?.map(
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/index.js b/apps/climatemappedafrica/src/pages/api/hurumap/index.js
deleted file mode 100644
index 857f87b2b..000000000
--- a/apps/climatemappedafrica/src/pages/api/hurumap/index.js
+++ /dev/null
@@ -1,14 +0,0 @@
-import { fetchProfile } from "@/climatemappedafrica/lib/hurumap";
-
-export default async function index(req, res) {
- if (req.method === "GET") {
- try {
- const result = await fetchProfile();
- return res.status(200).json(result);
- } catch (err) {
- return res.status(500).json(err.message);
- }
- }
-
- return res.status(405).end();
-}
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
index cc294e77f..cc81e2542 100644
--- a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
@@ -14,7 +14,7 @@ export default async function handler(req, res) {
}
try {
- const result = await fetchProfile(BASE_URL, id);
+ const result = await fetchProfile({ BASE_URL, profileId: id });
cache = result;
cacheExpiry = now + 5 * 60 * 1000;
return res.status(200).json(result);
diff --git a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
index a41986c5c..9c65fa381 100644
--- a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
+++ b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
@@ -24,8 +24,8 @@ function HURUMapURL(props) {
if (!value) return;
setLoading(true);
try {
- // For now we can use the profiles endpoint to check if the URL is validate
- // Ideally we should have a dedicated endpoint for this
+ // For now we can use the profiles endpoint to check if the URL is valid
+ // Ideally we should have a dedicated endpoint for this, like /api/v1/validate or /api/v1/health
const response = await fetch(`${value}/profiles`);
setIsValid(response.ok);
HURUMapAPIURLValid({
diff --git a/apps/climatemappedafrica/src/payload/globals/HURUMap/DataPanels.js b/apps/climatemappedafrica/src/payload/globals/HURUMap/DataPanels.js
index cf60493c5..450ef677e 100644
--- a/apps/climatemappedafrica/src/payload/globals/HURUMap/DataPanels.js
+++ b/apps/climatemappedafrica/src/payload/globals/HURUMap/DataPanels.js
@@ -8,6 +8,11 @@ const DataPanels = {
type: "array",
label: "Panel Items",
required: true,
+ admin: {
+ components: {
+ RowLabel: ({ data }) => data?.value,
+ },
+ },
fields: [
{
type: "select",
From cede73e4e08d9c2cd41679a81665a633e96bc3cc Mon Sep 17 00:00:00 2001
From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com>
Date: Fri, 8 Nov 2024 11:10:41 +0300
Subject: [PATCH 18/73] Pass HURUMAPAPIURL
---
apps/climatemappedafrica/src/lib/data/common/index.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/apps/climatemappedafrica/src/lib/data/common/index.js b/apps/climatemappedafrica/src/lib/data/common/index.js
index 571f7f973..1a753147e 100644
--- a/apps/climatemappedafrica/src/lib/data/common/index.js
+++ b/apps/climatemappedafrica/src/lib/data/common/index.js
@@ -143,6 +143,7 @@ export async function getPageProps(api, context) {
}
settings.hurumap = {
...otherHurumapSettings,
+ hurumapAPIURL,
profile,
profileId,
profilePage,
From fa316572305348bd914472ec8b14088035bf430b Mon Sep 17 00:00:00 2001
From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com>
Date: Fri, 8 Nov 2024 13:10:10 +0300
Subject: [PATCH 19/73] fully use user provided api url
---
.../src/components/ExplorePage/index.js | 7 ++++++-
.../ExplorePage/useProfileGeography.js | 7 +++++--
.../src/lib/data/blockify/explore-page.js | 16 ++++++++++++++--
.../src/lib/data/blockify/hero.js | 5 ++++-
.../climatemappedafrica/src/lib/hurumap/index.js | 16 ++++++++--------
.../pages/api/hurumap/geographies/[geoCode].js | 6 +++++-
.../src/pages/api/hurumap/index.js | 14 ++++++++++++++
.../src/pages/api/hurumap/profiles/[id].js | 3 +--
8 files changed, 57 insertions(+), 17 deletions(-)
create mode 100644 apps/climatemappedafrica/src/pages/api/hurumap/index.js
diff --git a/apps/climatemappedafrica/src/components/ExplorePage/index.js b/apps/climatemappedafrica/src/components/ExplorePage/index.js
index 35cc52c07..17313b26c 100644
--- a/apps/climatemappedafrica/src/components/ExplorePage/index.js
+++ b/apps/climatemappedafrica/src/components/ExplorePage/index.js
@@ -33,6 +33,7 @@ function initialState(
function ExplorePage({
rootGeography,
explorePagePath,
+ hurumapConfig,
panel: PanelProps = {},
profile: profileProp,
...props
@@ -92,7 +93,7 @@ function ExplorePage({
(state.primary.shouldFetch && state.primary.code) ||
(state.secondary?.shouldFetch && state.secondary?.code);
- const { data, error } = useProfileGeography(shouldFetch);
+ const { data, error } = useProfileGeography(shouldFetch, hurumapConfig);
useEffect(() => {
if (data) {
dispatch({
@@ -235,6 +236,10 @@ ExplorePage.propTypes = {
}),
),
]),
+ hurumapConfig: PropTypes.shape({
+ hurumapAPIURL: PropTypes.string,
+ profileId: PropTypes.number,
+ }),
};
export default ExplorePage;
diff --git a/apps/climatemappedafrica/src/components/ExplorePage/useProfileGeography.js b/apps/climatemappedafrica/src/components/ExplorePage/useProfileGeography.js
index 108fa7542..bbee038d2 100644
--- a/apps/climatemappedafrica/src/components/ExplorePage/useProfileGeography.js
+++ b/apps/climatemappedafrica/src/components/ExplorePage/useProfileGeography.js
@@ -2,9 +2,12 @@ import useSWR from "swr";
import fetchJson from "@/climatemappedafrica/utils/fetchJson";
-function useProfileGeography(shouldFetch) {
+function useProfileGeography(shouldFetch, hurumapConfig) {
+ const { BASE_URL, profileId } = hurumapConfig;
const fetcher = (code) => {
- return fetchJson(`/api/hurumap/geographies/${code}`);
+ return fetchJson(
+ `/api/hurumap/geographies/${code}?profileId=${profileId}&BASE_URL=${BASE_URL}`,
+ );
};
const { data, error } = useSWR(shouldFetch, fetcher);
diff --git a/apps/climatemappedafrica/src/lib/data/blockify/explore-page.js b/apps/climatemappedafrica/src/lib/data/blockify/explore-page.js
index 2f2179445..d5c5f9ae8 100644
--- a/apps/climatemappedafrica/src/lib/data/blockify/explore-page.js
+++ b/apps/climatemappedafrica/src/lib/data/blockify/explore-page.js
@@ -6,9 +6,11 @@ import { fetchProfileGeography } from "@/climatemappedafrica/lib/hurumap";
*/
async function explorePage(block, _api, _context, { hurumap }) {
const {
+ hurumapAPIURL,
items: panelItems,
labels: { dataNotAvailable, scrollToTop: scrollToTopLabel },
profile: hurumapProfile,
+ profileId,
profilePage,
rootGeography,
} = hurumap;
@@ -30,10 +32,16 @@ async function explorePage(block, _api, _context, { hurumap }) {
}
const [primaryCode, secondaryCode] = geoCodes;
- const primaryProfile = await fetchProfileGeography(primaryCode);
+ const primaryProfile = await fetchProfileGeography(primaryCode, {
+ BASE_URL: hurumapAPIURL,
+ profileId,
+ });
const profile = [primaryProfile];
if (secondaryCode) {
- const secondaryProfile = await fetchProfileGeography(secondaryCode);
+ const secondaryProfile = await fetchProfileGeography(secondaryCode, {
+ BASE_URL: hurumapAPIURL,
+ profileId,
+ });
profile.push(secondaryProfile);
}
@@ -46,6 +54,10 @@ async function explorePage(block, _api, _context, { hurumap }) {
id: "explore-page",
blockType: "explore-page",
choropleth,
+ hurumapConfig: {
+ hurumapAPIURL,
+ profileId,
+ },
rootGeography,
explorePagePath: profilePage.slug,
locations,
diff --git a/apps/climatemappedafrica/src/lib/data/blockify/hero.js b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
index 21d2140da..a69f0a24c 100644
--- a/apps/climatemappedafrica/src/lib/data/blockify/hero.js
+++ b/apps/climatemappedafrica/src/lib/data/blockify/hero.js
@@ -15,7 +15,10 @@ export default async function hero(block, _api, _context, { hurumap }) {
profilePage,
rootGeography: { center, code, hasData: pinRootGeography },
} = hurumap ?? { rootGeography: {} };
- const { geometries } = await fetchProfileGeography(code.toLowerCase());
+ const { geometries } = await fetchProfileGeography(code.toLowerCase(), {
+ BASE_URL: hurumapAPIURL,
+ profileId,
+ });
const { level } = geometries.boundary?.properties ?? {};
const childLevelMaps = {
continent: "country",
diff --git a/apps/climatemappedafrica/src/lib/hurumap/index.js b/apps/climatemappedafrica/src/lib/hurumap/index.js
index 1d1c78660..29a93ce36 100644
--- a/apps/climatemappedafrica/src/lib/hurumap/index.js
+++ b/apps/climatemappedafrica/src/lib/hurumap/index.js
@@ -1,10 +1,7 @@
import defaultIcon from "@/climatemappedafrica/assets/icons/eye-white.svg";
-import { hurumap } from "@/climatemappedafrica/config";
import fetchJson from "@/climatemappedafrica/utils/fetchJson";
import formatNumericalValue from "@/climatemappedafrica/utils/formatNumericalValue";
-const apiUrl = process.env.HURUMAP_API_URL || hurumap?.api?.url;
-
export async function fetchProfile({ BASE_URL, profileId }) {
const { configuration } = await fetchJson(
new URL(`/api/v1/profiles/${profileId}/?format=json`, BASE_URL),
@@ -91,12 +88,15 @@ function formatProfileGeographyData(data, parent) {
.filter((category) => category.children.length);
}
-export async function fetchProfileGeography(geoCode) {
+export async function fetchProfileGeography(
+ geoCode,
+ { BASE_URL, profileId, version = "Climate" },
+) {
// HURUmap codes are uppercased in the API
const json = await fetchJson(
new URL(
- `/api/v1/all_details/profile/1/geography/${geoCode.toUpperCase()}/?version=Climate`,
- apiUrl,
+ `/api/v1/all_details/profile/${profileId}/geography/${geoCode.toUpperCase()}/?version=${version}`,
+ BASE_URL,
),
);
const { boundary, children, parent_layers: parents } = json;
@@ -141,8 +141,8 @@ export async function fetchProfileGeography(geoCode) {
if (parentCode) {
const parentJson = await fetchJson(
new URL(
- `/api/v1/all_details/profile/1/geography/${parentCode.toUpperCase()}/?version=Climate`,
- apiUrl,
+ `/api/v1/all_details/profile/${profileId}/geography/${parentCode.toUpperCase()}/?version=${version}`,
+ BASE_URL,
),
);
parent.data = parentJson.profile.profile_data;
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/geographies/[geoCode].js b/apps/climatemappedafrica/src/pages/api/hurumap/geographies/[geoCode].js
index fe7619246..966f13e66 100644
--- a/apps/climatemappedafrica/src/pages/api/hurumap/geographies/[geoCode].js
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/geographies/[geoCode].js
@@ -1,10 +1,14 @@
import { fetchProfileGeography } from "@/climatemappedafrica/lib/hurumap";
export default async function index(req, res) {
+ const { profileId, BASE_URL } = req.query;
if (req.method === "GET") {
try {
const { geoCode } = req.query;
- const result = await fetchProfileGeography(geoCode);
+ const result = await fetchProfileGeography(geoCode, {
+ BASE_URL,
+ profileId,
+ });
return res.status(200).json(result);
} catch (err) {
return res.status(500).json(err.message);
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/index.js b/apps/climatemappedafrica/src/pages/api/hurumap/index.js
new file mode 100644
index 000000000..857f87b2b
--- /dev/null
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/index.js
@@ -0,0 +1,14 @@
+import { fetchProfile } from "@/climatemappedafrica/lib/hurumap";
+
+export default async function index(req, res) {
+ if (req.method === "GET") {
+ try {
+ const result = await fetchProfile();
+ return res.status(200).json(result);
+ } catch (err) {
+ return res.status(500).json(err.message);
+ }
+ }
+
+ return res.status(405).end();
+}
diff --git a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
index cc81e2542..2fcd65340 100644
--- a/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
+++ b/apps/climatemappedafrica/src/pages/api/hurumap/profiles/[id].js
@@ -4,8 +4,7 @@ let cache = null;
let cacheExpiry = 0;
export default async function handler(req, res) {
- const { id } = req.query;
- const { BASE_URL } = req.query;
+ const { id, BASE_URL } = req.query;
if (req.method === "GET") {
const now = Date.now();
From 7d4e02c594cd8fd85115ccf8f8abc9787fdadad1 Mon Sep 17 00:00:00 2001
From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com>
Date: Fri, 8 Nov 2024 13:50:35 +0300
Subject: [PATCH 20/73] Tiny fix
---
.../climatemappedafrica/src/payload/fields/HURUMapURL/index.js | 1 +
.../src/payload/globals/HURUMap/RootGeography.js | 3 ---
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
index 9c65fa381..2d6f7b8e5 100644
--- a/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
+++ b/apps/climatemappedafrica/src/payload/fields/HURUMapURL/index.js
@@ -7,6 +7,7 @@ import {
} from "payload/components/forms";
import { createElement, useState, useEffect } from "react";
+// TODO: @kelvinkipruto Handle i18n
function HURUMapURL(props) {
const {
admin: { description },
diff --git a/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js b/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
index 3dd7abfe2..56856d2b0 100644
--- a/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
+++ b/apps/climatemappedafrica/src/payload/globals/HURUMap/RootGeography.js
@@ -9,9 +9,6 @@ const RootGeography = {
en: "Root Geography",
},
type: "group",
- admin: {
- condition: (data) => Boolean(data?.profile),
- },
fields: [
{
name: "code",
From 90c17436fcedc59a0a09fa1ab9fc4f966734310c Mon Sep 17 00:00:00 2001
From: Kevin Koech
Date: Mon, 11 Nov 2024 15:11:09 +0300
Subject: [PATCH 21/73] Fixes Climatemapped Africa styling issues
---
.../src/components/AboutTeam/AboutTeam.js | 29 ++---
.../DropdownSearch/DownloadSearch.js | 3 +-
.../src/components/Footer/index.js | 8 +-
.../src/components/Footer/useStyles.js | 4 +-
.../src/components/Hero/Hero.js | 75 +++++--------
.../src/components/Hero/Hero.snap.js | 102 +++++++-----------
.../src/components/Hero/Map.js | 48 +++++++--
.../src/components/HowItWorks/index.js | 3 +
.../src/components/Menu/index.js | 26 +++--
.../Navigation/DesktopNavigation/index.js | 6 +-
10 files changed, 150 insertions(+), 154 deletions(-)
diff --git a/apps/climatemappedafrica/src/components/AboutTeam/AboutTeam.js b/apps/climatemappedafrica/src/components/AboutTeam/AboutTeam.js
index f5167ad09..a33d2d1c6 100644
--- a/apps/climatemappedafrica/src/components/AboutTeam/AboutTeam.js
+++ b/apps/climatemappedafrica/src/components/AboutTeam/AboutTeam.js
@@ -1,6 +1,5 @@
-import { Box, Grid, Typography, useMediaQuery } from "@mui/material";
+import { Box, Typography, useMediaQuery } from "@mui/material";
import { useTheme } from "@mui/material/styles";
-import { chunk, uniqueId } from "lodash";
import PropTypes from "prop-types";
import React, { useRef } from "react";
@@ -16,10 +15,12 @@ import useStyles from "./useStyles";
const responsive = {
desktop: {
- items: 1,
+ items: 4,
+ partialVisibilityGutter: 30,
},
tablet: {
- items: 1,
+ items: 2,
+ partialVisibilityGutter: 30,
},
};
@@ -33,8 +34,6 @@ function AboutTeam({ title, members: membersProp, ...props }) {
if (!membersProp?.length) {
return null;
}
- const chunkSize = isMdUp ? 4 : 2;
- const members = chunk(membersProp, chunkSize);
const scrollToTeam = () => {
if (ref.current && !isMdUp) {
ref.current.scrollIntoView({ behavior: "smooth" });
@@ -69,18 +68,12 @@ function AboutTeam({ title, members: membersProp, ...props }) {
responsive={responsive}
classes={{ dotList: classes.dotList }}
>
- {members.map((membersChunks) => (
-
- {membersChunks.map((member) => (
-
-
-
- ))}
-
+ {membersProp.map((member) => (
+
))}
diff --git a/apps/climatemappedafrica/src/components/DropdownSearch/DownloadSearch.js b/apps/climatemappedafrica/src/components/DropdownSearch/DownloadSearch.js
index b1f4b04ff..5fd43ea1e 100644
--- a/apps/climatemappedafrica/src/components/DropdownSearch/DownloadSearch.js
+++ b/apps/climatemappedafrica/src/components/DropdownSearch/DownloadSearch.js
@@ -22,6 +22,7 @@ function DropdownSearch({
icon: IconProp = SearchIcon,
placeholder,
variant,
+ sx,
...props
}) {
const router = useRouter();
@@ -96,7 +97,7 @@ function DropdownSearch({
);
return (
-
+
{label && (
({
copyrightText: {
color: palette.text.secondary,
order: 5,
- padding: `0 ${typography.pxToRem(5)}`,
+ padding: `0 ${typography.pxToRem(5)} 0 0`,
[breakpoints.up("lg")]: {
- padding: `0 ${typography.pxToRem(10)}`,
+ padding: `0 ${typography.pxToRem(10)} 0 0`,
},
},
}));
diff --git a/apps/climatemappedafrica/src/components/Hero/Hero.js b/apps/climatemappedafrica/src/components/Hero/Hero.js
index 91239fb64..919d2216c 100644
--- a/apps/climatemappedafrica/src/components/Hero/Hero.js
+++ b/apps/climatemappedafrica/src/components/Hero/Hero.js
@@ -2,9 +2,7 @@ import { RichTypography } from "@commons-ui/legacy";
import { Box, Grid, useMediaQuery } from "@mui/material";
import dynamic from "next/dynamic";
import PropTypes from "prop-types";
-import React, { useState } from "react";
-
-import Legend from "./Legend";
+import React from "react";
import heroBg from "@/climatemappedafrica/assets/images/bg-map-white.jpg";
import DropdownSearch from "@/climatemappedafrica/components/DropdownSearch";
@@ -26,11 +24,9 @@ function Hero({
level,
explorePageSlug,
averageTemperature,
- legend,
...props
}) {
const isUpLg = useMediaQuery((theme) => theme.breakpoints.up("lg"));
- const [hoverGeo, setHoverGeo] = useState(null);
const continentLevelZoom = isUpLg ? 3 : 2.1; // We have to reduce the zoom level for continent so that all countries(Including islands) are visible within the designs
const countryLevelZoom = isUpLg ? 6 : 5.25;
const zoom = level === "continent" ? continentLevelZoom : countryLevelZoom;
@@ -58,7 +54,14 @@ function Hero({
}}
>
-
+
{title}
-
-
- {comment}
-
+
+
+
+ {comment}
+
+
{/* Since map is dynamic-ally loaded, no need for implementation="css" */}
@@ -112,34 +114,11 @@ function Hero({
tileLayer={{
url: "https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png",
}}
- onLayerMouseOver={setHoverGeo}
featuredLocations={featuredLocations}
explorePageSlug={explorePageSlug}
{...props}
/>
) : null}
-
-
-
- {hoverGeo}
-
-
diff --git a/apps/climatemappedafrica/src/components/Hero/Hero.snap.js b/apps/climatemappedafrica/src/components/Hero/Hero.snap.js
index a0e855047..e8ba6f322 100644
--- a/apps/climatemappedafrica/src/components/Hero/Hero.snap.js
+++ b/apps/climatemappedafrica/src/components/Hero/Hero.snap.js
@@ -23,7 +23,7 @@ exports[` renders unchanged 1`] = `
class="MuiGrid-root MuiGrid-container css-11lq3yg-MuiGrid-root"
>
renders unchanged 1`] = `
-
- Search for a location
-
-
-
-
-
-
-
-
-
-
+ Search for a location
+
+
+