UX: fix #1922, previously selected option will be selected

This commit is contained in:
Pieter Vander Vennet 2024-04-27 22:03:00 +02:00
parent 2b2cfb5968
commit 45d962bcb6

View file

@ -30,7 +30,7 @@
import { placeholder } from "../../../Utils/placeholder" import { placeholder } from "../../../Utils/placeholder"
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, writable } from "svelte/store" import { get } from "svelte/store"
export let config: TagRenderingConfig export let config: TagRenderingConfig
export let tags: UIEventSource<Record<string, string>> export let tags: UIEventSource<Record<string, string>>
@ -68,13 +68,15 @@
/** /**
* Prepares and fills the checkedMappings * Prepares and fills the checkedMappings
*/ */
function initialize(tgs: Record<string, string>, confg: TagRenderingConfig) { 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))
// 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))
@ -85,7 +87,7 @@
checkedMappings?.length < confg.mappings.length + (confg.freeform ? 1 : 0)) checkedMappings?.length < confg.mappings.length + (confg.freeform ? 1 : 0))
) { ) {
const seenFreeforms = [] const seenFreeforms = []
// Initial setup of the mappings // Initial setup of the mappings; detect checked mappings
checkedMappings = [ checkedMappings = [
...confg.mappings.map((mapping) => { ...confg.mappings.map((mapping) => {
if (mapping.hideInAnswer === true) { if (mapping.hideInAnswer === true) {
@ -128,6 +130,8 @@
freeformInput.set(undefined) freeformInput.set(undefined)
} }
feedback.setData(undefined) feedback.setData(undefined)
} }
$: { $: {