Skip to content

Commit

Permalink
chore: refactor color scale handling to use arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
turban committed Sep 22, 2023
1 parent b1142fd commit 40e70ec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/util/favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ const models2objects = (config) => {
}
}

// Color scale needs to be stored as a string
if (Array.isArray(config.colorScale)) {
config.colorScale = config.colorScale.join(',')
}

return config
}

Expand Down
36 changes: 24 additions & 12 deletions src/util/getMigratedMapConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isString, isObject, sortBy } from 'lodash/fp'
import { EXTERNAL_LAYER } from '../constants/layers.js'

export const getMigratedMapConfig = (config, defaultBasemapId) =>
renameBoundaryLayerToOrgUnitLayer(
upgradeMapViews(
upgradeGisAppLayers(extractBasemap(config, defaultBasemapId))
)

Expand Down Expand Up @@ -80,14 +80,26 @@ const upgradeGisAppLayers = (config) => {

// Change layer name from boundary to orgUnit when loading an old map
// TODO: Change in db with an upgrade script
const renameBoundaryLayerToOrgUnitLayer = (config) => ({
...config,
mapViews: config.mapViews.map((v) =>
v.layer === 'boundary'
? {
...v,
layer: 'orgUnit',
}
: v
),
})
// TODO: Add support for colorScale array in db
const upgradeMapViews = (config) => {
if (
config.mapViews.find(
(view) =>
view.layer === 'boundary' || typeof view.colorScale === 'string'
)
) {
return {
...config,
mapViews: config.mapViews.map((view) => ({
...view,
layer: view.layer === 'boundary' ? 'orgUnit' : view.layer,
colorScale:
typeof view.colorScale === 'string'
? view.colorScale.split(',')
: view.colorScale,
})),
}
} else {
return config
}
}

0 comments on commit 40e70ec

Please sign in to comment.