- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Add assets search and enhance search commands #10789
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
Changes from 6 commits
07a4eb2
              d568629
              60ad2c0
              51f61f4
              1755080
              cbaf782
              fd01ac3
              d03d019
              e0b8256
              bfa81b6
              8e24098
              831d01d
              a08aa38
              034c3e0
              9b6c95a
              29f6c5c
              3f3c150
              eb35ebb
              5ea9be3
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| feat: | ||
| - Add assets search command to find dashboards and visualizations from global search ([#10789](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10789)) | ||
| - Add search submit commands for Enter-key triggered actions in global search ([#10789](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10789)) | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -5,6 +5,7 @@ | |
|  | ||
| import { ReactNode } from 'react'; | ||
| import { i18n } from '@osd/i18n'; | ||
| import { BehaviorSubject, Observable } from 'rxjs'; | ||
|  | ||
| /** | ||
| * search input match with `@` will handled by saved objects search command | ||
|  | @@ -46,16 +47,28 @@ export interface GlobalSearchCommand { | |
| * @param value search query | ||
| * @param callback callback function when search is done | ||
| */ | ||
| run(value: string, callback?: () => void): Promise<ReactNode[]>; | ||
| run(value: string, callback?: () => void, abortSignal?: AbortSignal): Promise<ReactNode[]>; | ||
| } | ||
|  | ||
| /** | ||
| * @experimental | ||
| */ | ||
| export interface GlobalSearchSubmitCommand { | ||
|          | ||
| id: string; | ||
| name: string; | ||
| run: (payload: { content: string }) => void; | ||
| } | ||
|  | ||
| export interface GlobalSearchServiceSetupContract { | ||
| registerSearchCommand(searchCommand: GlobalSearchCommand): void; | ||
| registerSearchSubmitCommand(searchResultCommand: GlobalSearchSubmitCommand): void; | ||
|          | ||
| } | ||
|  | ||
| export interface GlobalSearchServiceStartContract { | ||
| getAllSearchCommands(): GlobalSearchCommand[]; | ||
| unregisterSearchCommand(id: string): void; | ||
| unregisterSearchSubmitCommand(id: string): void; | ||
| getSearchSubmitCommands$: () => Observable<GlobalSearchSubmitCommand[]>; | ||
| } | ||
|  | ||
| /** | ||
|  | @@ -76,7 +89,8 @@ export interface GlobalSearchServiceStartContract { | |
| * @experimental | ||
| */ | ||
| export class GlobalSearchService { | ||
| private searchCommands = [] as GlobalSearchCommand[]; | ||
| private searchCommands: GlobalSearchCommand[] = []; | ||
| private searchSubmitCommands$ = new BehaviorSubject<GlobalSearchSubmitCommand[]>([]); | ||
|  | ||
| private registerSearchCommand(searchHandler: GlobalSearchCommand) { | ||
| const exists = this.searchCommands.find((item) => { | ||
|  | @@ -96,16 +110,39 @@ export class GlobalSearchService { | |
| }); | ||
| } | ||
|  | ||
| private registerSearchSubmitCommand = (searchSubmitCommand: GlobalSearchSubmitCommand) => { | ||
| const commands = this.searchSubmitCommands$.getValue(); | ||
| if (commands.find((command) => command.id === searchSubmitCommand.id)) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(`Duplicate SearchSubmitCommands id ${searchSubmitCommand.id} found`); | ||
| return; | ||
| } | ||
| this.searchSubmitCommands$.next([...commands, searchSubmitCommand]); | ||
| }; | ||
|  | ||
| private unregisterSearchSubmitCommand(id: string) { | ||
| const newCommands = this.searchSubmitCommands$.getValue().filter((item) => { | ||
| return item.id !== id; | ||
| }); | ||
| if (newCommands.length === this.searchSubmitCommands$.getValue().length) { | ||
| return; | ||
| } | ||
| this.searchSubmitCommands$.next(newCommands); | ||
| } | ||
|  | ||
| public setup(): GlobalSearchServiceSetupContract { | ||
| return { | ||
| registerSearchCommand: this.registerSearchCommand.bind(this), | ||
| registerSearchSubmitCommand: this.registerSearchSubmitCommand, | ||
|          | ||
| }; | ||
| } | ||
|  | ||
| public start(): GlobalSearchServiceStartContract { | ||
| return { | ||
| getAllSearchCommands: () => this.searchCommands, | ||
| getSearchSubmitCommands$: () => this.searchSubmitCommands$.asObservable(), | ||
| unregisterSearchCommand: this.unregisterSearchCommand.bind(this), | ||
| unregisterSearchSubmitCommand: this.unregisterSearchSubmitCommand.bind(this), | ||
| }; | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the function interface for better extensibility? in case there will be more context we will need to pass in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. I'm prefer to keep
value: stringandcallback?: () => voidas the old implementation. Since I don't want to change the navigation search implementation. The newabortSignalcan be wrapped with options. What do you think about it?