2020-04-30 21:59:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
2020-07-14 23:50:22 +02:00
|
|
|
import { CoreStart, HttpSetup, IUiSettingsClient } from 'kibana/public';
|
2020-04-30 21:59:35 +02:00
|
|
|
import angular from 'angular';
|
2020-06-12 23:43:02 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2020-04-30 21:59:35 +02:00
|
|
|
import { HttpRequestInit } from '../../../../src/core/public';
|
2020-07-14 23:50:22 +02:00
|
|
|
import { MonitoringStartPluginDependencies } from './types';
|
|
|
|
import { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public';
|
|
|
|
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
|
|
|
import { TypeRegistry } from '../../triggers_actions_ui/public/application/type_registry';
|
|
|
|
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
|
|
|
import { ActionTypeModel, AlertTypeModel } from '../../triggers_actions_ui/public/types';
|
2020-04-30 21:59:35 +02:00
|
|
|
|
2020-06-12 23:43:02 +02:00
|
|
|
interface BreadcrumbItem {
|
|
|
|
['data-test-subj']?: string;
|
|
|
|
href?: string;
|
|
|
|
text: string;
|
|
|
|
}
|
|
|
|
|
2020-04-30 21:59:35 +02:00
|
|
|
export interface KFetchQuery {
|
|
|
|
[key: string]: string | number | boolean | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface KFetchOptions extends HttpRequestInit {
|
|
|
|
pathname: string;
|
|
|
|
query?: KFetchQuery;
|
|
|
|
asSystemRequest?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface KFetchKibanaOptions {
|
|
|
|
prependBasePath?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IShims {
|
|
|
|
toastNotifications: CoreStart['notifications']['toasts'];
|
2020-07-14 23:50:22 +02:00
|
|
|
capabilities: CoreStart['application']['capabilities'];
|
2020-04-30 21:59:35 +02:00
|
|
|
getAngularInjector: () => angular.auto.IInjectorService;
|
|
|
|
getBasePath: () => string;
|
|
|
|
getInjected: (name: string, defaultValue?: unknown) => unknown;
|
2020-06-12 23:43:02 +02:00
|
|
|
breadcrumbs: {
|
|
|
|
set: (breadcrumbs: BreadcrumbItem[]) => void;
|
|
|
|
update: (breadcrumbs?: BreadcrumbItem[]) => void;
|
|
|
|
};
|
2020-04-30 21:59:35 +02:00
|
|
|
I18nContext: CoreStart['i18n']['Context'];
|
|
|
|
docLinks: CoreStart['docLinks'];
|
|
|
|
docTitle: CoreStart['chrome']['docTitle'];
|
2020-07-14 23:50:22 +02:00
|
|
|
timefilter: MonitoringStartPluginDependencies['data']['query']['timefilter']['timefilter'];
|
|
|
|
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
|
|
|
|
alertTypeRegistry: TypeRegistry<AlertTypeModel>;
|
|
|
|
uiSettings: IUiSettingsClient;
|
|
|
|
http: HttpSetup;
|
2020-04-30 21:59:35 +02:00
|
|
|
kfetch: (
|
|
|
|
{ pathname, ...options }: KFetchOptions,
|
|
|
|
kfetchOptions?: KFetchKibanaOptions | undefined
|
|
|
|
) => Promise<any>;
|
|
|
|
isCloud: boolean;
|
2020-07-14 23:50:22 +02:00
|
|
|
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
|
2020-04-30 21:59:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Legacy {
|
|
|
|
private static _shims: IShims;
|
|
|
|
|
|
|
|
public static init(
|
2020-07-14 23:50:22 +02:00
|
|
|
{ core, data, isCloud, triggersActionsUi }: MonitoringStartPluginDependencies,
|
2020-04-30 21:59:35 +02:00
|
|
|
ngInjector: angular.auto.IInjectorService
|
|
|
|
) {
|
|
|
|
this._shims = {
|
|
|
|
toastNotifications: core.notifications.toasts,
|
2020-07-14 23:50:22 +02:00
|
|
|
capabilities: core.application.capabilities,
|
2020-04-30 21:59:35 +02:00
|
|
|
getAngularInjector: (): angular.auto.IInjectorService => ngInjector,
|
|
|
|
getBasePath: (): string => core.http.basePath.get(),
|
|
|
|
getInjected: (name: string, defaultValue?: unknown): string | unknown =>
|
|
|
|
core.injectedMetadata.getInjectedVar(name, defaultValue),
|
|
|
|
breadcrumbs: {
|
2020-06-12 23:43:02 +02:00
|
|
|
set: (breadcrumbs: BreadcrumbItem[]) => this._shims.breadcrumbs.update(breadcrumbs),
|
|
|
|
update: (breadcrumbs?: BreadcrumbItem[]) => {
|
|
|
|
if (!breadcrumbs) {
|
|
|
|
const currentBreadcrumbs: Observable<any> & {
|
|
|
|
value?: BreadcrumbItem[];
|
|
|
|
} = core.chrome.getBreadcrumbs$()?.source;
|
|
|
|
breadcrumbs = currentBreadcrumbs?.value;
|
|
|
|
}
|
|
|
|
const globalStateStr = location.hash.split('?')[1];
|
|
|
|
if (
|
|
|
|
!breadcrumbs?.length ||
|
|
|
|
globalStateStr?.indexOf('_g') !== 0 ||
|
|
|
|
breadcrumbs[0].href?.split('?')[1] === globalStateStr
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
breadcrumbs.forEach((breadcrumb: BreadcrumbItem) => {
|
|
|
|
const breadcrumbHref = breadcrumb.href?.split('?')[0];
|
|
|
|
if (breadcrumbHref) {
|
|
|
|
breadcrumb.href = `${breadcrumbHref}?${globalStateStr}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
core.chrome.setBreadcrumbs(breadcrumbs.slice(0));
|
|
|
|
},
|
2020-04-30 21:59:35 +02:00
|
|
|
},
|
|
|
|
I18nContext: core.i18n.Context,
|
|
|
|
docLinks: core.docLinks,
|
|
|
|
docTitle: core.chrome.docTitle,
|
|
|
|
timefilter: data.query.timefilter.timefilter,
|
2020-07-14 23:50:22 +02:00
|
|
|
actionTypeRegistry: triggersActionsUi?.actionTypeRegistry,
|
|
|
|
alertTypeRegistry: triggersActionsUi?.alertTypeRegistry,
|
|
|
|
uiSettings: core.uiSettings,
|
|
|
|
http: core.http,
|
2020-04-30 21:59:35 +02:00
|
|
|
kfetch: async (
|
|
|
|
{ pathname, ...options }: KFetchOptions,
|
|
|
|
kfetchOptions?: KFetchKibanaOptions
|
|
|
|
) =>
|
|
|
|
await core.http.fetch(pathname, {
|
|
|
|
prependBasePath: kfetchOptions?.prependBasePath,
|
|
|
|
...options,
|
|
|
|
}),
|
|
|
|
isCloud,
|
2020-07-14 23:50:22 +02:00
|
|
|
triggersActionsUi,
|
2020-04-30 21:59:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static get shims(): Readonly<IShims> {
|
|
|
|
if (!Legacy._shims) {
|
|
|
|
throw new Error('Legacy needs to be initiated with Legacy.init(...) before use');
|
|
|
|
}
|
|
|
|
return Legacy._shims;
|
|
|
|
}
|
|
|
|
}
|