-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] DRY out createHref helper for navigateToUrl calls (…
…#78717) * DRY out createHref helper - that navigateToUrl will shortly also use + fix mockHistory type complaint * KibanaLogic: Update navigateToUrl to use createHref helper + add param.history value, since we're technically supposed to be using Kibana's passed history over anything from useHistory * Update breadcrumbs & eui link helpers w/ new KibanaLogic changes - navigateToUrl is now double-dipping createHref, so we update it to not do so - remove useHistory in favor of grabbing history from KibanaLogic * [Optional?] Update FlashMessages to grab history from KibanaLogic - since we're now storing it there, we might as well grab it as well instead of passing in props? * [Misc] Fix failing tests due to react router mock
- Loading branch information
Constance
authored
Sep 29, 2020
1 parent
66ad3b4
commit e873848
Showing
15 changed files
with
122 additions
and
39 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
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
...ins/enterprise_search/public/applications/shared/react_router_helpers/create_href.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,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 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 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
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