Skip to content

Commit

Permalink
oh-canvas: Fix exception on empty initial svg config (#2864)
Browse files Browse the repository at this point in the history
This fixes a nasty bug on initial setup of an embedded SVG that has no configuration yet.

---------

Also-by: Florian Hotze <dev@florianhotze.com>
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
  • Loading branch information
stefan-hoehn authored Nov 10, 2024
1 parent 3dfe023 commit 180cd78
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export default {
* Remember to unsubscribe from the mutations using {@link unsubscribeEmbeddedSvgStateTracking} when the component is destroyed.
*/
setupEmbeddedSvgStateTracking () {
if (!this.config.embeddedSvgActions) return

const svg = this.$refs.canvasBackground.querySelector('svg')
const subElements = svg.querySelectorAll('[openhab]')

Expand Down Expand Up @@ -146,7 +148,7 @@ export default {
if (this.context.editmode || (!this.context.editmode && this.config.embedSvgFlashing)) {
const tagName = el.tagName
// fill green if item config is available, red if config is still missing
const fillColor = (this.config.embeddedSvgActions[el.id]) ? 'rgb(0, 255, 0)' : 'rgb(255, 0, 0)'
const fillColor = (this.config.embeddedSvgActions && this.config.embeddedSvgActions[el.id]) ? 'rgb(0, 255, 0)' : 'rgb(255, 0, 0)'
if (tagName !== 'g' && !el.flashing) {
// sometimes instead of fill, stroke colors are used, so if fill = none, then we use stroke instead
const attributeName = (el.style.fill !== 'none') ? 'fill' : 'stroke'
Expand Down Expand Up @@ -190,7 +192,9 @@ export default {
if (this.context.editmode) {
this.openSvgSettingsPopup(el.id)
} else {
this.performAction(null, null, this.config.embeddedSvgActions[el.id], this.context)
if (this.config.embeddedSvgActions && this.config.embeddedSvgActions[el.id]) {
this.performAction(null, null, this.config.embeddedSvgActions[el.id], this.context)
}
}
},
/**
Expand Down

0 comments on commit 180cd78

Please sign in to comment.