Skip to content

Commit

Permalink
Regions tooltip can now display information for terrestrial protectio…
Browse files Browse the repository at this point in the history
…n coverage status
  • Loading branch information
SARodrigues committed Oct 11, 2024
1 parent 1a74247 commit c0e3032
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/map/attributions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Attributions: FC = () => {
$in: activeLayers,
},
},
populate: 'metadata',
populate: 'metadata,environment',
},
{
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const LayerManagerItem = ({ id, beforeId, settings }: LayerManagerItemProps) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
locale,
populate: 'metadata',
populate: 'metadata,environment',
});
const [, setLayersInteractive] = useAtom(layersInteractiveAtom);
const [, setLayersInteractiveIds] = useAtom(layersInteractiveIdsAtom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const GenericPopup: FCWithMessages<InteractionConfig & { layerId: number }> = ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
locale,
populate: 'metadata',
populate: 'metadata,environment',
},
{
query: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/containers/map/content/map/popup/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PopupItem: FCWithMessages<PopupItemProps> = ({ id }) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
locale,
populate: 'metadata',
populate: 'metadata,environment',
});

const attributes = data?.data?.attributes as LayerTyped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ProtectedAreaPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
locale,
populate: 'metadata',
populate: 'metadata,environment',
},
{
query: {
Expand Down
33 changes: 23 additions & 10 deletions frontend/src/containers/map/content/map/popup/regions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
const layersInteractiveIds = useAtomValue(layersInteractiveIdsAtom);

const layerQuery = useGetLayersId<{
environment: LayerTyped['environment']['data']['attributes'];
source: LayerTyped['config']['source'];
click: LayerTyped['interaction_config']['events'][0];
}>(
Expand All @@ -40,12 +41,13 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
locale,
populate: 'metadata',
populate: 'metadata,environment',
},
{
query: {
select: ({ data }) => ({
source: (data.attributes as LayerTyped).config?.source,
environment: (data.attributes as LayerTyped)?.environment?.data?.attributes,
source: (data.attributes as LayerTyped)?.config?.source,
click: (data.attributes as LayerTyped)?.interaction_config?.events.find(
(ev) => ev.type === 'click'
),
Expand All @@ -54,7 +56,7 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
}
);

const { source } = layerQuery.data;
const { source, environment } = layerQuery.data;

const DATA = useMemo(() => {
if (source?.type === 'vector' && rendered && popup && map) {
Expand Down Expand Up @@ -102,15 +104,22 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
},
environment: {
slug: {
$eq: 'marine',
$eq: environment.slug,
},
},
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
populate: {
location: {
fields: ['name', 'name_es', 'name_fr', 'code', 'total_marine_area'],
fields: [
'name',
'name_es',
'name_fr',
'code',
'total_marine_area',
'total_terrestrial_area',
],
},
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -188,6 +197,9 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {

if (!DATA) return null;

const totalLocationArea =
protectionCoverageStats?.location.data.attributes[`total_${environment.slug}_area`];

return (
<div className="space-y-2">
<h3 className="text-xl font-semibold">{localizedLocationName || '-'}</h3>
Expand All @@ -198,7 +210,11 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
{!isFetching && !!protectionCoverageStats && (
<>
<div className="space-y-2">
<div className="my-4 max-w-[95%] font-mono">{t('marine-conservation-coverage')}</div>
<div className="my-4 max-w-[95%] font-mono">
{environment?.slug === 'marine'
? t('marine-conservation-coverage')
: t('terrestrial-conservation-coverage')}
</div>
<div className="space-x-1 font-mono tracking-tighter text-black">
{formattedStats.percentage !== '-' &&
t.rich('percentage-bold', {
Expand All @@ -217,10 +233,7 @@ const RegionsPopup: FCWithMessages<{ layerId: number }> = ({ layerId }) => {
<div className="space-x-1 font-mono font-medium text-black">
{t('marine-protected-area', {
protectedArea: formattedStats.protectedArea,
totalArea: formatKM(
locale,
Number(protectionCoverageStats?.location.data.attributes.total_marine_area)
),
totalArea: formatKM(locale, Number(totalLocationArea)),
})}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"no-data-available": "No data available",
"no-results": "No results.",
"marine-conservation-coverage": "Marine Conservation Coverage",
"terrestrial-conservation-coverage": "Terrestrial Conservation Coverage",
"percentage": "{percentage}%",
"percentage-bold": "<b1>{percentage}</b1><b2>%</b2>",
"marine-protected-area": "{protectedArea} km² out of {totalArea} km²",
Expand Down

0 comments on commit c0e3032

Please sign in to comment.