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

[NP] Cutover ensureDefaultIndexPattern to kibana_utils #59895

Merged
merged 16 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 14 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
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 @@ -56,14 +56,17 @@ export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggRes
export { shortenDottedString } from '../../common/utils/shorten_dotted_string';
// @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 @@ -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);
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,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';
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, could you rename newPlatformto core since we're already in NP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, makes sense !
Just was hesitant to rename it after Joe gave this name 😃

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_utils.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 @@ -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';