Fix: generating layeroverview; performance: do not try to download ratings if no ratings element is present

This commit is contained in:
Pieter Vander Vennet 2023-11-19 05:05:15 +01:00
parent c13d80f062
commit fc62d41e1b
12 changed files with 67 additions and 15 deletions

View file

@ -123,6 +123,14 @@ export default class Constants {
"teardrop",
"triangle",
"crosshair",
"brick_wall_square",
"brick_wall_round",
"gps_arrow",
"checkmark",
"help",
"clock",
"invalid",
"close",
] as const
public static readonly defaultPinIcons: string[] = <any>Constants._defaultPinIcons

View file

@ -1193,6 +1193,32 @@ class ExpandMarkerRenderings extends DesugaringStep<IconConfigJson> {
}
}
export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
constructor() {
super(
"Adds the 'rating'-element if a reviews-element is used in the tagRenderings",
["titleIcons"],
"AddRatingBadge"
)
}
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
if (!json.tagRenderings) {
return json
}
const specialVis: RenderingSpecification[] = ValidationUtils.getAllSpecialVisualisations(
<QuestionableTagRenderingConfigJson[]>json.tagRenderings
)
const calledFuncs = new Set<string>(specialVis.map((rs) => rs["func"]))
if (calledFuncs.has("list_reviews")) {
;(<(string | TagRenderingConfigJson)[]>json.titleIcons).push("ratings")
}
return json
}
}
export class PrepareLayer extends Fuse<LayerConfigJson> {
constructor(state: DesugaringContext) {
super(
@ -1223,6 +1249,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
(layer) =>
new Concat(new ExpandTagRendering(state, layer, { noHardcodedStrings: true }))
),
new AddRatingBadge(),
new ExpandFilter(state)
)
}

View file

@ -110,7 +110,7 @@ export class DoesImageExist extends DesugaringStep<string> {
)
} else if (!this.doesPathExist(image)) {
context.err(
`Image with path ${image} does not exist; it is used in ${context}.\n Check for typo's and missing directories in the path.`
`Image with path ${image} does not exist.\n Check for typo's and missing directories in the path.`
)
} else {
context.err(

View file

@ -9,6 +9,12 @@ export default class ValidationUtils {
renderingConfigs: (TagRenderingConfigJson | QuestionableTagRenderingConfigJson)[]
): RenderingSpecification[] {
const visualisations: RenderingSpecification[] = []
if (!Array.isArray(renderingConfigs)) {
throw (
"Could not inspect renderingConfigs, not an array: " +
JSON.stringify(renderingConfigs)
)
}
for (const renderConfig of renderingConfigs) {
visualisations.push(...ValidationUtils.getSpecialVisualisationsWithArgs(renderConfig))
}