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 absolute option to ApplicationStart.getUrlForApp #57193

Merged

Conversation

pgayvallet
Copy link
Contributor

Summary

Fix #56868

Adds an absolute option to getUrlForApp to generate an absolute url instead of a 'relative' one

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Feb 10, 2020
@pgayvallet pgayvallet requested a review from a team as a code owner February 10, 2020 12:25
@pgayvallet pgayvallet added this to Code review in kibana-core [DEPRECATED] via automation Feb 10, 2020
@elasticmachine
Copy link
Contributor

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

Comment on lines +373 to +378
function relativeToAbsolute(url: string) {
// convert all link urls to absolute urls
const a = document.createElement('a');
a.setAttribute('href', url);
return a.href;
}
Copy link
Contributor Author

@pgayvallet pgayvallet Feb 10, 2020

Choose a reason for hiding this comment

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

So, this implementation can seems strange, as it relies on actual DOM a node behavior, however

  • This is the same approach that is currently used in NavLinks to creates the absolute url
  • The behavior is specified, this is not relying on internal browser implementation
  • This just works (tm), when other snippets to properly parse and convert a relative url to an absolute one are 'way' more complex, and requires to parse window.location to construct the url.

Still, tell me if we want to change the implementation

Comment on lines 591 to 599
it('creates absolute URLs when `absolute` parameter is true', async () => {
service.setup(setupDeps);
const { getUrlForApp } = await service.start(startDeps);

expect(getUrlForApp('app1', { absolute: true })).toBe('http://localhost/app/app1');
expect(getUrlForApp('app2', { path: 'deep/link', absolute: true })).toBe(
'http://localhost/app/app2/deep/link'
);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of current implementation, we cannot properly mock the 'location provider' to test this, so the actual protocol and domains are the jsdom's default: http: and localhost. Should I add a functional test to test the behavior in a real browser environ?

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that jsdom doesn't provide an easy way to mock it. I'd rather skip it then, since The behavior is specified, this is not relying on internal browser implementation

@kibanamachine
Copy link
Contributor

💛 Build succeeded, but was flaky

History

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

@pgayvallet pgayvallet merged commit 26ad756 into elastic:master Feb 13, 2020
kibana-core [DEPRECATED] automation moved this from Code review to Needs Backport Feb 13, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Feb 13, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 13, 2020
* master:
  add `absolute` option to `getUrlForApp` (elastic#57193)
  [Telemetry] Migrate public to NP (elastic#56285)
  address flaky test where instances might have different start… (elastic#57506)
  fix(NA): support legacy plugins path in plugins (elastic#57472)
  build immutable bundles for new platform plugins (elastic#53976)
  [SIEM] [Detection Engine] Reject if duplicate rule_id in request payload (elastic#57057)
  Add autocomplete="off" for input type="password" to appease the scanners (elastic#56922)
  Use default spaces suffix for signals index if spaces disabled (elastic#57244)
  [Alerting] Create alert design cleanup (elastic#56929)
pgayvallet added a commit that referenced this pull request Feb 13, 2020
@pgayvallet pgayvallet moved this from Needs Backport to Done (7.7) in kibana-core [DEPRECATED] Feb 13, 2020
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 13, 2020
* master: (22 commits)
  Use log4j pattern syntax (elastic#57433)
  [ML] Categorization field example endpoint tests (elastic#57471)
  [Lens] Filter out pinned filters from saved object of Lens (elastic#57197)
  Lens client side shim cleanup (elastic#56976)
  [Maps] do not show border color for icon in legend when border width is zero (elastic#57501)
  refactors 'data-providers' tests (elastic#57474)
  add `absolute` option to `getUrlForApp` (elastic#57193)
  [Telemetry] Migrate public to NP (elastic#56285)
  address flaky test where instances might have different start… (elastic#57506)
  fix(NA): support legacy plugins path in plugins (elastic#57472)
  build immutable bundles for new platform plugins (elastic#53976)
  [SIEM] [Detection Engine] Reject if duplicate rule_id in request payload (elastic#57057)
  Add autocomplete="off" for input type="password" to appease the scanners (elastic#56922)
  Use default spaces suffix for signals index if spaces disabled (elastic#57244)
  [Alerting] Create alert design cleanup (elastic#56929)
  Management Api - add to migration guide (elastic#56892)
  fixing maps (elastic#56706)
  [Maps] Autocomplete for custom color palettes and custom icon palettes (elastic#56446)
  [Alerting] make actionGroup name's i18n-able (elastic#57404)
  fixed flaky test (elastic#57490)
  ...

# Conflicts:
#	src/legacy/core_plugins/telemetry/public/components/__snapshots__/telemetry_form.test.js.snap
#	src/plugins/telemetry/public/components/telemetry_management_section.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform 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.7.0 v8.0.0
Projects
Development

Successfully merging this pull request may close these issues.

Add API for generating complete URLs to applications
4 participants