Skip to content

Commit 5b750a7

Browse files
authored
Merge pull request #18 from CIAT-DAPA/develop
Develop
2 parents 97c4577 + a4e96b1 commit 5b750a7

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

src/src/components/LayersMarkers/LayersMarkers.jsx

+27
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ import {
55
Marker,
66

77
Tooltip,
8+
9+
useMap
810

911
} from "react-leaflet";
1012
import L from "leaflet";
13+
import { useEffect } from "react";
1114
import './LayersMarkers'
1215
import { useContext } from "react";
1316
import { DataContext } from "../../context/context";
1417
import Configuration from "../../conf/Configuration";
18+
import config from './config.json';
1519

1620
const LayersMarkers=({option1Checked,option2Checked,accessions,
1721
clickedMarkerIndices,
@@ -37,6 +41,29 @@ const LayersMarkers=({option1Checked,option2Checked,accessions,
3741
}
3842
setClickedMarkerIndices(newSet);
3943
};
44+
45+
const map = useMap();
46+
const { iso, project } = useContext(DataContext);
47+
48+
useEffect(() => {
49+
50+
51+
if (accessions.length === 0 && layerr.length > 0 && project === "bolder") {
52+
53+
54+
if (iso && config.COUNTRY_BOUNDS[iso]) {
55+
const bounds = L.latLngBounds(config.COUNTRY_BOUNDS[iso]);
56+
57+
58+
if (map) {
59+
map.flyToBounds(bounds, { padding: [50, 50] });
60+
}
61+
} else {
62+
console.warn("No bounds found for ISO:", iso);
63+
}
64+
}
65+
}, [accessions, layerr, project, iso, map]);
66+
4067
return (
4168
<>
4269
{option1Checked == true &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"COUNTRY_BOUNDS": {
3+
"UG": [[-1.482, 29.573], [4.231, 35.000]],
4+
"TZ": [[-11.761, 29.338], [-0.95, 40.636]],
5+
"BJ": [[6.225, 0.775], [12.409, 3.851]],
6+
"GH": [[4.738, -3.244], [11.174, 1.191]]
7+
}
8+
}

src/src/components/filterLeft/FilterLeft.jsx

+22-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function FilterLeft({
4646
const [filteredCountries, setFilteredCountries] = useState(response);
4747
const { project, setProject } = useContext(DataContext);
4848
const [compProject, setCompProject] = useState('');
49+
const [majorCrops, setMajorCrops] = useState([]);
4950
const bolderCountries = response.filter((country) =>
5051
config.BOLDER_COUNTRIES.includes(country.name)
5152
);
@@ -60,9 +61,10 @@ function FilterLeft({
6061
);
6162

6263
setShowLandraceGroups(project === "lga");
64+
setMajorCrops([]);
6365
};
6466

65-
const [majorCrops, setMajorCrops] = useState([]);
67+
6668
useEffect(() => {
6769
if (compProject) {
6870
if (config.PROJECT_CROPS[compProject]) {
@@ -122,6 +124,11 @@ function FilterLeft({
122124
);
123125
setCountryIso(selectedCountry.iso_2);
124126
setIso(selectedCountry.iso_2);
127+
128+
if (compProject === "bolder" && selectedCountry) {
129+
const countryCrops = config.BOLDER_CROPS[selectedCountry.name] || [];
130+
setMajorCrops(countryCrops);
131+
}
125132
//console.log(selectedCountry.iso_2)
126133
setTimeout(() => {
127134
setIndexStep(1);
@@ -326,7 +333,7 @@ const overlayInfo = "Info: your CSV file must have the following columns: 'id',
326333
</Col>
327334
</Row>
328335

329-
{majorCrops && (
336+
{majorCrops.length > 0 ? (
330337
<CheckFilter
331338
title="Major Crops"
332339
toolTipTitle="Step 3"
@@ -337,7 +344,19 @@ const overlayInfo = "Info: your CSV file must have the following columns: 'id',
337344
idOnboarding="select-majorCrop"
338345
indexStep={indexStep}
339346
setIndexStep={setIndexStep}
340-
></CheckFilter>
347+
/>
348+
) : (
349+
<CheckFilter
350+
title="Major Crops"
351+
toolTipTitle="Step 3"
352+
toolTipDescription="No crops available"
353+
onDataChange={handleDataMajorCropChange}
354+
onChange={shouldReset}
355+
crop={[]}
356+
idOnboarding="select-majorCrop"
357+
indexStep={indexStep}
358+
setIndexStep={setIndexStep}
359+
/>
341360
)}
342361

343362
{showLandraceGroups && carouselMajorItemsNow && carouselMajorItemsNow.length == 1 && (

src/src/components/filterLeft/config.json

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
"Tanzania, United Republic of",
66
"Uganda"
77
],
8+
9+
"BOLDER_CROPS": {
10+
"Benin":["Bambara groundnut","Black Fonio","Jutemallow","Sweetberry","White Fonio"],
11+
"Ghana":["Amaranth caudatus","Amaranth dubius","Amaranth (Red)","Amaranth hypochondriacus","Baobab","Sesame","Turkeyberry"],
12+
"Tanzania, United Republic of":["Bambara groundnut","Eleusine indica (CWR)","Finger millet","Moringa oleifera","Sweetpotato"],
13+
"Uganda":["Cenchrus caudatus (CWR)","Cenchrus mezianus (CWR)", "Cenchrus procerus (CWR)", "Cenchrus ramosus (CWR)","Cenchrus unisetus (CWR)","Cowpea","Cucurbita moschata","Cucurbita pepo","Jackfruit","Pearl millet","Pumpkin"]
14+
},
15+
816
"PROJECT_CROPS": {
917
"bolder": [
1018
"Amaranth caudatus",

src/src/components/map/Map.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,13 @@ function Map({
147147
.then((response) => {
148148
setShow(false);
149149
if (response.data[0].accessions.length === 0) {
150+
if (project === 'lga'){
150151
setShowg(true);
151152
setCarouselMajorItems([]);
153+
}else{
154+
setAccessions([])
155+
}
156+
152157
} else {
153158
setAccessions(response.data.flatMap((crop) => crop.accessions));
154159
}
@@ -223,8 +228,13 @@ function Map({
223228
.then((response) => {
224229
setShow(false);
225230
if (response.data[0].accessions.length === 0) {
226-
setShowg(true);
227-
setCarouselMajorItems([]);
231+
if (project === 'lga'){
232+
setShowg(true);
233+
setCarouselMajorItems([]);
234+
}else{
235+
setAccessions([])
236+
}
237+
228238
} else {
229239
setAccessions(response.data.flatMap((crop) => crop.accessions));
230240
}
@@ -292,9 +302,12 @@ function Map({
292302
if (flatMapAccesons.length > 0) {
293303
setAccessions(flatMapAccesons);
294304
} else {
295-
setShowg(true);
305+
if (project === 'lga'){
306+
setShowg(true);
307+
setCarouselMajorItems([]);
308+
}
296309
setAccessions([]);
297-
setCarouselMajorItems([]);
310+
298311
}
299312
});
300313
}
@@ -324,8 +337,13 @@ function Map({
324337
setAccessions(flatMapAccesions);
325338
} else {
326339
setAccessions([]);
327-
setShowg(true);
328-
setCarouselMajorItems([]);
340+
if (project === 'lga'){
341+
setShowg(true);
342+
setCarouselMajorItems([]);
343+
}else{
344+
setAccessions([])
345+
}
346+
329347
}
330348
});
331349
}

0 commit comments

Comments
 (0)