Skip to content

Commit

Permalink
Cutover ensure_default_index_pattern to kibana_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Mar 11, 2020
1 parent 1082371 commit 8149cac
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export { IInjector } from 'ui/chrome';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export {
configureAppAngularModule,
ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -185,22 +183,19 @@ export function initDashboardApp(app, deps) {
},
toastNotifications: deps.core.notifications.toasts,
})
);
},
),
},
})
.when(createDashboardEditUrl(':id'), {
...defaults,
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
export { tabifyAggResponse } from '../../../data/public';
export { unhashUrl, redirectWhenMissing } from '../../../../../plugins/kibana_utils/public';
export {
unhashUrl,
redirectWhenMissing,
ensureDefaultIndexPattern,
formatMsg,
formatStack,
} from '../../../../../plugins/kibana_legacy/public';
} from '../../../../../plugins/kibana_utils/public';
export { formatMsg, formatStack } from '../../../../../plugins/kibana_legacy/public';

// EXPORT types
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ app.config($routeProvider => {
resolve: {
savedObjects: function($route, kbnUrl, Promise, $rootScope, history) {
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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants';
export { VisSavedObject, VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/';
export {
configureAppAngularModule,
ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { createHashHistory } from 'history';
import {
createKbnUrlStateStorage,
redirectWhenMissing,
ensureDefaultIndexPattern,
} from '../../../../../../plugins/kibana_utils/public';

import editorTemplate from './editor/editor.html';
Expand All @@ -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,
Expand Down Expand Up @@ -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, {
Expand All @@ -94,16 +93,15 @@ 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, {
...defaults,
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 });
Expand All @@ -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) {
Expand All @@ -146,9 +144,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);
Expand Down
5 changes: 1 addition & 4 deletions src/legacy/ui/public/legacy_compat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@
* under the License.
*/

export {
configureAppAngularModule,
ensureDefaultIndexPattern,
} from '../../../../plugins/kibana_legacy/public';
export { configureAppAngularModule } from '../../../../plugins/kibana_legacy/public';
1 change: 0 additions & 1 deletion src/plugins/kibana_legacy/public/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ 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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,8 +40,7 @@ let timeoutId: NodeJS.Timeout | undefined;
export async function ensureDefaultIndexPattern(
newPlatform: CoreStart,
data: DataPublicPluginStart,
$rootScope: IRootScopeService,
kbnUrl: any
history: History
) {
const patterns = await data.indexPatterns.getIds();
let defaultId = newPlatform.uiSettings.get('defaultIndex');
Expand Down Expand Up @@ -73,31 +71,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(
<I18nProvider>
<EuiCallOut
color="warning"
iconType="iInCircle"
title={i18n.translate('kibana_legacy.indexPattern.bannerLabel', {
defaultMessage:
"In order to visualize and explore data in Kibana, you'll need to create an index pattern to retrieve data from Elasticsearch.",
})}
/>
</I18nProvider>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
});
bannerId = newPlatform.overlays.banners.replace(
bannerId,
toMountPoint(
<EuiCallOut
color="warning"
iconType="iInCircle"
title={i18n.translate('kibana_legacy.indexPattern.bannerLabel', {
defaultMessage:
"In order to visualize and explore data in Kibana, you'll need to create an index pattern to retrieve data from Elasticsearch.",
})}
/>
)
);

// 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);
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(() => {});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/public/history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

export { removeQueryParam } from './remove_query_param';
export { redirectWhenMissing } from './redirect_when_missing';
export { ensureDefaultIndexPattern } from './ensure_default_index_pattern';
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,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';

0 comments on commit 8149cac

Please sign in to comment.