Skip to content

Commit a580dab

Browse files
fixed risk index value mapping (#14)
1 parent 8c3566b commit a580dab

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/pages/dashboard/services/PestAndDisease/RiskIndex.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ interface FormattedRiskIndexData {
2121
[day: string]: DailyData
2222
}
2323

24-
const riskLevelMapping: { [key: string]: number } = {
25-
'low': 0,
26-
'medium': 1,
27-
'high': 2,
24+
const riskLevelMapping = (label: string): number => {
25+
switch (label) {
26+
case 'low':
27+
return 0;
28+
case 'moderate':
29+
return 1;
30+
case 'high':
31+
return 2;
32+
default:
33+
return 0;
34+
}
2835
};
2936

3037
const riskLevelLabels = ['low', 'medium', 'high'];
@@ -78,6 +85,12 @@ const RiskIndexPage = () => {
7885
}
7986
}, [response]);
8087

88+
useEffect(() => {
89+
if (formattedData) {
90+
console.log(formattedData);
91+
}
92+
}, [formattedData])
93+
8194
return (
8295
<>
8396
<ParcelSelectionModule></ParcelSelectionModule>
@@ -111,7 +124,7 @@ const RiskIndexPage = () => {
111124
<Box display={'flex'} flexDirection={'column'} gap={2}>
112125
{Object.entries(formattedData).map(([date, dailyData]: [string, DailyData]) => {
113126
const numericalRiskData = dailyData.riskIndex?.map(
114-
(status) => riskLevelMapping[status]
127+
(status) => riskLevelMapping(status)
115128
).filter(value => value !== undefined) as number[] || [];
116129
return <Card key={`id-date-${date}`}>
117130
<CardContent>

0 commit comments

Comments
 (0)