From cbc7fa6553b364c49d3961d552b8e81e3358b972 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 18 Jan 2022 18:12:24 +0100 Subject: [PATCH] Fix tests, fix long load by offloading minimap detection to generateLayerOverview --- Models/Constants.ts | 2 +- .../Conversion/LegacyJsonConvert.ts | 48 +++++++++++++++++++ Models/ThemeConfig/LayerConfig.ts | 4 +- UI/Popup/FeatureInfoBox.ts | 29 +---------- Utils.ts | 2 +- scripts/build.sh | 4 +- 6 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Models/Constants.ts b/Models/Constants.ts index 1c21b178d..e60afebba 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.15.0-alpha"; + public static vNumber = "0.14.1-alpha"; public static ImgurApiKey = '7070e7167f0a25a' public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" diff --git a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts index 69faf4d28..42b9cddb1 100644 --- a/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts +++ b/Models/ThemeConfig/Conversion/LegacyJsonConvert.ts @@ -9,6 +9,7 @@ import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"; import {LayerConfigJson} from "../Json/LayerConfigJson"; import Constants from "../../Constants"; import {AllKnownLayouts} from "../../../Customizations/AllKnownLayouts"; +import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation"; export interface DesugaringContext { tagRenderings: Map @@ -153,6 +154,52 @@ class Fuse extends DesugaringStep { } +class AddMiniMap extends DesugaringStep { + constructor() { + super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]); + } + + /** + * 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)]); + for (const translation of translations) { + for (const key in translation.translations) { + if (!translation.translations.hasOwnProperty(key)) { + continue + } + const template = translation.translations[key] + const parts = SubstitutedTranslation.ExtractSpecialComponents(template) + const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap") + if (hasMiniMap) { + return true; + } + } + } + return false; + } + + convert(state: DesugaringContext, layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } { + + + + const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap( tr)) ?? true + if (!hasMinimap) { + layerConfig = {...layerConfig} + layerConfig.tagRenderings = [...layerConfig.tagRenderings] + layerConfig.tagRenderings.push(state.tagRenderings.get("minimap")) + } + + return { + errors:[], + warnings: [], + result: layerConfig + }; + } +} + class ExpandTagRendering extends Conversion { constructor() { super("Converts a tagRenderingSpec into the full tagRendering", []); @@ -1000,6 +1047,7 @@ export class PrepareTheme extends Fuse { new AddDefaultLayers(), new AddDependencyLayersToTheme(), new OnEvery("layers", new PrepareLayer()), + new OnEvery("layers", new AddMiniMap()) ); } } \ No newline at end of file diff --git a/Models/ThemeConfig/LayerConfig.ts b/Models/ThemeConfig/LayerConfig.ts index 9385ee57f..62a1788f6 100644 --- a/Models/ThemeConfig/LayerConfig.ts +++ b/Models/ThemeConfig/LayerConfig.ts @@ -235,13 +235,13 @@ export default class LayerConfig extends WithContextLoader { } } - const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? []; + const missingIds = Utils.NoNull(json.tagRenderings)?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? []; if (missingIds?.length > 0 && official) { console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds) throw "Missing ids in tagrenderings" } - this.tagRenderings = (json.tagRenderings ?? []).map((tr, i) => new TagRenderingConfig(tr, this.id + ".tagRenderings[" + i + "]")) + this.tagRenderings = (Utils.NoNull(json.tagRenderings) ?? []).map((tr, i) => new TagRenderingConfig(tr, this.id + ".tagRenderings[" + i + "]")) this.filters = (json.filter ?? []).map((option, i) => { return new FilterConfig(option, `${context}.filter-[${i}]`) diff --git a/UI/Popup/FeatureInfoBox.ts b/UI/Popup/FeatureInfoBox.ts index f22f38930..0bcfd6197 100644 --- a/UI/Popup/FeatureInfoBox.ts +++ b/UI/Popup/FeatureInfoBox.ts @@ -13,9 +13,7 @@ import DeleteWizard from "./DeleteWizard"; import SplitRoadWizard from "./SplitRoadWizard"; import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"; import LayerConfig from "../../Models/ThemeConfig/LayerConfig"; -import {Translation} from "../i18n/Translation"; import {Utils} from "../../Utils"; -import {SubstitutedTranslation} from "../SubstitutedTranslation"; import MoveWizard from "./MoveWizard"; import Toggle from "../Input/Toggle"; @@ -162,11 +160,6 @@ export default class FeatureInfoBox extends ScrollableFullScreen { } - const hasMinimap = layerConfig.tagRenderings.some(tr => FeatureInfoBox.hasMinimap(tr)) - if (!hasMinimap) { - allRenderings.push(new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("minimap"), State.state)) - } - editElements.push( new VariableUiElement( State.state.osmConnection.userDetails @@ -214,27 +207,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen { return new Combine(allRenderings).SetClass("block") } - /** - * Returns true if this tag rendering has a minimap in some language. - * Note: this minimap can be hidden by conditions - */ - private static hasMinimap(renderingConfig: TagRenderingConfig): boolean { - const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]); - for (const translation of translations) { - for (const key in translation.translations) { - if (!translation.translations.hasOwnProperty(key)) { - continue - } - const template = translation.translations[key] - const parts = SubstitutedTranslation.ExtractSpecialComponents(template) - const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap") - if (hasMiniMap) { - return true; - } - } - } - return false; - } + } diff --git a/Utils.ts b/Utils.ts index 103b4f949..25f898575 100644 --- a/Utils.ts +++ b/Utils.ts @@ -137,7 +137,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } public static NoNull(array: T[]): T[] { - return array.filter(o => o !== undefined && o !== null) + return array?.filter(o => o !== undefined && o !== null) } public static Hist(array: string[]): Map { diff --git a/scripts/build.sh b/scripts/build.sh index 0c230ad43..6f38dcca4 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -15,7 +15,7 @@ npm run test && npm run generate:layouts if [ $? -ne 0 ]; then - echo "ERROR" + echo "ERROR - stopping the build" exit 1 fi @@ -23,6 +23,8 @@ fi cp -r assets/layers/ dist/assets/layers/ cp -r assets/themes/ dist/assets/themes/ cp -r assets/svg/ dist/assets/svg/ +cp assets/*.png dist/assets/ +cp assets/*.svg dist/assets/ SRC_MAPS="--no-source-maps" BRANCH=`git rev-parse --abbrev-ref HEAD`