Fix: allow to delete freeform values in more cases

This commit is contained in:
Pieter Vander Vennet 2024-02-13 00:22:47 +01:00
parent c2d8ff906b
commit 9b78838745
3 changed files with 13 additions and 3 deletions

View file

@ -1,6 +1,7 @@
import { TagsFilter } from "./TagsFilter" import { TagsFilter } from "./TagsFilter"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson" import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { Tag } from "./Tag" import { Tag } from "./Tag"
import { ExpressionSpecification } from "maplibre-gl"
export default class ComparingTag implements TagsFilter { export default class ComparingTag implements TagsFilter {
private readonly _key: string private readonly _key: string
@ -12,7 +13,7 @@ export default class ComparingTag implements TagsFilter {
key: string, key: string,
predicate: (value: string | undefined) => boolean, predicate: (value: string | undefined) => boolean,
representation: "<" | ">" | "<=" | ">=", representation: "<" | ">" | "<=" | ">=",
boundary: string boundary: string,
) { ) {
this._key = key this._key = key
this._predicate = predicate this._predicate = predicate
@ -125,4 +126,8 @@ export default class ComparingTag implements TagsFilter {
visit(f: (TagsFilter) => void) { visit(f: (TagsFilter) => void) {
f(this) f(this)
} }
asMapboxExpression(): ExpressionSpecification {
return [this._representation, ["get", this._key], this._boundary]
}
} }

View file

@ -2,6 +2,7 @@ import { TagsFilter } from "./TagsFilter"
import { Tag } from "./Tag" import { Tag } from "./Tag"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson" import { TagConfigJson } from "../../Models/ThemeConfig/Json/TagConfigJson"
import { ExpressionSpecification } from "maplibre-gl"
/** /**
* The substituting-tag uses the tags of a feature a variables and replaces them. * The substituting-tag uses the tags of a feature a variables and replaces them.
@ -23,6 +24,10 @@ export default class SubstitutingTag implements TagsFilter {
this._invert = invert this._invert = invert
} }
asMapboxExpression(): ExpressionSpecification {
throw new Error("Method not implemented.")
}
private static substituteString(template: string, dict: Record<string, string>): string { private static substituteString(template: string, dict: Record<string, string>): string {
for (const k in dict) { for (const k in dict) {
template = template.replace(new RegExp("\\{" + k + "\\}", "g"), dict[k]) template = template.replace(new RegExp("\\{" + k + "\\}", "g"), dict[k])

View file

@ -153,7 +153,7 @@
} }
}) })
$: { $: {
if (allowDeleteOfFreeform && $freeformInput === undefined && $freeformInputUnvalidated === "" && mappings?.length === 0) { if (allowDeleteOfFreeform && $freeformInput === undefined && $freeformInputUnvalidated === "" && (mappings?.length ?? 0) === 0) {
selectedTags = new Tag(config.freeform.key, "") selectedTags = new Tag(config.freeform.key, "")
} else { } else {
@ -394,7 +394,7 @@
<!-- TagRenderingQuestion-buttons --> <!-- TagRenderingQuestion-buttons -->
<slot name="cancel" /> <slot name="cancel" />
<slot name="save-button" {selectedTags}> <slot name="save-button" {selectedTags}>
{#if allowDeleteOfFreeform && mappings?.length === 0 && $freeformInput === undefined && $freeformInputUnvalidated === ""} {#if allowDeleteOfFreeform && (mappings?.length ?? 0) === 0 && $freeformInput === undefined && $freeformInputUnvalidated === ""}
<button class="primary flex" on:click|stopPropagation|preventDefault={onSave}> <button class="primary flex" on:click|stopPropagation|preventDefault={onSave}>
<TrashIcon class="w-6 h-6 text-red-500" /> <TrashIcon class="w-6 h-6 text-red-500" />
<Tr t={Translations.t.general.eraseValue}/> <Tr t={Translations.t.general.eraseValue}/>