Skip to content

Commit

Permalink
Merge pull request #313 from Vizzuality/SKY30-459-fe-modify-target-wi…
Browse files Browse the repository at this point in the history
…dget-to-include-country-level-target-details

Update the target on the conservation widget
  • Loading branch information
clementprdhomme authored Oct 9, 2024
2 parents 5d99474 + 3ff92dd commit 7d5b2b1
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 13 deletions.
14 changes: 10 additions & 4 deletions cms/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,9 @@
"total_terrestrial_area",
"terrestrial_bounds",
"name_es",
"name_fr"
"name_fr",
"marine_target",
"marine_target_year"
]
},
"conditions": [],
Expand Down Expand Up @@ -1102,7 +1104,9 @@
"total_terrestrial_area",
"terrestrial_bounds",
"name_es",
"name_fr"
"name_fr",
"marine_target",
"marine_target_year"
]
},
"conditions": [],
Expand All @@ -1126,7 +1130,9 @@
"total_terrestrial_area",
"terrestrial_bounds",
"name_es",
"name_fr"
"name_fr",
"marine_target",
"marine_target_year"
]
},
"conditions": [],
Expand Down Expand Up @@ -2176,4 +2182,4 @@
"actionParameters": {}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,34 @@
"sortable": true
}
},
"marine_target": {
"edit": {
"label": "marine_target",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "marine_target",
"searchable": true,
"sortable": true
}
},
"marine_target_year": {
"edit": {
"label": "marine_target_year",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "marine_target_year",
"searchable": true,
"sortable": true
}
},
"createdAt": {
"edit": {
"label": "createdAt",
Expand Down Expand Up @@ -355,6 +383,16 @@
"name": "total_terrestrial_area",
"size": 4
}
],
[
{
"name": "marine_target",
"size": 4
},
{
"name": "marine_target_year",
"size": 4
}
]
],
"list": [
Expand Down
8 changes: 8 additions & 0 deletions cms/src/api/location/content-types/location/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
"name_fr": {
"type": "string",
"required": true
},
"marine_target": {
"type": "integer",
"min": 0,
"max": 100
},
"marine_target_year": {
"type": "integer"
}
}
}
6 changes: 6 additions & 0 deletions cms/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,12 @@ export interface ApiLocationLocation extends Schema.CollectionType {
terrestrial_bounds: Attribute.JSON;
name_es: Attribute.String & Attribute.Required;
name_fr: Attribute.String & Attribute.Required;
marine_target: Attribute.Integer &
Attribute.SetMinMax<{
min: 0;
max: 100;
}>;
marine_target_year: Attribute.Integer;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
Expand Down
20 changes: 15 additions & 5 deletions frontend/src/components/charts/conservation-chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import ChartTooltip from './tooltip';
type ConservationChartProps = {
className?: string;
displayTarget?: boolean;
target?: number;
targetYear?: number;
tooltipSlug: string;
data: {
year?: number;
percentage: number;
Expand All @@ -44,6 +47,9 @@ const MAX_NUM_YEARS = 20;
const ConservationChart: FCWithMessages<ConservationChartProps> = ({
className,
displayTarget = true,
target = 30,
targetYear = 2030,
tooltipSlug,
data,
}) => {
const t = useTranslations('components.chart-conservation');
Expand Down Expand Up @@ -134,7 +140,7 @@ const ConservationChart: FCWithMessages<ConservationChartProps> = ({
{
locale,
filters: {
slug: '30x30-target',
slug: tooltipSlug,
},
},
{
Expand Down Expand Up @@ -182,23 +188,27 @@ const ConservationChart: FCWithMessages<ConservationChartProps> = ({
{displayTarget && (
<ReferenceLine
xAxisId={1}
y={30}
y={target}
label={(props) => {
const { viewBox } = props;
return (
<g>
<text {...viewBox} x={viewBox.x + 5} y={viewBox.y - 2}>
{t('30x30-target')}
{t.rich('percentage-target', { target })}
</text>
<foreignObject
{...viewBox}
x={viewBox.x + t('30x30-target').length * 7.5}
x={
viewBox.x + (t.rich('percentage-target', { target }) as string).length * 7.5
}
y={viewBox.y - 17}
width="160"
height="160"
>
<TooltipButton
text={dataInfo?.attributes.content}
text={dataInfo?.attributes.content
.replace('{target}', `${target}`)
.replace('{target_year}', `${targetYear}`)}
className="mt-1 hover:bg-transparent"
/>
</foreignObject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MarineConservationWidget: FCWithMessages<MarineConservationWidgetProps> =
// @ts-ignore
populate: {
location: {
fields: ['code', 'total_marine_area'],
fields: ['code', 'total_marine_area', 'marine_target', 'marine_target_year'],
},
environment: {
fields: ['slug'],
Expand Down Expand Up @@ -126,6 +126,8 @@ const MarineConservationWidget: FCWithMessages<MarineConservationWidgetProps> =
protectedPercentage: percentageFormatted,
protectedArea: protectedAreaFormatted,
totalArea: totalAreaFormatted,
target: location.marine_target,
targetYear: location.marine_target_year,
};
}, [locale, location, aggregatedData]);

Expand Down Expand Up @@ -182,8 +184,11 @@ const MarineConservationWidget: FCWithMessages<MarineConservationWidgetProps> =
)}
<ConservationChart
className="-ml-8 aspect-[16/10]"
displayTarget={location?.code === 'GLOB'}
tooltipSlug="30x30-marine-target"
data={chartData}
displayTarget={!!stats?.target}
target={stats?.target ?? undefined}
targetYear={stats?.targetYear ?? undefined}
/>
{tab !== 'marine' && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const TerrestrialConservationWidget: FCWithMessages<TerrestrialConservationWidge
)}
<ConservationChart
className="-ml-8 aspect-[16/10]"
tooltipSlug="30x30-terrestrial-target"
displayTarget={location?.code === 'GLOB'}
data={chartData}
/>
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/types/generated/strapi.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,8 @@ export type ProtectionCoverageStatLocationDataAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: ProtectionCoverageStatLocationDataAttributesCreatedBy;
Expand Down Expand Up @@ -2820,6 +2822,8 @@ export type PaChildrenDataItemAttributesLocationDataAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: PaChildrenDataItemAttributesLocationDataAttributesCreatedBy;
Expand Down Expand Up @@ -3643,6 +3647,8 @@ export type MpaaProtectionLevelStatLocationDataAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: MpaaProtectionLevelStatLocationDataAttributesCreatedBy;
Expand Down Expand Up @@ -5139,6 +5145,8 @@ export interface Location {
terrestrial_bounds?: unknown;
name_es: string;
name_fr: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: LocationCreatedBy;
Expand Down Expand Up @@ -5236,6 +5244,8 @@ export type LocationGroupsDataItemAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: LocationGroupsDataItemAttributesCreatedBy;
Expand Down Expand Up @@ -6582,6 +6592,8 @@ export type HabitatStatLocationDataAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: HabitatStatLocationDataAttributesCreatedBy;
Expand Down Expand Up @@ -7589,6 +7601,8 @@ export type FishingProtectionLevelStatLocationDataAttributes = {
terrestrial_bounds?: unknown;
name_es?: string;
name_fr?: string;
marine_target?: number;
marine_target_year?: number;
createdAt?: string;
updatedAt?: string;
createdBy?: FishingProtectionLevelStatLocationDataAttributesCreatedBy;
Expand Down
4 changes: 2 additions & 2 deletions frontend/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@
"not-visible-due-to-error": "The current widget is not visible due to an error"
},
"chart-conservation": {
"30x30-target": "30x30 Target",
"year-value": "Year: {value}",
"coverage-value": "Coverage: {percentage}",
"historical-trend": "Historical Trend",
"future-projection": "Future Projection",
"historical": "Historical"
"historical": "Historical",
"percentage-target": "{target}% target"
},
"chart-horizontal-bar": {
"marine-protected-percentage": "{percentage}<b>%</b>",
Expand Down

0 comments on commit 7d5b2b1

Please sign in to comment.