Skip to content

Commit

Permalink
Merge pull request #134 from Vizzuality/SKY30-181-m-2-marine-conserva…
Browse files Browse the repository at this point in the history
…tion-coverage-area-should-be-the-protected-area-not-the-total-area

[SKY30-181] Marine Conservation Coverage area should be the protected area, not the total area
  • Loading branch information
andresgnlez authored Jan 17, 2024
2 parents 4b00b3d + b3c6efa commit 7872b67
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const ProtectedAreaPopup = ({ locationId }: { locationId: number }) => {
{format({
value: DATA?.REP_M_AREA,
id: 'formatKM',
options: {
maximumSignificantDigits: 3,
},
})}
Km<sup>2</sup>
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { groupBy } from 'lodash-es';

import ConservationChart from '@/components/charts/conservation-chart';
import Widget from '@/components/widget';
import { formatKM } from '@/lib/utils/formats';
import { useGetProtectionCoverageStats } from '@/types/generated/protection-coverage-stat';
import type { LocationGroupsDataItemAttributes } from '@/types/generated/strapi.schemas';

Expand Down Expand Up @@ -85,13 +86,11 @@ const MarineConservationWidget: React.FC<MarineConservationWidgetProps> = ({ loc
maximumFractionDigits: 0,
});
const percentageFormatted = formatter.format((protectedArea / totalArea) * 100);
const totalAreaFormatted = Intl.NumberFormat('en-US', {
notation: 'standard',
}).format(totalArea);
const protectedAreaFormatted = formatKM(protectedArea);

return {
protectedPercentage: percentageFormatted,
totalArea: totalAreaFormatted,
protectedArea: protectedAreaFormatted,
};
}, [location, mergedProtectionStats]);

Expand Down Expand Up @@ -158,7 +157,7 @@ const MarineConservationWidget: React.FC<MarineConservationWidgetProps> = ({ loc
<span className="text-lg">%</span>
</span>
<span className="space-x-1 text-lg ">
<span>{stats?.totalArea}</span>
<span>{stats?.protectedArea}</span>
<span>
km<sup>2</sup>
</span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function formatKM(value: number, options?: Intl.NumberFormatOptions) {
compactDisplay: 'short',
unit: 'kilometer',
unitDisplay: 'short',
maximumSignificantDigits: 3,
maximumFractionDigits: 0,
...options,
});

Expand Down

0 comments on commit 7872b67

Please sign in to comment.