forked from MapComplete/MapComplete
Save extra tags
This commit is contained in:
parent
a944a26e9c
commit
f49c64a201
4 changed files with 57 additions and 5 deletions
|
@ -13,14 +13,17 @@
|
|||
* All props for this input helper
|
||||
*/
|
||||
export let value: UIEventSource<string> = new UIEventSource<string>(undefined)
|
||||
// Since we're getting extra tags aside from the standard we need to export them
|
||||
export let extraTags: UIEventSource<Record<string, string>>
|
||||
export let feature: Feature
|
||||
export let tags: UIEventSource<Record<string, string>>
|
||||
export let helperArgs: (string | number | boolean)[]
|
||||
export let key: string
|
||||
|
||||
let maintag = helperArgs[0].toString()
|
||||
let tag = key
|
||||
|
||||
let selectedItem: NSIItem
|
||||
|
||||
const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}`
|
||||
|
||||
// Check if the path exists in the NSI file
|
||||
|
@ -64,6 +67,10 @@
|
|||
/**
|
||||
* Some interfaces for the NSI files
|
||||
*/
|
||||
|
||||
/**
|
||||
* Main name suggestion index file
|
||||
*/
|
||||
interface NSIFile {
|
||||
_meta: {
|
||||
version: string
|
||||
|
@ -95,6 +102,22 @@
|
|||
}
|
||||
fromTemplate?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when an item is selected
|
||||
*/
|
||||
function select(item: NSIItem) {
|
||||
value.setData(item.tags[tag])
|
||||
selectedItem = item
|
||||
// Tranform the object into record<string, string> and remove the tag we're using, as well as the maintag
|
||||
const tags = Object.entries(item.tags).reduce((acc, [key, value]) => {
|
||||
if (key !== tag && key !== maintag.split("=")[0]) {
|
||||
acc[key] = value
|
||||
}
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
extraTags.setData(tags)
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
|
@ -104,7 +127,12 @@
|
|||
<div
|
||||
class="m-1 h-fit rounded-full border border-black p-4 text-center"
|
||||
on:click={() => {
|
||||
value.setData(item.tags[tag])
|
||||
select(item)
|
||||
}}
|
||||
on:keydown={(e) => {
|
||||
if (e.key === "Enter") {
|
||||
select(item)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{item.displayName}
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
export let feature: Feature
|
||||
export let args: (string | number | boolean)[] = undefined
|
||||
export let state: SpecialVisualizationState
|
||||
export let tags: UIEventSource<Record<string, string>>
|
||||
export let helperArgs: (string | number | boolean)[]
|
||||
export let key: string
|
||||
export let extraTags: UIEventSource<Record<string, string>>
|
||||
|
||||
let properties = { feature, args: args ?? [] }
|
||||
</script>
|
||||
|
@ -55,5 +55,5 @@
|
|||
{:else if type === "wikidata"}
|
||||
<ToSvelte construct={() => InputHelpers.constructWikidataHelper(value, properties)} />
|
||||
{:else if type === "nsi"}
|
||||
<NameSuggestionIndexInput {value} {feature} {tags} {helperArgs} {key} />
|
||||
<NameSuggestionIndexInput {value} {feature} {helperArgs} {key} {extraTags} />
|
||||
{/if}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue