-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…64867) * add defaultPath to `AppBase` and use it in `navigateToApp` * add removeSlashes util * adapt `toNavLink` to handle defaultPath * update generated doc * codestyle * add FTR test * address comments * add tests
- Loading branch information
1 parent
eb05f6e
commit e5946ce
Showing
16 changed files
with
320 additions
and
36 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
docs/development/core/public/kibana-plugin-core-public.appbase.defaultpath.md
This file contains 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,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-core-public](./kibana-plugin-core-public.md) > [AppBase](./kibana-plugin-core-public.appbase.md) > [defaultPath](./kibana-plugin-core-public.appbase.defaultpath.md) | ||
|
||
## AppBase.defaultPath property | ||
|
||
Allow to define the default path a user should be directed to when navigating to the app. When defined, this value will be used as a default for the `path` option when calling [navigateToApp](./kibana-plugin-core-public.applicationstart.navigatetoapp.md)<!-- -->\`<!-- -->, and will also be appended to the [application navLink](./kibana-plugin-core-public.chromenavlink.md) in the navigation bar. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
defaultPath?: string; | ||
``` |
This file contains 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 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 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 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 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 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 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 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,71 @@ | ||
/* | ||
* 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 { removeSlashes, appendAppPath } from './utils'; | ||
|
||
describe('removeSlashes', () => { | ||
it('only removes duplicates by default', () => { | ||
expect(removeSlashes('/some//url//to//')).toEqual('/some/url/to/'); | ||
expect(removeSlashes('some/////other//url')).toEqual('some/other/url'); | ||
}); | ||
|
||
it('remove trailing slash when `trailing` is true', () => { | ||
expect(removeSlashes('/some//url//to//', { trailing: true })).toEqual('/some/url/to'); | ||
}); | ||
|
||
it('remove leading slash when `leading` is true', () => { | ||
expect(removeSlashes('/some//url//to//', { leading: true })).toEqual('some/url/to/'); | ||
}); | ||
|
||
it('does not removes duplicates when `duplicates` is false', () => { | ||
expect(removeSlashes('/some//url//to/', { leading: true, duplicates: false })).toEqual( | ||
'some//url//to/' | ||
); | ||
expect(removeSlashes('/some//url//to/', { trailing: true, duplicates: false })).toEqual( | ||
'/some//url//to' | ||
); | ||
}); | ||
|
||
it('accept mixed options', () => { | ||
expect( | ||
removeSlashes('/some//url//to/', { leading: true, duplicates: false, trailing: true }) | ||
).toEqual('some//url//to'); | ||
expect( | ||
removeSlashes('/some//url//to/', { leading: true, duplicates: true, trailing: true }) | ||
).toEqual('some/url/to'); | ||
}); | ||
}); | ||
|
||
describe('appendAppPath', () => { | ||
it('appends the appBasePath with given path', () => { | ||
expect(appendAppPath('/app/my-app', '/some-path')).toEqual('/app/my-app/some-path'); | ||
expect(appendAppPath('/app/my-app/', 'some-path')).toEqual('/app/my-app/some-path'); | ||
expect(appendAppPath('/app/my-app', 'some-path')).toEqual('/app/my-app/some-path'); | ||
expect(appendAppPath('/app/my-app', '')).toEqual('/app/my-app'); | ||
}); | ||
|
||
it('preserves the trailing slash only if included in the hash', () => { | ||
expect(appendAppPath('/app/my-app', '/some-path/')).toEqual('/app/my-app/some-path'); | ||
expect(appendAppPath('/app/my-app', '/some-path#/')).toEqual('/app/my-app/some-path#/'); | ||
expect(appendAppPath('/app/my-app', '/some-path#/hash/')).toEqual( | ||
'/app/my-app/some-path#/hash/' | ||
); | ||
expect(appendAppPath('/app/my-app', '/some-path#/hash')).toEqual('/app/my-app/some-path#/hash'); | ||
}); | ||
}); |
This file contains 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,54 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Utility to remove trailing, leading or duplicate slashes. | ||
* By default will only remove duplicates. | ||
*/ | ||
export const removeSlashes = ( | ||
url: string, | ||
{ | ||
trailing = false, | ||
leading = false, | ||
duplicates = true, | ||
}: { trailing?: boolean; leading?: boolean; duplicates?: boolean } = {} | ||
): string => { | ||
if (duplicates) { | ||
url = url.replace(/\/{2,}/g, '/'); | ||
} | ||
if (trailing) { | ||
url = url.replace(/\/$/, ''); | ||
} | ||
if (leading) { | ||
url = url.replace(/^\//, ''); | ||
} | ||
return url; | ||
}; | ||
|
||
export const appendAppPath = (appBasePath: string, path: string = '') => { | ||
// Only prepend slash if not a hash or query path | ||
path = path === '' || path.startsWith('#') || path.startsWith('?') ? path : `/${path}`; | ||
// Do not remove trailing slash when in hashbang | ||
const removeTrailing = path.indexOf('#') === -1; | ||
return removeSlashes(`${appBasePath}${path}`, { | ||
trailing: removeTrailing, | ||
duplicates: true, | ||
leading: false, | ||
}); | ||
}; |
Oops, something went wrong.