From 7b472a66f960e896360317cc979744381362e951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sandvik?= Date: Wed, 14 Aug 2024 10:51:04 +0200 Subject: [PATCH 1/5] fix: ee layer filters defaults to empty array --- src/loaders/earthEngineLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index 703f82ea3..a89c79688 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -149,7 +149,7 @@ const earthEngineLoader = async (config) => { const { unit, period, - filters, + filters = [], description, source, sourceUrl, From e02585522275d727a15ed64abb0c300067123998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sandvik?= Date: Wed, 14 Aug 2024 12:01:26 +0200 Subject: [PATCH 2/5] EE loader backward compatibility --- src/loaders/earthEngineLoader.js | 53 +++++++++++++++----------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index a89c79688..6f21de209 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -84,48 +84,43 @@ const earthEngineLoader = async (config) => { // From database as favorite layerConfig = JSON.parse(config.config) - const { filter, params } = layerConfig - - // Backward compability for layers saved before 2.41 - if (filter) { - layerConfig.period = getPeriodFromFilter(filter, layerConfig.id) - delete layerConfig.filter - } - - // Backward compability for layers saved before 2.41 - if (params) { - layerConfig.style = params - if (params.palette) { - layerConfig.style.palette = params.palette.split(',') - } - delete layerConfig.params - } - // Backward compability for layers with periods saved before 2.36 - // (could also be fixed in a db update script) if (layerConfig.image) { const filter = layerConfig.filter?.[0] if (filter) { - const period = filter.arguments?.[1] + const id = filter.arguments?.[1] let name = String(layerConfig.image) + let year - if (typeof period === 'string' && period.length > 4) { - const year = period.substring(0, 4) - filter.year = parseInt(year, 10) + if (typeof id === 'string' && id.length > 4) { + year = id.substring(0, 4) + } - if (name.slice(-4) === year) { - name = name.slice(0, -4) - } + layerConfig.period = { + id, + name, + year: parseInt(year, 10), } - filter.name = name + delete layerConfig.filter } + delete layerConfig.image + } else if (layerConfig.filter) { + // Backward compability for layers saved before v100.6.0 + layerConfig.period = getPeriodFromFilter(filter, layerConfig.id) + delete layerConfig.filter } - // Backward compability for layers saved before 2.40 - if (typeof layerConfig.params?.palette === 'string') { - layerConfig.params.palette = layerConfig.params.palette.split(',') + // Backward compability for layers saved before v100.6.0 + if (layerConfig.params) { + layerConfig.style = layerConfig.params + // Backward compability for layers saved before 2.40 + if (typeof layerConfig.params.palette === 'string') { + layerConfig.style.palette = + layerConfig.params.palette.split(',') + } + delete layerConfig.params } dataset = getEarthEngineLayer(layerConfig.id) From 5ace1b77ab9329c8dfa42c1a0337fbe9324696f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sandvik?= Date: Wed, 14 Aug 2024 12:12:45 +0200 Subject: [PATCH 3/5] chore: code cleaning --- src/loaders/earthEngineLoader.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index 6f21de209..8f609beef 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -90,18 +90,13 @@ const earthEngineLoader = async (config) => { if (filter) { const id = filter.arguments?.[1] - let name = String(layerConfig.image) - let year + const name = String(layerConfig.image) + const year = + typeof id === 'string' && id.length > 4 + ? parseInt(id.substring(0, 4), 10) + : undefined - if (typeof id === 'string' && id.length > 4) { - year = id.substring(0, 4) - } - - layerConfig.period = { - id, - name, - year: parseInt(year, 10), - } + layerConfig.period = { id, name, year } delete layerConfig.filter } From e690bd0cfb7809de49298dd9114c056490d53465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Sandvik?= Date: Wed, 14 Aug 2024 14:06:35 +0200 Subject: [PATCH 4/5] fix: add check if filters prop exist --- src/loaders/earthEngineLoader.js | 2 +- src/util/pluginHelper.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index 8f609beef..73bd5922c 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -139,7 +139,7 @@ const earthEngineLoader = async (config) => { const { unit, period, - filters = [], + filters, description, source, sourceUrl, diff --git a/src/util/pluginHelper.js b/src/util/pluginHelper.js index 2054118ab..bdcce9442 100644 --- a/src/util/pluginHelper.js +++ b/src/util/pluginHelper.js @@ -2,15 +2,16 @@ const didViewsChange = (oldViews, newViews) => { return newViews.some((newView, i) => { const oldView = oldViews[i] + // EE layers don't have filters if ( - oldView.filters.length !== newView.filters.length || + oldView.filters?.length !== newView?.filters.length || oldView.rows.length !== newView.rows.length ) { return true } if ( - newView.filters.some((filter, j) => { + newView.filters?.some((filter, j) => { const oldItemIds = oldView.filters[j].items.map( (item) => item.id ) From e15a019c80c78bd7bf8e2aaa16bc95c6363ceabf Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Thu, 15 Aug 2024 14:55:20 +0200 Subject: [PATCH 5/5] chore: check if layer is ee layer --- src/loaders/earthEngineLoader.js | 9 +++++---- src/util/__tests__/pluginHelper.spec.js | 12 ++++++++++++ src/util/pluginHelper.js | 10 ++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/loaders/earthEngineLoader.js b/src/loaders/earthEngineLoader.js index 73bd5922c..d41410e37 100644 --- a/src/loaders/earthEngineLoader.js +++ b/src/loaders/earthEngineLoader.js @@ -84,8 +84,8 @@ const earthEngineLoader = async (config) => { // From database as favorite layerConfig = JSON.parse(config.config) - // Backward compability for layers with periods saved before 2.36 if (layerConfig.image) { + // Backward compability for layers with periods saved before 2.36 const filter = layerConfig.filter?.[0] if (filter) { @@ -107,10 +107,9 @@ const earthEngineLoader = async (config) => { delete layerConfig.filter } - // Backward compability for layers saved before v100.6.0 if (layerConfig.params) { + // Backward compability for layers saved before v100.6.0 layerConfig.style = layerConfig.params - // Backward compability for layers saved before 2.40 if (typeof layerConfig.params.palette === 'string') { layerConfig.style.palette = layerConfig.params.palette.split(',') @@ -125,7 +124,9 @@ const earthEngineLoader = async (config) => { } delete config.config - delete config.filters // Backend returns empty filters array + // Remove the always empty filters array from saved map layer object + // so as not to overwrite the filters array from the layer config + delete config.filters } else { dataset = getEarthEngineLayer(layerConfig.id) } diff --git a/src/util/__tests__/pluginHelper.spec.js b/src/util/__tests__/pluginHelper.spec.js index 182698154..07d7e9cb2 100644 --- a/src/util/__tests__/pluginHelper.spec.js +++ b/src/util/__tests__/pluginHelper.spec.js @@ -76,4 +76,16 @@ describe('didViewsChange', () => { ] expect(didViewsChange(oldViews, newViews)).toEqual(false) }) + + it('should always return false for earth engine layer', () => { + const oldViews = [{ layer: 'earthEngine', rows: [] }] + const newViews = [ + { + layer: 'earthEngine', + filters: [], + rows: [], + }, + ] + expect(didViewsChange(oldViews, newViews)).toEqual(false) + }) }) diff --git a/src/util/pluginHelper.js b/src/util/pluginHelper.js index bdcce9442..0741ca7da 100644 --- a/src/util/pluginHelper.js +++ b/src/util/pluginHelper.js @@ -1,17 +1,23 @@ +import { EARTH_ENGINE_LAYER } from '../constants/layers.js' + const didViewsChange = (oldViews, newViews) => { return newViews.some((newView, i) => { const oldView = oldViews[i] // EE layers don't have filters + if (oldView.layer === EARTH_ENGINE_LAYER) { + return false + } + if ( - oldView.filters?.length !== newView?.filters.length || + oldView.filters.length !== newView.filters.length || oldView.rows.length !== newView.rows.length ) { return true } if ( - newView.filters?.some((filter, j) => { + newView.filters.some((filter, j) => { const oldItemIds = oldView.filters[j].items.map( (item) => item.id )