Skip to content

Commit

Permalink
[Rename] Refactored src/plugins/url_forwarding directory (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: Mihir Soni <[email protected]>
  • Loading branch information
mihirsoni authored Mar 11, 2021
1 parent 8f25176 commit bfb0cc8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
7 changes: 0 additions & 7 deletions src/plugins/url_forwarding/kibana.json

This file was deleted.

7 changes: 7 additions & 0 deletions src/plugins/url_forwarding/opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "urlForwarding",
"version": "opensearchDashboards",
"server": false,
"ui": true,
"requiredPlugins": ["opensearchDashboardsLegacy"]
}
18 changes: 9 additions & 9 deletions src/plugins/url_forwarding/public/forward_app/forward_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
* under the License.
*/

import { App, AppMountParameters, CoreSetup } from 'kibana/public';
import { App, AppMountParameters, CoreSetup } from 'opensearch-dashboards/public';
import { AppNavLinkStatus } from '../../../../core/public';
import { navigateToLegacyKibanaUrl } from './navigate_to_legacy_kibana_url';
import { navigateToLegacyOpenSearchDashboardsUrl } from './navigate_to_legacy_opensearch_dashboards_url';
import { ForwardDefinition, UrlForwardingStart } from '../plugin';

export const createLegacyUrlForwardApp = (
core: CoreSetup<{}, UrlForwardingStart>,
forwards: ForwardDefinition[]
): App => ({
id: 'kibana',
id: 'opensearch-dashboards',
chromeless: true,
title: 'Legacy URL migration',
appRoute: '/app/kibana#/',
appRoute: '/app/opensearch-dashboards#/',
navLinkStatus: AppNavLinkStatus.hidden,
async mount(params: AppMountParameters) {
const hash = params.history.location.hash.substr(1);

if (!hash) {
const [, , kibanaLegacyStart] = await core.getStartServices();
kibanaLegacyStart.navigateToDefaultApp();
const [, , opensearchDashboardsLegacyStart] = await core.getStartServices();
opensearchDashboardsLegacyStart.navigateToDefaultApp();
}

const [
Expand All @@ -46,11 +46,11 @@ export const createLegacyUrlForwardApp = (
},
] = await core.getStartServices();

const result = await navigateToLegacyKibanaUrl(hash, forwards, basePath, application);
const result = await navigateToLegacyOpenSearchDashboardsUrl(hash, forwards, basePath, application);

if (!result.navigated) {
const [, , kibanaLegacyStart] = await core.getStartServices();
kibanaLegacyStart.navigateToDefaultApp();
const [, , opensearchDashboardsLegacyStart] = await core.getStartServices();
opensearchDashboardsLegacyStart.navigateToDefaultApp();
}

return () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/

import { ForwardDefinition } from '../index';
import { navigateToLegacyKibanaUrl } from './navigate_to_legacy_kibana_url';
import { navigateToLegacyOpenSearchDashboardsUrl } from './navigate_to_legacy_opensearch_dashboards_url';
import { CoreStart } from '../../../../core/public';
import { coreMock } from '../../../../core/public/mocks';

describe('migrate legacy kibana urls', () => {
describe('migrate legacy OpenSearch Dashboards urls', () => {
let forwardDefinitions: ForwardDefinition[];
let coreStart: CoreStart;

Expand All @@ -38,7 +38,7 @@ describe('migrate legacy kibana urls', () => {
});

it('should do nothing if no forward definition is found', () => {
const result = navigateToLegacyKibanaUrl(
const result = navigateToLegacyOpenSearchDashboardsUrl(
'/myOtherApp/deep/path',
forwardDefinitions,
coreStart.http.basePath,
Expand All @@ -50,7 +50,7 @@ describe('migrate legacy kibana urls', () => {
});

it('should call navigateToApp with migrated URL', () => {
const result = navigateToLegacyKibanaUrl(
const result = navigateToLegacyOpenSearchDashboardsUrl(
'/myApp/deep/path',
forwardDefinitions,
coreStart.http.basePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { ApplicationStart, IBasePath } from 'kibana/public';
import { ApplicationStart, IBasePath } from 'opensearch-dashboards/public';
import { ForwardDefinition } from '../index';
import { normalizePath } from './normalize_path';

export const navigateToLegacyKibanaUrl = (
export const navigateToLegacyOpenSearchDashboardsUrl = (
path: string,
forwards: ForwardDefinition[],
basePath: IBasePath,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/url_forwarding/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const createSetupContract = (): Setup => ({
const createStartContract = (): Start => ({
getForwards: jest.fn(),
navigateToDefaultApp: jest.fn(),
navigateToLegacyKibanaUrl: jest.fn(),
navigateToLegacyOpenSearchDashboardsUrl: jest.fn(),
});

export const urlForwardingPluginMock = {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/url_forwarding/public/navigate_to_default_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { ApplicationStart, IBasePath } from 'kibana/public';
import { ApplicationStart, IBasePath } from 'opensearch-dashboards/public';
import { ForwardDefinition } from './plugin';

export function navigateToDefaultApp(
Expand All @@ -28,8 +28,8 @@ export function navigateToDefaultApp(
currentAppId: string | undefined,
overwriteHash: boolean
) {
// navigate to the respective path in the legacy kibana plugin by default (for unmigrated plugins)
let targetAppId = 'kibana';
// navigate to the respective path in the legacy OpenSearch Dashboards plugin by default (for unmigrated plugins)
let targetAppId = 'opensearchDashboards';
let targetAppPath = `#/${defaultAppId}`;

// try to find an existing redirect for the target path if possible
Expand All @@ -41,7 +41,7 @@ export function navigateToDefaultApp(
}

// when the correct app is already loaded, just set the hash to the right value
// otherwise use navigateToApp (or setting href in case of kibana app)
// otherwise use navigateToApp (or setting href in case of OpenSearchDashboards, app)
if (currentAppId !== targetAppId) {
application.navigateToApp(targetAppId, { path: targetAppPath, replace: true });
} else if (overwriteHash) {
Expand Down
22 changes: 11 additions & 11 deletions src/plugins/url_forwarding/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* under the License.
*/

import { CoreStart, CoreSetup } from 'kibana/public';
import { KibanaLegacyStart } from 'src/plugins/kibana_legacy/public';
import { CoreStart, CoreSetup } from 'opensearch-dashboards/public';
import { OpenSearchDashboardsLegacyStart } from 'src/plugins/opensearch_dashboards_legacy/public';
import { Subscription } from 'rxjs';
import { navigateToDefaultApp } from './navigate_to_default_app';
import { createLegacyUrlForwardApp } from './forward_app';
import { navigateToLegacyKibanaUrl } from './forward_app/navigate_to_legacy_kibana_url';
import { navigateToLegacyOpenSearchDashboardsUrl } from './forward_app/navigate_to_legacy_opensearch_dashboards_url';

export interface ForwardDefinition {
legacyAppId: string;
Expand All @@ -39,7 +39,7 @@ export class UrlForwardingPlugin {
core.application.register(createLegacyUrlForwardApp(core, this.forwardDefinitions));
return {
/**
* Forwards URLs within the legacy `kibana` app to a new platform application.
* Forwards URLs within the legacy `opensearchDashboards` app to a new platform application.
*
* @param legacyAppId The name of the old app to forward URLs from
* @param newAppId The name of the new app that handles the URLs now
Expand All @@ -64,8 +64,8 @@ export class UrlForwardingPlugin {
* ```
* This will cause the following redirects:
*
* * app/kibana#/old/ -> app/new#/home
* * app/kibana#/old/item/123 -> app/new#/items/123
* * app/opensearch-dashboards#/old/ -> app/new#/home
* * app/opensearch-dashboards#/old/item/123 -> app/new#/items/123
*
*/
forwardApp: (
Expand All @@ -84,21 +84,21 @@ export class UrlForwardingPlugin {

public start(
{ application, http: { basePath }, uiSettings }: CoreStart,
{ kibanaLegacy }: { kibanaLegacy: KibanaLegacyStart }
{ opensearchDashboardsLegacy }: { opensearchDashboardsLegacy: OpenSearchDashboardsLegacyStart }
) {
this.currentAppIdSubscription = application.currentAppId$.subscribe((currentAppId) => {
this.currentAppId = currentAppId;
});
return {
/**
* Navigates to the app defined as kibana.defaultAppId.
* Navigates to the app defined as opensearch-dashboards.defaultAppId.
* This takes redirects into account and uses the right mechanism to navigate.
*/
navigateToDefaultApp: (
{ overwriteHash }: { overwriteHash: boolean } = { overwriteHash: true }
) => {
navigateToDefaultApp(
kibanaLegacy.config.defaultAppId,
opensearchDashboardsLegacy.config.defaultAppId,
this.forwardDefinitions,
application,
basePath,
Expand All @@ -112,8 +112,8 @@ export class UrlForwardingPlugin {
* If no matching forward is found, `{ navigated: false }` will be returned.
* @param hash
*/
navigateToLegacyKibanaUrl: (hash: string) => {
return navigateToLegacyKibanaUrl(hash, this.forwardDefinitions, basePath, application);
navigateToLegacyOpenSearchDashboardsUrl: (hash: string) => {
return navigateToLegacyOpenSearchDashboardsUrl(hash, this.forwardDefinitions, basePath, application);
},
/**
* @deprecated
Expand Down

0 comments on commit bfb0cc8

Please sign in to comment.