From 42012ac7f7f1cf7408db004aacf695433fc24f3f Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 10 Jul 2022 18:20:42 +0200 Subject: [PATCH] Add some tests --- Logic/Tags/TagUtils.ts | 25 ++++++++++++++++++------- UI/Popup/TagRenderingQuestion.ts | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Logic/Tags/TagUtils.ts b/Logic/Tags/TagUtils.ts index 7086f7a14..0440ffd2a 100644 --- a/Logic/Tags/TagUtils.ts +++ b/Logic/Tags/TagUtils.ts @@ -116,12 +116,21 @@ export class TagUtils { * Given multiple tagsfilters which can be used as answer, will take the tags with the same keys together as set. * E.g: * - * FlattenMultiAnswer([and: [ "x=a", "y=0;1"], and: ["x=b", "y=2"], and: ["x=", "y=3"]]) - * will result in - * ["x=a;b", "y=0;1;2;3"] - * - * @param tagsFilters - * @constructor + * const tag = TagUtils.Tag({"and": [ + * { + * and: [ "x=a", "y=0;1"], + * }, + * { + * and: ["x=", "y=3"] + * }, + * { + * and: ["x=b", "y=2"] + * } + * ]}) + * TagUtils.FlattenMultiAnswer([tag]) // => TagUtils.Tag({and:["x=a;b", "y=0;1;2;3"] }) + * + * TagUtils.FlattenMultiAnswer(([new Tag("x","y"), new Tag("a","b")])) // => new And([new Tag("x","y"), new Tag("a","b")]) + * TagUtils.FlattenMultiAnswer(([new Tag("x","")])) // => new And([new Tag("x","")]) */ static FlattenMultiAnswer(tagsFilters: TagsFilter[]): And { if (tagsFilters === undefined) { @@ -131,7 +140,9 @@ export class TagUtils { let keyValues = TagUtils.SplitKeys(tagsFilters); const and: TagsFilter[] = [] for (const key in keyValues) { - and.push(new Tag(key, Utils.Dedup(keyValues[key]).join(";"))); + const values = Utils.Dedup(keyValues[key]).filter(v => v !== "") + values.sort() + and.push(new Tag(key, values.join(";"))); } return new And(and); } diff --git a/UI/Popup/TagRenderingQuestion.ts b/UI/Popup/TagRenderingQuestion.ts index 34b0e3d9c..ed00ceb82 100644 --- a/UI/Popup/TagRenderingQuestion.ts +++ b/UI/Popup/TagRenderingQuestion.ts @@ -39,7 +39,7 @@ import {SearchablePillsSelector} from "../Input/SearchableMappingsSelector"; */ export default class TagRenderingQuestion extends Combine { - constructor(tags: UIEventSource, + constructor(tags: UIEventSource & {id: string}>, configuration: TagRenderingConfig, state?: FeaturePipelineState, options?: { @@ -88,7 +88,7 @@ export default class TagRenderingQuestion extends Combine { )) const save = () => { - const selection = inputElement.GetValue().data; + const selection = TagUtils.FlattenMultiAnswer([inputElement.GetValue().data]); if (selection) { (state?.changes) .applyAction(new ChangeTagAction(