This commit is contained in:
Pieter Vander Vennet 2024-05-03 18:44:37 +02:00
parent 6524366eb5
commit d488f8c9b2
2 changed files with 44 additions and 11 deletions

View file

@ -79,7 +79,7 @@
console.log("Applying questions to ask") console.log("Applying questions to ask")
const qta = questionsToAsk.data const qta = questionsToAsk.data
firstQuestion.setData(undefined) firstQuestion.setData(undefined)
allQuestionsToAsk.setData([]) //allQuestionsToAsk.setData([])
await Utils.awaitAnimationFrame() await Utils.awaitAnimationFrame()
firstQuestion.setData(qta[0]) firstQuestion.setData(qta[0])
allQuestionsToAsk.setData(qta) allQuestionsToAsk.setData(qta)

View file

@ -35,6 +35,7 @@
export let config: TagRenderingConfig export let config: TagRenderingConfig
export let tags: UIEventSource<Record<string, string>> export let tags: UIEventSource<Record<string, string>>
export let selectedElement: Feature export let selectedElement: Feature
export let state: SpecialVisualizationState export let state: SpecialVisualizationState
export let layer: LayerConfig | undefined export let layer: LayerConfig | undefined
@ -69,7 +70,10 @@
/** /**
* Prepares and fills the checkedMappings * Prepares and fills the checkedMappings
*/ */
console.log("Initing ", config.id)
function initialize(tgs: Record<string, string>, confg: TagRenderingConfig): void { function initialize(tgs: Record<string, string>, confg: TagRenderingConfig): void {
console.trace("Initing question state for", confg.id, config.id)
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
@ -77,7 +81,7 @@
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){ if (selectedMapping < 0) {
selectedMapping = undefined selectedMapping = undefined
} }
// We received a new config -> reinit // We received a new config -> reinit
@ -137,11 +141,35 @@
} }
$: { let usedKeys: string[] = config.usedTags().flatMap(t => t.usedKeys())
// Even though 'config' is not declared as a store, Svelte uses it as one to update the component /**
// We want to (re)-initialize whenever the 'tags' or 'config' change - but not when 'checkedConfig' changes * The 'minimalTags' is a subset of the tags of the feature, only containing the values relevant for this object.
initialize($tags, config) * The main goal is to be stable and only 'ping' when an actual change is relevant
} */
let minimalTags = new UIEventSource<Record<string, string>>(undefined)
tags.addCallbackAndRunD(tags => {
const previousMinimal = minimalTags.data
const newMinimal: Record<string, string> = {}
let somethingChanged = previousMinimal === undefined
for (const key of usedKeys) {
const newValue = tags[key]
somethingChanged ||= previousMinimal?.[key] !== newValue
if (newValue !== undefined && newValue !== null) {
newMinimal[key] = newValue
}
}
if (somethingChanged) {
console.log("Updating minimal tags to", newMinimal,"of",config.id)
minimalTags.setData(newMinimal)
}
})
minimalTags.addCallbackAndRunD(tgs => {
initialize(tgs, config)
})
onDestroy( onDestroy(
freeformInput.subscribe((freeformValue) => { freeformInput.subscribe((freeformValue) => {
if (!mappings || mappings?.length == 0 || config.freeform?.key === undefined) { if (!mappings || mappings?.length == 0 || config.freeform?.key === undefined) {
@ -178,8 +206,13 @@
checkedMappings, checkedMappings,
tags.data tags.data
) )
if(state.featureSwitches.featureSwitchIsDebugging.data){ if (state.featureSwitches.featureSwitchIsDebugging.data) {
console.log("Constructing change spec from", {freeform: $freeformInput, selectedMapping, checkedMappings, currentTags: tags.data}, " --> ", selectedTags) console.log("Constructing change spec from", {
freeform: $freeformInput,
selectedMapping,
checkedMappings,
currentTags: tags.data
}, " --> ", selectedTags)
} }
} catch (e) { } catch (e) {
console.error("Could not calculate changeSpecification:", e) console.error("Could not calculate changeSpecification:", e)
@ -194,7 +227,7 @@
} }
if (layer === undefined || (layer?.source === null && layer.id !== "favourite")) { if (layer === undefined || (layer?.source === null && layer.id !== "favourite")) {
/** /**
* This is a special, priviliged layer. * This is a special, privileged layer.
* We simply apply the tags onto the records * We simply apply the tags onto the records
*/ */
const kv = selectedTags.asChange(tags.data) const kv = selectedTags.asChange(tags.data)
@ -277,7 +310,7 @@
feature={selectedElement} feature={selectedElement}
/> />
</div> </div>
{/if} {/if}
{/if} {/if}
</legend> </legend>