Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into lowercase-nor…
Browse files Browse the repository at this point in the history
…malizer
  • Loading branch information
madirey committed Oct 1, 2020
2 parents f03fada + 7836998 commit 0753542
Show file tree
Hide file tree
Showing 216 changed files with 5,213 additions and 1,581 deletions.
2 changes: 1 addition & 1 deletion docs/developer/contributing/development-github.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Pull requests are made into the `master` branch and then backported when it is s
* Breaking changes do not get backported and only go into `master`.
* All non-breaking changes can be backported to the `<major>.x` branch.
* Features should not be backported to a `<major>.<minor>` branch.
* Bugs can be backported to a `<major>.<minor>` branch if the changes are safe and appropriate. Safety is a judgment call you make based on factors like the bug's severity, test coverage, confidence in the changes, etc. Your reasoning should be included in the pull request description.
* Bug fixes can be backported to a `<major>.<minor>` branch if the changes are safe and appropriate. Safety is a judgment call you make based on factors like the bug's severity, test coverage, confidence in the changes, etc. Your reasoning should be included in the pull request description.
* Documentation changes can be backported to any branch at any time.

[discrete]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

## ApplicationStart.getUrlForApp() method

Returns an URL to a given app, including the global base path. By default, the URL is relative (/basePath/app/my-app). Use the `absolute` option to generate an absolute url (http://host:port/basePath/app/my-app)
Returns the absolute path (or URL) to a given app, including the global base path.

Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's location.
By default, it returns the absolute path of the application (e.g `/basePath/app/my-app`<!-- -->). Use the `absolute` option to generate an absolute url instead (e.g `http://host:port/basePath/app/my-app`<!-- -->)

Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's current location.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface ApplicationStart

| Method | Description |
| --- | --- |
| [getUrlForApp(appId, options)](./kibana-plugin-core-public.applicationstart.geturlforapp.md) | Returns an URL to a given app, including the global base path. By default, the URL is relative (/basePath/app/my-app). Use the <code>absolute</code> option to generate an absolute url (http://host:port/basePath/app/my-app)<!-- -->Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's location. |
| [getUrlForApp(appId, options)](./kibana-plugin-core-public.applicationstart.geturlforapp.md) | Returns the absolute path (or URL) to a given app, including the global base path.<!-- -->By default, it returns the absolute path of the application (e.g <code>/basePath/app/my-app</code>). Use the <code>absolute</code> option to generate an absolute url instead (e.g <code>http://host:port/basePath/app/my-app</code>)<!-- -->Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's current location. |
| [navigateToApp(appId, options)](./kibana-plugin-core-public.applicationstart.navigatetoapp.md) | Navigate to a given app |
| [navigateToUrl(url)](./kibana-plugin-core-public.applicationstart.navigatetourl.md) | Navigate to given url, which can either be an absolute url or a relative path, in a SPA friendly way when possible.<!-- -->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 <code>appRoute</code> configuration)<!-- -->Then a SPA navigation will be performed using <code>navigateToApp</code> using the corresponding application and path. Otherwise, fallback to a full page reload to navigate to the url using <code>window.location.assign</code> |
| [navigateToUrl(url)](./kibana-plugin-core-public.applicationstart.navigatetourl.md) | Navigate to given URL in a SPA friendly way when possible (when the URL will redirect to a valid application within the current basePath).<!-- -->The method resolves pathnames the same way browsers do when resolving a <code>&lt;a href&gt;</code> value. The provided <code>url</code> 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 <code>appRoute</code> configuration)<!-- -->Then a SPA navigation will be performed using <code>navigateToApp</code> using the corresponding application and path. Otherwise, fallback to a full page reload to navigate to the url using <code>window.location.assign</code> |
| [registerMountContext(contextName, provider)](./kibana-plugin-core-public.applicationstart.registermountcontext.md) | Register a context provider for application mounting. Will only be available to applications that depend on the plugin that registered this context. Deprecated, use [CoreSetup.getStartServices](./kibana-plugin-core-public.coresetup.getstartservices.md)<!-- -->. |

Original file line number Diff line number Diff line change
Expand Up @@ -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).

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)

