UBERF-4348: Mentions. Fix render props types and component props types (#4022)

Signed-off-by: Maxim Karmatskikh <mkarmatskih@gmail.com>
This commit is contained in:
Maksim Karmatskikh 2023-11-21 04:32:49 +01:00 committed by GitHub
parent 273f3de0a3
commit d36dcdc7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -38,10 +38,15 @@
const client = getClient()
client.findAll(presentation.class.ObjectSearchCategory, { context: 'mention' }).then(async (results) => {
categories = results
updateItems(query)
})
client
.findAll(presentation.class.ObjectSearchCategory, { context: 'mention' })
.then(async (results) => {
categories = results
await updateItems(query)
})
.catch((e) => {
console.error(e)
})
const dispatch = createEventDispatcher()
@ -76,8 +81,8 @@
if (key.key === 'Enter' || key.key === 'Tab') {
key.preventDefault()
key.stopPropagation()
const searchItem = items[selection]
if (searchItem) {
if (selection < items.length) {
const searchItem = items[selection]
dispatchItem(searchItem.item)
return true
} else {
@ -87,8 +92,6 @@
return false
}
export function done () {}
function packSearchResultsForListView (sections: SearchSection[]): SearchItem[] {
let results: SearchItem[] = []
for (const section of sections) {
@ -161,10 +164,11 @@
const sections = await doFulltextSearch(classesToSearch, query)
items = packSearchResultsForListView(sections)
}
$: updateItems(query)
$: void updateItems(query)
</script>
{#if (items.length === 0 && query !== '') || items.length > 0}
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<form class="antiPopup mentionPoup" on:keydown={onKeyDown} use:resizeObserver={() => dispatch('changeSize')}>
<div class="ap-scroll" bind:this={scrollContainer}>
<div class="ap-box">
@ -185,6 +189,7 @@
<svelte:fragment slot="item" let:item={num}>
{@const item = items[num]}
{@const doc = item.item}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="ap-menuItem withComp"
on:click={() => {

View File

@ -34,15 +34,15 @@ function createIndexedReader (
}
}
function readAndMapProps (reader: IndexedReader, props: ClassSearchConfigProps[]): Record<string, string> {
const res: Record<string, string> = {}
function readAndMapProps (reader: IndexedReader, props: ClassSearchConfigProps[]): Record<string, any> {
const res: Record<string, any> = {}
for (const prop of props) {
if (typeof prop === 'string') {
res[prop] = reader.get(prop)
} else {
for (const [propName, rest] of Object.entries(prop)) {
if (rest.length > 1) {
const val = reader.getDoc(rest[0])?.get(rest[1]) ?? ''
const val = reader.getDoc(rest[0])?.get(rest[1])
res[propName] = Array.isArray(val) ? val[0] : val
}
}
@ -135,6 +135,6 @@ export function mapSearchResultDoc (hierarchy: Hierarchy, raw: IndexedDoc): Sear
return doc
}
function fillTemplate (tmpl: string, props: Record<string, string>): string {
function fillTemplate (tmpl: string, props: Record<string, any>): string {
return tmpl.replace(/{(.*?)}/g, (_, key: string) => props[key])
}