From 65dbcb4f122df3f4526d8cda3da6a230931ad887 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 21 Jan 2022 02:15:53 +0100 Subject: [PATCH 1/2] Fix broken minimap detection --- .../Conversion/LegacyJsonConvert.ts | 9 ++-- test/LegacyThemeLoader.spec.ts | 54 +++++++++++++++++-- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts index df9408a8ea..f256fcfd3e 100644 --- a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts +++ b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts @@ -10,6 +10,7 @@ import {LayerConfigJson} from "../Json/LayerConfigJson"; import Constants from "../../Constants"; import {AllKnownLayouts} from "../../../Customizations/AllKnownLayouts"; import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation"; +import Translations from "../../../UI/i18n/Translations"; export interface DesugaringContext { tagRenderings: Map @@ -154,7 +155,7 @@ class Fuse extends DesugaringStep { } -class AddMiniMap extends DesugaringStep { +export class AddMiniMap extends DesugaringStep { constructor() { super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]); } @@ -163,8 +164,10 @@ class AddMiniMap extends DesugaringStep { * Returns true if this tag rendering has a minimap in some language. * Note: this minimap can be hidden by conditions */ - private static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean { - const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]); + public static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean { + const translations: any[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]) + .map(Translations.T); + for (const translation of translations) { for (const key in translation.translations) { if (!translation.translations.hasOwnProperty(key)) { diff --git a/test/LegacyThemeLoader.spec.ts b/test/LegacyThemeLoader.spec.ts index f29e9c6e1e..b53826622f 100644 --- a/test/LegacyThemeLoader.spec.ts +++ b/test/LegacyThemeLoader.spec.ts @@ -1,5 +1,5 @@ import T from "./TestHelper"; -import {FixLegacyTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert"; +import {AddMiniMap, FixLegacyTheme} from "../Models/ThemeConfig/Conversion/LegacyJsonConvert"; import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; import {LayerConfigJson} from "../Models/ThemeConfig/Json/LayerConfigJson"; import {TagRenderingConfigJson} from "../Models/ThemeConfig/Json/TagRenderingConfigJson"; @@ -146,14 +146,62 @@ export default class LegacyThemeLoaderSpec extends T { ["Walking_node_theme", () => { const config = LegacyThemeLoaderSpec.walking_node_theme - const fixed = new FixLegacyTheme().convert({tagRenderings: new Map(), sharedLayers: new Map()}, + const fixed = new FixLegacyTheme().convert({ + tagRenderings: new Map(), + sharedLayers: new Map() + }, // @ts-ignore config, "While testing") T.isTrue(fixed.errors.length === 0, "Could not fix the legacy theme") const theme = new LayoutConfig(fixed.result) - }] + }], + ["Detect minimaps", () => { + function shouldHave(config: TagRenderingConfigJson) { + T.equals(AddMiniMap.hasMinimap(config), true, "Did _not_ dected a minimap, even though there is one in " + JSON.stringify(config)) + } + + function shouldNot(config: TagRenderingConfigJson) { + T.equals(AddMiniMap.hasMinimap(config), false, "Did erronously dected a minimap, even though there is none in " + JSON.stringify(config)) + } + + shouldHave({ + render: "{minimap()}" + }); + shouldHave({ + render: {en:"{minimap()}"} + }); + shouldHave({ + render: {en:"{minimap()}",nl:"{minimap()}"} + }); + shouldHave({ + render: {en:"{minimap()}",nl:"No map for the dutch!"} + }); + + shouldHave({ + render: "{minimap()}" + }) + shouldHave({ + render: "{minimap(18,featurelist)}" + }) + shouldHave({ + mappings: [ + { + if: "xyz=abc", + then: "{minimap(18,featurelist)}" + } + ] + }) + shouldNot({ + render: "Some random value {key}" + }) + shouldNot({ + render: "Some random value {minimap}" + }) + + } + ] ] ); } From eb8fea56929d09230181e3d30a14e0952cb7c98b Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 21 Jan 2022 02:22:59 +0100 Subject: [PATCH 2/2] Fix caching --- .../Sources/FilteringFeatureSource.ts | 15 +++++++++------ Models/Constants.ts | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts index 1250184063..075182acec 100644 --- a/Logic/FeatureSource/Sources/FilteringFeatureSource.ts +++ b/Logic/FeatureSource/Sources/FilteringFeatureSource.ts @@ -82,12 +82,15 @@ export default class FilteringFeatureSource implements FeatureSourceForLayer, Ti } } - const tagsFilter = Array.from(layer.appliedFilters.data.values()); - for (const filter of tagsFilter ?? []) { - const neededTags : TagsFilter = filter?.currentFilter - if (neededTags !== undefined && !neededTags.matchesProperties(f.feature.properties)) { - // Hidden by the filter on the layer itself - we want to hide it no matter wat - return false; + const appliedFilters = layer.appliedFilters?.data + if(appliedFilters !== undefined){ + const tagsFilter = Array.from(appliedFilters.values()); + for (const filter of tagsFilter ?? []) { + const neededTags : TagsFilter = filter?.currentFilter + if (neededTags !== undefined && !neededTags.matchesProperties(f.feature.properties)) { + // Hidden by the filter on the layer itself - we want to hide it no matter wat + return false; + } } } diff --git a/Models/Constants.ts b/Models/Constants.ts index 78f81b633c..4407fbacfc 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import {Utils} from "../Utils"; export default class Constants { - public static vNumber = "0.14.1"; + public static vNumber = "0.14.2"; public static ImgurApiKey = '7070e7167f0a25a' public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85"