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 relative path handling to application.navigateToUrl #78565

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Sep 28, 2020

Summary

Fix #78007

  • fix a bug causing navigateToUrl to prepend the basePath when invoking it with a non basePath-prefixed absolute path to a valid app instead of redirecting to the given absolute path.
  • Add relative path support to navigateToUrl, that follows the browser's <a href> resolution logic.
  • move the application service utilities and associated tests to distinct files
  • fix doc that was sometimes misleadingly using the relative path term instead of the correct absolute path one.

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.10.0 labels Sep 28, 2020
@pgayvallet
Copy link
Contributor Author

@flash1293 could you confirm the PR addresses both issues from #78007?

@pgayvallet pgayvallet marked this pull request as ready for review September 28, 2020 12:08
@pgayvallet pgayvallet requested a review from a team as a code owner September 28, 2020 12:08
@elasticmachine
Copy link
Contributor

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

Comment on lines +39 to +46
export const parseAppUrl = (
url: string,
basePath: IBasePath,
apps: Map<string, App<unknown>>,
currentUrl: string = window.location.href
): ParsedAppUrl | undefined => {
const currentOrigin = getUrlOrigin(currentUrl);
if (!currentOrigin) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual diff for the changes on parseAppUrl can be seen in this commit: e14858f

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in Chrome and the navigation using a URL like ../app/kibana#/dashboard/edf84fe0-e1a0-11e7-b6d5-4dc382ef7f5b works fine. This fixes #77733 LGTM

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

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

Mostly left documentation nits

src/core/public/application/types.ts Outdated Show resolved Hide resolved
src/core/public/application/types.ts Outdated Show resolved Hide resolved
? AppNavLinkStatus.hidden
: AppNavLinkStatus.visible
: app.navLinkStatus!;
const { updater$, mount, ...infos } = app;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think it would be safer to pick the safe properties instead of using the rest spread so that we don't forget to remove any future sensitive properties (we'll probably get a type error in the test, but still feels more brittle).

import { App, ParsedAppUrl } from '../types';

/**
* Parse given url and return the associated app id and path if any app matches, or undefined if none do.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Parse given url and return the associated app id and path if any app matches, or undefined if none do.
* Parse given URL and return the associated app id and path if any app matches, or undefined if none do.

* Parse given url and return the associated app id and path if any app matches, or undefined if none do.
* Input can either be:
*
* - a absolute path containing the basePath,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* - a absolute path containing the basePath,
* - an absolute path containing the basePath,

* - a absolute path containing the basePath,
* e.g `/base-path/app/my-app/some-path`
*
* - an absolute url matching the `origin` of the kibana instance (as seen by the browser),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* - an absolute url matching the `origin` of the kibana instance (as seen by the browser),
* - an absolute URL matching the `origin` of the Kibana instance (as seen by the browser),

@@ -4,9 +4,11 @@

## ApplicationStart.navigateToUrl() method

Navigate to given url, which can either be an absolute url or a relative path, in a SPA friendly way when possible.
Navigate to given url in a SPA friendly way when possible (when the url will redirect to a valid application within the current basePath).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Navigate to given url in a SPA friendly way when possible (when the url will redirect to a valid application within the current basePath).
Navigate to given URL in a SPA friendly way when possible (when the URL will redirect to a valid application within the current basePath).


If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration)
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href)
The method resolves pathnames the same way browsers do when resolving an `<a href>` value. The provided URL can be: - an absolute URL - an absolute path - a path relative to the current URL (window.location.href)

If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration)
The method resolves pathnames the same way browsers do when resolving a `<a href>` value. The provided url can be: - an absolute url - an absolute path - a path relative to the current url (window.location.href)

If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If all these criteria are true for the given url: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration)
If all these criteria are true for the given URL: - (only for absolute URLs) The origin of the URL matches the origin of the browser's current location - The resolved pathname of the provided URL/path starts with the current basePath (eg. /mybasepath/s/my-space) - The pathname segment after the basePath matches any known application route (eg. /app/<id>/ or any application's `appRoute` configuration)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id before after diff
core 433 438 +5

async chunks size

id before after diff
graph 1.3MB 1.3MB +380.0B

page load bundle size

id before after diff
core 659.8KB 660.6KB +832.0B
data 1.3MB 1.3MB +380.0B
ingestManager 509.8KB 510.2KB +380.0B
uiActionsEnhanced 320.7KB 321.0KB +380.0B
total +1.9KB

History

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

@pgayvallet pgayvallet merged commit 4ee3677 into elastic:master Oct 1, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Oct 1, 2020
)

* split application utilities and associated tests to distinct files

* do not match app if path does not start with the basePath

* add relative paths support to `navigateToUrl`

* add null-check error

* update generated doc

* nits on doc
pgayvallet added a commit that referenced this pull request Oct 1, 2020
…79139)

* split application utilities and associated tests to distinct files

* do not match app if path does not start with the basePath

* add relative paths support to `navigateToUrl`

* add null-check error

* update generated doc

* nits on doc
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.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core.application.navigateToUrl not handling relative paths
5 participants