Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin crashes for Earth Engine layers in the dashboard #3302

Merged
merged 8 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 25 additions & 34 deletions src/loaders/earthEngineLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,37 @@ 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) {
// Backward compability for layers with periods saved before 2.36
const filter = layerConfig.filter?.[0]

if (filter) {
const period = filter.arguments?.[1]
let name = String(layerConfig.image)

if (typeof period === 'string' && period.length > 4) {
const year = period.substring(0, 4)
filter.year = parseInt(year, 10)
const id = filter.arguments?.[1]
const name = String(layerConfig.image)
const year =
typeof id === 'string' && id.length > 4
? parseInt(id.substring(0, 4), 10)
: undefined

if (name.slice(-4) === year) {
name = name.slice(0, -4)
}
}
layerConfig.period = { id, name, year }

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(',')
if (layerConfig.params) {
// Backward compability for layers saved before v100.6.0
layerConfig.style = layerConfig.params
if (typeof layerConfig.params.palette === 'string') {
layerConfig.style.palette =
layerConfig.params.palette.split(',')
}
delete layerConfig.params
}

dataset = getEarthEngineLayer(layerConfig.id)
Expand All @@ -135,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)
}
Expand Down
12 changes: 12 additions & 0 deletions src/util/__tests__/pluginHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
7 changes: 7 additions & 0 deletions src/util/pluginHelper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
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.rows.length !== newView.rows.length
Expand Down
Loading