Skip to content
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

Merged

Conversation

pgayvallet
Copy link
Contributor

Summary

Fix #68527

Add a replace option to the navigateToApp application API to use history.replace instead of history.push

Checklist

@pgayvallet pgayvallet added release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.9.0 v8.0.0 labels Jun 9, 2020
Comment on lines +929 to +934
it('use `history.replace` instead of `history.push`', async () => {
service.setup(setupDeps);

const { navigateToApp } = await service.start(startDeps);

await navigateToApp('myTestApp', { replace: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reproduced/added a subset of the navigateToApp test suite, as the suite is big and as it's internally using the same logic.

Comment on lines +667 to +670
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines +677 to +683
/**
* 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Comment on lines -688 to +708
navigateToApp(appId: string, options?: { path?: string; state?: any }): Promise<void>;
navigateToApp(appId: string, options?: NavigateToAppOptions): Promise<void>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I also add the option to navigateToUrl ?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@pgayvallet pgayvallet marked this pull request as ready for review June 9, 2020 20:33
@pgayvallet pgayvallet requested a review from a team as a code owner June 9, 2020 20:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet pgayvallet requested a review from flash1293 June 9, 2020 20:33
/**
* optional state to forward to the application
*/
state?: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't it be unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown probably makes more sense. Can change that in this PR, that should be quite small.

Comment on lines -688 to +708
navigateToApp(appId: string, options?: { path?: string; state?: any }): Promise<void>;
navigateToApp(appId: string, options?: NavigateToAppOptions): Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -924,6 +924,63 @@ describe('#start()', () => {
await navigateToApp('baseApp:legacyApp1');
expect(setupDeps.redirectTo).toHaveBeenCalledWith('/test/app/baseApp');
});

describe('when `replace` option is true', () => {
Copy link
Contributor

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

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit 74ceb70 into elastic:master Jun 11, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Jun 11, 2020
* add `replace` option to `navigateToApp`

* use `unknown` type for state

* add test when `replace` is false
pgayvallet added a commit that referenced this pull request Jun 11, 2020
* add `replace` option to `navigateToApp`

* use `unknown` type for state

* add test when `replace` is false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace option for navigateToApp
4 participants