From 7fb97478e9cb59816f92bb48c185484f67122e3f Mon Sep 17 00:00:00 2001 From: Maxim Karmatskikh Date: Tue, 28 Nov 2023 22:06:43 +0100 Subject: [PATCH] UBERF-4446: Move search from text editor Signed-off-by: Maxim Karmatskikh --- .../src/components/SearchResult.svelte} | 0 packages/presentation/src/index.ts | 2 + .../src/search.ts | 39 +++++++++++++---- .../src/components/MentionList.svelte | 7 ++- .../src/components/MentionPopup.svelte | 34 ++------------- packages/text-editor/src/index.ts | 2 - .../src/components/ActionsPopup.svelte | 43 ++++--------------- 7 files changed, 51 insertions(+), 76 deletions(-) rename packages/{text-editor/src/components/MentionResult.svelte => presentation/src/components/SearchResult.svelte} (100%) rename packages/{text-editor => presentation}/src/search.ts (67%) diff --git a/packages/text-editor/src/components/MentionResult.svelte b/packages/presentation/src/components/SearchResult.svelte similarity index 100% rename from packages/text-editor/src/components/MentionResult.svelte rename to packages/presentation/src/components/SearchResult.svelte diff --git a/packages/presentation/src/index.ts b/packages/presentation/src/index.ts index e734f22b87..d64c38cb73 100644 --- a/packages/presentation/src/index.ts +++ b/packages/presentation/src/index.ts @@ -43,6 +43,7 @@ export { default as Breadcrumbs } from './components/breadcrumbs/Breadcrumbs.sve export { default as BreadcrumbsElement } from './components/breadcrumbs/BreadcrumbsElement.svelte' export { default as ComponentExtensions } from './components/extensions/ComponentExtensions.svelte' export { default as DocCreateExtComponent } from './components/extensions/DocCreateExtComponent.svelte' +export { default as SearchResult } from './components/SearchResult.svelte' export { default } from './plugin' export * from './types' export * from './utils' @@ -53,3 +54,4 @@ export * from './context' export * from './pipeline' export * from './components/extensions/manager' export * from './rules' +export * from './search' diff --git a/packages/text-editor/src/search.ts b/packages/presentation/src/search.ts similarity index 67% rename from packages/text-editor/src/search.ts rename to packages/presentation/src/search.ts index 7a8fec54db..9ae6ea7f37 100644 --- a/packages/text-editor/src/search.ts +++ b/packages/presentation/src/search.ts @@ -14,12 +14,11 @@ // import type { Class, Ref, Doc, SearchResultDoc, TxOperations } from '@hcengineering/core' -import { type ObjectSearchCategory } from '@hcengineering/presentation' +import { type ObjectSearchCategory } from './types' +import plugin from './plugin' +import { getClient } from './utils' -/** - * @public - */ -export interface SearchSection { +interface SearchSection { category: ObjectSearchCategory items: SearchResultDoc[] } @@ -33,7 +32,7 @@ export interface SearchItem { category: ObjectSearchCategory } -export function findCategoryByClass ( +function findCategoryByClass ( categories: ObjectSearchCategory[], _class: Ref> ): ObjectSearchCategory | undefined { @@ -45,7 +44,7 @@ export function findCategoryByClass ( return undefined } -export function packSearchResultsForListView (sections: SearchSection[]): SearchItem[] { +function packSearchResultsForListView (sections: SearchSection[]): SearchItem[] { let results: SearchItem[] = [] for (const section of sections) { const category = section.category @@ -62,7 +61,7 @@ export function packSearchResultsForListView (sections: SearchSection[]): Search return results } -export async function doFulltextSearch ( +async function doFulltextSearch ( client: TxOperations, classes: Array>>, query: string, @@ -98,3 +97,27 @@ export async function doFulltextSearch ( return sections } + +const categoriesByContext = new Map() + +export async function searchFor (context: 'mention' | 'spotlight', query: string): Promise { + const client = getClient() + let categories + if (categoriesByContext.get(context) === undefined) { + categories = await client.findAll(plugin.class.ObjectSearchCategory, { context }) + categoriesByContext.set(context, categories) + } + if (categories === undefined) { + return [] + } + + const classesToSearch: Array>> = [] + for (const cat of categories) { + if (cat.classToSearch !== undefined) { + classesToSearch.push(cat.classToSearch) + } + } + + const sections = await doFulltextSearch(client, classesToSearch, query, categories) + return packSearchResultsForListView(sections) +} diff --git a/packages/text-editor/src/components/MentionList.svelte b/packages/text-editor/src/components/MentionList.svelte index d4aea65ab2..fe35c43b40 100644 --- a/packages/text-editor/src/components/MentionList.svelte +++ b/packages/text-editor/src/components/MentionList.svelte @@ -59,7 +59,7 @@ return searchPopup?.onKeyDown(ev) } - export function done () {} + export function done (): void {} function updateStyle (): void { const rect = clientRect() @@ -84,7 +84,10 @@ } let style = 'visibility: hidden' - $: if (popup) updateStyle() + $: if (popup !== undefined && popup !== null) { + updateStyle() + } + let wPopup: number = 0 diff --git a/packages/text-editor/src/components/MentionPopup.svelte b/packages/text-editor/src/components/MentionPopup.svelte index ed492febe9..a353e36744 100644 --- a/packages/text-editor/src/components/MentionPopup.svelte +++ b/packages/text-editor/src/components/MentionPopup.svelte @@ -16,30 +16,12 @@ @@ -128,7 +102,7 @@ dispatchItem(doc) }} > - + diff --git a/packages/text-editor/src/index.ts b/packages/text-editor/src/index.ts index 60fb38a1a2..8f54323c9c 100644 --- a/packages/text-editor/src/index.ts +++ b/packages/text-editor/src/index.ts @@ -32,12 +32,10 @@ export { default as TextEditor } from './components/TextEditor.svelte' export { default as TextEditorStyleToolbar } from './components/TextEditorStyleToolbar.svelte' export { default as AttachIcon } from './components/icons/Attach.svelte' export { default as TableOfContents } from './components/toc/TableOfContents.svelte' -export { default as MentionResult } from './components/MentionResult.svelte' export * from './components/node-view' export { default } from './plugin' export * from './types' export * from './utils' -export * from './search' export { FocusExtension, type FocusOptions, type FocusStorage } from './components/extension/focus' export { HeadingsExtension, type HeadingsOptions, type HeadingsStorage } from './components/extension/headings' diff --git a/plugins/view-resources/src/components/ActionsPopup.svelte b/plugins/view-resources/src/components/ActionsPopup.svelte index 3504f85527..05af2e5304 100644 --- a/plugins/view-resources/src/components/ActionsPopup.svelte +++ b/plugins/view-resources/src/components/ActionsPopup.svelte @@ -13,13 +13,16 @@ // limitations under the License. -->