Move angular related parts from kibana_legacy to monitoring (#114977)

* Move angular related parts from kibana_legacy to monitoring

Closes: #114977

* remove private

* move format angular http error into monitoring

* fix translations
This commit is contained in:
Alexey Antonov 2021-10-15 17:02:23 +03:00 committed by GitHub
parent 7daf707cb9
commit 50e4ae7179
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 27 additions and 267 deletions

View file

@ -14,7 +14,4 @@ import { KibanaLegacyPlugin } from './plugin';
export const plugin = () => new KibanaLegacyPlugin();
export * from './plugin';
export * from './angular';
export * from './notify';
export * from './utils';

View file

@ -8,8 +8,3 @@
export { formatESMsg } from './format_es_msg';
export { formatMsg } from './format_msg';
export {
isAngularHttpError,
formatAngularHttpError,
AngularHttpError,
} from './format_angular_http_error';

View file

@ -1,10 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
// @ts-ignore
export { PrivateProvider, IPrivate } from './private';

View file

@ -1,13 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { IServiceProvider } from 'angular';
export type IPrivate = <T>(provider: (...injectable: any[]) => T) => T;
export function PrivateProvider(): IServiceProvider;

View file

@ -1,192 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/**
* # `Private()`
* Private module loader, used to merge angular and require js dependency styles
* by allowing a require.js module to export a single provider function that will
* create a value used within an angular application. This provider can declare
* angular dependencies by listing them as arguments, and can be require additional
* Private modules.
*
* ## Define a private module provider:
* ```js
* export default function PingProvider($http) {
* this.ping = function () {
* return $http.head('/health-check');
* };
* };
* ```
*
* ## Require a private module:
* ```js
* export default function ServerHealthProvider(Private, Promise) {
* let ping = Private(require('ui/ping'));
* return {
* check: Promise.method(function () {
* let attempts = 0;
* return (function attempt() {
* attempts += 1;
* return ping.ping()
* .catch(function (err) {
* if (attempts < 3) return attempt();
* })
* }())
* .then(function () {
* return true;
* })
* .catch(function () {
* return false;
* });
* })
* }
* };
* ```
*
* # `Private.stub(provider, newInstance)`
* `Private.stub()` replaces the instance of a module with another value. This is all we have needed until now.
*
* ```js
* beforeEach(inject(function ($injector, Private) {
* Private.stub(
* // since this module just exports a function, we need to change
* // what Private returns in order to modify it's behavior
* require('ui/agg_response/hierarchical/_build_split'),
* sinon.stub().returns(fakeSplit)
* );
* }));
* ```
*
* # `Private.swap(oldProvider, newProvider)`
* This new method does an 1-for-1 swap of module providers, unlike `stub()` which replaces a modules instance.
* Pass the module you want to swap out, and the one it should be replaced with, then profit.
*
* Note: even though this example shows `swap()` being called in a config
* function, it can be called from anywhere. It is particularly useful
* in this scenario though.
*
* ```js
* beforeEach(module('kibana', function (PrivateProvider) {
* PrivateProvider.swap(
* function StubbedRedirectProvider($decorate) {
* // $decorate is a function that will instantiate the original module when called
* return sinon.spy($decorate());
* }
* );
* }));
* ```
*
* @param {[type]} prov [description]
*/
import _ from 'lodash';
const nextId = _.partial(_.uniqueId, 'privateProvider#');
function name(fn) {
return fn.name || fn.toString().split('\n').shift();
}
export function PrivateProvider() {
const provider = this;
// one cache/swaps per Provider
const cache = {};
const swaps = {};
// return the uniq id for this function
function identify(fn) {
if (typeof fn !== 'function') {
throw new TypeError('Expected private module "' + fn + '" to be a function');
}
if (fn.$$id) return fn.$$id;
else return (fn.$$id = nextId());
}
provider.stub = function (fn, instance) {
cache[identify(fn)] = instance;
return instance;
};
provider.swap = function (fn, prov) {
const id = identify(fn);
swaps[id] = prov;
};
provider.$get = [
'$injector',
function PrivateFactory($injector) {
// prevent circular deps by tracking where we came from
const privPath = [];
const pathToString = function () {
return privPath.map(name).join(' -> ');
};
// call a private provider and return the instance it creates
function instantiate(prov, locals) {
if (~privPath.indexOf(prov)) {
throw new Error(
'Circular reference to "' +
name(prov) +
'"' +
' found while resolving private deps: ' +
pathToString()
);
}
privPath.push(prov);
const context = {};
let instance = $injector.invoke(prov, context, locals);
if (!_.isObject(instance)) instance = context;
privPath.pop();
return instance;
}
// retrieve an instance from cache or create and store on
function get(id, prov, $delegateId, $delegateProv) {
if (cache[id]) return cache[id];
let instance;
if ($delegateId != null && $delegateProv != null) {
instance = instantiate(prov, {
$decorate: _.partial(get, $delegateId, $delegateProv),
});
} else {
instance = instantiate(prov);
}
return (cache[id] = instance);
}
// main api, get the appropriate instance for a provider
function Private(prov) {
let id = identify(prov);
let $delegateId;
let $delegateProv;
if (swaps[id]) {
$delegateId = id;
$delegateProv = prov;
prov = swaps[$delegateId];
id = identify(prov);
}
return get(id, prov, $delegateId, $delegateProv);
}
Private.stub = provider.stub;
Private.swap = provider.swap;
return Private;
},
];
}

View file

@ -7,14 +7,7 @@
"githubTeam": "stack-monitoring-ui"
},
"configPath": ["monitoring"],
"requiredPlugins": [
"licensing",
"features",
"data",
"navigation",
"kibanaLegacy",
"observability"
],
"requiredPlugins": ["licensing", "features", "data", "navigation", "observability"],
"optionalPlugins": [
"infra",
"usageCollection",
@ -27,5 +20,12 @@
],
"server": true,
"ui": true,
"requiredBundles": ["kibanaUtils", "home", "alerting", "kibanaReact", "licenseManagement"]
"requiredBundles": [
"kibanaUtils",
"home",
"alerting",
"kibanaReact",
"licenseManagement",
"kibanaLegacy"
]
}

