Feature: Properly fix postfixdistinguished

This commit is contained in:
Pieter Vander Vennet 2025-03-28 12:49:28 +01:00
parent 7268e2290f
commit 7d8d4fa074

View file

@ -5,10 +5,7 @@ import { TagUtils } from "../../Logic/Tags/TagUtils"
import { And } from "../../Logic/Tags/And"
import { Utils } from "../../Utils"
import { Tag } from "../../Logic/Tags/Tag"
import {
MappingConfigJson,
QuestionableTagRenderingConfigJson,
} from "./Json/QuestionableTagRenderingConfigJson"
import { MappingConfigJson, QuestionableTagRenderingConfigJson } from "./Json/QuestionableTagRenderingConfigJson"
import Validators, { ValidatorType } from "../../UI/InputElement/Validators"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import { RegexTag } from "../../Logic/Tags/RegexTag"
@ -688,6 +685,43 @@ export default class TagRenderingConfig {
}
}
/**
*
* TagRenderingConfig.splitPostfixDistinguished("€10") // => {value: "€10", denomination: ""}
* TagRenderingConfig.splitPostfixDistinguished(" €10 / day ") // => {value: "€10", denomination: "day"}
*
*/
private static splitPostfixDistinguished(part: string): { value: string, denomination: string } {
const i = part.indexOf("/")
if (i < 0) {
return { value: part, denomination: "" }
}
const value = part.substring(0, i).trim()
const denomination = part.substring(i + 1).trim()
return { value, denomination }
}
/**
* Converts the freeform value into a postfix-table, e.g.
*
*
* const charge = "€5/student;€6/citizen;€7/adult;€4/disabled;€10"
* TagRenderingConfig.buildPostfixTable(charge) // => {"student": "€5", "citizen": "€6", "adult": "€7", "disabled": "€4", "":"€10"}
*
*/
private static buildPostfixTable(v: string): Record<string, string> {
const allValues = v.split(";").map((s) => s.trim())
const perPostfix: Record<string, string> = {}
for (const part of allValues) {
const { denomination, value } = TagRenderingConfig.splitPostfixDistinguished(part)
if (value === "") {
continue
}
perPostfix[denomination] = value.trim()
}
return perPostfix
}
/**
* Given a value for the freeform key and an overview of the selected mappings, construct the correct tagsFilter to apply.
* Result should be interpreted as "and"
@ -753,12 +787,8 @@ export default class TagRenderingConfig {
const pf = this.freeform?.postfixDistinguished
if (pf) {
const v = currentProperties[this.freeform.key] ?? ""
const allValues = v.split(";").map((s) => s.trim())
const perPostfix: Record<string, string> = {}
for (const value of allValues) {
const [v, postfix] = value.split("/").map((s) => s.trim())
perPostfix[postfix ?? pf] = v.trim()
}
const perPostfix = TagRenderingConfig.buildPostfixTable(v)
if (freeformValue === "" || freeformValue === undefined) {
delete perPostfix[this.freeform.postfixDistinguished]
} else {
@ -981,17 +1011,8 @@ export default class TagRenderingConfig {
if (!distinguish) {
return value
}
const parts = value.split(";")
for (const part of parts) {
if (part.indexOf("/") < 0) {
continue
}
const [v, denom] = part.split("/").map((s) => s.trim())
if (denom === distinguish) {
return v
}
}
return ""
const perPostfix = TagRenderingConfig.buildPostfixTable(value)
return perPostfix[distinguish] ?? ""
}
/**