mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-21 07:46:24 +00:00
Fix search in slash command menu (#7495)
Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
parent
617f48c2fd
commit
5933f16f95
@ -26,6 +26,8 @@
|
|||||||
import Spinner from './Spinner.svelte'
|
import Spinner from './Spinner.svelte'
|
||||||
import IconCheck from './icons/Check.svelte'
|
import IconCheck from './icons/Check.svelte'
|
||||||
import IconSearch from './icons/Search.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 placeholder: IntlString | undefined = undefined
|
||||||
export let placeholderParam: any | undefined = undefined
|
export let placeholderParam: any | undefined = undefined
|
||||||
@ -40,7 +42,7 @@
|
|||||||
export let loading: boolean = false
|
export let loading: boolean = false
|
||||||
|
|
||||||
let popupElement: HTMLDivElement | undefined = undefined
|
let popupElement: HTMLDivElement | undefined = undefined
|
||||||
let search: string = ''
|
export let search: string = ''
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
@ -82,14 +84,33 @@
|
|||||||
if (key.code === 'Enter') {
|
if (key.code === 'Enter') {
|
||||||
key.preventDefault()
|
key.preventDefault()
|
||||||
key.stopPropagation()
|
key.stopPropagation()
|
||||||
sendSelect(value[selection].id)
|
sendSelect(filteredObjects[selection].id)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const manager = createFocusManager()
|
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'
|
$: huge = size === 'medium' || size === 'large'
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
export let clientRect: () => ClientRect
|
export let clientRect: () => ClientRect
|
||||||
export let command: (props: any) => void
|
export let command: (props: any) => void
|
||||||
export let close: () => void
|
export let close: () => void
|
||||||
|
export let query: string = ''
|
||||||
|
|
||||||
let popup: HTMLDivElement
|
let popup: HTMLDivElement
|
||||||
let dummyPopup: PopupResult
|
let dummyPopup: PopupResult
|
||||||
@ -113,7 +114,7 @@
|
|||||||
updateStyle()
|
updateStyle()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SelectPopup bind:this={menuPopup} value={items} onSelect={handleSelected} />
|
<SelectPopup bind:this={menuPopup} search={query} value={items} onSelect={handleSelected} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
Loading…
Reference in New Issue
Block a user