forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace] Add global search bar into left nav (opensearch-project#8538
) * search bar on left nav Signed-off-by: Hailong Cui <[email protected]> search bar on left nav Signed-off-by: Hailong Cui <[email protected]> compressed input Signed-off-by: Hailong Cui <[email protected]> * support search dev tools Signed-off-by: Hailong Cui <[email protected]> * enable devtools search only if new home is enabled Signed-off-by: Hailong Cui <[email protected]> * add unit test Signed-off-by: Hailong Cui <[email protected]> add more unit test Signed-off-by: Hailong Cui <[email protected]> * Changeset file for PR opensearch-project#8538 created/updated * fix incorrect variable name Signed-off-by: Hailong Cui <[email protected]> * dismiss tooltip when close popover Signed-off-by: Hailong Cui <[email protected]> * style adjustment Signed-off-by: Hailong Cui <[email protected]> * address review comments Signed-off-by: Hailong Cui <[email protected]> * rename search stategy to searchHandler Signed-off-by: Hailong Cui <[email protected]> * rename to searchCommand Signed-off-by: Hailong Cui <[email protected]> * exclude parent pages Signed-off-by: Hailong Cui <[email protected]> * remove duplicate return Signed-off-by: Hailong Cui <[email protected]> * address review comments Signed-off-by: Hailong Cui <[email protected]> * wording change for strategy Signed-off-by: Hailong Cui <[email protected]> * add icon for data adminstration & settings Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
- Loading branch information
Showing
31 changed files
with
1,698 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Workspace] Add global search bar into left nav ([#8538](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8538)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/core/public/chrome/global_search/global_search_service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// test global_search_service.ts | ||
import { GlobalSearchService } from './global_search_service'; | ||
|
||
describe('GlobalSearchService', () => { | ||
it('registerSearchCommand', async () => { | ||
const globalSearchService = new GlobalSearchService(); | ||
const setup = globalSearchService.setup(); | ||
const start = globalSearchService.start(); | ||
|
||
setup.registerSearchCommand({ | ||
id: 'test1', | ||
type: 'PAGES', | ||
run: async (query) => { | ||
return []; | ||
}, | ||
}); | ||
|
||
expect(start.getAllSearchCommands()).toHaveLength(1); | ||
expect(start.getAllSearchCommands()[0].id).toEqual('test1'); | ||
expect(start.getAllSearchCommands()[0].type).toEqual('PAGES'); | ||
}); | ||
|
||
it('registerSearchCommand with duplicate id', async () => { | ||
const globalSearchService = new GlobalSearchService(); | ||
const setup = globalSearchService.setup(); | ||
const start = globalSearchService.start(); | ||
|
||
setup.registerSearchCommand({ | ||
id: 'test2', | ||
type: 'PAGES', | ||
run: async (query) => { | ||
return []; | ||
}, | ||
}); | ||
|
||
setup.registerSearchCommand({ | ||
id: 'test2', | ||
type: 'SAVED_OBJECTS', | ||
run: async (query) => { | ||
return []; | ||
}, | ||
}); | ||
|
||
// the second one will not overwrite the first one | ||
expect(start.getAllSearchCommands()).toHaveLength(1); | ||
expect(start.getAllSearchCommands()[0].id).toEqual('test2'); | ||
expect(start.getAllSearchCommands()[0].type).toEqual('PAGES'); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
src/core/public/chrome/global_search/global_search_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ReactNode } from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
|
||
/** | ||
* search input match with `@` will handled by saved objects search command | ||
* search input match with `>` will handled by plugin customized commands | ||
*/ | ||
export const SAVED_OBJECTS_SYMBOL = '@'; | ||
export const COMMANDS_SYMBOL = '>'; | ||
|
||
export const SearchCommandTypes = { | ||
PAGES: { | ||
description: i18n.translate('core.globalSearch.pages.description', { defaultMessage: 'Pages' }), | ||
alias: null, | ||
}, | ||
SAVED_OBJECTS: { | ||
description: i18n.translate('core.globalSearch.assets.description', { | ||
defaultMessage: 'Assets', | ||
}), | ||
alias: SAVED_OBJECTS_SYMBOL, | ||
}, | ||
} as const; | ||
|
||
export type SearchCommandKeyTypes = keyof typeof SearchCommandTypes; | ||
|
||
/** | ||
* @experimental | ||
*/ | ||
export interface GlobalSearchCommand { | ||
/** | ||
* unique id of this command | ||
*/ | ||
id: string; | ||
/** | ||
* search command type | ||
* @type {SearchCommandTypes} | ||
*/ | ||
type: SearchCommandKeyTypes; | ||
/** | ||
* do the search and return search result with a React element | ||
* @param value search query | ||
* @param callback callback function when search is done | ||
*/ | ||
run(value: string, callback?: () => void): Promise<ReactNode[]>; | ||
} | ||
|
||
export interface GlobalSearchServiceSetupContract { | ||
registerSearchCommand(searchCommand: GlobalSearchCommand): void; | ||
} | ||
|
||
export interface GlobalSearchServiceStartContract { | ||
getAllSearchCommands(): GlobalSearchCommand[]; | ||
} | ||
|
||
/** | ||
* {@link GlobalSearchCommand | APIs} for registering new global search command when do search from header search bar . | ||
* | ||
* @example | ||
* Register a GlobalSearchCommand to search pages | ||
* ```jsx | ||
* chrome.globalSearch.registerSearchCommand({ | ||
* id: 'test', | ||
* type: SearchObjectTypes.PAGES, | ||
* run: async (query) => { | ||
* return []; | ||
* }, | ||
* }) | ||
* ``` | ||
* | ||
* @experimental | ||
*/ | ||
export class GlobalSearchService { | ||
private searchCommands = [] as GlobalSearchCommand[]; | ||
|
||
private registerSearchCommand(searchHandler: GlobalSearchCommand) { | ||
const exists = this.searchCommands.find((item) => { | ||
return item.id === searchHandler.id; | ||
}); | ||
if (exists) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Duplicate SearchCommands id ${searchHandler.id} found`); | ||
return; | ||
} | ||
this.searchCommands.push(searchHandler); | ||
} | ||
|
||
public setup(): GlobalSearchServiceSetupContract { | ||
return { | ||
registerSearchCommand: this.registerSearchCommand.bind(this), | ||
}; | ||
} | ||
|
||
public start(): GlobalSearchServiceStartContract { | ||
return { | ||
getAllSearchCommands: () => this.searchCommands, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './global_search_service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/core/public/chrome/ui/header/__snapshots__/collapsible_nav_group_enabled.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.