forked from MapComplete/MapComplete
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.
|
* Given multiple tagsfilters which can be used as answer, will take the tags with the same keys together as set.
|
||||||
* E.g:
|
* E.g:
|
||||||
*
|
*
|
||||||
* FlattenMultiAnswer([and: [ "x=a", "y=0;1"], and: ["x=b", "y=2"], and: ["x=", "y=3"]])
|
* const tag = TagUtils.Tag({"and": [
|
||||||
* will result in
|
* {
|
||||||
* ["x=a;b", "y=0;1;2;3"]
|
* and: [ "x=a", "y=0;1"],
|
||||||
*
|
* },
|
||||||
* @param tagsFilters
|
* {
|
||||||
* @constructor
|
* 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 {
|
static FlattenMultiAnswer(tagsFilters: TagsFilter[]): And {
|
||||||
if (tagsFilters === undefined) {
|
if (tagsFilters === undefined) {
|
||||||
|
@ -131,7 +140,9 @@ export class TagUtils {
|
||||||
let keyValues = TagUtils.SplitKeys(tagsFilters);
|
let keyValues = TagUtils.SplitKeys(tagsFilters);
|
||||||
const and: TagsFilter[] = []
|
const and: TagsFilter[] = []
|
||||||
for (const key in keyValues) {
|
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);
|
return new And(and);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import {SearchablePillsSelector} from "../Input/SearchableMappingsSelector";
|
||||||
*/
|
*/
|
||||||
export default class TagRenderingQuestion extends Combine {
|
export default class TagRenderingQuestion extends Combine {
|
||||||
|
|
||||||
constructor(tags: UIEventSource<any>,
|
constructor(tags: UIEventSource<Record<string, string> & {id: string}>,
|
||||||
configuration: TagRenderingConfig,
|
configuration: TagRenderingConfig,
|
||||||
state?: FeaturePipelineState,
|
state?: FeaturePipelineState,
|
||||||
options?: {
|
options?: {
|
||||||
|
@ -88,7 +88,7 @@ export default class TagRenderingQuestion extends Combine {
|
||||||
))
|
))
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
const selection = inputElement.GetValue().data;
|
const selection = TagUtils.FlattenMultiAnswer([inputElement.GetValue().data]);
|
||||||
if (selection) {
|
if (selection) {
|
||||||
(state?.changes)
|
(state?.changes)
|
||||||
.applyAction(new ChangeTagAction(
|
.applyAction(new ChangeTagAction(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue