Studio: hide informational message, hide irrelevant quesionts for theme

This commit is contained in:
Pieter Vander Vennet 2024-01-22 01:01:38 +01:00
parent 4f21550301
commit 3d5e117989
3 changed files with 77 additions and 57 deletions

View file

@ -1,4 +1,14 @@
import { Concat, Conversion, DesugaringContext, DesugaringStep, Each, Fuse, On, Pass, SetDefault } from "./Conversion" import {
Concat,
Conversion,
DesugaringContext,
DesugaringStep,
Each,
Fuse,
On,
Pass,
SetDefault,
} from "./Conversion"
import { LayoutConfigJson } from "../Json/LayoutConfigJson" import { LayoutConfigJson } from "../Json/LayoutConfigJson"
import { PrepareLayer } from "./PrepareLayer" import { PrepareLayer } from "./PrepareLayer"
import { LayerConfigJson } from "../Json/LayerConfigJson" import { LayerConfigJson } from "../Json/LayerConfigJson"
@ -19,7 +29,7 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
super( super(
"Converts the identifier of a builtin layer into the actual layer, or converts a 'builtin' syntax with override in the fully expanded form. Note that 'tagRenderings+' will be inserted before 'leftover-questions'", "Converts the identifier of a builtin layer into the actual layer, or converts a 'builtin' syntax with override in the fully expanded form. Note that 'tagRenderings+' will be inserted before 'leftover-questions'",
[], [],
"SubstituteLayer", "SubstituteLayer"
) )
this._state = state this._state = state
} }
@ -70,15 +80,16 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
(found["tagRenderings"] ?? []).length > 0 (found["tagRenderings"] ?? []).length > 0
) { ) {
context.err( context.err(
`When overriding a layer, an override is not allowed to override into tagRenderings. Use "+tagRenderings" or "tagRenderings+" instead to prepend or append some questions.`, `When overriding a layer, an override is not allowed to override into tagRenderings. Use "+tagRenderings" or "tagRenderings+" instead to prepend or append some questions.`
) )
} }
try { try {
const trPlus = json["override"]["tagRenderings+"] const trPlus = json["override"]["tagRenderings+"]
if(trPlus){ if (trPlus) {
let index = found.tagRenderings.findIndex(tr => tr["id"] === "leftover-questions") let index = found.tagRenderings.findIndex(
if(index < 0){ (tr) => tr["id"] === "leftover-questions"
)
if (index < 0) {
index = found.tagRenderings.length index = found.tagRenderings.length
} }
found.tagRenderings.splice(index, 0, ...trPlus) found.tagRenderings.splice(index, 0, ...trPlus)
@ -90,14 +101,18 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
} catch (e) { } catch (e) {
context.err( context.err(
`Could not apply an override due to: ${e}.\nThe override is: ${JSON.stringify( `Could not apply an override due to: ${e}.\nThe override is: ${JSON.stringify(
json["override"], json["override"]
)}`, )}`
) )
} }
if (json["hideTagRenderingsWithLabels"]) { if (json["hideTagRenderingsWithLabels"]) {
if (typeof json["hideTagRenderingsWithLabels"] === "string") { if (typeof json["hideTagRenderingsWithLabels"] === "string") {
throw "At " + context + ".hideTagRenderingsWithLabels should be a list containing strings, you specified a string" throw (
"At " +
context +
".hideTagRenderingsWithLabels should be a list containing strings, you specified a string"
)
} }
const hideLabels: Set<string> = new Set(json["hideTagRenderingsWithLabels"]) const hideLabels: Set<string> = new Set(json["hideTagRenderingsWithLabels"])
// These labels caused at least one deletion // These labels caused at least one deletion
@ -111,9 +126,9 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
usedLabels.add(labels[forbiddenLabel]) usedLabels.add(labels[forbiddenLabel])
context.info( context.info(
"Dropping tagRendering " + "Dropping tagRendering " +
tr["id"] + tr["id"] +
" as it has a forbidden label: " + " as it has a forbidden label: " +
labels[forbiddenLabel], labels[forbiddenLabel]
) )
continue continue
} }
@ -122,7 +137,7 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
if (hideLabels.has(tr["id"])) { if (hideLabels.has(tr["id"])) {
usedLabels.add(tr["id"]) usedLabels.add(tr["id"])
context.info( context.info(
"Dropping tagRendering " + tr["id"] + " as its id is a forbidden label", "Dropping tagRendering " + tr["id"] + " as its id is a forbidden label"
) )
continue continue
} }
@ -131,10 +146,10 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
usedLabels.add(tr["group"]) usedLabels.add(tr["group"])
context.info( context.info(
"Dropping tagRendering " + "Dropping tagRendering " +
tr["id"] + tr["id"] +
" as its group `" + " as its group `" +
tr["group"] + tr["group"] +
"` is a forbidden label", "` is a forbidden label"
) )
continue continue
} }
@ -145,8 +160,8 @@ class SubstituteLayer extends Conversion<string | LayerConfigJson, LayerConfigJs
if (unused.length > 0) { if (unused.length > 0) {
context.err( context.err(
"This theme specifies that certain tagrenderings have to be removed based on forbidden layers. One or more of these layers did not match any tagRenderings and caused no deletions: " + "This theme specifies that certain tagrenderings have to be removed based on forbidden layers. One or more of these layers did not match any tagRenderings and caused no deletions: " +
unused.join(", ") + unused.join(", ") +
"\n This means that this label can be removed or that the original tagRendering that should be deleted does not have this label anymore", "\n This means that this label can be removed or that the original tagRendering that should be deleted does not have this label anymore"
) )
} }
found.tagRenderings = filtered found.tagRenderings = filtered
@ -163,7 +178,7 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> {
super( super(
"Adds the default layers, namely: " + Constants.added_by_default.join(", "), "Adds the default layers, namely: " + Constants.added_by_default.join(", "),
["layers"], ["layers"],
"AddDefaultLayers", "AddDefaultLayers"
) )
this._state = state this._state = state
} }
@ -178,7 +193,7 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> {
if (v === undefined) { if (v === undefined) {
const msg = `Default layer ${layerName} not found. ${state.sharedLayers.size} layers are available` const msg = `Default layer ${layerName} not found. ${state.sharedLayers.size} layers are available`
if (layerName === "favourite") { if (layerName === "favourite") {
context.warn(msg) // context.warn(msg)
continue continue
} }
context.err(msg) context.err(msg)
@ -187,10 +202,10 @@ class AddDefaultLayers extends DesugaringStep<LayoutConfigJson> {
if (alreadyLoaded.has(v.id)) { if (alreadyLoaded.has(v.id)) {
context.warn( context.warn(
"Layout " + "Layout " +
context + context +
" already has a layer with name " + " already has a layer with name " +
v.id + v.id +
"; skipping inclusion of this builtin layer", "; skipping inclusion of this builtin layer"
) )
continue continue
} }
@ -206,14 +221,14 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
super( super(
"For every layer in the 'layers'-list, create a new layer which'll import notes. (Note that priviliged layers and layers which have a geojson-source set are ignored)", "For every layer in the 'layers'-list, create a new layer which'll import notes. (Note that priviliged layers and layers which have a geojson-source set are ignored)",
["layers"], ["layers"],
"AddImportLayers", "AddImportLayers"
) )
} }
convert(json: LayoutConfigJson, context: ConversionContext): LayoutConfigJson { convert(json: LayoutConfigJson, context: ConversionContext): LayoutConfigJson {
if (!(json.enableNoteImports ?? true)) { if (!(json.enableNoteImports ?? true)) {
context.info( context.info(
"Not creating a note import layers for theme " + json.id + " as they are disabled", "Not creating a note import layers for theme " + json.id + " as they are disabled"
) )
return json return json
} }
@ -248,7 +263,7 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
try { try {
const importLayerResult = creator.convert( const importLayerResult = creator.convert(
layer, layer,
context.inOperation(this.name).enter(i1), context.inOperation(this.name).enter(i1)
) )
if (importLayerResult !== undefined) { if (importLayerResult !== undefined) {
json.layers.push(importLayerResult) json.layers.push(importLayerResult)
@ -267,7 +282,7 @@ class AddContextToTranslationsInLayout extends DesugaringStep<LayoutConfigJson>
super( super(
"Adds context to translations, including the prefix 'themes:json.id'; this is to make sure terms in an 'overrides' or inline layer are linkable too", "Adds context to translations, including the prefix 'themes:json.id'; this is to make sure terms in an 'overrides' or inline layer are linkable too",
["_context"], ["_context"],
"AddContextToTranlationsInLayout", "AddContextToTranlationsInLayout"
) )
} }
@ -282,7 +297,7 @@ class ApplyOverrideAll extends DesugaringStep<LayoutConfigJson> {
super( super(
"Applies 'overrideAll' onto every 'layer'. The 'overrideAll'-field is removed afterwards", "Applies 'overrideAll' onto every 'layer'. The 'overrideAll'-field is removed afterwards",
["overrideAll", "layers"], ["overrideAll", "layers"],
"ApplyOverrideAll", "ApplyOverrideAll"
) )
} }
@ -310,8 +325,9 @@ class ApplyOverrideAll extends DesugaringStep<LayoutConfigJson> {
if (!layer.tagRenderings) { if (!layer.tagRenderings) {
layer.tagRenderings = tagRenderingsPlus layer.tagRenderings = tagRenderingsPlus
} else { } else {
let index = layer.tagRenderings.findIndex(
let index = layer.tagRenderings.findIndex(tr => tr["id"] === "leftover-questions") (tr) => tr["id"] === "leftover-questions"
)
if (index < 0) { if (index < 0) {
index = layer.tagRenderings.length - 1 index = layer.tagRenderings.length - 1
} }
@ -338,7 +354,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
Some layers (e.g. \`all_buildings_and_walls\' or \'streets_with_a_name\') are invisible, so by default, \'force_load\' is set too. Some layers (e.g. \`all_buildings_and_walls\' or \'streets_with_a_name\') are invisible, so by default, \'force_load\' is set too.
`, `,
["layers"], ["layers"],
"AddDependencyLayersToTheme", "AddDependencyLayersToTheme"
) )
this._state = state this._state = state
} }
@ -346,7 +362,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
private static CalculateDependencies( private static CalculateDependencies(
alreadyLoaded: LayerConfigJson[], alreadyLoaded: LayerConfigJson[],
allKnownLayers: Map<string, LayerConfigJson>, allKnownLayers: Map<string, LayerConfigJson>,
themeId: string, themeId: string
): { config: LayerConfigJson; reason: string }[] { ): { config: LayerConfigJson; reason: string }[] {
const dependenciesToAdd: { config: LayerConfigJson; reason: string }[] = [] const dependenciesToAdd: { config: LayerConfigJson; reason: string }[] = []
const loadedLayerIds: Set<string> = new Set<string>(alreadyLoaded.map((l) => l.id)) const loadedLayerIds: Set<string> = new Set<string>(alreadyLoaded.map((l) => l.id))
@ -369,7 +385,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
for (const layerConfig of alreadyLoaded) { for (const layerConfig of alreadyLoaded) {
try { try {
const layerDeps = DependencyCalculator.getLayerDependencies( const layerDeps = DependencyCalculator.getLayerDependencies(
new LayerConfig(layerConfig, themeId + "(dependencies)"), new LayerConfig(layerConfig, themeId + "(dependencies)")
) )
dependencies.push(...layerDeps) dependencies.push(...layerDeps)
} catch (e) { } catch (e) {
@ -406,10 +422,10 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
if (dep === undefined) { if (dep === undefined) {
const message = [ const message = [
"Loading a dependency failed: layer " + "Loading a dependency failed: layer " +
unmetDependency.neededLayer + unmetDependency.neededLayer +
" is not found, neither as layer of " + " is not found, neither as layer of " +
themeId + themeId +
" nor as builtin layer.", " nor as builtin layer.",
reason, reason,
"Loaded layers are: " + alreadyLoaded.map((l) => l.id).join(","), "Loaded layers are: " + alreadyLoaded.map((l) => l.id).join(","),
] ]
@ -425,7 +441,7 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
}) })
loadedLayerIds.add(dep.id) loadedLayerIds.add(dep.id)
unmetDependencies = unmetDependencies.filter( unmetDependencies = unmetDependencies.filter(
(d) => d.neededLayer !== unmetDependency.neededLayer, (d) => d.neededLayer !== unmetDependency.neededLayer
) )
} }
} while (unmetDependencies.length > 0) } while (unmetDependencies.length > 0)
@ -446,14 +462,12 @@ class AddDependencyLayersToTheme extends DesugaringStep<LayoutConfigJson> {
const dependencies = AddDependencyLayersToTheme.CalculateDependencies( const dependencies = AddDependencyLayersToTheme.CalculateDependencies(
layers, layers,
allKnownLayers, allKnownLayers,
theme.id, theme.id
) )
for (const dependency of dependencies) {
}
if (dependencies.length > 0) { if (dependencies.length > 0) {
for (const dependency of dependencies) { for (const dependency of dependencies) {
context.info( context.info(
"Added " + dependency.config.id + " to the theme. " + dependency.reason, "Added " + dependency.config.id + " to the theme. " + dependency.reason
) )
} }
} }
@ -495,7 +509,7 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
super( super(
"Generates a warning if a theme uses an unsubstituted layer", "Generates a warning if a theme uses an unsubstituted layer",
["layers"], ["layers"],
"WarnForUnsubstitutedLayersInTheme", "WarnForUnsubstitutedLayersInTheme"
) )
} }
@ -507,7 +521,7 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
context context
.enter("layers") .enter("layers")
.err( .err(
"No layers are defined. You must define at least one layer to have a valid theme", "No layers are defined. You must define at least one layer to have a valid theme"
) )
return json return json
} }
@ -531,10 +545,10 @@ class WarnForUnsubstitutedLayersInTheme extends DesugaringStep<LayoutConfigJson>
context.warn( context.warn(
"The theme " + "The theme " +
json.id + json.id +
" has an inline layer: " + " has an inline layer: " +
layer["id"] + layer["id"] +
". This is discouraged.", ". This is discouraged."
) )
} }
return json return json
@ -548,7 +562,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
state: DesugaringContext, state: DesugaringContext,
options?: { options?: {
skipDefaultLayers: false | boolean skipDefaultLayers: false | boolean
}, }
) { ) {
super( super(
"Fully prepares and expands a theme", "Fully prepares and expands a theme",
@ -568,7 +582,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
? new Pass("AddDefaultLayers is disabled due to the set flag") ? new Pass("AddDefaultLayers is disabled due to the set flag")
: new AddDefaultLayers(state), : new AddDefaultLayers(state),
new AddDependencyLayersToTheme(state), new AddDependencyLayersToTheme(state),
new AddImportLayers(), new AddImportLayers()
) )
this.state = state this.state = state
} }
@ -583,13 +597,13 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
const needsNodeDatabase = result.layers?.some((l: LayerConfigJson) => const needsNodeDatabase = result.layers?.some((l: LayerConfigJson) =>
l.tagRenderings?.some((tr) => l.tagRenderings?.some((tr) =>
ValidationUtils.getSpecialVisualisations(<any>tr)?.some( ValidationUtils.getSpecialVisualisations(<any>tr)?.some(
(special) => special.needsNodeDatabase, (special) => special.needsNodeDatabase
), )
), )
) )
if (needsNodeDatabase) { if (needsNodeDatabase) {
context.info( context.info(
"Setting 'enableNodeDatabase' as this theme uses a special visualisation which needs to keep track of _all_ nodes", "Setting 'enableNodeDatabase' as this theme uses a special visualisation which needs to keep track of _all_ nodes"
) )
result.enableNodeDatabase = true result.enableNodeDatabase = true
} }

View file

@ -209,6 +209,9 @@ export abstract class EditJsonState<T> {
return [] return []
} }
return msgs.filter((msg) => { return msgs.filter((msg) => {
if (msg.level === "debug" || msg.level === "information") {
return false
}
const pth = msg.context.path const pth = msg.context.path
for (let i = 0; i < Math.min(pth.length, path.length); i++) { for (let i = 0; i < Math.min(pth.length, path.length); i++) {
if (pth[i] !== path[i]) { if (pth[i] !== path[i]) {

View file

@ -20,6 +20,9 @@
const perRegion: Record<string, ConfigMeta[]> = {} const perRegion: Record<string, ConfigMeta[]> = {}
for (const schemaElement of schema) { for (const schemaElement of schema) {
if(schemaElement.path.length > 1 && schemaElement.path[0] === "layers"){
continue
}
const key = schemaElement.hints.group ?? "no-group" const key = schemaElement.hints.group ?? "no-group"
const list = perRegion[key] ?? (perRegion[key] = []) const list = perRegion[key] ?? (perRegion[key] = [])
list.push(schemaElement) list.push(schemaElement)