Fix some crashes in TagRenderingQuestion

This commit is contained in:
Pieter Vander Vennet 2024-04-27 22:23:48 +02:00
parent 16686dd281
commit 9ead113555

View file

@ -31,6 +31,7 @@
import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid" import { TrashIcon } from "@rgossiaux/svelte-heroicons/solid"
import { Tag } from "../../../Logic/Tags/Tag" import { Tag } from "../../../Logic/Tags/Tag"
import { get } from "svelte/store" import { get } from "svelte/store"
import Markdown from "../../Base/Markdown.svelte"
export let config: TagRenderingConfig export let config: TagRenderingConfig
export let tags: UIEventSource<Record<string, string>> export let tags: UIEventSource<Record<string, string>>
@ -68,15 +69,17 @@
/** /**
* Prepares and fills the checkedMappings * Prepares and fills the checkedMappings
*/ */
function initialize(tgs: Record<string, string>, confg: TagRenderingConfig): void{ function initialize(tgs: Record<string, string>, confg: TagRenderingConfig): void {
mappings = confg.mappings?.filter((m) => { mappings = confg.mappings?.filter((m) => {
if (typeof m.hideInAnswer === "boolean") { if (typeof m.hideInAnswer === "boolean") {
return !m.hideInAnswer return !m.hideInAnswer
} }
return !m.hideInAnswer.matchesProperties(tgs) return !m.hideInAnswer.matchesProperties(tgs)
}) })
selectedMapping = mappings.findIndex(mapping => mapping.if.matchesProperties(tgs) || mapping.alsoShowIf?.matchesProperties(tgs)) selectedMapping = mappings?.findIndex(mapping => mapping.if.matchesProperties(tgs) || mapping.alsoShowIf?.matchesProperties(tgs))
if(selectedMapping < 0){
selectedMapping = undefined
}
// We received a new config -> reinit // We received a new config -> reinit
unit = layer?.units?.find((unit) => unit.appliesToKeys.has(config.freeform?.key)) unit = layer?.units?.find((unit) => unit.appliesToKeys.has(config.freeform?.key))
@ -99,7 +102,7 @@
seenFreeforms.push(newProps[confg.freeform.key]) seenFreeforms.push(newProps[confg.freeform.key])
} }
return matches return matches
}), })
] ]
if (tgs !== undefined && confg.freeform) { if (tgs !== undefined && confg.freeform) {
@ -207,7 +210,7 @@
dispatch("saved", { config, applied: selectedTags }) dispatch("saved", { config, applied: selectedTags })
const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, { const change = new ChangeTagAction(tags.data.id, selectedTags, tags.data, {
theme: tags.data["_orig_theme"] ?? state.layout.id, theme: tags.data["_orig_theme"] ?? state.layout.id,
changeType: "answer", changeType: "answer"
}) })
freeformInput.set(undefined) freeformInput.set(undefined)
selectedMapping = undefined selectedMapping = undefined
@ -259,15 +262,19 @@
</div> </div>
{#if config.questionhint} {#if config.questionhint}
<div class="max-h-60 overflow-y-auto"> {#if config.questionHintIsMd}
<SpecialTranslation <Markdown src={config.questionHint} />
t={config.questionhint} {:else}
{tags} <div class="max-h-60 overflow-y-auto">
{state} <SpecialTranslation
{layer} t={config.questionhint}
feature={selectedElement} {tags}
/> {state}
</div> {layer}
feature={selectedElement}
/>
</div>
{/if}
{/if} {/if}
</legend> </legend>