forked from MapComplete/MapComplete
		
	Fix: fix partially #2343
This commit is contained in:
		
							parent
							
								
									7e854bb164
								
							
						
					
					
						commit
						c68bce2421
					
				
					 2 changed files with 56 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -223,7 +223,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                inline: json.freeform.inline ?? false,
 | 
			
		||||
                default: json.freeform.default,
 | 
			
		||||
                postfixDistinguished: json.freeform.postfixDistinguished?.trim(),
 | 
			
		||||
                args: json.freeform.helperArgs,
 | 
			
		||||
                args: json.freeform.helperArgs
 | 
			
		||||
            }
 | 
			
		||||
            if (json.freeform["extraTags"] !== undefined) {
 | 
			
		||||
                throw `Freeform.extraTags is defined. This should probably be 'freeform.addExtraTag' (at ${context})`
 | 
			
		||||
| 
						 | 
				
			
			@ -447,7 +447,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
            iconClass,
 | 
			
		||||
            addExtraTags,
 | 
			
		||||
            searchTerms: mapping.searchTerms,
 | 
			
		||||
            priorityIf: prioritySearch,
 | 
			
		||||
            priorityIf: prioritySearch
 | 
			
		||||
        }
 | 
			
		||||
        if (isQuestionable) {
 | 
			
		||||
            if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -554,7 +554,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                    then: new TypedTranslation<object>(
 | 
			
		||||
                        this.render.replace("{" + this.freeform.key + "}", leftover).translations,
 | 
			
		||||
                        this.render.context
 | 
			
		||||
                    ),
 | 
			
		||||
                    )
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -607,7 +607,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                        return {
 | 
			
		||||
                            then: this.render.PartialSubs({ [this.freeform.key]: v.trim() }),
 | 
			
		||||
                            icon: this.renderIcon,
 | 
			
		||||
                            iconClass: this.renderIconClass,
 | 
			
		||||
                            iconClass: this.renderIconClass
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -662,7 +662,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                    key: commonKey,
 | 
			
		||||
                    values: Utils.NoNull(
 | 
			
		||||
                        values.map((arr) => arr.filter((item) => item.k === commonKey)[0]?.v)
 | 
			
		||||
                    ),
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -677,7 +677,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
            return {
 | 
			
		||||
                key,
 | 
			
		||||
                type: this.freeform.type,
 | 
			
		||||
                values,
 | 
			
		||||
                values
 | 
			
		||||
            }
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            console.error("Could not create FreeformValues for tagrendering", this.id)
 | 
			
		||||
| 
						 | 
				
			
			@ -746,14 +746,18 @@ export default class TagRenderingConfig {
 | 
			
		|||
        if (freeformValue === "") {
 | 
			
		||||
            freeformValue = undefined
 | 
			
		||||
        }
 | 
			
		||||
        if (this.freeform?.postfixDistinguished && freeformValue !== undefined) {
 | 
			
		||||
        if (this.freeform?.postfixDistinguished) {
 | 
			
		||||
            const allValues = currentProperties[this.freeform.key].split(";").map((s) => s.trim())
 | 
			
		||||
            const perPostfix: Record<string, string> = {}
 | 
			
		||||
            for (const value of allValues) {
 | 
			
		||||
                const [v, postfix] = value.split("/")
 | 
			
		||||
                perPostfix[postfix.trim()] = v.trim()
 | 
			
		||||
            }
 | 
			
		||||
            perPostfix[this.freeform.postfixDistinguished] = freeformValue
 | 
			
		||||
            if (freeformValue === "" || freeformValue === undefined) {
 | 
			
		||||
                delete perPostfix[this.freeform.postfixDistinguished]
 | 
			
		||||
            } else {
 | 
			
		||||
                perPostfix[this.freeform.postfixDistinguished] = freeformValue
 | 
			
		||||
            }
 | 
			
		||||
            const keys = Object.keys(perPostfix)
 | 
			
		||||
            keys.sort()
 | 
			
		||||
            freeformValue = keys.map((k) => perPostfix[k] + "/" + k).join("; ")
 | 
			
		||||
| 
						 | 
				
			
			@ -783,7 +787,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
            // Either no mappings, or this is a radio-button selected freeform value
 | 
			
		||||
            const tag = new And([
 | 
			
		||||
                new Tag(this.freeform.key, freeformValue),
 | 
			
		||||
                ...(this.freeform.addExtraTags ?? []),
 | 
			
		||||
                ...(this.freeform.addExtraTags ?? [])
 | 
			
		||||
            ])
 | 
			
		||||
            const newProperties = tag.applyOn(currentProperties)
 | 
			
		||||
            if (this.invalidValues?.matchesProperties(newProperties)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -807,7 +811,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                selectedMappings.push(
 | 
			
		||||
                    new And([
 | 
			
		||||
                        new Tag(this.freeform.key, freeformValue),
 | 
			
		||||
                        ...(this.freeform.addExtraTags ?? []),
 | 
			
		||||
                        ...(this.freeform.addExtraTags ?? [])
 | 
			
		||||
                    ])
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -845,12 +849,12 @@ export default class TagRenderingConfig {
 | 
			
		|||
        if (useFreeform) {
 | 
			
		||||
            return new And([
 | 
			
		||||
                new Tag(this.freeform.key, freeformValue),
 | 
			
		||||
                ...(this.freeform.addExtraTags ?? []),
 | 
			
		||||
                ...(this.freeform.addExtraTags ?? [])
 | 
			
		||||
            ])
 | 
			
		||||
        } else if (singleSelectedMapping !== undefined) {
 | 
			
		||||
            return new And([
 | 
			
		||||
                this.mappings[singleSelectedMapping].if,
 | 
			
		||||
                ...(this.mappings[singleSelectedMapping].addExtraTags ?? []),
 | 
			
		||||
                ...(this.mappings[singleSelectedMapping].addExtraTags ?? [])
 | 
			
		||||
            ])
 | 
			
		||||
        } else {
 | 
			
		||||
            console.error("TagRenderingConfig.ConstructSpecification has a weird fallback for", {
 | 
			
		||||
| 
						 | 
				
			
			@ -858,7 +862,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                singleSelectedMapping,
 | 
			
		||||
                multiSelectedMapping,
 | 
			
		||||
                currentProperties,
 | 
			
		||||
                useFreeform,
 | 
			
		||||
                useFreeform
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            return undefined
 | 
			
		||||
| 
						 | 
				
			
			@ -888,11 +892,11 @@ export default class TagRenderingConfig {
 | 
			
		|||
                    }
 | 
			
		||||
                    const msgs: string[] = [
 | 
			
		||||
                        icon +
 | 
			
		||||
                            " " +
 | 
			
		||||
                            "*" +
 | 
			
		||||
                            m.then.textFor(lang) +
 | 
			
		||||
                            "* is shown if with " +
 | 
			
		||||
                            m.if.asHumanString(true, false, {}),
 | 
			
		||||
                        " " +
 | 
			
		||||
                        "*" +
 | 
			
		||||
                        m.then.textFor(lang) +
 | 
			
		||||
                        "* is shown if with " +
 | 
			
		||||
                        m.if.asHumanString(true, false, {})
 | 
			
		||||
                    ]
 | 
			
		||||
 | 
			
		||||
                    if (m.hideInAnswer === true) {
 | 
			
		||||
| 
						 | 
				
			
			@ -901,7 +905,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
                    if (m.ifnot !== undefined) {
 | 
			
		||||
                        msgs.push(
 | 
			
		||||
                            "Unselecting this answer will add " +
 | 
			
		||||
                                m.ifnot.asHumanString(true, false, {})
 | 
			
		||||
                            m.ifnot.asHumanString(true, false, {})
 | 
			
		||||
                        )
 | 
			
		||||
                    }
 | 
			
		||||
                    return msgs.join(". ")
 | 
			
		||||
| 
						 | 
				
			
			@ -925,7 +929,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
        if (this.labels?.length > 0) {
 | 
			
		||||
            labels = [
 | 
			
		||||
                "This tagrendering has labels ",
 | 
			
		||||
                ...this.labels.map((label) => "`" + label + "`"),
 | 
			
		||||
                ...this.labels.map((label) => "`" + label + "`")
 | 
			
		||||
            ].join("\n")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -938,7 +942,7 @@ export default class TagRenderingConfig {
 | 
			
		|||
            freeform,
 | 
			
		||||
            mappings,
 | 
			
		||||
            condition,
 | 
			
		||||
            labels,
 | 
			
		||||
            labels
 | 
			
		||||
        ].join("\n")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -964,6 +968,32 @@ export default class TagRenderingConfig {
 | 
			
		|||
        return Utils.NoNull(tags)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the freeform value that should be initially shown in the question
 | 
			
		||||
     * @param properties
 | 
			
		||||
     */
 | 
			
		||||
    public initialFreeformValue(properties: Record<string, string>): string {
 | 
			
		||||
        const value = properties[this.freeform.key]
 | 
			
		||||
        if (!value) {
 | 
			
		||||
            return ""
 | 
			
		||||
        }
 | 
			
		||||
        const distinguish = this.freeform.postfixDistinguished
 | 
			
		||||
        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 ""
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The keys that should be erased if one has to revert to 'unknown'.
 | 
			
		||||
     * Might give undefined if setting to unknown is not possible
 | 
			
		||||
| 
						 | 
				
			
			@ -1050,7 +1080,7 @@ export class TagRenderingConfigUtils {
 | 
			
		|||
                clone.mappings?.map((m) => {
 | 
			
		||||
                    const mapping = {
 | 
			
		||||
                        ...m,
 | 
			
		||||
                        priorityIf: m.priorityIf ?? TagUtils.Tag("id~*"),
 | 
			
		||||
                        priorityIf: m.priorityIf ?? TagUtils.Tag("id~*")
 | 
			
		||||
                    }
 | 
			
		||||
                    if (m.if.usedKeys().indexOf("nobrand") < 0) {
 | 
			
		||||
                        // Erase 'nobrand=yes', unless this option explicitly sets it
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue