From 07efd4ef2c9a9aa16950a33f862676bb6cbcc3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=A3o=20Rodrigues?= Date: Tue, 5 Sep 2023 11:32:33 +0100 Subject: [PATCH] Revert "Revert "FLAG-900: Undefined year causing an error in the TCL due to Fires widget in protected and some custom area dashboards"" --- .../fires/tree-loss-fires-annual/index.js | 17 +++++++---------- services/analysis-cached.js | 4 +++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/widgets/fires/tree-loss-fires-annual/index.js b/components/widgets/fires/tree-loss-fires-annual/index.js index fe00d018da..a1205fb6a8 100644 --- a/components/widgets/fires/tree-loss-fires-annual/index.js +++ b/components/widgets/fires/tree-loss-fires-annual/index.js @@ -19,9 +19,6 @@ import { import getWidgetProps from './selectors'; -const MAX_YEAR = 2022; -const MIN_YEAR = 2001; - const getGlobalLocation = (params) => ({ adm0: params.type === 'global' ? null : params.adm0, adm1: params.type === 'global' ? null : params.adm1, @@ -638,9 +635,11 @@ export default { settings: { threshold: 30, ifl: 2000, + startYear: 2001, + endYear: 2022, }, getData: (params = {}) => { - const { adm0, adm1, adm2, type } = params || {}; + const { adm0, adm1, adm2, type, startYear, endYear } = params || {}; const globalLocation = { adm0: type === 'global' ? null : adm0, @@ -666,19 +665,17 @@ export default { }; } - const { startYear, endYear, range } = getYearsRangeFromMinMax( - MIN_YEAR, - MAX_YEAR - ); + const { range: yearsRange } = getYearsRangeFromMinMax(startYear, endYear); + return { ...data, settings: { startYear, endYear, - yearsRange: range, + yearsRange, }, options: { - years: range, + years: yearsRange, }, }; }); diff --git a/services/analysis-cached.js b/services/analysis-cached.js index f9bce06026..299ee31820 100644 --- a/services/analysis-cached.js +++ b/services/analysis-cached.js @@ -19,7 +19,7 @@ const SQL_QUERIES = { lossFires: 'SELECT {select_location}, umd_tree_cover_loss__year, SUM(umd_tree_cover_loss__ha) AS umd_tree_cover_loss__ha, SUM(umd_tree_cover_loss_from_fires__ha) AS "umd_tree_cover_loss_from_fires__ha" FROM data {WHERE} GROUP BY umd_tree_cover_loss__year, {location} ORDER BY umd_tree_cover_loss__year, {location}', lossFiresOTF: - 'SELECT umd_tree_cover_loss__year, sum(umd_tree_cover_loss__ha), sum(umd_tree_cover_loss_from_fires__ha) FROM data WHERE umd_tree_cover_loss__year >= {startYear} AND umd_tree_cover_loss__year <= {endYear} AND umd_tree_cover_density_2000__threshold >= 30 GROUP BY umd_tree_cover_loss__year', + 'SELECT umd_tree_cover_loss__year, sum(umd_tree_cover_loss__ha), sum(umd_tree_cover_loss_from_fires__ha) FROM data WHERE umd_tree_cover_loss__year >= {startYear} AND umd_tree_cover_loss__year <= {endYear} AND umd_tree_cover_density_2000__threshold >= {threshold} GROUP BY umd_tree_cover_loss__year', emissions: 'SELECT {select_location}, umd_tree_cover_loss__year, SUM("gfw_gross_emissions_co2e_all_gases__Mg") AS "gfw_gross_emissions_co2e_all_gases__Mg", SUM("gfw_full_extent_gross_emissions_non_CO2__Mg_CO2e") AS "gfw_gross_emissions_co2e_non_co2__Mg", SUM("gfw_full_extent_gross_emissions_CO2_only__Mg_CO2") AS "gfw_gross_emissions_co2e_co2_only__Mg" FROM data {WHERE} GROUP BY umd_tree_cover_loss__year, {location} ORDER BY umd_tree_cover_loss__year, {location}', emissionsLossOTF: @@ -817,6 +817,7 @@ export const getLossFiresOTF = (params) => { geostore, startYear, endYear, + threshold, } = params || {}; const geostoreId = geostore.id || adm0; @@ -827,6 +828,7 @@ export const getLossFiresOTF = (params) => { `${urlBase + sql}&geostore_id=${geostoreId}` .replace('{startYear}', startYear) .replace('{endYear}', endYear) + .replace('{threshold}', threshold) ); if (download) {