-
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 absolute
option to ApplicationStart.getUrlForApp
#57193
Add absolute
option to ApplicationStart.getUrlForApp
#57193
Conversation
Pinging @elastic/kibana-platform (Team:Platform) |
function relativeToAbsolute(url: string) { | ||
// convert all link urls to absolute urls | ||
const a = document.createElement('a'); | ||
a.setAttribute('href', url); | ||
return a.href; | ||
} |
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.
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
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' | ||
); | ||
}); |
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.
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?
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.
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
…-for-app-absolute
…-for-app-absolute
…-for-app-absolute
💛 Build succeeded, but was flaky
History
To update your PR or re-run it, just comment with: |
* 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)
* 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
Summary
Fix #56868
Adds an
absolute
option togetUrlForApp
to generate an absolute url instead of a 'relative' oneChecklist
Delete any items that are not applicable to this PR.
For maintainers