From 76a9a2ee23dcf61097d33fcbe556df7a46d9a395 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 4 Sep 2024 02:48:05 +0200 Subject: [PATCH] Themes: don't show 'mark as unknown' if this would break the source-filter --- src/Models/ThemeConfig/TagRenderingConfig.ts | 13 ++++++++++++- .../Popup/TagRendering/TagRenderingQuestion.svelte | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Models/ThemeConfig/TagRenderingConfig.ts b/src/Models/ThemeConfig/TagRenderingConfig.ts index b37997be0..3408cbcd9 100644 --- a/src/Models/ThemeConfig/TagRenderingConfig.ts +++ b/src/Models/ThemeConfig/TagRenderingConfig.ts @@ -18,6 +18,7 @@ import { GeoOperations } from "../../Logic/GeoOperations" import { Feature } from "geojson" import MarkdownUtils from "../../Utils/MarkdownUtils" import { UploadableTag } from "../../Logic/Tags/TagTypes" +import LayerConfig from "./LayerConfig" export interface Mapping { readonly if: UploadableTag @@ -924,7 +925,7 @@ export default class TagRenderingConfig { * The keys that should be erased if one has to revert to 'unknown'. * Might give undefined if setting to unknown is not possible */ - public removeToSetUnknown(): string[] | undefined { + public removeToSetUnknown(partOfLayer: LayerConfig, currentTags: Record): string[] | undefined { const toDelete = new Set() if (this.freeform) { toDelete.add(this.freeform.key) @@ -949,6 +950,16 @@ export default class TagRenderingConfig { } } + + currentTags = { ...currentTags } + for (const key of toDelete) { + delete currentTags[key] + } + const required = partOfLayer.source.osmTags + if (!required.matchesProperties(currentTags)) { + return undefined + } + return Array.from(toDelete) } } diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 3fc4f3b7f..1139601af 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -67,7 +67,7 @@ /** * IF set: we can remove the current answer by deleting all those keys */ - let settableKeys = config.removeToSetUnknown() + let settableKeys = tags.mapD(tags => config.removeToSetUnknown(layer, tags)) let unknownModal = new UIEventSource(false) let searchTerm: UIEventSource = new UIEventSource("") @@ -325,7 +325,7 @@ } function clearAnswer() { - const tagsToSet = settableKeys.map(k => new Tag(k, "")) + const tagsToSet = settableKeys.data.map(k => new Tag(k, "")) const change = new ChangeTagAction(tags.data.id, new And(tagsToSet), tags.data, { theme: tags.data["_orig_theme"] ?? state.layout.id, changeType: "answer", @@ -526,7 +526,7 @@ v === "yes" || v === "full" || v === "always")}>
- {#each settableKeys as key} + {#each $settableKeys as key} {key} @@ -550,7 +550,7 @@ style="z-index: 11" > - {#if settableKeys && $isKnown && !matchesEmpty } + {#if $settableKeys && $isKnown && !matchesEmpty }