Fix search in slash command menu (#7495)

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko 2024-12-18 07:32:30 +03:00 committed by GitHub
parent 617f48c2fd
commit 5933f16f95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 4 deletions

View File

@ -26,6 +26,8 @@
import Spinner from './Spinner.svelte'
import IconCheck from './icons/Check.svelte'
import IconSearch from './icons/Search.svelte'
import { translate } from '@hcengineering/platform'
import { themeStore } from '@hcengineering/theme'
export let placeholder: IntlString | undefined = undefined
export let placeholderParam: any | undefined = undefined
@ -40,7 +42,7 @@
export let loading: boolean = false
let popupElement: HTMLDivElement | undefined = undefined
let search: string = ''
export let search: string = ''
const dispatch = createEventDispatcher()
@ -82,14 +84,33 @@
if (key.code === 'Enter') {
key.preventDefault()
key.stopPropagation()
sendSelect(value[selection].id)
sendSelect(filteredObjects[selection].id)
return true
}
return false
}
const manager = createFocusManager()
$: filteredObjects = value.filter((el) => (el.label ?? el.text ?? '').toLowerCase().includes(search.toLowerCase()))
let itemLabelsTranslation: Map<string, string> = new Map<string, string>()
async function translateLabels (values: SelectPopupValueType[]): Promise<void> {
const translateValue: (value: SelectPopupValueType) => Promise<[string, string] | null> = async (e) => {
if (e.label === undefined) {
return null
}
const text = await translate(e.label, {}, $themeStore.language)
return [e.label, text]
}
const promises = values.map(translateValue)
const result: Array<readonly [string, string] | null> = await Promise.all(promises)
itemLabelsTranslation = new Map(result.filter((r) => r !== null) as Array<readonly [string, string]>)
}
$: void translateLabels(value)
$: filteredObjects = value.filter((el) =>
(itemLabelsTranslation.get(el.label ?? '') ?? el.text ?? '').toLowerCase().includes(search.toLowerCase())
)
$: huge = size === 'medium' || size === 'large'

View File

@ -28,6 +28,7 @@
export let clientRect: () => ClientRect
export let command: (props: any) => void
export let close: () => void
export let query: string = ''
let popup: HTMLDivElement
let dummyPopup: PopupResult
@ -113,7 +114,7 @@
updateStyle()
}}
>
<SelectPopup bind:this={menuPopup} value={items} onSelect={handleSelected} />
<SelectPopup bind:this={menuPopup} search={query} value={items} onSelect={handleSelected} />
</div>
<style lang="scss">