Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search in slash command menu #7495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/ui/src/components/SelectPopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +42,7 @@
export let loading: boolean = false

let popupElement: HTMLDivElement | undefined = undefined
let search: string = ''
export let search: string = ''

const dispatch = createEventDispatcher()

Expand Down Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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">
Expand Down
Loading