Add option that a TagRendering can automatically introduce a builtin filter when added

This commit is contained in:
Pieter Vander Vennet 2024-07-18 15:35:56 +02:00
parent f33e9f78b7
commit 5bd14c64da
10 changed files with 54 additions and 16 deletions

View file

@ -613,7 +613,6 @@
}
],
"filter": [
"open_now",
{
"id": "speech_output",
"options": [

View file

@ -893,7 +893,6 @@
"description"
],
"filter": [
"open_now",
{
"id": "sells_second-hand",
"options": [

View file

@ -435,7 +435,6 @@
"check_date"
],
"filter": [
"open_now",
"accepts_debit_cards",
"accepts_credit_cards"
],

View file

@ -1304,10 +1304,10 @@
}
]
},
"has_organic",
"sugar_free",
"gluten_free",
"lactose_free",
"filters.has_organic",
"filters.sugar_free",
"filters.gluten_free",
"filters.lactose_free",
"accepts_cash",
"accepts_cards",
"dogs"

View file

@ -663,9 +663,6 @@
}
]
},
"accepts_cash",
"accepts_cards",
"has_organic",
{
"id": "second_hand",
"options": [
@ -686,9 +683,7 @@
}
]
},
"sugar_free",
"gluten_free",
"lactose_free"
"filters.has_organic"
],
"deletion": {
"softDeletionTags": {

View file

@ -236,8 +236,11 @@ export class GenerateFavouritesLayer extends Script {
if (seenTitleIcons.has(titleIcon.id)) {
continue
}
if(titleIcon.id === undefined){
continue
}
seenTitleIcons.add(titleIcon.id)
console.log("Adding ", titleIcon.id)
console.log("Adding title icon", titleIcon.id)
titleIcons.push(titleIcon)
}
}

View file

@ -332,6 +332,7 @@ class LayerOverviewUtils extends Script {
return <QuestionableTagRenderingConfigJson[]>sharedQuestions.tagRenderings
}
return this.getSharedTagRenderings(
doesImageExist,
dict,

View file

@ -62,8 +62,37 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
const newFilters: FilterConfigJson[] = []
const filters = <(FilterConfigJson | string)[]>json.filter
for (let i = 0; i < json.tagRenderings?.length; i++){
const tagRendering = <TagRenderingConfigJson> json.tagRenderings[i]
if(!tagRendering.filter){
continue
}
for (const filterName of tagRendering.filter ?? []) {
if(typeof filterName !== "string"){
context.enters("tagRenderings",i,"filter").err("Not a string: "+ filterName)
}
const exists = filters.some(existing => {
const id : string = existing["id"] ?? existing
return filterName === id || (filterName.startsWith("filters.") && filterName.endsWith("."+id))
})
if(exists){
continue
}
if(!filterName){
context.err("Got undefined as filter expansion in "+tagRendering["id"])
continue
}
console.log("Adding filter",filterName," due to", tagRendering["id"])
filters.push(filterName)
}
}
for (let i = 0; i < filters.length; i++) {
const filter = filters[i]
if(filter === undefined){
continue
}
if (typeof filter !== "string") {
newFilters.push(filter)
continue
@ -85,7 +114,7 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
osmTags: mapping.if,
}))
options.unshift({
question: {
question: matchingTr["question"] ?? {
en: "All types",
},
osmTags: undefined,
@ -113,7 +142,11 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
const expandedFilter = (<(FilterConfigJson | string)[]>layer.filter).find(
(f) => typeof f !== "string" && f.id === expectedId
)
newFilters.push(<FilterConfigJson>expandedFilter)
if(expandedFilter === undefined){
context.err("Did not find filter with name "+filter)
}else{
newFilters.push(<FilterConfigJson>expandedFilter)
}
} else {
// This is a bootstrapping-run, we can safely ignore this
}

View file

@ -1761,6 +1761,10 @@ export class ValidateFilter extends DesugaringStep<FilterConfigJson> {
// Calling another filter, we skip
return filter
}
if(filter === undefined){
context.err("Trying to validate a filter, but this filter is undefined")
return undefined
}
for (const option of filter.options) {
for (let i = 0; i < option.fields?.length ?? 0; i++) {
const field = option.fields[i]

View file

@ -222,4 +222,9 @@ export interface TagRenderingConfigJson {
* Values are split on ` ` (space)
*/
classes?: string
/**
* This tagRendering can introduce this builtin filter
*/
filter?: string[]
}