Skip to content

Commit

Permalink
Merge pull request #220 from wearepal/bugfix
Browse files Browse the repository at this point in the history
Fix issues with MapLayerComponent crashing when applying name to layer
  • Loading branch information
paulthatjazz authored Dec 5, 2023
2 parents 275eac6 + eeb7b56 commit 39a31e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class MapLayerComponent extends BaseComponent {
else {
delete editorNode.meta.errorMessage

if (inputs["in"][0]) this.callback(node.id, editorNode.data.name as string, inputs["in"][0] as BooleanTileGrid | NumericTileGrid | CategoricalTileGrid)
const name = editorNode.data.name as string

if (inputs["in"][0]) this.callback(node.id, name ? (name !== "" ? name.trim() : undefined) : undefined, inputs["in"][0] as BooleanTileGrid | NumericTileGrid | CategoricalTileGrid)
else editorNode.meta.errorMessage = 'No input'

}
Expand Down
10 changes: 8 additions & 2 deletions app/javascript/projects/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { cloneDeep, isEqual } from "lodash"
import { Action } from "./actions"
import { Project, State } from "./state"
import { Layer, Project, State } from "./state"

const nodeIdtoLayer = (nodeId: number, layers: Record<number, Layer>) => {
const layerArray = Object.values(layers)
const foundLayer = layerArray.find(layer => "nodeId" in layer && layer.nodeId === nodeId)
return foundLayer
}

const reduceProject = (state: Project, action: Action): Project => {
switch (action.type) {
Expand Down Expand Up @@ -37,7 +43,7 @@ const reduceProject = (state: Project, action: Action): Project => {
case "MutateLayer": {
const { id, data } = action
const layers = cloneDeep(state.layers)
Object.assign(layers[id], data)
Object.assign(layers[id] || nodeIdtoLayer(id, layers), data)
return { ...state, layers }
}

Expand Down

0 comments on commit 39a31e3

Please sign in to comment.