Fix: fix #2343, properly fix "postfixDistinguished", also when marking as unknown

This commit is contained in:
Pieter Vander Vennet 2025-03-09 23:23:37 +01:00
parent 0cf3d07100
commit 2286ec964f
5 changed files with 122 additions and 102 deletions

View file

@ -734,7 +734,7 @@ export default class TagRenderingConfig {
singleSelectedMapping: number,
multiSelectedMapping: boolean[] | undefined,
currentProperties: Record<string, string>
): UploadableTag {
): UploadableTag[] {
if (typeof freeformValue === "string") {
freeformValue = freeformValue?.trim()
}
@ -782,14 +782,14 @@ export default class TagRenderingConfig {
const freeformOnly = { [this.freeform.key]: freeformValue }
const matchingMapping = this.mappings?.find((m) => m.if.matchesProperties(freeformOnly))
if (matchingMapping) {
return new And([matchingMapping.if, ...(matchingMapping.addExtraTags ?? [])])
return [matchingMapping.if, ...(matchingMapping.addExtraTags ?? [])]
}
// Either no mappings, or this is a radio-button selected freeform value
const tag = new And([
const tag = [
new Tag(this.freeform.key, freeformValue),
...(this.freeform.addExtraTags ?? [])
])
const newProperties = tag.applyOn(currentProperties)
]
const newProperties = new And(tag).applyOn(currentProperties)
if (this.invalidValues?.matchesProperties(newProperties)) {
return undefined
}
@ -816,14 +816,9 @@ export default class TagRenderingConfig {
)
}
const and = TagUtils.FlattenMultiAnswer([...selectedMappings, ...unselectedMappings])
if (and.and.length === 0) {
if (and.length === 0) {
return undefined
}
console.log(
">>> New properties",
TagUtils.asProperties(and, currentProperties),
this.invalidValues
)
if (
this.invalidValues?.matchesProperties(TagUtils.asProperties(and, currentProperties))
) {
@ -847,15 +842,15 @@ export default class TagRenderingConfig {
!someMappingIsShown ||
singleSelectedMapping === undefined)
if (useFreeform) {
return new And([
return [
new Tag(this.freeform.key, freeformValue),
...(this.freeform.addExtraTags ?? [])
])
]
} else if (singleSelectedMapping !== undefined) {
return new And([
return [
this.mappings[singleSelectedMapping].if,
...(this.mappings[singleSelectedMapping].addExtraTags ?? [])
])
]
} else {
console.error("TagRenderingConfig.ConstructSpecification has a weird fallback for", {
freeformValue,
@ -864,7 +859,6 @@ export default class TagRenderingConfig {
currentProperties,
useFreeform
})
return undefined
}
}
@ -998,7 +992,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(
private removeToSetUnknown(
partOfLayer: LayerConfig,
currentTags: Record<string, string>
): string[] | undefined {
@ -1042,6 +1036,23 @@ export default class TagRenderingConfig {
return Array.from(toDelete)
}
/**
* Gives all the tags that should be applied to "reset" the freeform key to an "unknown" state
*/
public markUnknown(layer: LayerConfig, currentProperties: Record<string, string>): UploadableTag[] {
if (this.freeform?.postfixDistinguished) {
const allValues = currentProperties[this.freeform.key].split(";").filter(
part => part.split("/")[1]?.trim() !== this.freeform.postfixDistinguished
)
return [new Tag(this.freeform.key, allValues.join(";"))]
}
const keys = this.removeToSetUnknown(layer, currentProperties)
return keys?.map(k => new Tag(k, ""))
}
}
export class TagRenderingConfigUtils {