Add some tests
This commit is contained in:
parent
6f5283a2d2
commit
42012ac7f7
2 changed files with 20 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import {SearchablePillsSelector} from "../Input/SearchableMappingsSelector";
|
|||
*/
|
||||
export default class TagRenderingQuestion extends Combine {
|
||||
|
||||
constructor(tags: UIEventSource<any>,
|
||||
constructor(tags: UIEventSource<Record<string, string> & {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(
|
||||
|
|
Loading…
Reference in a new issue