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
54 changes: 22 additions & 32 deletions src/loaders/earthEngineLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,48 +84,38 @@ 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]
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(',')
// Backward compability for layers saved before v100.6.0
if (layerConfig.params) {
layerConfig.style = layerConfig.params
// Backward compability for layers saved before 2.40
jenniferarnesen marked this conversation as resolved.
Show resolved Hide resolved
if (typeof layerConfig.params.palette === 'string') {
layerConfig.style.palette =
layerConfig.params.palette.split(',')
}
delete layerConfig.params
}

dataset = getEarthEngineLayer(layerConfig.id)
Expand Down
5 changes: 3 additions & 2 deletions src/util/pluginHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Loading