From fbe6e9ca3c56075b8f736709cc512d5ab9b0c518 Mon Sep 17 00:00:00 2001 From: Liza K Date: Fri, 20 Dec 2019 15:39:24 +0000 Subject: [PATCH 1/2] ts --- src/legacy/core_plugins/data/public/plugin.ts | 13 ++++++++-- .../data/public/search/expressions/esaggs.ts | 26 +++++++------------ ...d_failure_open_modal_button.test.mocks.tsx | 19 ++++++-------- .../shard_failure_open_modal_button.tsx | 6 ++--- .../search/fetch/handle_response.test.ts | 26 +++++++++---------- .../public/search/fetch/handle_response.tsx | 7 ++--- .../search/search_source/search_source.ts | 2 +- .../edit_index_pattern/edit_index_pattern.js | 2 +- src/plugins/data/public/services.ts | 5 ++++ .../field_wildcard/field_wildcard.test.ts | 0 .../public/field_wildcard/field_wildcard.ts | 0 .../public/field_wildcard/index.ts | 0 src/plugins/kibana_utils/public/index.ts | 1 + 13 files changed, 56 insertions(+), 51 deletions(-) rename src/{legacy/ui => plugins/kibana_utils}/public/field_wildcard/field_wildcard.test.ts (100%) rename src/{legacy/ui => plugins/kibana_utils}/public/field_wildcard/field_wildcard.ts (100%) rename src/{legacy/ui => plugins/kibana_utils}/public/field_wildcard/index.ts (100%) diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 6c67408158b51..893e477b38583 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -21,8 +21,13 @@ import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { SearchService, SearchStart } from './search'; import { DataPublicPluginStart } from '../../../../plugins/data/public'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { setFieldFormats } from '../../../../plugins/data/public/services'; +import { + setFieldFormats, + setNotifications, + setIndexPatterns, + setQueryService, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../plugins/data/public/services'; export interface DataPluginStartDependencies { data: DataPublicPluginStart; @@ -57,6 +62,10 @@ export class DataPlugin implements Plugin { // Create a new search source that inherits the original search source @@ -216,7 +210,7 @@ const handleCourierRequest = async ({ } inspectorAdapters.data.setTabularLoader( - () => buildTabularInspectorData((searchSource as any).tabifiedResponse, queryFilter), + () => buildTabularInspectorData((searchSource as any).tabifiedResponse, filterManager), { returnsFormattedValues: true } ); @@ -259,10 +253,8 @@ export const esaggs = (): ExpressionFunction { - return { - npStart: { - core: { - overlays: { - openModal, - }, - }, - }, - }; -}); +setOverlays(({ + openModal, +} as unknown) as OverlayStart); diff --git a/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx index d81ee70a4611c..c3ff042083473 100644 --- a/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/components/shard_failure_open_modal_button.tsx @@ -17,11 +17,11 @@ * under the License. */ import React from 'react'; -// @ts-ignore -import { npStart } from 'ui/new_platform'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButton, EuiTextAlign } from '@elastic/eui'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getOverlays } from '../../../../../../../plugins/data/public/services'; import { toMountPoint } from '../../../../../../../plugins/kibana_react/public'; import { ShardFailureModal } from './shard_failure_modal'; import { ResponseWithShardFailure, Request } from './shard_failure_types'; @@ -34,7 +34,7 @@ interface Props { export function ShardFailureOpenModalButton({ request, response, title }: Props) { function onClick() { - const modal = npStart.core.overlays.openModal( + const modal = getOverlays().openModal( toMountPoint( { - return { - toastNotifications: { - addWarning: jest.fn(), - }, - }; -}); +// Temporary disable eslint, will be removed after moving to new platform folder +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { notificationServiceMock } from '../../../../../../core/public/notifications/notifications_service.mock'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { setNotifications } from '../../../../../../plugins/data/public/services'; jest.mock('@kbn/i18n', () => { return { @@ -37,8 +34,11 @@ jest.mock('@kbn/i18n', () => { }); describe('handleResponse', () => { + const notifications = notificationServiceMock.createStartContract(); + beforeEach(() => { - (toastNotifications.addWarning as jest.Mock).mockReset(); + setNotifications(notifications); + (notifications.toasts.addWarning as jest.Mock).mockReset(); }); test('should notify if timed out', () => { @@ -48,8 +48,8 @@ describe('handleResponse', () => { }; const result = handleResponse(request, response); expect(result).toBe(response); - expect(toastNotifications.addWarning).toBeCalled(); - expect((toastNotifications.addWarning as jest.Mock).mock.calls[0][0].title).toMatch( + expect(notifications.toasts.addWarning).toBeCalled(); + expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch( 'request timed out' ); }); @@ -63,8 +63,8 @@ describe('handleResponse', () => { }; const result = handleResponse(request, response); expect(result).toBe(response); - expect(toastNotifications.addWarning).toBeCalled(); - expect((toastNotifications.addWarning as jest.Mock).mock.calls[0][0].title).toMatch( + expect(notifications.toasts.addWarning).toBeCalled(); + expect((notifications.toasts.addWarning as jest.Mock).mock.calls[0][0].title).toMatch( 'shards failed' ); }); diff --git a/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx b/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx index e3fd5ad15242d..a08b7d14fd1c3 100644 --- a/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx +++ b/src/legacy/core_plugins/data/public/search/fetch/handle_response.tsx @@ -20,15 +20,16 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiSpacer } from '@elastic/eui'; -import { toastNotifications } from 'ui/notify/toasts'; import { ShardFailureOpenModalButton } from './components/shard_failure_open_modal_button'; import { Request, ResponseWithShardFailure } from './components/shard_failure_types'; import { SearchRequest, SearchResponse } from '../types'; import { toMountPoint } from '../../../../../../plugins/kibana_react/public'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { getNotifications } from '../../../../../../plugins/data/public/services'; export function handleResponse(request: SearchRequest, response: SearchResponse) { if (response.timed_out) { - toastNotifications.addWarning({ + getNotifications().toasts.addWarning({ title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', { defaultMessage: 'Data might be incomplete because your request timed out', }), @@ -62,7 +63,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse) ); - toastNotifications.addWarning({ title, text }); + getNotifications().toasts.addWarning({ title, text }); } return response; diff --git a/src/legacy/core_plugins/data/public/search/search_source/search_source.ts b/src/legacy/core_plugins/data/public/search/search_source/search_source.ts index 01fc34e230a31..6efcae4d4b88d 100644 --- a/src/legacy/core_plugins/data/public/search/search_source/search_source.ts +++ b/src/legacy/core_plugins/data/public/search/search_source/search_source.ts @@ -72,9 +72,9 @@ import _ from 'lodash'; import { npSetup } from 'ui/new_platform'; import chrome from 'ui/chrome'; -import { fieldWildcardFilter } from 'ui/field_wildcard'; import { normalizeSortRequest } from './normalize_sort_request'; import { fetchSoon } from '../fetch'; +import { fieldWildcardFilter } from '../../../../../../plugins/kibana_utils/public'; import { getHighlightRequest, esFilters, esQuery } from '../../../../../../plugins/data/public'; import { RequestFailure } from '../fetch/errors'; import { filterDocvalueFields } from './filter_docvalue_fields'; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/edit_index_pattern.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/edit_index_pattern.js index 9d84c03383743..ffc9aed9a27a3 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/edit_index_pattern.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/edit_index_pattern.js @@ -27,7 +27,7 @@ import { fatalError, toastNotifications } from 'ui/notify'; import uiRoutes from 'ui/routes'; import { uiModules } from 'ui/modules'; import template from './edit_index_pattern.html'; -import { fieldWildcardMatcher } from 'ui/field_wildcard'; +import { fieldWildcardMatcher } from '../../../../../../../../plugins/kibana_utils/public'; import { setup as managementSetup } from '../../../../../../management/public/legacy'; import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; diff --git a/src/plugins/data/public/services.ts b/src/plugins/data/public/services.ts index 4a832105b6991..76b3283220f67 100644 --- a/src/plugins/data/public/services.ts +++ b/src/plugins/data/public/services.ts @@ -22,6 +22,7 @@ import { CoreStart } from 'kibana/public'; import { FieldFormatsStart } from '.'; import { createGetterSetter } from '../../kibana_utils/public'; import { IndexPatternsContract } from './index_patterns'; +import { DataPublicPluginStart } from './types'; export const [getNotifications, setNotifications] = createGetterSetter( 'Notifications' @@ -36,3 +37,7 @@ export const [getOverlays, setOverlays] = createGetterSetter( 'IndexPatterns' ); + +export const [getQueryService, setQueryService] = createGetterSetter< + DataPublicPluginStart['query'] +>('Query'); diff --git a/src/legacy/ui/public/field_wildcard/field_wildcard.test.ts b/src/plugins/kibana_utils/public/field_wildcard/field_wildcard.test.ts similarity index 100% rename from src/legacy/ui/public/field_wildcard/field_wildcard.test.ts rename to src/plugins/kibana_utils/public/field_wildcard/field_wildcard.test.ts diff --git a/src/legacy/ui/public/field_wildcard/field_wildcard.ts b/src/plugins/kibana_utils/public/field_wildcard/field_wildcard.ts similarity index 100% rename from src/legacy/ui/public/field_wildcard/field_wildcard.ts rename to src/plugins/kibana_utils/public/field_wildcard/field_wildcard.ts diff --git a/src/legacy/ui/public/field_wildcard/index.ts b/src/plugins/kibana_utils/public/field_wildcard/index.ts similarity index 100% rename from src/legacy/ui/public/field_wildcard/index.ts rename to src/plugins/kibana_utils/public/field_wildcard/index.ts diff --git a/src/plugins/kibana_utils/public/index.ts b/src/plugins/kibana_utils/public/index.ts index 6e6b5c582b0eb..af2fc9e31b21b 100644 --- a/src/plugins/kibana_utils/public/index.ts +++ b/src/plugins/kibana_utils/public/index.ts @@ -21,6 +21,7 @@ export { defer } from '../common'; export * from './core'; export * from './errors'; export * from './field_mapping'; +export * from './field_wildcard'; export * from './parse'; export * from './render_complete'; export * from './resize_checker'; From 8dbfb8c0284a4cc5808f6db361ecfce8abb729c0 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 23 Dec 2019 11:20:37 +0000 Subject: [PATCH 2/2] fix import path --- .../core_plugins/data/public/search/expressions/esaggs.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts b/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts index e24dd69e1d397..4ec4dbd7f88d6 100644 --- a/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts +++ b/src/legacy/core_plugins/data/public/search/expressions/esaggs.ts @@ -21,13 +21,19 @@ import { get, has } from 'lodash'; import { i18n } from '@kbn/i18n'; import { AggConfigs } from 'ui/agg_types/agg_configs'; import { createFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; -import { Query, TimeRange, esFilters, getTime, FilterManager } from 'src/plugins/data/public'; import { KibanaContext, KibanaDatatable, ExpressionFunction, KibanaDatatableColumn, } from 'src/plugins/expressions/public'; +import { + Query, + TimeRange, + esFilters, + getTime, + FilterManager, +} from '../../../../../../plugins/data/public'; import { SearchSource, ISearchSource,