-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Enterprise Search] DRY out createHref helper for navigateToUrl calls #78717
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e329ed4
DRY out createHref helper
cee-chen 9bee2e9
KibanaLogic: Update navigateToUrl to use createHref helper
cee-chen a60020b
Update breadcrumbs & eui link helpers w/ new KibanaLogic changes
cee-chen e5f8e15
[Optional?] Update FlashMessages to grab history from KibanaLogic
cee-chen 87578f8
[Misc] Fix failing tests due to react router mock
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
...ins/enterprise_search/public/applications/shared/react_router_helpers/create_href.test.ts
This file contains hidden or 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,19 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { mockHistory } from '../../__mocks__'; | ||
|
|
||
| import { createHref } from './'; | ||
|
|
||
| describe('createHref', () => { | ||
| it('generates a path with the React Router basename included', () => { | ||
| expect(createHref('/test', mockHistory)).toEqual('/app/enterprise_search/test'); | ||
| }); | ||
|
|
||
| it('does not include the basename if shouldNotCreateHref is passed', () => { | ||
| expect(createHref('/test', mockHistory, { shouldNotCreateHref: true })).toEqual('/test'); | ||
| }); | ||
| }); |
27 changes: 27 additions & 0 deletions
27
.../plugins/enterprise_search/public/applications/shared/react_router_helpers/create_href.ts
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { History } from 'history'; | ||
|
|
||
| /** | ||
| * This helper uses React Router's createHref function to generate links with router basenames accounted for. | ||
| * For example, if we perform navigateToUrl('/engines') within App Search, we expect the app basename | ||
| * to be taken into account to be intelligently routed to '/app/enterprise_search/app_search/engines'. | ||
| * | ||
| * This helper accomplishes that, while still giving us an escape hatch for navigation *between* apps. | ||
| * For example, if we want to navigate the user from App Search to Enterprise Search we could | ||
| * navigateToUrl('/app/enterprise_search', { shouldNotCreateHref: true }) | ||
| */ | ||
| export interface ICreateHrefOptions { | ||
| shouldNotCreateHref?: boolean; | ||
| } | ||
| export const createHref = ( | ||
| path: string, | ||
| history: History, | ||
| options?: ICreateHrefOptions | ||
| ): string => { | ||
| return options?.shouldNotCreateHref ? path : history.createHref({ pathname: path }); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not super invested in this change (e5f8e15) and would love to get a confidence check from others if they like DRYing out
props: param.historyor nah. Happy to revert if nah!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.
I like this approach, personally.