From 1a88c112899abe97399f13e0038b26dc476e4560 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 22 Nov 2024 10:37:00 +0100 Subject: [PATCH] fix: don't show default label if another is found in features edit --- umap/static/umap/js/modules/data/features.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/data/features.js b/umap/static/umap/js/modules/data/features.js index 70c4b50e..d148779c 100644 --- a/umap/static/umap/js/modules/data/features.js +++ b/umap/static/umap/js/modules/data/features.js @@ -236,15 +236,23 @@ class Feature { container.appendChild(builder.build()) const properties = [] + let labelKeyFound = undefined for (const property of this.datalayer._propertiesIndex) { - if ([U.DEFAULT_LABEL_KEY, 'description'].includes(property)) { + if (!labelKeyFound && U.LABEL_KEYS.includes(property)) { + labelKeyFound = property + continue + } + if (property === 'description') { continue } properties.push([`properties.${property}`, { label: property }]) } // We always want name and description for now (properties management to come) properties.unshift('properties.description') - properties.unshift(`properties.${U.DEFAULT_LABEL_KEY}`) + if (!labelKeyFound) { + labelKeyFound = U.DEFAULT_LABEL_KEY + } + properties.unshift([`properties.${labelKeyFound}`, { label: labelKeyFound }]) builder = new U.FormBuilder(this, properties, { id: 'umap-feature-properties', }) @@ -257,7 +265,7 @@ class Feature { this.getAdvancedEditActions(advancedActions) const onLoad = this._umap.editPanel.open({ content: container }) onLoad.then(() => { - builder.helpers['properties.name'].input.focus() + builder.helpers[`properties.${labelKeyFound}`].input.focus() }) this._umap.editedFeature = this if (!this.ui.isOnScreen(this._umap._leafletMap.getBounds())) this.zoomTo(event) @@ -330,7 +338,6 @@ class Feature { } for (const key of keys) { const value = this.properties[key] - console.log(key, value) if (value) return value } return this.datalayer.getName()