-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Migrate base path APIs and UiSettings client to new platform #22694
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
Merged
spalger
merged 26 commits into
elastic:master
from
spalger:migrate-new-platform/ui-settings-client
Sep 8, 2018
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d02cd0e
create basePath service for new platform
68f7f01
migrate ui settings to new platform
743b553
[ui/core/uiSetttings] actually await expect(promise) calls
spalger 9618563
Merge branch 'master' of github.com:elastic/kibana into HEAD
df345e1
[ui/core/uiSettings] add tests for uiSettingsService
05d9b8e
test out mock class helper
b772a7d
fix reference to uiSettings.subscribe()
4691b7b
[ui/chrome/test] derive basePath from internals like legacy implement…
dc9f43b
Merge branch 'master' of github.com:elastic/kibana into migrate-new-p…
dc5ddc7
[core/public/uiSettingsClient/types] include all properties, even uns…
02f0cc9
fix typos
63bcb4d
limit exported types to those in use
f5e6643
remove unnecessary copy of modify_url util in ui/public
1bcd411
remove unnecessary types from JSDoc
60d8924
use Number constructor rather than parseInt
cf2e10f
[core/public/legacyService] test that uiSettings is initialized
a7db8fd
[core/public/uiSettingsClient] use readonly when possible
ea4cf06
[core/public/uiSettingsClient] use imported type since available
ddbd2b8
[core/public/uiSettingsClient] remove unnecessary Boolean cast
8dec538
Merge branch 'master' of github.com:elastic/kibana into migrate-new-p…
d2f5816
[core/public/basePath/removeBasePath] handle a couple edge-cases better
aa60f3e
fix modifyUrl import
aac0a7c
fix another modifyUrl import (this time run eslint to verify :P)
19eb622
Merge branch 'master' of github.com:elastic/kibana into migrate-new-p…
b1a6ddf
[jest] update snapshots
spalger 596ca89
import directly from core when necessary to avoid infecting jest with…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { BasePathService } from './base_path_service'; | ||
|
|
||
| function setup(options: any = {}) { | ||
| const injectedBasePath: string = | ||
| options.injectedBasePath === undefined ? '/foo/bar' : options.injectedBasePath; | ||
|
|
||
| const service = new BasePathService(); | ||
|
|
||
| const injectedMetadata = { | ||
| getBasePath: jest.fn().mockReturnValue(injectedBasePath), | ||
| } as any; | ||
|
|
||
| const startContract = service.start({ | ||
| injectedMetadata, | ||
| }); | ||
|
|
||
| return { | ||
| service, | ||
| startContract, | ||
| injectedBasePath, | ||
| }; | ||
| } | ||
|
|
||
| describe('startContract.get()', () => { | ||
| it('returns an empty string if no basePath is injected', () => { | ||
| const { startContract } = setup({ injectedBasePath: null }); | ||
| expect(startContract.get()).toBe(''); | ||
| }); | ||
|
|
||
| it('returns the injected basePath', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.get()).toBe('/foo/bar'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('startContract.addToPath()', () => { | ||
| it('adds the base path to the path if it is relative and starts with a slash', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.addToPath('/a/b')).toBe('/foo/bar/a/b'); | ||
| }); | ||
|
|
||
| it('leaves the query string and hash of path unchanged', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.addToPath('/a/b?x=y#c/d/e')).toBe('/foo/bar/a/b?x=y#c/d/e'); | ||
| }); | ||
|
|
||
| it('returns the path unchanged if it does not start with a slash', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.addToPath('a/b')).toBe('a/b'); | ||
| }); | ||
|
|
||
| it('returns the path unchanged it it has a hostname', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.addToPath('http://localhost:5601/a/b')).toBe('http://localhost:5601/a/b'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('startContract.removeFromPath()', () => { | ||
| it('removes the basePath if relative path starts with it', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.removeFromPath('/foo/bar/a/b')).toBe('/a/b'); | ||
| }); | ||
|
|
||
| it('leaves query string and hash intact', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.removeFromPath('/foo/bar/a/b?c=y#1234')).toBe('/a/b?c=y#1234'); | ||
| }); | ||
|
|
||
| it('ignores urls with hostnames', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.removeFromPath('http://localhost:5601/foo/bar/a/b')).toBe( | ||
| 'http://localhost:5601/foo/bar/a/b' | ||
| ); | ||
| }); | ||
|
|
||
| it('returns slash if path is just basePath', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.removeFromPath('/foo/bar')).toBe('/'); | ||
| }); | ||
|
|
||
| it('returns full path if basePath is not its own segment', () => { | ||
| const { startContract } = setup(); | ||
| expect(startContract.removeFromPath('/foo/barhop')).toBe('/foo/barhop'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { InjectedMetadataStartContract } from '../injected_metadata'; | ||
| import { modifyUrl } from '../utils'; | ||
|
|
||
| interface Deps { | ||
| injectedMetadata: InjectedMetadataStartContract; | ||
| } | ||
|
|
||
| export class BasePathService { | ||
| public start({ injectedMetadata }: Deps) { | ||
| const basePath = injectedMetadata.getBasePath() || ''; | ||
|
|
||
| return { | ||
| /** | ||
| * Get the current basePath as defined by the server | ||
| */ | ||
| get() { | ||
| return basePath; | ||
| }, | ||
|
|
||
| /** | ||
| * Add the current basePath to a path string. | ||
| * @param path A relative url including the leading `/`, otherwise it will be returned without modification | ||
| */ | ||
| addToPath(path: string) { | ||
| return modifyUrl(path, parts => { | ||
| if (!parts.hostname && parts.pathname && parts.pathname.startsWith('/')) { | ||
| parts.pathname = `${basePath}${parts.pathname}`; | ||
| } | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Remove the basePath from a path that starts with it | ||
| * @param path A relative url that starts with the basePath, which will be stripped | ||
| */ | ||
| removeFromPath(path: string) { | ||
| if (!basePath) { | ||
| return path; | ||
| } | ||
|
|
||
| if (path === basePath) { | ||
| return '/'; | ||
| } | ||
|
|
||
| if (path.startsWith(basePath + '/')) { | ||
| return path.slice(basePath.length); | ||
| } | ||
|
|
||
| return path; | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export type BasePathStartContract = ReturnType<BasePathService['start']>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ export interface InjectedMetadataParams { | |
| injectedMetadata: { | ||
| version: string; | ||
| buildNumber: number; | ||
| basePath: string; | ||
| legacyMetadata: { | ||
| [key: string]: any; | ||
| }; | ||
|
|
@@ -42,6 +43,14 @@ export class InjectedMetadataService { | |
|
|
||
| public start() { | ||
| return { | ||
| getBasePath: () => { | ||
| return this.state.basePath; | ||
| }, | ||
|
|
||
| getKibanaVersion: () => { | ||
| return this.getKibanaVersion(); | ||
|
Contributor
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. note: haha, my IDE mistakenly marks this as a recursive call :) |
||
| }, | ||
|
|
||
| getLegacyMetadata: () => { | ||
| return this.state.legacyMetadata; | ||
| }, | ||
|
|
||
26 changes: 26 additions & 0 deletions
26
src/core/public/legacy_platform/__snapshots__/legacy_platform_service.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
question:
basePathis always going to be a string, just will be 0-length one ifbasePathisn't defined, correct? (just was a bit confused byinjectedBasePath: nullinbase_path_service.test.ts)