Skip to content

Commit

Permalink
Merge branch 'develop' into SKY30-443-fe-tables-pagination-and-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprdhomme committed Oct 3, 2024
2 parents a1d7fd5 + 3eb1edc commit 77f54b5
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 104 deletions.
9 changes: 3 additions & 6 deletions cms/config/sync/admin-role.strapi-author.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand Down Expand Up @@ -901,8 +900,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand All @@ -926,8 +924,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand Down
9 changes: 3 additions & 6 deletions cms/config/sync/admin-role.strapi-editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand Down Expand Up @@ -884,8 +883,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand All @@ -907,8 +905,7 @@
"protection_coverage_stats",
"totalTerrestrialArea",
"name_es",
"name_fr",
"mpaa_fully_highly_protected_area"
"name_fr"
],
"locales": []
},
Expand Down
2 changes: 1 addition & 1 deletion cms/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2246,4 +2246,4 @@
"actionParameters": {}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,6 @@
{
"name": "name",
"size": 6
},
{
"name": "name_es",
"size": 6
}
],
[
{
"name": "name_fr",
"size": 6
}
],
[
Expand Down Expand Up @@ -358,12 +348,6 @@
"size": 6
}
],
[
{
"name": "mpaa_fully_highly_protected_area",
"size": 4
}
],
[
{
"name": "marine_bounds",
Expand All @@ -380,6 +364,20 @@
{
"name": "mpaa_protection_level_stat",
"size": 6
},
{
"name": "name_es",
"size": 6
}
],
[
{
"name": "name_fr",
"size": 6
},
{
"name": "mpaa_fully_highly_protected_area",
"size": 4
}
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,93 +313,95 @@
}
},
"layouts": {
"list": [
"id",
"name",
"area",
"year"
],
"edit": [
[
{
"name": "name",
"size": 6
},
{
"name": "environment",
"size": 6
"name": "area",
"size": 4
}
],
[
{
"name": "location",
"size": 6
"name": "year",
"size": 4
},
{
"name": "designation",
"name": "protection_status",
"size": 6
}
],
[
{
"name": "year",
"size": 4
},
"name": "bbox",
"size": 12
}
],
[
{
"name": "area",
"size": 4
"name": "children",
"size": 6
},
{
"name": "coverage",
"size": 4
"name": "data_source",
"size": 6
}
],
[
{
"name": "data_source",
"name": "mpaa_establishment_stage",
"size": 6
},
{
"name": "protection_status",
"name": "location",
"size": 6
}
],
[
{
"name": "iucn_category",
"size": 6
"name": "wdpaid",
"size": 4
},
{
"name": "mpaa_establishment_stage",
"name": "mpaa_protection_level",
"size": 6
}
],
[
{
"name": "mpaa_protection_level",
"name": "iucn_category",
"size": 6
},
{
"name": "wdpaid",
"size": 4
"name": "designation",
"size": 6
}
],
[
{
"name": "parent",
"name": "environment",
"size": 6
},
{
"name": "children",
"size": 6
"name": "coverage",
"size": 4
}
],
[
{
"name": "bbox",
"size": 12
"name": "parent",
"size": 6
}
]
],
"list": [
"id",
"name",
"area",
"year"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@
{
"name": "year",
"size": 4
},
{
"name": "is_last_year",
"size": 4
}
],
[
Expand All @@ -272,6 +268,12 @@
"name": "oecms",
"size": 4
},
{
"name": "is_last_year",
"size": 4
}
],
[
{
"name": "global_contribution",
"size": 4
Expand Down
6 changes: 0 additions & 6 deletions cms/config/sync/user-role.public.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@
{
"action": "api::mpaa-protection-level.mpaa-protection-level.findOne"
},
{
"action": "api::pa.pa.find"
},
{
"action": "api::pa.pa.findOne"
},
{
"action": "api::protection-coverage-stat.protection-coverage-stat.find"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,6 @@ const FishingProtectionWidget: FCWithMessages<FishingProtectionWidgetProps> = ({
}
);

const { data: metadataWidget } = useGetDataInfos(
{
locale,
filters: {
slug: 'fishing-protection-widget',
},
populate: 'data_sources',
},
{
query: {
select: ({ data }) =>
data[0]
? {
info: data[0].attributes.content,
sources: data[0].attributes?.data_sources?.data?.map(
({ attributes: { title, url } }) => ({
title,
url,
})
),
}
: undefined,
},
}
);

const { data: metadata } = useGetDataInfos(
{
locale,
Expand Down Expand Up @@ -110,11 +84,17 @@ const FishingProtectionWidget: FCWithMessages<FishingProtectionWidgetProps> = ({
if (!protectionLevelsData.length) return [];

const parsedProtectionLevel = (label: string, protectionLevel, stats) => {
const totalAreaPercentage = (stats?.area / stats?.pct) * 100;

// There are circumstances in which pct is 0, which will cause the percentage calculation to be NaN.
// This is a safeguard so that if the data is unexpected, we don't display NaN on the screen.
if (isNaN(totalAreaPercentage)) return null;

return {
title: label,
slug: protectionLevel.slug,
background: FISHING_PROTECTION_CHART_COLORS[protectionLevel.slug],
totalArea: (stats?.area / stats?.pct) * 100,
totalArea: totalAreaPercentage,
protectedArea: stats?.area,
info: metadata?.info,
sources: metadata?.sources,
Expand All @@ -130,24 +110,26 @@ const FishingProtectionWidget: FCWithMessages<FishingProtectionWidgetProps> = ({
return parsedProtectionLevel(t('highly-protected-from-fishing'), protectionLevel, data);
});

return parsedFishingProtectionLevelData ?? [];
return parsedFishingProtectionLevelData?.filter(Boolean) ?? [];
}, [t, protectionLevelsData, metadata]);

const noData = !widgetChartData.length;

const loading = isFetchingProtectionLevelsData;

return (
<Widget
title={t('fishing-protection')}
title={t('level-of-fishing-protection')}
lastUpdated={protectionLevelsData[0]?.attributes?.updatedAt}
noData={noData}
loading={loading}
info={metadataWidget?.info}
sources={metadataWidget?.sources}
>
{widgetChartData.map((chartData) => (
<HorizontalBarChart key={chartData.slug} className="py-2" data={chartData} />
<HorizontalBarChart
key={chartData.slug}
className="py-2"
data={chartData}
showTarget={false}
/>
))}
</Widget>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"administrative-boundary": "Administrative boundary",
"national-level-contribution": "National level contribution",
"global": "Global",
"fishing-protection": "Fishing Protection",
"level-of-fishing-protection": "Level of Fishing Protection",
"highly-protected-from-fishing": "Highly protected from fishing",
"summary": "Summary",
"terrestrial": "Terrestrial",
Expand Down

0 comments on commit 77f54b5

Please sign in to comment.