View file

@ -15,10 +15,7 @@ import { upperFirst } from 'lodash';
import { CoreStart } from 'kibana/public';
import { i18nDirective, i18nFilter, I18nProvider } from './angular_i18n';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import {
createTopNavDirective,
createTopNavHelper,
} from '../../../../../src/plugins/kibana_legacy/public';
import { createTopNavDirective, createTopNavHelper } from './top_nav';
import { MonitoringStartPluginDependencies } from '../types';
import { GlobalState } from '../url_state';
import { getSafeForExternalLink } from '../lib/get_safe_for_external_link';

View file

@ -1,15 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import { IHttpResponse } from 'angular';
import type { IHttpResponse } from 'angular';
export type AngularHttpError = IHttpResponse<{ message: string }>;
type AngularHttpError = IHttpResponse<{ message: string }>;
export function isAngularHttpError(error: any): error is AngularHttpError {
return (
@ -25,7 +24,7 @@ export function formatAngularHttpError(error: AngularHttpError) {
// is an Angular $http "error object"
if (error.status === -1) {
// status = -1 indicates that the request was failed to reach the server
return i18n.translate('kibana_legacy.notify.fatalError.unavailableServerErrorMessage', {
return i18n.translate('xpack.monitoring.notify.fatalError.unavailableServerErrorMessage', {
defaultMessage:
'An HTTP request has failed to connect. ' +
'Please check if the Kibana server is running and that your browser has a working connection, ' +
@ -33,7 +32,7 @@ export function formatAngularHttpError(error: AngularHttpError) {
});
}
return i18n.translate('kibana_legacy.notify.fatalError.errorStatusMessage', {
return i18n.translate('xpack.monitoring.notify.fatalError.errorStatusMessage', {
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
values: {
errStatus: error.status,

View file

@ -8,7 +8,7 @@
import angular, { IModule } from 'angular';
import { uiRoutes } from './helpers/routes';
import { Legacy } from '../legacy_shims';
import { configureAppAngularModule } from '../../../../../src/plugins/kibana_legacy/public';
import { configureAppAngularModule } from '../angular/top_nav';
import { localAppModule, appModuleName } from './app_modules';
import { APP_WRAPPER_CLASS } from '../../../../../src/core/public';
@ -28,7 +28,6 @@ export class AngularApp {
externalConfig,
triggersActionsUi,
usageCollection,
kibanaLegacy,
appMountParameters,
} = deps;
const app: IModule = localAppModule(deps);
@ -43,7 +42,6 @@ export class AngularApp {
isCloud,
pluginInitializerContext,
externalConfig,
kibanaLegacy,
triggersActionsUi,
usageCollection,
appMountParameters,

View file

@ -1,9 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
@ -23,7 +22,7 @@ import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'kibana/public';
import { History } from 'history';
import { CoreStart } from 'kibana/public';
import { formatAngularHttpError, isAngularHttpError } from '../notify/lib';
import { formatAngularHttpError, isAngularHttpError } from '../helpers/format_angular_http_error';
export interface RouteConfiguration {
controller?: string | ((...args: any[]) => void);

View file

@ -1,10 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export * from './angular_config';
// @ts-ignore
export { createTopNavDirective, createTopNavHelper, loadKbnTopNavDirectives } from './kbn_top_nav';

View file

@ -1,9 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Injectable, IDirectiveFactory, IScope, IAttributes, IController } from 'angular';

View file

@ -1,9 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import angular from 'angular';

View file

@ -92,7 +92,6 @@ export class MonitoringPlugin
const externalConfig = this.getExternalConfig();
const deps: MonitoringStartPluginDependencies = {
navigation: pluginsStart.navigation,
kibanaLegacy: pluginsStart.kibanaLegacy,
element: params.element,
core: coreStart,
data: pluginsStart.data,
@ -112,7 +111,6 @@ export class MonitoringPlugin
isCloud: deps.isCloud,
pluginInitializerContext: deps.pluginInitializerContext,
externalConfig: deps.externalConfig,
kibanaLegacy: deps.kibanaLegacy,
triggersActionsUi: deps.triggersActionsUi,
usageCollection: deps.usageCollection,
appMountParameters: deps.appMountParameters,

View file

@ -9,7 +9,6 @@ import { PluginInitializerContext, CoreStart, AppMountParameters } from 'kibana/
import { NavigationPublicPluginStart as NavigationStart } from '../../../../src/plugins/navigation/public';
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import { TriggersAndActionsUIPublicPluginStart } from '../../triggers_actions_ui/public';
import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
@ -20,7 +19,6 @@ export { MLJobs } from '../server/lib/elasticsearch/get_ml_jobs';
export interface MonitoringStartPluginDependencies {
navigation: NavigationStart;
data: DataPublicPluginStart;
kibanaLegacy: KibanaLegacyStart;
element: HTMLElement;
core: CoreStart;
isCloud: boolean;

View file

@ -4175,8 +4175,6 @@
"inspector.requests.statisticsTabLabel": "統計",
"inspector.title": "インスペクター",
"inspector.view": "{viewName} を表示",
"kibana_legacy.notify.fatalError.errorStatusMessage": "エラー {errStatus} {errStatusText}: {errMessage}",
"kibana_legacy.notify.fatalError.unavailableServerErrorMessage": "HTTP リクエストで接続に失敗しました。Kibana サーバーが実行されていて、ご使用のブラウザの接続が正常に動作していることを確認するか、システム管理者にお問い合わせください。",
"kibana_legacy.notify.toaster.errorStatusMessage": "エラー {errStatus} {errStatusText}: {errMessage}",
"kibana_legacy.notify.toaster.unavailableServerErrorMessage": "HTTP リクエストで接続に失敗しました。Kibana サーバーが実行されていて、ご使用のブラウザの接続が正常に動作していることを確認するか、システム管理者にお問い合わせください。",
"kibana_utils.history.savedObjectIsMissingNotificationMessage": "保存されたオブジェクトがありません",

View file

@ -4215,8 +4215,6 @@
"inspector.requests.statisticsTabLabel": "统计信息",
"inspector.title": "检查器",
"inspector.view": "视图:{viewName}",
"kibana_legacy.notify.fatalError.errorStatusMessage": "错误 {errStatus} {errStatusText}{errMessage}",
"kibana_legacy.notify.fatalError.unavailableServerErrorMessage": "HTTP 请求无法连接。请检查 Kibana 服务器是否正在运行以及您的浏览器是否具有有效的连接,或请联系您的系统管理员。",
"kibana_legacy.notify.toaster.errorStatusMessage": "错误 {errStatus} {errStatusText}{errMessage}",
"kibana_legacy.notify.toaster.unavailableServerErrorMessage": "HTTP 请求无法连接。请检查 Kibana 服务器是否正在运行以及您的浏览器是否具有有效的连接,或请联系您的系统管理员。",
"kibana_utils.history.savedObjectIsMissingNotificationMessage": "已保存对象缺失",