Skip to content

Commit

Permalink
Rename kibana_legacy to opensearch_dashboards_legacy (#37) (#154)
Browse files Browse the repository at this point in the history
* Rename kibana_legacy to opensearch_dashboards_legacy (#37)

Signed-off-by: Bishoy Boktor <boktorbb@amazon.com>
  • Loading branch information
boktorbb authored and mihirsoni committed Mar 20, 2021
1 parent b18e706 commit 380d84d
Show file tree
Hide file tree
Showing 49 changed files with 109 additions and 110 deletions.
7 changes: 0 additions & 7 deletions src/plugins/kibana_legacy/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions src/plugins/kibana_legacy/kibana.json

This file was deleted.

7 changes: 7 additions & 0 deletions src/plugins/opensearch_dashboards_legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpenSearch-Dashboards-legacy

This plugin contains several helpers and services to integrate pieces of the legacy OpenSearch Dashboards app with the new OpenSearch Dashboards platform.

This plugin will be removed once all parts of legacy OpenSearch Dashboards are removed from other plugins.

All of this plugin should be considered deprecated. New code should never integrate with the services provided from this plugin.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema, TypeOf } from '@osd/config-schema';

export const configSchema = schema.object({
defaultAppId: schema.string({ defaultValue: 'home' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "opensearchDashboardsLegacy",
"version": "opensearchDashboards",
"server": true,
"ui": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import $ from 'jquery';
import { set } from '@elastic/safer-lodash-set';
import { get } from 'lodash';
import * as Rx from 'rxjs';
import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'kibana/public';
import { ChromeBreadcrumb, EnvironmentMode, PackageInfo } from 'opensearch-dashboards/public';
import { History } from 'history';

import { CoreStart } from 'kibana/public';
import { CoreStart } from 'opensearch-dashboards/public';
import { isSystemApiRequest } from '../utils';
import { formatAngularHttpError, isAngularHttpError } from '../notify/lib';

Expand Down Expand Up @@ -86,10 +86,10 @@ export const configureAppAngularModule = (
const packageInfo = newPlatform.env.packageInfo;

angularModule
.value('kbnVersion', packageInfo.version)
.value('osdVersion', packageInfo.version)
.value('buildNum', packageInfo.buildNum)
.value('buildSha', packageInfo.buildSha)
.value('esUrl', getEsUrl(core))
.value('opensearchUrl', getOpenSearchUrl(core))
.value('uiCapabilities', core.application.capabilities)
.config(setupCompileProvider(newPlatform.env.mode.dev))
.config(setupLocationProvider())
Expand All @@ -102,9 +102,9 @@ export const configureAppAngularModule = (
.run($setupUICapabilityRedirect(core));
};

const getEsUrl = (newPlatform: CoreStart) => {
const getOpenSearchUrl = (newPlatform: CoreStart) => {
const a = document.createElement('a');
a.href = newPlatform.http.basePath.prepend('/elasticsearch');
a.href = newPlatform.http.basePath.prepend('/opensearch');
const protocolPort = /https/.test(a.protocol) ? 443 : 80;
const port = a.port || protocolPort;
return {
Expand Down Expand Up @@ -146,9 +146,9 @@ const setupLocationProvider = () => ($locationProvider: ILocationProvider) => {

export const $setupXsrfRequestInterceptor = (version: string) => {
// Configure jQuery prefilter
$.ajaxPrefilter(({ kbnXsrfToken = true }: any, originalOptions, jqXHR) => {
if (kbnXsrfToken) {
jqXHR.setRequestHeader('kbn-version', version);
$.ajaxPrefilter(({ osdXsrfToken = true }: any, originalOptions, jqXHR) => {
if (osdXsrfToken) {
jqXHR.setRequestHeader('osd-version', version);
}
});

Expand All @@ -157,9 +157,9 @@ export const $setupXsrfRequestInterceptor = (version: string) => {
$httpProvider.interceptors.push(() => {
return {
request(opts) {
const { kbnXsrfToken = true } = opts as any;
if (kbnXsrfToken) {
set(opts, ['headers', 'kbn-version'], version);
const { osdXsrfToken = true } = opts as any;
if (osdXsrfToken) {
set(opts, ['headers', 'osd-version'], version);
}
return opts;
},
Expand Down Expand Up @@ -198,11 +198,11 @@ const $setupUICapabilityRedirect = (newPlatform: CoreStart) => (
$rootScope: IRootScopeService,
$injector: any
) => {
const isKibanaAppRoute = window.location.pathname.endsWith('/app/kibana');
// this feature only works within kibana app for now after everything is
const isOpenSearchDashboardsAppRoute = window.location.pathname.endsWith('/app/opensearch-dashboards');
// this feature only works within opensearch dashboards app for now after everything is
// switched to the application service, this can be changed to handle all
// apps.
if (!isKibanaAppRoute) {
if (!isOpenSearchDashboardsAppRoute) {
return;
}
$rootScope.$on(
Expand All @@ -223,7 +223,7 @@ const $setupUICapabilityRedirect = (newPlatform: CoreStart) => (
/**
* internal angular run function that will be called when angular bootstraps and
* lets us integrate with the angular router so that we can automatically clear
* the breadcrumbs if we switch to a Kibana app that does not use breadcrumbs correctly
* the breadcrumbs if we switch to a OpenSearch Dashboards app that does not use breadcrumbs correctly
*/
const $setupBreadcrumbsAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
$rootScope: IRootScopeService,
Expand Down Expand Up @@ -276,7 +276,7 @@ const $setupBreadcrumbsAutoClear = (newPlatform: CoreStart, isLocalAngular: bool
/**
* internal angular run function that will be called when angular bootstraps and
* lets us integrate with the angular router so that we can automatically clear
* the badge if we switch to a Kibana app that does not use the badge correctly
* the badge if we switch to a OpenSearch Dashboards app that does not use the badge correctly
*/
const $setupBadgeAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
$rootScope: IRootScopeService,
Expand Down Expand Up @@ -321,7 +321,7 @@ const $setupBadgeAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) =
/**
* internal angular run function that will be called when angular bootstraps and
* lets us integrate with the angular router so that we can automatically clear
* the helpExtension if we switch to a Kibana app that does not set its own
* the helpExtension if we switch to a OpenSearch Dashboards app that does not set its own
* helpExtension
*/
const $setupHelpExtensionAutoClear = (newPlatform: CoreStart, isLocalAngular: boolean) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export { PromiseServiceCreator } from './promises';
export { watchMultiDecorator } from './watch_multi';
export * from './angular_config';
// @ts-ignore
export { createTopNavDirective, createTopNavHelper, loadKbnTopNavDirectives } from './kbn_top_nav';
export { createTopNavDirective, createTopNavHelper, loadOsdTopNavDirectives } from './osd_top_nav';
export { subscribeWithScope } from './subscribe_with_scope';
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createTopNavDirective() {
restrict: 'E',
template: '',
compile: (elem) => {
const child = document.createElement('kbn-top-nav-helper');
const child = document.createElement('osd-top-nav-helper');

// Copy attributes to the child directive
for (const attr of elem[0].attributes) {
Expand Down Expand Up @@ -118,12 +118,12 @@ export const createTopNavHelper = ({ TopNavMenu }) => (reactDirective) => {

let isLoaded = false;

export function loadKbnTopNavDirectives(navUi) {
export function loadOsdTopNavDirectives(navUi) {
if (!isLoaded) {
isLoaded = true;
angular
.module('kibana')
.directive('kbnTopNav', createTopNavDirective)
.directive('kbnTopNavHelper', createTopNavHelper(navUi));
.module('opensearchDashboards')
.directive('osdTopNav', createTopNavDirective)
.directive('osdTopNavHelper', createTopNavHelper(navUi));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function callInDigest($scope: IScope, fn: () => void, fatalError?: FatalErrorFn)
// this is terrible, but necessary to synchronously deliver subscription values
// to angular scopes. This is required by some APIs, like the `config` service,
// and beneficial for root level directives where additional digest cycles make
// kibana sluggish to load.
// opensearch dashboards sluggish to load.
//
// If you copy this code elsewhere you better have a good reason :)
if ($scope.$root.$$phase) {
Expand Down Expand Up @@ -67,8 +67,7 @@ export function subscribeWithScope<T>(
observer.error(error);
} else {
throw new Error(
`Uncaught error in subscribeWithScope(): ${
error ? error.stack || error.message : error
`Uncaught error in subscribeWithScope(): ${error ? error.stack || error.message : error
}`
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { KibanaLegacyPlugin } from './plugin';
import { PluginInitializerContext } from 'opensearch-dashboards/public';
import { OpenSearchDashboardsLegacyPlugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) =>
new KibanaLegacyPlugin(initializerContext);
new OpenSearchDashboardsLegacyPlugin(initializerContext);

export * from './plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { KibanaLegacyPlugin } from './plugin';
import { OpenSearchDashboardsLegacyPlugin } from './plugin';

export type Setup = jest.Mocked<ReturnType<KibanaLegacyPlugin['setup']>>;
export type Start = jest.Mocked<ReturnType<KibanaLegacyPlugin['start']>>;
export type Setup = jest.Mocked<ReturnType<OpenSearchDashboardsLegacyPlugin['setup']>>;
export type Start = jest.Mocked<ReturnType<OpenSearchDashboardsLegacyPlugin['start']>>;

const createSetupContract = (): Setup => ({});

Expand All @@ -35,7 +35,7 @@ const createStartContract = (): Start => ({
loadFontAwesome: jest.fn(),
});

export const kibanaLegacyPluginMock = {
export const opensearchDashboardsLegacyPluginMock = {
createSetupContract,
createStartContract,
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { i18n } from '@kbn/i18n';
import { i18n } from '@osd/i18n';
import { IHttpResponse } from 'angular';

export type AngularHttpError = IHttpResponse<{ message: string }>;
Expand All @@ -36,15 +36,15 @@ 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('opensearch_dashboards_legacy.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, ' +
'Please check if the OpenSearch Dashboards server is running and that your browser has a working connection, ' +
'or contact your system administrator.',
});
}

return i18n.translate('kibana_legacy.notify.fatalError.errorStatusMessage', {
return i18n.translate('opensearch_dashboards_legacy.notify.fatalError.errorStatusMessage', {
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
values: {
errStatus: error.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { formatMsg } from './format_msg';
import expect from '@kbn/expect';
import expect from '@osd/expect';

describe('formatMsg', () => {
test('should prepend the second argument to result', () => {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('formatMsg', () => {
);
});

test('should handle an extended elasticsearch error', () => {
test('should handle an extended opensearch error', () => {
const err = {
resp: {
error: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { formatESMsg } from './format_es_msg';
import { i18n } from '@osd/i18n';
import { formatOpenSearchMsg } from './format_opensearch_msg';
const has = _.has;

/**
* Formats the error message from an error object, extended elasticsearch
* Formats the error message from an error object, extended opensearch
* object or simple string; prepends optional second parameter to the message
* @param {Error|String} err
* @param {String} source - Prefix for message indicating source (optional)
Expand All @@ -35,26 +35,26 @@ export function formatMsg(err: Record<string, any> | string, source: string = ''
message += source + ': ';
}

const esMsg = formatESMsg(err);
const opensearchMsg = formatOpenSearchMsg(err);

if (typeof err === 'string') {
message += err;
} else if (esMsg) {
message += esMsg;
} else if (opensearchMsg) {
message += opensearchMsg;
} else if (err instanceof Error) {
message += formatMsg.describeError(err);
} else if (has(err, 'status') && has(err, 'data')) {
// is an Angular $http "error object"
if (err.status === -1) {
// status = -1 indicates that the request was failed to reach the server
message += i18n.translate('kibana_legacy.notify.toaster.unavailableServerErrorMessage', {
message += i18n.translate('opensearch_dashboards_legacy.notify.toaster.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, ' +
'Please check if the OpenSearch Dashboards server is running and that your browser has a working connection, ' +
'or contact your system administrator.',
});
} else {
message += i18n.translate('kibana_legacy.notify.toaster.errorStatusMessage', {
message += i18n.translate('opensearch_dashboards_legacy.notify.toaster.errorStatusMessage', {
defaultMessage: 'Error {errStatus} {errStatusText}: {errMessage}',
values: {
errStatus: err.status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
* under the License.
*/

import { formatESMsg } from './format_es_msg';
import expect from '@kbn/expect';
import { formatOpenSearchMsg } from './format_opensearch_msg';
import expect from '@osd/expect';

describe('formatESMsg', () => {
describe('formatOpenSearchMsg', () => {
test('should return undefined if passed a basic error', () => {
const err = new Error('This is a normal error');

const actual = formatESMsg(err);
const actual = formatOpenSearchMsg(err);

expect(actual).to.be(undefined);
});

test('should return undefined if passed a string', () => {
const err = 'This is a error string';

const actual = formatESMsg(err);
const actual = formatOpenSearchMsg(err);

expect(actual).to.be(undefined);
});

test('should return the root_cause if passed an extended elasticsearch', () => {
const err = new Error('This is an elasticsearch error');
test('should return the root_cause if passed an extended opensearch', () => {
const err = new Error('This is an opensearch error');
err.resp = {
error: {
root_cause: [
Expand All @@ -49,13 +49,13 @@ describe('formatESMsg', () => {
},
};

const actual = formatESMsg(err);
const actual = formatOpenSearchMsg(err);

expect(actual).to.equal('I am the detailed message');
});

test('should combine the reason messages if more than one is returned.', () => {
const err = new Error('This is an elasticsearch error');
const err = new Error('This is an opensearch error');
err.resp = {
error: {
root_cause: [
Expand All @@ -69,7 +69,7 @@ describe('formatESMsg', () => {
},
};

const actual = formatESMsg(err);
const actual = formatOpenSearchMsg(err);

expect(actual).to.equal('I am the detailed message 1\nI am the detailed message 2');
});
Expand Down
Loading

0 comments on commit 380d84d

Please sign in to comment.