From 8332650ea3a4882d428953d60b42cde602a7f511 Mon Sep 17 00:00:00 2001 From: Robin van der Linde Date: Mon, 29 Apr 2024 00:54:32 +0200 Subject: [PATCH] Clear tags from old presets --- .../Helpers/NameSuggestionIndexInput.svelte | 16 ++++++++++++++++ .../TagRendering/TagRenderingQuestion.svelte | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte index a9e472a086..fe9e2dca4d 100644 --- a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte +++ b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte @@ -117,6 +117,22 @@ } return acc }, {} as Record) + + // Also check if the object currently matches a different item, based on the key + const otherItem = items.find((item) => item.tags[tag] === feature.properties[key]) + + // If the other item is not the same as the selected item, we need to make sure we clear any old keys we don't need anymore by setting them to an empty string + if (otherItem && otherItem !== item) { + Object.keys(otherItem.tags).forEach((key) => { + // If we have a different value for the key, we don't need to clear it + if (!tags[key] && key !== tag && key !== maintag.split("=")[0]) { + console.log(`Clearing key ${key}`) + tags[key] = "" + } + }) + } + + // Finally, set the extra tags extraTags.setData(tags) } diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index f18c962fe5..843bd0726c 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -188,7 +188,6 @@ } function onSave(_ = undefined) { - console.log("Extra tags to save", extraTags.data) if (selectedTags === undefined) { return }