Skip to content

Commit

Permalink
analysis filters: uses official short name
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Mar 6, 2025
1 parent 577044f commit aac6d3d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/src/modules/indicators/indicators.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class IndicatorsService extends AppBaseService<
attributes: [
'id',
'name',
'shortName',
'description',
'category',
'unit',
Expand Down
4 changes: 2 additions & 2 deletions client/cypress/e2e/analysis/filters-map.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Analysis filters', () => {
const firstIndicator = interception.response.body?.data[0];
cy.get('[data-testid="select-indicators-filter"]').should(
'contain',
firstIndicator?.attributes.metadata.short_name,
firstIndicator?.attributes.shortName,
);
cy.url().should('include', `indicators=${firstIndicator?.id}`);
});
Expand All @@ -40,7 +40,7 @@ describe('Analysis filters', () => {
const thirdIndicator = interception.response.body?.data[2];
cy.get('[data-testid="select-indicators-filter"]')
.type('{downarrow}{downarrow}{enter}')
.should('contain', thirdIndicator?.attributes.metadata.short_name);
.should('contain', thirdIndicator?.attributes.shortName);
cy.url().should('include', `indicators=${thirdIndicator?.id}`);
});
});
Expand Down
6 changes: 6 additions & 0 deletions client/cypress/fixtures/indicators/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"attributes": {
"id": "5c133ba4-da24-46db-9c6c-ece7520f01b0",
"name": "Cropland expansion in natural ecosystems",
"shortName": "Net cropland expansion",
"description": "The annual average area of cropland expansion into natural ecosystems occuring within a 50km radius attributable to the raw material sourced.",
"category": "Natural ecosystem conversion",
"status": "active",
Expand Down Expand Up @@ -47,6 +48,7 @@
"attributes": {
"id": "936d0a9f-fe48-42b4-9433-63282d4dada5",
"name": "Deforestation footprint (sLUC)",
"shortName": "Deforestation footprint (sLUC)",
"description": "The deforestation footprint (sLUC) indicator quantifies the annual average area of deforestation within a 50km radius attributable to the raw material sourced.",
"category": "Natural ecosystem conversion",
"status": "active",
Expand Down Expand Up @@ -86,6 +88,7 @@
"attributes": {
"id": "d5f945c9-8636-45a2-a7c9-67a1dc8e687a",
"name": "Freshwater nutrient load assimilation volume",
"shortName": "Nutrient load",
"description": "The freshwater nutrient load assimilation volume indicator estimates the annual average water volume required to assimilate the nutrient load added by the raw material sourced.",
"category": "Water quality",
"status": "active",
Expand Down Expand Up @@ -121,6 +124,7 @@
"attributes": {
"id": "a39394be-ad57-41bc-9c2c-be0949ec6193",
"name": "Excess freshwater nutrient load assimilation volume",
"shortName": "Excess nutrient load",
"description": "The excess freshwater nutrient load assimilation volume indicator aims to quantify the volume by which nutrient load associated with the raw material sourced must be decreased to achieve the desired instream nutrient concentration.",
"category": "Water quality",
"status": "active",
Expand Down Expand Up @@ -159,6 +163,7 @@
"attributes": {
"id": "ffdd6f19-6737-4a10-9d36-5243d3f14b45",
"name": "Excess surface or groundwater use",
"shortName": "Unsustainable water use",
"description": "The excess surface or groundwater use indicator calculates the volume by which the water consumption associated with the production of the raw material sourced must be decreased to reduce pressure on nature.",
"category": "Water quantity",
"status": "active",
Expand Down Expand Up @@ -196,6 +201,7 @@
"attributes": {
"id": "9c2124c7-5df0-40d5-962e-d35480d48cd3",
"name": "Surface or groundwater use",
"shortName": "Water use",
"description": "The surface or groundwater use indicator estimates the volume of surface or groundwater that is consumed in the production of the raw material sourced.",
"category": "Water quantity",
"status": "active",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const IndicatorsFilter = () => {
const options = useMemo<TreeSelectOption[]>(() => {
const categories = Array.from(new Set(data?.map(({ category }) => category).filter(Boolean)));

const categoryGroups = categories.map((category) => {
return categories.map((category) => {
const indicators = data?.filter((indicator) => indicator.category === category);
const categoryOptions = indicators.map(
(indicator) =>
({
label: indicator.metadata?.short_name,
label: indicator.shortName ?? indicator.name,
value: indicator.id,
}) satisfies TreeSelectOption<(typeof indicator)['id']>,
);
Expand All @@ -44,8 +44,6 @@ const IndicatorsFilter = () => {
children: categoryOptions,
} satisfies HasParentProperty<TreeSelectOption<typeof category>>;
});

return categoryGroups;
}, [data]);

const allNodes = useMemo(() => options?.flatMap((opt) => flattenTree(opt)), [options]);
Expand Down Expand Up @@ -92,8 +90,7 @@ const IndicatorsFilter = () => {

const initialSelectedOptions = useMemo(() => {
if (syncedIndicators && options?.length) {
const selectedOptions = allNodes.filter(({ value }) => syncedIndicators.includes(value));
return selectedOptions;
return allNodes.filter(({ value }) => syncedIndicators.includes(value));
}
return undefined;
}, [syncedIndicators, options, allNodes]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ const IndicatorsMapFilter = () => {
new Set(data?.map(({ category }) => category).filter(Boolean)),
).sort((a, b) => a.localeCompare(b));

const categoryGroups = categories.map((category) => {
return categories.map((category) => {
const indicators = data?.filter((indicator) => indicator.category === category);
const categoryOptions = indicators.map((indicator) => ({
label: indicator.metadata?.short_name,
label: indicator.shortName ?? indicator.name,
value: indicator.id,
disabled: indicator.status === 'inactive',
}));
return { label: category, value: category, options: categoryOptions };
});

return categoryGroups;
}, [data]);

const indicatorName = useMemo(() => {
const indicator = data?.find((indicator) => indicator.id === value);
return indicator?.metadata?.short_name;
if (!indicator) return '';

return indicator.shortName ?? indicator.name;
}, [data, value]);

const handleChange = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion client/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface IndicatorMetadata {
export interface Indicator {
id: string;
name: string;
shortName: string;
nameCode: string;
status: 'active' | 'inactive';
type: 'indicators';
Expand Down Expand Up @@ -199,7 +200,6 @@ export type BusinessUnits = {
name: string;
children: BusinessUnits[];
type: 'businessUnits';
id: string;
attributes: BusinessUnitsAttributes;
status: 'inactive' | 'active';
};
Expand Down

0 comments on commit aac6d3d

Please sign in to comment.