Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate url forwarding logic and legacy services #76892

Merged
merged 9 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ in Kibana, e.g. visualizations. It has the form of a flyout panel.


|{kib-repo}blob/{branch}/src/plugins/kibana_legacy/README.md[kibanaLegacy]
|This plugin will contain several helpers and services to integrate pieces of the legacy Kibana app with the new Kibana platform.
|This plugin contains several helpers and services to integrate pieces of the legacy Kibana app with the new Kibana platform.


|{kib-repo}blob/{branch}/src/plugins/kibana_react/README.md[kibanaReact]
Expand Down Expand Up @@ -172,6 +172,10 @@ which also contains the timelion APIs and backend, look at the vis_type_timelion
|An API for:


|{kib-repo}blob/{branch}/src/plugins/url_forwarding/README.md[urlForwarding]
|This plugins contains helpers to redirect legacy URLs. It can be used to forward old URLs to their new counterparts.


|{kib-repo}blob/{branch}/src/plugins/usage_collection/README.md[usageCollection]
|Usage Collection allows collecting usage data for other services to consume (telemetry and monitoring).
To integrate with the telemetry services for usage collection of your feature, there are 2 steps:
Expand Down
2 changes: 1 addition & 1 deletion src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ import { npStart: { plugins } } from 'ui/new_platform';
| `import 'ui/filter_bar'` | `import { FilterBar } from '../data/public'` | Directive is deprecated. |
| `import 'ui/query_bar'` | `import { QueryStringInput } from '../data/public'` | Directives are deprecated. |
| `import 'ui/search_bar'` | `import { SearchBar } from '../data/public'` | Directive is deprecated. |
| `import 'ui/kbn_top_nav'` | `import { TopNavMenu } from '../navigation/public'` | Directive was moved to `src/plugins/kibana_legacy`. |
| `import 'ui/kbn_top_nav'` | `import { TopNavMenu } from '../navigation/public'` | Directive was removed. |
| `ui/saved_objects/components/saved_object_finder` | `import { SavedObjectFinder } from '../saved_objects/public'` | |
| `core_plugins/interpreter` | `plugins.data.expressions` |
| `ui/courier` | `plugins.data.search` |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dashboard/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"embeddable",
"inspector",
"kibanaLegacy",
"urlForwarding",
"navigation",
"uiActions",
"savedObjects"
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/dashboard/public/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { NavigationPublicPluginStart as NavigationStart } from '../../../navigat
import { DataPublicPluginStart } from '../../../data/public';
import { SharePluginStart } from '../../../share/public';
import { KibanaLegacyStart, configureAppAngularModule } from '../../../kibana_legacy/public';
import { UrlForwardingStart } from '../../../url_forwarding/public';
import { SavedObjectLoader, SavedObjectsStart } from '../../../saved_objects/public';

