mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-14 12:25:17 +00:00
UBERF-8629 Use ObjectIdentifier for mentions (#7280)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
81ac18ee8b
commit
066c18cf13
@ -15,12 +15,23 @@
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { SearchResultDoc } from '@hcengineering/core'
|
import { SearchResultDoc } from '@hcengineering/core'
|
||||||
import presentation, { SearchResult, reduceCalls, searchFor, type SearchItem } from '@hcengineering/presentation'
|
import { getResource } from '@hcengineering/platform'
|
||||||
|
import presentation, {
|
||||||
|
SearchResult,
|
||||||
|
getClient,
|
||||||
|
reduceCalls,
|
||||||
|
searchFor,
|
||||||
|
type SearchItem
|
||||||
|
} from '@hcengineering/presentation'
|
||||||
import { Label, ListView, resizeObserver } from '@hcengineering/ui'
|
import { Label, ListView, resizeObserver } from '@hcengineering/ui'
|
||||||
|
import view from '@hcengineering/view'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
export let query: string = ''
|
export let query: string = ''
|
||||||
|
|
||||||
|
const client = getClient()
|
||||||
|
const hierarchy = client.getHierarchy()
|
||||||
|
|
||||||
let items: SearchItem[] = []
|
let items: SearchItem[] = []
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
@ -29,10 +40,21 @@
|
|||||||
let scrollContainer: HTMLElement
|
let scrollContainer: HTMLElement
|
||||||
let selection = 0
|
let selection = 0
|
||||||
|
|
||||||
function dispatchItem (item: SearchResultDoc): void {
|
async function getIdentifier (item: SearchResultDoc): Promise<string | undefined> {
|
||||||
|
const identifierProvider = hierarchy.classHierarchyMixin(item.doc._class, view.mixin.ObjectIdentifier)
|
||||||
|
if (identifierProvider === undefined) {
|
||||||
|
return item.shortTitle ?? item.title
|
||||||
|
}
|
||||||
|
|
||||||
|
const resource = await getResource(identifierProvider.provider)
|
||||||
|
return await resource(client, item.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSelectItem (item: SearchResultDoc): Promise<void> {
|
||||||
|
const identifier = await getIdentifier(item)
|
||||||
dispatch('close', {
|
dispatch('close', {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
label: item.shortTitle ?? item.title,
|
label: identifier,
|
||||||
objectclass: item.doc._class
|
objectclass: item.doc._class
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -58,7 +80,7 @@
|
|||||||
key.stopPropagation()
|
key.stopPropagation()
|
||||||
if (selection < items.length) {
|
if (selection < items.length) {
|
||||||
const searchItem = items[selection]
|
const searchItem = items[selection]
|
||||||
dispatchItem(searchItem.item)
|
void handleSelectItem(searchItem.item)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
@ -102,7 +124,7 @@
|
|||||||
<div
|
<div
|
||||||
class="ap-menuItem withComp h-8"
|
class="ap-menuItem withComp h-8"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dispatchItem(doc)
|
void handleSelectItem(doc)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SearchResult value={doc} />
|
<SearchResult value={doc} />
|
||||||
|
Loading…
Reference in New Issue
Block a user