Skip to content

Commit 3f3c150

Browse files
committed
Fix duplicate null key and expose registerSearchCommand in start contract
Signed-off-by: Lin Wang <[email protected]>
1 parent 29f6c5c commit 3f3c150

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/core/public/chrome/global_search/global_search_service.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ export interface GlobalSearchServiceStartContract {
173173
* ```
174174
*/
175175
getAllSearchCommands$: () => Observable<GlobalSearchCommand[]>;
176+
/**
177+
* Registers a search command that will be executed when users perform searches in the global search bar.
178+
* Each command must have a unique ID and will be invoked based on the search query pattern.
179+
*
180+
* @param searchCommand - The search command to register
181+
* @throws Warning if a command with the same ID already exists
182+
*
183+
* @example
184+
* ```typescript
185+
* chrome.globalSearch.registerSearchCommand({
186+
* id: 'my-search-command',
187+
* type: 'PAGES',
188+
* run: async (query, callback, abortSignal) => {
189+
* // Perform search logic
190+
* return [<SearchResult key="1">Result 1</SearchResult>];
191+
* }
192+
* });
193+
* ```
194+
*/
195+
registerSearchCommand(searchCommand: GlobalSearchCommand): void;
176196
}
177197

178198
/**
@@ -229,6 +249,7 @@ export class GlobalSearchService {
229249
getAllSearchCommands: () => this.searchCommands,
230250
unregisterSearchCommand: this.unregisterSearchCommand.bind(this),
231251
getAllSearchCommands$: () => this.searchCommands$.asObservable(),
252+
registerSearchCommand: this.registerSearchCommand.bind(this),
232253
};
233254
}
234255
}

src/core/public/chrome/ui/header/header_search_bar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const HeaderSearchBar = ({ globalSearchCommands, panel, onSearchResultCli
101101

102102
const resultSection = (items: ReactNode[], sectionHeader: string | undefined) => {
103103
return (
104-
<EuiFlexGroup direction="column" gutterSize="xs">
104+
<EuiFlexGroup direction="column" gutterSize="xs" key={sectionHeader}>
105105
{sectionHeader && (
106106
<EuiFlexItem>
107107
<EuiTitle size="s">

0 commit comments

Comments
 (0)