forked from MapComplete/MapComplete
Scripts: reorder tagRenderings, fix tests
This commit is contained in:
parent
bba8546a55
commit
2e66278291
5 changed files with 50 additions and 9 deletions
|
@ -1092,15 +1092,47 @@ class DeriveSource extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
}
|
||||
|
||||
export class OrderLayer extends DesugaringStep<LayerConfigJson> {
|
||||
export class OrderTagRendering extends DesugaringStep<TagRenderingConfigJson | string> {
|
||||
constructor() {
|
||||
super("OrderTagRendering", "Places all components of a tagRendering in a fixed order")
|
||||
}
|
||||
|
||||
private static readonly tagRenderingAttributesOrder: ReadonlyArray<string> = [
|
||||
"id", "labels", "description", "question", "questionHint", "render", "icon", "freeform", "mappings",
|
||||
"condition", "metacondition", "filter",
|
||||
|
||||
]
|
||||
|
||||
convert(json: TagRenderingConfigJson, context: ConversionContext): TagRenderingConfigJson {
|
||||
if (typeof json !== "object") {
|
||||
return json
|
||||
}
|
||||
console.log("Ordering", json.id, OrderTagRendering.tagRenderingAttributesOrder)
|
||||
return Utils.reorder(json, OrderTagRendering.tagRenderingAttributesOrder)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class OrderLayer extends DesugaringStep<string | LayerConfigJson> {
|
||||
private static readonly layerAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
||||
(<ConfigMeta[]>layerconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||
)
|
||||
|
||||
constructor() {
|
||||
super("OrderLayer", "Reorders the layer to the default order")
|
||||
super("OrderLayer", "Reorders a tagRendering to the default order")
|
||||
}
|
||||
|
||||
public convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
|
||||
public convert(json: LayerConfigJson | string, context: ConversionContext): LayerConfigJson | string {
|
||||
if (typeof json !== "object") {
|
||||
return json
|
||||
}
|
||||
if (typeof json === "string") {
|
||||
return json
|
||||
}
|
||||
// @ts-ignore
|
||||
json = new On<"tagRenderings", TagRenderingConfigJson[], LayerConfigJson>("tagRenderings", new Each(
|
||||
new OrderTagRendering(),
|
||||
)).convert(<LayerConfigJson>json, context)
|
||||
return Utils.reorder(json, OrderLayer.layerAttributesOrder)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue