From e67c3ffa522b298027595af1edb5f21ea42432c8 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 28 Jun 2022 01:38:57 +0200 Subject: [PATCH] Add error if hideInAnswer:true and addExtraTags are used in the same mapping, fix #906 --- Models/ThemeConfig/TagRenderingConfig.ts | 7 ++++++- assets/layers/playground/playground.json | 5 +---- assets/themes/uk_addresses/uk_addresses.json | 15 --------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Models/ThemeConfig/TagRenderingConfig.ts b/Models/ThemeConfig/TagRenderingConfig.ts index 431080b1b3..9881c9abf0 100644 --- a/Models/ThemeConfig/TagRenderingConfig.ts +++ b/Models/ThemeConfig/TagRenderingConfig.ts @@ -206,6 +206,11 @@ export default class TagRenderingConfig { } else if (mapping.hideInAnswer !== undefined) { hideInAnswer = TagUtils.Tag(mapping.hideInAnswer, `${context}.mapping[${i}].hideInAnswer`); } + const addExtraTags = (mapping.addExtraTags ?? []).map((str, j) => TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`)); + if(hideInAnswer === true && addExtraTags.length > 0){ + throw `${ctx}: Invalid mapping: 'hideInAnswer' is set to 'true', but 'addExtraTags' is enabled as well. This means that extra tags will be applied if this mapping is chosen as answer, but it cannot be chosen as answer. This either indicates a thought error or obsolete code that must be removed.` + } + let icon = undefined; let iconClass = "small" if(mapping.icon !== undefined){ @@ -223,7 +228,7 @@ export default class TagRenderingConfig { hideInAnswer, icon, iconClass, - addExtraTags: (mapping.addExtraTags ?? []).map((str, j) => TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`)) + addExtraTags }; if (this.question) { if (hideInAnswer !== true && mp.if !== undefined && !mp.if.isUsableAsAnswer()) { diff --git a/assets/layers/playground/playground.json b/assets/layers/playground/playground.json index f25f8a4017..31dd33268b 100644 --- a/assets/layers/playground/playground.json +++ b/assets/layers/playground/playground.json @@ -347,10 +347,7 @@ "fr": "Réservée aux élèves de l’école", "es": "Solo accesibles para estudiantes de la escuela" }, - "hideInAnswer": true, - "addExtraTags": [ - "fee=no" - ] + "hideInAnswer": true }, { "if": "access=private", diff --git a/assets/themes/uk_addresses/uk_addresses.json b/assets/themes/uk_addresses/uk_addresses.json index 7abc1cde1b..79351d220f 100644 --- a/assets/themes/uk_addresses/uk_addresses.json +++ b/assets/themes/uk_addresses/uk_addresses.json @@ -271,9 +271,6 @@ { "if": "not:addr:unit=yes", "then": "
Sub-unit (e.g. 1, Flat 2, Unit C)
There is no sub-unit within this address
", - "addExtraTags": [ - "addr:unit=" - ], "hideInAnswer": true }, { @@ -360,9 +357,6 @@ "then": { "en": "
Number (e.g. 1, 1A, 2)
This building has no house number
" }, - "addExtraTags": [ - "addr:housenumber=" - ], "hideInAnswer": true }, { @@ -402,9 +396,6 @@ "then": { "en": "
Place (e.g. Castle Mews, West Business Park)
No extra place name is given or needed
" }, - "addExtraTags": [ - "addr:substreet=" - ], "hideInAnswer": true }, { @@ -448,9 +439,6 @@ "then": { "en": "
Place (e.g. Castle Mews, West Business Park)
No extra place name is given or needed
" }, - "addExtraTags": [ - "addr:substreet=" - ], "hideInAnswer": true }, { @@ -554,9 +542,6 @@ { "if": "not:addr:parentstreet=yes", "then": "
Parent street name
No parent street name is needed within this address
", - "addExtraTags": [ - "addr:parentstreet=" - ], "hideInAnswer": true }, {