UX: styling, fix import, hide brands immediately, sort brands by frequency, see #2071

This commit is contained in:
Pieter Vander Vennet 2024-08-09 14:43:30 +02:00
parent 6c6f988f3c
commit a70dbf0043
3 changed files with 24 additions and 12 deletions

View file

@ -142,9 +142,15 @@ export default class NameSuggestionIndex {
type: string,
tags: Record<string, string>,
country: string[],
location?: [number, number]
location?: [number, number],
options?:{
/**
* If set, sort by frequency instead of alphabetically
*/
sortByFrequency: boolean
}
): Promise<Mapping[]> {
const mappings: Mapping[] = []
const mappings: (Mapping & {frequency: number})[] = []
const frequencies = await NameSuggestionIndex.fetchFrequenciesFor(type, country)
for (const key in tags) {
if (key.startsWith("_")) {
@ -180,7 +186,7 @@ export default class NameSuggestionIndex {
addExtraTags: Object.keys(tags)
.filter((k) => k !== type)
.map((k) => new Tag(k, tags[k])),
then: new TypedTranslation<Record<string, never>>({ "*": nsiItem.displayName }),
then: new TypedTranslation<Record<string, never>>({ "*": nsiItem.displayName +" "+(frequency) }),
hideInAnswer: false,
ifnot: undefined,
alsoShowIf: undefined,
@ -190,9 +196,14 @@ export default class NameSuggestionIndex {
// As such, it should be "true" but this is not supported
priorityIf: frequency > 0 ? new RegexTag("id", /.*/) : undefined,
searchTerms: { "*": [nsiItem.displayName, nsiItem.id] },
frequency: frequency ?? -1
})
}
}
if(options?.sortByFrequency){
mappings.sort((a, b) => b.frequency - a.frequency)
}
return mappings
}