-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
add replace
option to navigateToApp
API
#68700
Changes from 1 commit
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,22 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [NavigateToAppOptions](./kibana-plugin-core-public.navigatetoappoptions.md) | ||
|
||
## NavigateToAppOptions interface | ||
|
||
Options for the [navigateToApp API](./kibana-plugin-core-public.applicationstart.navigatetoapp.md) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface NavigateToAppOptions | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| [path](./kibana-plugin-core-public.navigatetoappoptions.path.md) | <code>string</code> | optional path inside application to deep link to. If undefined, will use [the app's default path](./kibana-plugin-core-public.appbase.defaultpath.md)<!-- -->\` as default. | | ||
| [replace](./kibana-plugin-core-public.navigatetoappoptions.replace.md) | <code>boolean</code> | if true, will not create a new history entry when navigating (using <code>replace</code> instead of <code>push</code>) | | ||
| [state](./kibana-plugin-core-public.navigatetoappoptions.state.md) | <code>any</code> | optional state to forward to the application | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [NavigateToAppOptions](./kibana-plugin-core-public.navigatetoappoptions.md) > [path](./kibana-plugin-core-public.navigatetoappoptions.path.md) | ||
|
||
## NavigateToAppOptions.path property | ||
|
||
optional path inside application to deep link to. If undefined, will use [the app's default path](./kibana-plugin-core-public.appbase.defaultpath.md)<!-- -->\` as default. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
path?: string; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [NavigateToAppOptions](./kibana-plugin-core-public.navigatetoappoptions.md) > [replace](./kibana-plugin-core-public.navigatetoappoptions.replace.md) | ||
|
||
## NavigateToAppOptions.replace property | ||
|
||
if true, will not create a new history entry when navigating (using `replace` instead of `push`<!-- -->) | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
replace?: boolean; | ||
``` | ||
|
||
## Remarks | ||
|
||
This option not be used when navigating from and/or to legacy applications. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [NavigateToAppOptions](./kibana-plugin-core-public.navigatetoappoptions.md) > [state](./kibana-plugin-core-public.navigatetoappoptions.state.md) | ||
|
||
## NavigateToAppOptions.state property | ||
|
||
optional state to forward to the application | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
state?: any; | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -924,6 +924,63 @@ describe('#start()', () => { | |
await navigateToApp('baseApp:legacyApp1'); | ||
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/baseApp'); | ||
}); | ||
|
||
describe('when `replace` option is true', () => { | ||
it('use `history.replace` instead of `history.push`', async () => { | ||
service.setup(setupDeps); | ||
|
||
const { navigateToApp } = await service.start(startDeps); | ||
|
||
await navigateToApp('myTestApp', { replace: true }); | ||
Comment on lines
+932
to
+937
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only reproduced/added a subset of the |
||
expect(MockHistory.replace).toHaveBeenCalledWith('/app/myTestApp', undefined); | ||
|
||
await navigateToApp('myOtherApp', { replace: true }); | ||
expect(MockHistory.replace).toHaveBeenCalledWith('/app/myOtherApp', undefined); | ||
}); | ||
|
||
it('includes state if specified', async () => { | ||
const { register } = service.setup(setupDeps); | ||
|
||
register(Symbol(), createApp({ id: 'app2', appRoute: '/custom/path' })); | ||
|
||
const { navigateToApp } = await service.start(startDeps); | ||
|
||
await navigateToApp('myTestApp', { state: 'my-state', replace: true }); | ||
expect(MockHistory.replace).toHaveBeenCalledWith('/app/myTestApp', 'my-state'); | ||
|
||
await navigateToApp('app2', { state: 'my-state', replace: true }); | ||
expect(MockHistory.replace).toHaveBeenCalledWith('/custom/path', 'my-state'); | ||
}); | ||
it('appends a path if specified', async () => { | ||
const { register } = service.setup(setupDeps); | ||
|
||
register(Symbol(), createApp({ id: 'app2', appRoute: '/custom/path' })); | ||
|
||
const { navigateToApp } = await service.start(startDeps); | ||
|
||
await navigateToApp('myTestApp', { path: 'deep/link/to/location/2', replace: true }); | ||
expect(MockHistory.replace).toHaveBeenCalledWith( | ||
'/app/myTestApp/deep/link/to/location/2', | ||
undefined | ||
); | ||
|
||
await navigateToApp('app2', { path: 'deep/link/to/location/2', replace: true }); | ||
expect(MockHistory.replace).toHaveBeenCalledWith( | ||
'/custom/path/deep/link/to/location/2', | ||
undefined | ||
); | ||
}); | ||
it('do not change the behavior when in legacy mode', async () => { | ||
setupDeps.http = httpServiceMock.createSetupContract({ basePath: '/test' }); | ||
setupDeps.injectedMetadata.getLegacyMode.mockReturnValue(true); | ||
service.setup(setupDeps); | ||
|
||
const { navigateToApp } = await service.start(startDeps); | ||
|
||
await navigateToApp('alpha', { replace: true }); | ||
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/alpha'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('navigateToUrl', () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -661,6 +661,28 @@ export interface InternalApplicationSetup extends Pick<ApplicationSetup, 'regist | |
): void; | ||
} | ||
|
||
/** | ||
* Options for the {@link ApplicationStart.navigateToApp | navigateToApp API} | ||
*/ | ||
export interface NavigateToAppOptions { | ||
/** | ||
* optional path inside application to deep link to. | ||
* If undefined, will use {@link AppBase.defaultPath | the app's default path}` as default. | ||
Comment on lines
+667
to
+670
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted the options type, as the inline definition was starting to be too big imho. |
||
*/ | ||
path?: string; | ||
/** | ||
* optional state to forward to the application | ||
*/ | ||
state?: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: shouldn't it be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* if true, will not create a new history entry when navigating (using `replace` instead of `push`) | ||
* | ||
* @remarks | ||
* This option not be used when navigating from and/or to legacy applications. | ||
*/ | ||
replace?: boolean; | ||
Comment on lines
+677
to
+683
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flash1293 as discussed on slack, I only implemented this option for KP apps. (KP to KP navigation). Can you confirm that it's alright? |
||
} | ||
|
||
/** @public */ | ||
export interface ApplicationStart { | ||
/** | ||
|
@@ -681,11 +703,9 @@ export interface ApplicationStart { | |
* Navigate to a given app | ||
* | ||
* @param appId | ||
* @param options.path - optional path inside application to deep link to. | ||
* If undefined, will use {@link AppBase.defaultPath | the app's default path}` as default. | ||
* @param options.state - optional state to forward to the application | ||
* @param options - navigation options | ||
*/ | ||
navigateToApp(appId: string, options?: { path?: string; state?: any }): Promise<void>; | ||
navigateToApp(appId: string, options?: NavigateToAppOptions): Promise<void>; | ||
Comment on lines
-688
to
+708
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I also add the option to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to do it for the sake of consistency. However, we can wait until someone requests this functionality. |
||
|
||
/** | ||
* Navigate to given url, which can either be an absolute url or a relative path, in a SPA friendly way when possible. | ||
|
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.
optional: we could add a test with
replace: false