Then a SPA navigation will be performed using `navigateToApp` using the corresponding application and path. Otherwise, fallback to a full page reload to navigate to the url using `window.location.assign`

Expand All @@ -20,7 +22,7 @@ navigateToUrl(url: string): Promise<void>;

| Parameter | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | an absolute url, or a relative path, to navigate to. |
| url | <code>string</code> | an absolute URL, an absolute path or a relative path, to navigate to. |

<b>Returns:</b>

Expand All @@ -35,11 +37,14 @@ navigateToUrl(url: string): Promise<void>;
// will call `application.navigateToApp('discover', { path: '/some-path?foo=bar'})`
application.navigateToUrl('https://kibana:8080/base-path/s/my-space/app/discover/some-path?foo=bar')
application.navigateToUrl('/base-path/s/my-space/app/discover/some-path?foo=bar')
application.navigateToUrl('./discover/some-path?foo=bar')

// will perform a full page reload using `window.location.assign`
application.navigateToUrl('https://elsewhere:8080/base-path/s/my-space/app/discover/some-path') // origin does not match
application.navigateToUrl('/app/discover/some-path') // does not include the current basePath
application.navigateToUrl('/base-path/s/my-space/app/unknown-app/some-path') // unknown application
application.navigateToUrl('../discover') // resolve to `/base-path/s/my-space/discover` which is not a path of a known app.
application.navigateToUrl('../../other-space/discover') // resolve to `/base-path/s/other-space/discover` which is not within the current basePath.