// required for i18nIdDirective
Expand Down Expand Up @@ -69,8 +70,8 @@ export interface RenderDeps {
localStorage: Storage;
share?: SharePluginStart;
usageCollection?: UsageCollectionSetup;
navigateToDefaultApp: KibanaLegacyStart['navigateToDefaultApp'];
navigateToLegacyKibanaUrl: KibanaLegacyStart['navigateToLegacyKibanaUrl'];
navigateToDefaultApp: UrlForwardingStart['navigateToDefaultApp'];
navigateToLegacyKibanaUrl: UrlForwardingStart['navigateToLegacyKibanaUrl'];
scopedHistory: () => ScopedHistory;
savedObjects: SavedObjectsStart;
restorePreviousUrl: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ import {
AngularHttpError,
KibanaLegacyStart,
subscribeWithScope,
migrateLegacyQuery,
} from '../../../kibana_legacy/public';
import { migrateLegacyQuery } from './lib/migrate_legacy_query';

export interface DashboardAppControllerDependencies extends RenderDeps {
$scope: DashboardAppScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { History } from 'history';

import { Filter, Query, TimefilterContract as Timefilter } from 'src/plugins/data/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
import { migrateLegacyQuery } from '../../../kibana_legacy/public';
import { migrateLegacyQuery } from './lib/migrate_legacy_query';

import { ViewMode } from '../embeddable_plugin';
import { getAppStateDefaults, migrateAppState, getDashboardIdFromUrl } from './lib';
Expand Down
21 changes: 17 additions & 4 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
SavedObjectsClientContract,
ScopedHistory,
} from 'src/core/public';
import { UrlForwardingSetup, UrlForwardingStart } from 'src/plugins/url_forwarding/public';
import { UsageCollectionSetup } from '../../usage_collection/public';
import {
CONTEXT_MENU_TRIGGER,
Expand Down Expand Up @@ -125,6 +126,7 @@ interface SetupDependencies {
embeddable: EmbeddableSetup;
home?: HomePublicPluginSetup;
kibanaLegacy: KibanaLegacySetup;
urlForwarding: UrlForwardingSetup;
share?: SharePluginSetup;
uiActions: UiActionsSetup;
usageCollection?: UsageCollectionSetup;
Expand All @@ -133,6 +135,7 @@ interface SetupDependencies {
interface StartDependencies {
data: DataPublicPluginStart;
kibanaLegacy: KibanaLegacyStart;
urlForwarding: UrlForwardingStart;
embeddable: EmbeddableStart;
inspector: InspectorStartContract;
navigation: NavigationStart;
Expand Down Expand Up @@ -190,7 +193,16 @@ export class DashboardPlugin

public setup(
core: CoreSetup<StartDependencies, DashboardStart>,
{ share, uiActions, embeddable, home, kibanaLegacy, data, usageCollection }: SetupDependencies
{
share,
uiActions,
embeddable,
home,
kibanaLegacy,
urlForwarding,
data,
usageCollection,
}: SetupDependencies
): Setup {
this.dashboardFeatureFlagConfig = this.initializerContext.config.get<
DashboardFeatureFlagConfig
Expand Down Expand Up @@ -311,7 +323,8 @@ export class DashboardPlugin
navigation,
share: shareStart,
data: dataStart,
kibanaLegacy: { dashboardConfig, navigateToDefaultApp, navigateToLegacyKibanaUrl },
kibanaLegacy: { dashboardConfig },
urlForwarding: { navigateToDefaultApp, navigateToLegacyKibanaUrl },
savedObjects,
} = pluginsStart;

Expand Down Expand Up @@ -357,7 +370,7 @@ export class DashboardPlugin
initAngularBootstrap();

core.application.register(app);
kibanaLegacy.forwardApp(
urlForwarding.forwardApp(
DashboardConstants.DASHBOARDS_ID,
DashboardConstants.DASHBOARDS_ID,
(path) => {
Expand All @@ -366,7 +379,7 @@ export class DashboardPlugin
return `#/list${tail || ''}`;
}
);
kibanaLegacy.forwardApp(
urlForwarding.forwardApp(
DashboardConstants.DASHBOARD_ID,
DashboardConstants.DASHBOARDS_ID,
(path) => {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"usageCollection",
"kibanaUtils",
"kibanaReact",
"kibanaLegacy",
"inspector"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { migrateLegacyQuery } from '../../../../kibana_legacy/common';
import { migrateLegacyQuery } from './migrate_legacy_query';
import { SearchSource, SearchSourceDependencies } from './search_source';
import { IndexPatternsContract } from '../../index_patterns/index_patterns';
import { SearchSourceFields } from './types';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { has } from 'lodash';
import { Query } from 'src/plugins/data/public';

/**
* Creates a standardized query object from old queries that were either strings or pure ES query DSL
*
* @param query - a legacy query, what used to be stored in SearchSource's query property
* @return Object
*/

export function migrateLegacyQuery(query: Query | { [key: string]: any } | string): Query {
// Lucene was the only option before, so language-less queries are all lucene
if (!has(query, 'language')) {
return { query, language: 'lucene' };
}

return query as Query;
}
2 changes: 1 addition & 1 deletion src/plugins/dev_tools/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"version": "kibana",
"server": false,
"ui": true,
"requiredPlugins": ["kibanaLegacy"]
"requiredPlugins": ["urlForwarding"]
}
6 changes: 3 additions & 3 deletions src/plugins/dev_tools/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { i18n } from '@kbn/i18n';
import { sortBy } from 'lodash';

import { AppNavLinkStatus, DEFAULT_APP_CATEGORIES } from '../../../core/public';
import { KibanaLegacySetup } from '../../kibana_legacy/public';
import { UrlForwardingSetup } from '../../url_forwarding/public';
import { CreateDevToolArgs, DevToolApp, createDevToolApp } from './dev_tool';

import './index.scss';
Expand All @@ -51,7 +51,7 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
return sortBy([...this.devTools.values()], 'order');
}

public setup(coreSetup: CoreSetup, { kibanaLegacy }: { kibanaLegacy: KibanaLegacySetup }) {
public setup(coreSetup: CoreSetup, { urlForwarding }: { urlForwarding: UrlForwardingSetup }) {
const { application: applicationSetup, getStartServices } = coreSetup;

applicationSetup.register({
Expand All @@ -75,7 +75,7 @@ export class DevToolsPlugin implements Plugin<DevToolsSetup, void> {
},
});

kibanaLegacy.forwardApp('dev_tools', 'dev_tools');
urlForwarding.forwardApp('dev_tools', 'dev_tools');

return {
register: (devToolArgs: CreateDevToolArgs) => {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"embeddable",
"inspector",
"kibanaLegacy",
"urlForwarding",
"navigation",
"uiActions",
"visualizations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
withNotifyOnErrors,
} from '../../../../kibana_utils/public';
import { esFilters, Filter, Query } from '../../../../data/public';
import { migrateLegacyQuery } from '../../../../kibana_legacy/public';
import { migrateLegacyQuery } from '../helpers/migrate_legacy_query';

export interface AppState {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/discover/public/application/angular/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ getAngularModule().config(($routeProvider: any) => {
const path = window.location.hash.substr(1);
getUrlTracker().restorePreviousUrl();
$rootScope.$applyAsync(() => {
const { kibanaLegacy } = getServices();
const { navigated } = kibanaLegacy.navigateToLegacyKibanaUrl(path);
const { urlForwarding } = getServices();
const { navigated } = urlForwarding.navigateToLegacyKibanaUrl(path);
if (!navigated) {
kibanaLegacy.navigateToDefaultApp();
urlForwarding.navigateToDefaultApp();
}
});
// prevent angular from completing the navigation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { has } from 'lodash';
import { Query } from 'src/plugins/data/public';

/**
* Creates a standardized query object from old queries that were either strings or pure ES query DSL
*
* @param query - a legacy query, what used to be stored in SearchSource's query property
* @return Object
*/

export function migrateLegacyQuery(query: Query | { [key: string]: any } | string): Query {
// Lucene was the only option before, so language-less queries are all lucene
if (!has(query, 'language')) {
return { query, language: 'lucene' };
}

return query as Query;
}
3 changes: 3 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { DiscoverStartPlugins } from './plugin';
import { createSavedSearchesLoader, SavedSearch } from './saved_searches';
import { getHistory } from './kibana_services';
import { KibanaLegacyStart } from '../../kibana_legacy/public';
import { UrlForwardingStart } from '../../url_forwarding/public';

export interface DiscoverServices {
addBasePath: (path: string) => string;
Expand All @@ -59,6 +60,7 @@ export interface DiscoverServices {
metadata: { branch: string };
share?: SharePluginStart;
kibanaLegacy: KibanaLegacyStart;
urlForwarding: UrlForwardingStart;
timefilter: TimefilterContract;
toastNotifications: ToastsStart;
getSavedSearchById: (id: string) => Promise<SavedSearch>;
Expand Down Expand Up @@ -100,6 +102,7 @@ export async function buildServices(
},
share: plugins.share,
kibanaLegacy: plugins.kibanaLegacy,
urlForwarding: plugins.urlForwarding,
timefilter: plugins.data.query.timefilter.timefilter,
toastNotifications: core.notifications.toasts,
uiSettings: core.uiSettings,
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/discover/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NavigationPublicPluginStart as NavigationStart } from 'src/plugins/navi
import { SharePluginStart, SharePluginSetup, UrlGeneratorContract } from 'src/plugins/share/public';
import { VisualizationsStart, VisualizationsSetup } from 'src/plugins/visualizations/public';
import { KibanaLegacySetup, KibanaLegacyStart } from 'src/plugins/kibana_legacy/public';
import { UrlForwardingSetup, UrlForwardingStart } from 'src/plugins/url_forwarding/public';
import { HomePublicPluginSetup } from 'src/plugins/home/public';
import { Start as InspectorPublicPluginStart } from 'src/plugins/inspector/public';
import { DataPublicPluginStart, DataPublicPluginSetup, esFilters } from '../../data/public';
Expand Down Expand Up @@ -119,6 +120,7 @@ export interface DiscoverSetupPlugins {
uiActions: UiActionsSetup;
embeddable: EmbeddableSetup;
kibanaLegacy: KibanaLegacySetup;
urlForwarding: UrlForwardingSetup;
home?: HomePublicPluginSetup;
visualizations: VisualizationsSetup;
data: DataPublicPluginSetup;
Expand All @@ -135,6 +137,7 @@ export interface DiscoverStartPlugins {
data: DataPublicPluginStart;
share?: SharePluginStart;
kibanaLegacy: KibanaLegacyStart;
urlForwarding: UrlForwardingStart;
inspector: InspectorPublicPluginStart;
visualizations: VisualizationsStart;
}
Expand Down Expand Up @@ -267,13 +270,13 @@ export class DiscoverPlugin
},
});

plugins.kibanaLegacy.forwardApp('doc', 'discover', (path) => {
plugins.urlForwarding.forwardApp('doc', 'discover', (path) => {
return `#${path}`;
});
plugins.kibanaLegacy.forwardApp('context', 'discover', (path) => {
plugins.urlForwarding.forwardApp('context', 'discover', (path) => {
return `#${path}`;
});
plugins.kibanaLegacy.forwardApp('discover', 'discover', (path) => {
plugins.urlForwarding.forwardApp('discover', 'discover', (path) => {
const [, id, tail] = /discover\/([^\?]+)(.*)/.exec(path) || [];
if (!id) {
return `#${path.replace('/discover', '') || '/'}`;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["data", "kibanaLegacy"],
"requiredPlugins": ["data", "urlForwarding"],
"optionalPlugins": ["usageCollection", "telemetry"],
"requiredBundles": [
"kibanaReact"
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/home/public/application/components/home_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import { useMount } from 'react-use';

const RedirectToDefaultApp = () => {
useMount(() => {
const { kibanaLegacy } = getServices();
kibanaLegacy.navigateToDefaultApp();
const { urlForwarding } = getServices();
urlForwarding.navigateToDefaultApp();
});
return null;
};
Expand Down
Loading