diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts
index b497f73f3df2a..3f81bfe5aadf2 100644
--- a/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts
+++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts
@@ -33,7 +33,6 @@ export { IInjector } from 'ui/chrome';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export {
configureAppAngularModule,
- ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js
index f7baba663da75..64abbdfb87d58 100644
--- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js
+++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/legacy_app.js
@@ -23,11 +23,11 @@ import dashboardTemplate from './dashboard_app.html';
import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html';
import { createHashHistory } from 'history';
-import { ensureDefaultIndexPattern } from '../legacy_imports';
import { initDashboardAppDirective } from './dashboard_app';
import { createDashboardEditUrl, DashboardConstants } from './dashboard_constants';
import {
createKbnUrlStateStorage,
+ ensureDefaultIndexPattern,
redirectWhenMissing,
InvalidJSONProperty,
SavedObjectNotFound,
@@ -137,8 +137,8 @@ export function initDashboardApp(app, deps) {
});
},
resolve: {
- dash: function($rootScope, $route, kbnUrl, history) {
- return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl).then(() => {
+ dash: function($route, history) {
+ return ensureDefaultIndexPattern(deps.core, deps.data, history).then(() => {
const savedObjectsClient = deps.savedObjectsClient;
const title = $route.current.params.title;
if (title) {
@@ -172,11 +172,9 @@ export function initDashboardApp(app, deps) {
controller: createNewDashboardCtrl,
requireUICapability: 'dashboard.createNew',
resolve: {
- dash: function($rootScope, kbnUrl, history) {
- return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl)
- .then(() => {
- return deps.savedDashboards.get();
- })
+ dash: history =>
+ ensureDefaultIndexPattern(deps.core, deps.data, history)
+ .then(() => deps.savedDashboards.get())
.catch(
redirectWhenMissing({
history,
@@ -185,8 +183,7 @@ export function initDashboardApp(app, deps) {
},
toastNotifications: deps.core.notifications.toasts,
})
- );
- },
+ ),
},
})
.when(createDashboardEditUrl(':id'), {
@@ -194,13 +191,11 @@ export function initDashboardApp(app, deps) {
template: dashboardTemplate,
controller: createNewDashboardCtrl,
resolve: {
- dash: function($rootScope, $route, kbnUrl, history) {
+ dash: function($route, kbnUrl, history) {
const id = $route.current.params.id;
- return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl)
- .then(() => {
- return deps.savedDashboards.get(id);
- })
+ return ensureDefaultIndexPattern(deps.core, deps.data, history)
+ .then(() => deps.savedDashboards.get(id))
.then(savedDashboard => {
deps.chrome.recentlyAccessed.add(
savedDashboard.getFullPath(),
diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts
index 5f3dbb65fd8ff..725e94f16e2e8 100644
--- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts
+++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts
@@ -54,14 +54,17 @@ import { search } from '../../../../../plugins/data/public';
export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggResponse } = search;
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
-export { subscribeWithScope } from '../../../../../plugins/kibana_legacy/public';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
-export { unhashUrl, redirectWhenMissing } from '../../../../../plugins/kibana_utils/public';
export {
+ unhashUrl,
+ redirectWhenMissing,
ensureDefaultIndexPattern,
+} from '../../../../../plugins/kibana_utils/public';
+export {
formatMsg,
formatStack,
+ subscribeWithScope,
} from '../../../../../plugins/kibana_legacy/public';
// EXPORT types
diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js
index 6978781fe6696..9a383565f4f43 100644
--- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js
+++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js
@@ -115,9 +115,9 @@ app.config($routeProvider => {
template: indexTemplate,
reloadOnSearch: false,
resolve: {
- savedObjects: function($route, kbnUrl, Promise, $rootScope) {
+ savedObjects: function($route, Promise) {
const savedSearchId = $route.current.params.id;
- return ensureDefaultIndexPattern(core, data, $rootScope, kbnUrl).then(() => {
+ return ensureDefaultIndexPattern(core, data, history).then(() => {
const { appStateContainer } = getState({ history });
const { index } = appStateContainer.getState();
return Promise.props({
diff --git a/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts b/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts
index 69af466a03729..e6b7a29e28d89 100644
--- a/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts
+++ b/src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts
@@ -33,7 +33,6 @@ export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants';
export { VisSavedObject, VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/';
export {
configureAppAngularModule,
- ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js
index 1002f401706cd..0f1d50b149cd9 100644
--- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js
+++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/legacy_app.js
@@ -24,6 +24,7 @@ import { createHashHistory } from 'history';
import {
createKbnUrlStateStorage,
redirectWhenMissing,
+ ensureDefaultIndexPattern,
} from '../../../../../../plugins/kibana_utils/public';
import editorTemplate from './editor/editor.html';
@@ -32,7 +33,6 @@ import visualizeListingTemplate from './listing/visualize_listing.html';
import { initVisualizeAppDirective } from './visualize_app';
import { VisualizeConstants } from './visualize_constants';
import { VisualizeListingController } from './listing/visualize_listing';
-import { ensureDefaultIndexPattern } from '../legacy_imports';
import {
getLandingBreadcrumbs,
@@ -82,8 +82,7 @@ export function initVisualizeApp(app, deps) {
controllerAs: 'listingController',
resolve: {
createNewVis: () => false,
- hasDefaultIndex: ($rootScope, kbnUrl) =>
- ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl),
+ hasDefaultIndex: history => ensureDefaultIndexPattern(deps.core, deps.data, history),
},
})
.when(VisualizeConstants.WIZARD_STEP_1_PAGE_PATH, {
@@ -94,8 +93,7 @@ export function initVisualizeApp(app, deps) {
controllerAs: 'listingController',
resolve: {
createNewVis: () => true,
- hasDefaultIndex: ($rootScope, kbnUrl) =>
- ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl),
+ hasDefaultIndex: history => ensureDefaultIndexPattern(deps.core, deps.data, history),
},
})
.when(VisualizeConstants.CREATE_PATH, {
@@ -103,7 +101,7 @@ export function initVisualizeApp(app, deps) {
template: editorTemplate,
k7Breadcrumbs: getCreateBreadcrumbs,
resolve: {
- savedVis: function($route, $rootScope, kbnUrl, history) {
+ savedVis: function($route, history) {
const { core, data, savedVisualizations, visualizations, toastNotifications } = deps;
const visTypes = visualizations.all();
const visType = find(visTypes, { name: $route.current.params.type });
@@ -121,7 +119,7 @@ export function initVisualizeApp(app, deps) {
);
}
- return ensureDefaultIndexPattern(core, data, $rootScope, kbnUrl)
+ return ensureDefaultIndexPattern(core, data, history)
.then(() => savedVisualizations.get($route.current.params))
.then(savedVis => {
if (savedVis.vis.type.setup) {
@@ -144,9 +142,9 @@ export function initVisualizeApp(app, deps) {
template: editorTemplate,
k7Breadcrumbs: getEditBreadcrumbs,
resolve: {
- savedVis: function($route, $rootScope, kbnUrl, history) {
+ savedVis: function($route, history) {
const { chrome, core, data, savedVisualizations, toastNotifications } = deps;
- return ensureDefaultIndexPattern(core, data, $rootScope, kbnUrl)
+ return ensureDefaultIndexPattern(core, data, history)
.then(() => savedVisualizations.get($route.current.params.id))
.then(savedVis => {
chrome.recentlyAccessed.add(savedVis.getFullPath(), savedVis.title, savedVis.id);
diff --git a/src/legacy/ui/public/legacy_compat/index.ts b/src/legacy/ui/public/legacy_compat/index.ts
index 3b700c8d59399..2067fa6489304 100644
--- a/src/legacy/ui/public/legacy_compat/index.ts
+++ b/src/legacy/ui/public/legacy_compat/index.ts
@@ -17,7 +17,4 @@
* under the License.
*/
-export {
- configureAppAngularModule,
- ensureDefaultIndexPattern,
-} from '../../../../plugins/kibana_legacy/public';
+export { configureAppAngularModule } from '../../../../plugins/kibana_legacy/public';
diff --git a/src/plugins/kibana_legacy/public/angular/index.ts b/src/plugins/kibana_legacy/public/angular/index.ts
index 5fc37ac39612a..16bae6c4cffe0 100644
--- a/src/plugins/kibana_legacy/public/angular/index.ts
+++ b/src/plugins/kibana_legacy/public/angular/index.ts
@@ -21,7 +21,6 @@ export { PromiseServiceCreator } from './promises';
// @ts-ignore
export { watchMultiDecorator } from './watch_multi';
export * from './angular_config';
-export { ensureDefaultIndexPattern } from './ensure_default_index_pattern';
// @ts-ignore
export { createTopNavDirective, createTopNavHelper, loadKbnTopNavDirectives } from './kbn_top_nav';
export { subscribeWithScope } from './subscribe_with_scope';
diff --git a/src/plugins/kibana_legacy/public/angular/ensure_default_index_pattern.tsx b/src/plugins/kibana_utils/public/history/ensure_default_index_pattern.tsx
similarity index 67%
rename from src/plugins/kibana_legacy/public/angular/ensure_default_index_pattern.tsx
rename to src/plugins/kibana_utils/public/history/ensure_default_index_pattern.tsx
index 1a3bb84ae7575..7992f650cb372 100644
--- a/src/plugins/kibana_legacy/public/angular/ensure_default_index_pattern.tsx
+++ b/src/plugins/kibana_utils/public/history/ensure_default_index_pattern.tsx
@@ -18,14 +18,13 @@
*/
import { contains } from 'lodash';
-import { IRootScopeService } from 'angular';
import React from 'react';
-import ReactDOM from 'react-dom';
+import { History } from 'history';
import { i18n } from '@kbn/i18n';
-import { I18nProvider } from '@kbn/i18n/react';
import { EuiCallOut } from '@elastic/eui';
import { CoreStart } from 'kibana/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
+import { toMountPoint } from '../../../kibana_react/public';
let bannerId: string;
let timeoutId: NodeJS.Timeout | undefined;
@@ -39,18 +38,17 @@ let timeoutId: NodeJS.Timeout | undefined;
* resolve to wait for the URL change to happen.
*/
export async function ensureDefaultIndexPattern(
- newPlatform: CoreStart,
+ core: CoreStart,
data: DataPublicPluginStart,
- $rootScope: IRootScopeService,
- kbnUrl: any
+ history: History
) {
const patterns = await data.indexPatterns.getIds();
- let defaultId = newPlatform.uiSettings.get('defaultIndex');
+ let defaultId = core.uiSettings.get('defaultIndex');
let defined = !!defaultId;
const exists = contains(patterns, defaultId);
if (defined && !exists) {
- newPlatform.uiSettings.remove('defaultIndex');
+ core.uiSettings.remove('defaultIndex');
defaultId = defined = false;
}
@@ -61,10 +59,9 @@ export async function ensureDefaultIndexPattern(
// If there is any index pattern created, set the first as default
if (patterns.length >= 1) {
defaultId = patterns[0];
- newPlatform.uiSettings.set('defaultIndex', defaultId);
+ core.uiSettings.set('defaultIndex', defaultId);
} else {
- const canManageIndexPatterns =
- newPlatform.application.capabilities.management.kibana.index_patterns;
+ const canManageIndexPatterns = core.application.capabilities.management.kibana.index_patterns;
const redirectTarget = canManageIndexPatterns ? '/management/kibana/index_pattern' : '/home';
if (timeoutId) {
@@ -73,31 +70,27 @@ export async function ensureDefaultIndexPattern(
// Avoid being hostile to new users who don't have an index pattern setup yet
// give them a friendly info message instead of a terse error message
- bannerId = newPlatform.overlays.banners.replace(bannerId, (element: HTMLElement) => {
- ReactDOM.render(
-
-
- ,
- element
- );
- return () => ReactDOM.unmountComponentAtNode(element);
- });
+ bannerId = core.overlays.banners.replace(
+ bannerId,
+ toMountPoint(
+
+ )
+ );
// hide the message after the user has had a chance to acknowledge it -- so it doesn't permanently stick around
timeoutId = setTimeout(() => {
- newPlatform.overlays.banners.remove(bannerId);
+ core.overlays.banners.remove(bannerId);
timeoutId = undefined;
}, 15000);
- kbnUrl.change(redirectTarget);
- $rootScope.$digest();
+ history.push(redirectTarget);
// return never-resolving promise to stop resolving and wait for the url change
return new Promise(() => {});
diff --git a/src/plugins/kibana_utils/public/history/index.ts b/src/plugins/kibana_utils/public/history/index.ts
index bb13ea09f928a..1a73bbb6b04a1 100644
--- a/src/plugins/kibana_utils/public/history/index.ts
+++ b/src/plugins/kibana_utils/public/history/index.ts
@@ -19,3 +19,4 @@
export { removeQueryParam } from './remove_query_param';
export { redirectWhenMissing } from './redirect_when_missing';
+export { ensureDefaultIndexPattern } from './ensure_default_index_pattern';
diff --git a/src/plugins/kibana_utils/public/index.ts b/src/plugins/kibana_utils/public/index.ts
index 47f90cbe2a627..1876e688c989a 100644
--- a/src/plugins/kibana_utils/public/index.ts
+++ b/src/plugins/kibana_utils/public/index.ts
@@ -73,5 +73,5 @@ export {
StartSyncStateFnType,
StopSyncStateFnType,
} from './state_sync';
-export { removeQueryParam, redirectWhenMissing } from './history';
+export { removeQueryParam, redirectWhenMissing, ensureDefaultIndexPattern } from './history';
export { applyDiff } from './state_management/utils/diff_object';