```

35 changes: 29 additions & 6 deletions docs/user/dashboard/vega-reference.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For additional *Vega* and *Vega-Lite* information, refer to the reference sectio

{kib} has extended Vega and Vega-Lite with extensions that support:

* Default height and width
* Automatic sizing
* Default theme to match {kib}
* Writing {es} queries using the time range and filters from dashboards
* Using the Elastic Map Service in Vega maps
Expand All @@ -22,12 +22,35 @@ For additional *Vega* and *Vega-Lite* information, refer to the reference sectio

[float]
[[vega-sizing-and-positioning]]
==== Default height and width
==== Automatic sizing

By default, Vega visualizations use the `autosize = { type: 'fit', contains: 'padding' }` layout.
`fit` uses all available space, ignores `width` and `height` values,
and respects the padding values. To override this behavior, change the
`autosize` value.
Most users will want their Vega visualizations to take the full available space, so unlike
Vega examples, `width` and `height` are not required parameters in {kib}. To set the width
or height manually, set `autosize: none`. For example, to set the height to a specific pixel value:

```
autosize: none
width: container
height: 200
```

The default {kib} settings which are inherited by your visualizations are:

```
autosize: {
type: fit
contains: padding
}
width: container
height: container
```

{kib} is able to merge your custom `autosize` settings with the defaults. The options `fit-x`
and `fit-y` are supported but not recommended over the default `fit` setting.

To learn more, read about
https://vega.github.io/vega/docs/specification/#autosize[autosize]
in the Vega documentation.

[float]
[[vega-theme]]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"devDependencies": {
"@babel/parser": "^7.11.2",
"@babel/types": "^7.11.0",
"@elastic/apm-rum": "^5.6.0",
"@elastic/apm-rum": "^5.6.1",
"@elastic/charts": "21.1.2",
"@elastic/ems-client": "7.10.0",
"@elastic/eslint-config-kibana": "0.15.0",
Expand Down Expand Up @@ -478,7 +478,7 @@
"tree-kill": "^1.2.2",
"typescript": "4.0.2",
"ui-select": "0.19.8",
"vega": "^5.16.1",
"vega": "^5.17.0",
"vega-lite": "^4.16.8",
"vega-schema-url-parser": "^2.1.0",
"vega-tooltip": "^0.24.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-std/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export { mapToObject } from './map_to_object';
export { merge } from './merge';
export { pick } from './pick';
export { withTimeout } from './promise';
export { isRelativeUrl, modifyUrl, URLMeaningfulParts } from './url';
export { isRelativeUrl, modifyUrl, getUrlOrigin, URLMeaningfulParts } from './url';
export { unset } from './unset';
export { getFlattenedObject } from './get_flattened_object';
26 changes: 25 additions & 1 deletion packages/kbn-std/src/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { modifyUrl, isRelativeUrl } from './url';
import { modifyUrl, isRelativeUrl, getUrlOrigin } from './url';

describe('modifyUrl()', () => {
test('throws an error with invalid input', () => {
Expand Down Expand Up @@ -83,3 +83,27 @@ describe('isRelativeUrl()', () => {
expect(isRelativeUrl(' //evil.com')).toBe(false);
});
});

describe('getOrigin', () => {
describe('when passing an absolute url', () => {
it('return origin without port when the url does not have a port', () => {
expect(getUrlOrigin('https://example.com/file/to/path?example')).toEqual(
'https://example.com'
);
});
it('return origin with port when the url does have a port', () => {
expect(getUrlOrigin('http://example.com:80/path/to/file')).toEqual('http://example.com:80');
});
});
describe('when passing a non absolute url', () => {
it('returns null for relative url', () => {
expect(getUrlOrigin('./path/to/file')).toBeNull();
});
it('returns null for absolute path', () => {
expect(getUrlOrigin('/path/to/file')).toBeNull();
});
it('returns null for empty url', () => {
expect(getUrlOrigin('')).toBeNull();
});
});
});
11 changes: 11 additions & 0 deletions packages/kbn-std/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,14 @@ export function isRelativeUrl(candidatePath: string) {
}
return true;
}

/**
* Returns the origin (protocol + host + port) from given `url` if `url` is a valid absolute url, or null otherwise
*/
export function getUrlOrigin(url: string): string | null {
const obj = parseUrl(url);
if (!obj.protocol && !obj.hostname) {
return null;
}
return `${obj.protocol}//${obj.hostname}${obj.port ? `:${obj.port}` : ''}`;
}
26 changes: 18 additions & 8 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,17 @@ export interface ApplicationStart {
navigateToApp(appId: string, options?: NavigateToAppOptions): Promise<void>;

/**
* 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).
*
* If all these criteria are true for the given url:
* 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 pathname of the URL starts with the current basePath (eg. /mybasepath/s/my-space)
* - 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)
*
* Then a SPA navigation will be performed using `navigateToApp` using the corresponding application and path.
Expand All @@ -727,23 +733,27 @@ export interface ApplicationStart {
* // will call `application.navigateToApp('discover', { path: '/some-path?foo=bar'})`
* application.navigateToUrl('https://kibana:8080/base-path/s/my-space/app/discover/some-path?foo=bar')
* application.navigateToUrl('/base-path/s/my-space/app/discover/some-path?foo=bar')
* application.navigateToUrl('./discover/some-path?foo=bar')
*
* // will perform a full page reload using `window.location.assign`
* application.navigateToUrl('https://elsewhere:8080/base-path/s/my-space/app/discover/some-path') // origin does not match
* application.navigateToUrl('/app/discover/some-path') // does not include the current basePath
* application.navigateToUrl('/base-path/s/my-space/app/unknown-app/some-path') // unknown application
* application.navigateToUrl('../discover') // resolve to `/base-path/s/my-space/discover` which is not a path of a known app.
* application.navigateToUrl('../../other-space/discover') // resolve to `/base-path/s/other-space/discover` which is not within the current basePath.
* ```
*
* @param url - an absolute url, or a relative path, to navigate to.
* @param url - an absolute URL, an absolute path or a relative path, to navigate to.
*/
navigateToUrl(url: string): Promise<void>;

/**
* Returns an URL to a given app, including the global base path.
* By default, the URL is relative (/basePath/app/my-app).
* Use the `absolute` option to generate an absolute url (http://host:port/basePath/app/my-app)
* Returns the absolute path (or URL) to a given app, including the global base path.
*
* By default, it returns the absolute path of the application (e.g `/basePath/app/my-app`).
* Use the `absolute` option to generate an absolute url instead (e.g `http://host:port/basePath/app/my-app`)
*
* Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's location.
* Note that when generating absolute urls, the origin (protocol, host and port) are determined from the browser's current location.
*
* @param appId
* @param options.path - optional path inside application to deep link to
Expand Down
Loading

0 comments on commit 0753542

Please sign in to comment.