Fix tests, fix long load by offloading minimap detection to generateLayerOverview

This commit is contained in:
pietervdvn 2022-01-18 18:12:24 +01:00
parent d7f8ff01d5
commit cbc7fa6553
6 changed files with 56 additions and 33 deletions

View file

@ -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"

View file

@ -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<string, TagRenderingConfigJson>
@ -153,6 +154,52 @@ class Fuse<T> extends DesugaringStep<T> {
}
class AddMiniMap extends DesugaringStep<LayerConfigJson> {
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(<TagRenderingConfigJson> 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<string | TagRenderingConfigJson | { builtin: string | string[], override: any }, TagRenderingConfigJson[]> {
constructor() {
super("Converts a tagRenderingSpec into the full tagRendering", []);
@ -1000,6 +1047,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
new AddDefaultLayers(),
new AddDependencyLayersToTheme(),
new OnEvery("layers", new PrepareLayer()),
new OnEvery("layers", new AddMiniMap())
);
}
}

View file

@ -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(<TagRenderingConfigJson>tr, this.id + ".tagRenderings[" + i + "]"))
this.tagRenderings = (Utils.NoNull(json.tagRenderings) ?? []).map((tr, i) => new TagRenderingConfig(<TagRenderingConfigJson>tr, this.id + ".tagRenderings[" + i + "]"))
this.filters = (json.filter ?? []).map((option, i) => {
return new FilterConfig(option, `${context}.filter-[${i}]`)

View file

@ -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;
}
}

View file

@ -137,7 +137,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
}
public static NoNull<T>(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<string, number> {

View file

@ -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`