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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
SetDefault,
|
||||
} from "./Conversion"
|
||||
import { ThemeConfigJson } from "../Json/ThemeConfigJson"
|
||||
import { PrepareLayer, RewriteSpecial } from "./PrepareLayer"
|
||||
import { OrderLayer, PrepareLayer, RewriteSpecial } from "./PrepareLayer"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import Constants from "../../Constants"
|
||||
|
|
@ -611,13 +611,15 @@ class PostvalidateTheme extends DesugaringStep<ThemeConfigJson> {
|
|||
return json
|
||||
}
|
||||
}
|
||||
export class OrderTheme extends DesugaringStep<ThemeConfigJson> {
|
||||
export class OrderTheme extends Fuse<ThemeConfigJson> {
|
||||
private static readonly themeAttributesOrder: ReadonlyArray<string> = Utils.Dedup(
|
||||
(<ConfigMeta[]>themeconfig).filter((c) => c.path.length === 1).map((c) => c.path[0])
|
||||
)
|
||||
|
||||
constructor() {
|
||||
super("OrderLayer", "Reorders the layer to the default order")
|
||||
super("Reorders the layer to the default order",
|
||||
new On("layers", new Each(new OrderLayer()))
|
||||
)
|
||||
}
|
||||
|
||||
public convert(json: ThemeConfigJson, context: ConversionContext): ThemeConfigJson {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue