forked from MapComplete/MapComplete
Fix bug in bind, fix bug in tagrenderingquestion
This commit is contained in:
parent
2813c31a93
commit
b6b20ed3ca
2 changed files with 44 additions and 31 deletions
|
@ -191,15 +191,20 @@ export class UIEventSource<T> {
|
|||
* Monadic bind function
|
||||
*/
|
||||
public bind<X>(f: ((t: T) => UIEventSource<X>)): UIEventSource<X> {
|
||||
const mapped = this.map(f)
|
||||
const sink = new UIEventSource<X>(undefined)
|
||||
const seenEventSources = new Set<UIEventSource<X>>();
|
||||
this.addCallbackAndRun(data => {
|
||||
const eventSource = f(data)
|
||||
if(eventSource === undefined){
|
||||
mapped.addCallbackAndRun(newEventSource => {
|
||||
|
||||
if (newEventSource === undefined) {
|
||||
sink.setData(undefined)
|
||||
}else if(!seenEventSources.has(eventSource)){
|
||||
eventSource.addCallbackAndRun(mappedData => sink.setData(mappedData))
|
||||
seenEventSources.add(eventSource)
|
||||
} else if (!seenEventSources.has(newEventSource)) {
|
||||
seenEventSources.add(newEventSource)
|
||||
newEventSource.addCallbackAndRun(resultData => {
|
||||
if (mapped.data === newEventSource) {
|
||||
sink.setData(resultData);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -70,7 +70,10 @@ export default class TagRenderingQuestion extends Combine {
|
|||
return TagRenderingQuestion.GenerateFullQuestion(tags, applicableMappings, configuration, options)
|
||||
})
|
||||
)*/
|
||||
super([TagRenderingQuestion.GenerateFullQuestion(tags, (configuration.mappings??[]).filter(mapping => mapping.hideInAnswer !== undefined), configuration, options)])
|
||||
|
||||
const applicableMappings = Utils.NoNull((configuration.mappings??[]).filter(mapping => mapping.hideInAnswer !== undefined))
|
||||
|
||||
super([TagRenderingQuestion.GenerateFullQuestion(tags, applicableMappings, configuration, options)])
|
||||
}
|
||||
|
||||
private static GenerateFullQuestion(tags: UIEventSource<any>,
|
||||
|
@ -163,6 +166,13 @@ export default class TagRenderingQuestion extends Combine {
|
|||
applicableUnit: Unit,
|
||||
tagsSource: UIEventSource<any>)
|
||||
: InputElement<TagsFilter> {
|
||||
|
||||
// FreeForm input will be undefined if not present; will already contain a special input element if applicable
|
||||
const ff = TagRenderingQuestion.GenerateFreeform(configuration, applicableUnit, tagsSource);
|
||||
|
||||
|
||||
|
||||
const hasImages = applicableMappings.filter(mapping => mapping.then.ExtractImages().length > 0).length > 0
|
||||
let inputEls: InputElement<TagsFilter>[];
|
||||
|
||||
|
||||
|
@ -173,11 +183,11 @@ export default class TagRenderingQuestion extends Combine {
|
|||
return undefined
|
||||
}
|
||||
if (!ifNotsPresent) {
|
||||
return undefined
|
||||
return []
|
||||
}
|
||||
if (configuration.multiAnswer) {
|
||||
// The multianswer will do the ifnot configuration themself
|
||||
return undefined
|
||||
return []
|
||||
}
|
||||
|
||||
const negativeMappings = []
|
||||
|
@ -193,8 +203,6 @@ export default class TagRenderingQuestion extends Combine {
|
|||
|
||||
}
|
||||
|
||||
const ff = TagRenderingQuestion.GenerateFreeform(configuration, applicableUnit, tagsSource);
|
||||
const hasImages = applicableMappings.filter(mapping => mapping.then.ExtractImages().length > 0).length > 0
|
||||
|
||||
if (applicableMappings.length < 8 || configuration.multiAnswer || hasImages || ifNotsPresent) {
|
||||
inputEls = (applicableMappings ?? []).map((mapping, i) => TagRenderingQuestion.GenerateMappingElement(tagsSource, mapping, allIfNotsExcept(i)));
|
||||
|
@ -226,7 +234,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
}
|
||||
|
||||
if (configuration.multiAnswer) {
|
||||
return TagRenderingQuestion.GenerateMultiAnswer(configuration, inputEls, ff, configuration.mappings.map(mp => mp.ifnot))
|
||||
return TagRenderingQuestion.GenerateMultiAnswer(configuration, inputEls, ff, applicableMappings.map(mp => mp.ifnot))
|
||||
} else {
|
||||
return new RadioButton(inputEls, {selectFirstAsDefault: false})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue