Skip to content

Commit

Permalink
Merge branch 'master' into fix_siem_histogram_titles
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 13, 2020
2 parents f9eae9b + 26ad756 commit a9298fa
Show file tree
Hide file tree
Showing 107 changed files with 1,854 additions and 3,103 deletions.
5 changes: 4 additions & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"savedObjects": "src/plugins/saved_objects",
"server": "src/legacy/server",
"statusPage": "src/legacy/core_plugins/status_page",
"telemetry": "src/legacy/core_plugins/telemetry",
"telemetry": [
"src/legacy/core_plugins/telemetry",
"src/plugins/telemetry"
],
"tileMap": "src/legacy/core_plugins/tile_map",
"timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion", "src/plugins/timelion"],
"uiActions": "src/plugins/ui_actions",
Expand Down
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) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ApplicationStart](./kibana-plugin-public.applicationstart.md) &gt; [currentAppId$](./kibana-plugin-public.applicationstart.currentappid_.md)

## ApplicationStart.currentAppId$ property

An observable that emits the current application id and each subsequent id update.

<b>Signature:</b>

```typescript
currentAppId$: Observable<string | undefined>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

## ApplicationStart.getUrlForApp() method

Returns a relative URL to a given app, including the global base path.
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)

Note that when generating absolute urls, the protocol, host and port are determined from the browser location.

<b>Signature:</b>

```typescript
getUrlForApp(appId: string, options?: {
path?: string;
absolute?: boolean;
}): string;
```

Expand All @@ -19,7 +22,7 @@ getUrlForApp(appId: string, options?: {
| Parameter | Type | Description |
| --- | --- | --- |
| appId | <code>string</code> | |
| options | <code>{</code><br/><code> path?: string;</code><br/><code> }</code> | |
| options | <code>{</code><br/><code> path?: string;</code><br/><code> absolute?: boolean;</code><br/><code> }</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export interface ApplicationStart
| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-public.applicationstart.capabilities.md) | <code>RecursiveReadonly&lt;Capabilities&gt;</code> | Gets the read-only capabilities. |
| [currentAppId$](./kibana-plugin-public.applicationstart.currentappid_.md) | <code>Observable&lt;string &#124; undefined&gt;</code> | An observable that emits the current application id and each subsequent id update. |

## Methods

| Method | Description |
| --- | --- |
| [getUrlForApp(appId, options)](./kibana-plugin-public.applicationstart.geturlforapp.md) | Returns a relative URL to a given app, including the global base path. |
| [getUrlForApp(appId, options)](./kibana-plugin-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 protocol, host and port are determined from the browser location. |
| [navigateToApp(appId, options)](./kibana-plugin-public.applicationstart.navigatetoapp.md) | Navigate to a given app |
| [registerMountContext(contextName, provider)](./kibana-plugin-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-public.coresetup.getstartservices.md)<!-- -->. |

17 changes: 11 additions & 6 deletions src/core/public/application/application_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ const createInternalSetupContractMock = (): jest.Mocked<InternalApplicationSetup
registerMountContext: jest.fn(),
});

const createStartContractMock = (): jest.Mocked<ApplicationStart> => ({
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
});
const createStartContractMock = (): jest.Mocked<ApplicationStart> => {
const currentAppId$ = new Subject<string | undefined>();

return {
currentAppId$: currentAppId$.asObservable(),
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
navigateToApp: jest.fn(),
getUrlForApp: jest.fn(),
registerMountContext: jest.fn(),
};
};

const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart> => {
const currentAppId$ = new Subject<string | undefined>();
Expand Down
11 changes: 10 additions & 1 deletion src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,23 @@ describe('#start()', () => {

it('creates URLs with path parameter', async () => {
service.setup(setupDeps);

const { getUrlForApp } = await service.start(startDeps);

expect(getUrlForApp('app1', { path: 'deep/link' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '/deep//link/' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: '//deep/link//' })).toBe('/base-path/app/app1/deep/link');
expect(getUrlForApp('app1', { path: 'deep/link///' })).toBe('/base-path/app/app1/deep/link');
});

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/base-path/app/app1');
expect(getUrlForApp('app2', { path: 'deep/link', absolute: true })).toBe(
'http://localhost/base-path/app/app2/deep/link'
);
});
});

describe('navigateToApp', () => {
Expand Down
16 changes: 14 additions & 2 deletions src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,13 @@ export class ApplicationService {
takeUntil(this.stop$)
),
registerMountContext: this.mountContext.registerContext,
getUrlForApp: (appId, { path }: { path?: string } = {}) =>
http.basePath.prepend(getAppUrl(availableMounters, appId, path)),
getUrlForApp: (
appId,
{ path, absolute = false }: { path?: string; absolute?: boolean } = {}
) => {
const relUrl = http.basePath.prepend(getAppUrl(availableMounters, appId, path));
return absolute ? relativeToAbsolute(relUrl) : relUrl;
},
navigateToApp: async (appId, { path, state }: { path?: string; state?: any } = {}) => {
if (await this.shouldNavigate(overlays)) {
this.appLeaveHandlers.delete(this.currentAppId$.value!);
Expand Down Expand Up @@ -364,3 +369,10 @@ const updateStatus = <T extends AppBase>(app: T, statusUpdaters: AppUpdaterWrapp
...changes,
};
};

function relativeToAbsolute(url: string) {
// convert all link urls to absolute urls
const a = document.createElement('a');
a.setAttribute('href', url);
return a.href;
}
21 changes: 17 additions & 4 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,17 @@ export interface ApplicationStart {
navigateToApp(appId: string, options?: { path?: string; state?: any }): Promise<void>;

/**
* Returns a relative URL to a given app, including the global base path.
* 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)
*
* Note that when generating absolute urls, the protocol, host and port are determined from the browser location.
*
* @param appId
* @param options.path - optional path inside application to deep link to
* @param options.absolute - if true, will returns an absolute url instead of a relative one
*/
getUrlForApp(appId: string, options?: { path?: string }): string;
getUrlForApp(appId: string, options?: { path?: string; absolute?: boolean }): string;

/**
* Register a context provider for application mounting. Will only be available to applications that depend on the
Expand All @@ -612,11 +618,19 @@ export interface ApplicationStart {
contextName: T,
provider: IContextProvider<AppMountDeprecated, T>
): void;

/**
* An observable that emits the current application id and each subsequent id update.
*/
currentAppId$: Observable<string | undefined>;
}

/** @internal */
export interface InternalApplicationStart
extends Pick<ApplicationStart, 'capabilities' | 'navigateToApp' | 'getUrlForApp'> {
extends Pick<
ApplicationStart,
'capabilities' | 'navigateToApp' | 'getUrlForApp' | 'currentAppId$'
> {
/**
* Apps available based on the current capabilities.
* Should be used to show navigation links and make routing decisions.
Expand All @@ -640,7 +654,6 @@ export interface InternalApplicationStart
): void;

// Internal APIs
currentAppId$: Observable<string | undefined>;
getComponent(): JSX.Element | null;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/public/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class LegacyPlatformService {
const legacyCore: LegacyCoreStart = {
...core,
application: {
currentAppId$: core.application.currentAppId$,
capabilities: core.application.capabilities,
getUrlForApp: core.application.getUrlForApp,
navigateToApp: core.application.navigateToApp,
Expand Down
1 change: 1 addition & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function createPluginStartContext<
): CoreStart {
return {
application: {
currentAppId$: deps.application.currentAppId$,
capabilities: deps.application.capabilities,
navigateToApp: deps.application.navigateToApp,
getUrlForApp: deps.application.getUrlForApp,
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export interface ApplicationSetup {
// @public (undocumented)
export interface ApplicationStart {
capabilities: RecursiveReadonly<Capabilities>;
currentAppId$: Observable<string | undefined>;
getUrlForApp(appId: string, options?: {
path?: string;
absolute?: boolean;
}): string;
navigateToApp(appId: string, options?: {
path?: string;
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/config/deprecation/core_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({
renameFromRoot('optimize.lazyHost', 'optimize.watchHost'),
renameFromRoot('optimize.lazyPrebuild', 'optimize.watchPrebuild'),
renameFromRoot('optimize.lazyProxyTimeout', 'optimize.watchProxyTimeout'),
renameFromRoot('xpack.xpack_main.telemetry.config', 'telemetry.config'),
renameFromRoot('xpack.xpack_main.telemetry.url', 'telemetry.url'),
renameFromRoot('xpack.xpack_main.telemetry.enabled', 'telemetry.enabled'),
renameFromRoot('xpack.telemetry.enabled', 'telemetry.enabled'),
renameFromRoot('xpack.telemetry.config', 'telemetry.config'),
renameFromRoot('xpack.telemetry.banner', 'telemetry.banner'),
Expand Down
31 changes: 3 additions & 28 deletions src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,16 @@
*/

import { npSetup, npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { HomePlugin, LegacyAngularInjectedDependencies } from './plugin';
import { TelemetryOptInProvider } from '../../../telemetry/public/services';
import { IPrivate } from '../../../../../plugins/kibana_legacy/public';

/**
* Get dependencies relying on the global angular context.
* They also have to get resolved together with the legacy imports above
*/
async function getAngularDependencies(): Promise<LegacyAngularInjectedDependencies> {
const injector = await chrome.dangerouslyGetActiveInjector();

const Private = injector.get<IPrivate>('Private');

const telemetryEnabled = npStart.core.injectedMetadata.getInjectedVar('telemetryEnabled');
const telemetryBanner = npStart.core.injectedMetadata.getInjectedVar('telemetryBanner');
const telemetryOptInProvider = Private(TelemetryOptInProvider);

return {
telemetryOptInProvider,
shouldShowTelemetryOptIn:
telemetryEnabled && telemetryBanner && !telemetryOptInProvider.getOptIn(),
};
}
import { HomePlugin } from './plugin';

(async () => {
const instance = new HomePlugin();
instance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
metadata: npStart.core.injectedMetadata.getLegacyMetadata(),
getAngularDependencies,
},
});
instance.start(npStart.core, {
...npStart.plugins,
});

instance.start(npStart.core, npStart.plugins);
})();
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/home/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
UiSettingsState,
} from 'kibana/public';
import { UiStatsMetricType } from '@kbn/analytics';
import { TelemetryPluginStart } from '../../../../../plugins/telemetry/public';
import {
Environment,
HomePublicPluginSetup,
Expand All @@ -53,7 +54,6 @@ export interface HomeKibanaServices {
};
getInjected: (name: string, defaultValue?: any) => unknown;
chrome: ChromeStart;
telemetryOptInProvider: any;
uiSettings: IUiSettingsClient;
config: KibanaLegacySetup['config'];
homeConfig: HomePublicPluginSetup['config'];
Expand All @@ -64,10 +64,10 @@ export interface HomeKibanaServices {
banners: OverlayStart['banners'];
trackUiMetric: (type: UiStatsMetricType, eventNames: string | string[], count?: number) => void;
getBasePath: () => string;
shouldShowTelemetryOptIn: boolean;
docLinks: DocLinksStart;
addBasePath: (url: string) => string;
environment: Environment;
telemetry?: TelemetryPluginStart;
}

let services: HomeKibanaServices | null = null;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a9298fa

Please sign in to comment.