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

Clean up search servie #53701

Merged
merged 2 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,6 +62,10 @@ export class DataPlugin implements Plugin<void, DataStart, {}, DataPluginStartDe
public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart {
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
setQueryService(data.query);
setIndexPatterns(data.indexPatterns);
setFieldFormats(data.fieldFormats);
setNotifications(core.notifications);

return {
search: this.search.start(core),
Expand Down
32 changes: 15 additions & 17 deletions src/legacy/core_plugins/data/public/search/expressions/esaggs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,34 @@ 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 chrome from 'ui/chrome';
import { Query, TimeRange, esFilters } from 'src/plugins/data/public';
import {
KibanaContext,
KibanaDatatable,
ExpressionFunction,
KibanaDatatableColumn,
} from 'src/plugins/expressions/public';
import { npStart } from 'ui/new_platform';
import {
Query,
TimeRange,
esFilters,
getTime,
FilterManager,
} from '../../../../../../plugins/data/public';
import {
SearchSource,
ISearchSource,
getRequestInspectorStats,
getResponseInspectorStats,
} from '../../../../../ui/public/courier';
// @ts-ignore
import {
FilterBarQueryFilterProvider,
QueryFilter,
} from '../../../../../ui/public/filter_manager/query_filter';

import { buildTabularInspectorData } from '../../../../../ui/public/inspector/build_tabular_inspector_data';
import { calculateObjectHash } from '../../../../visualizations/public';
import { getTime } from '../../../../../ui/public/timefilter';
// @ts-ignore
import { tabifyAggResponse } from '../../../../../ui/public/agg_response/tabify/tabify';
import { PersistedState } from '../../../../../ui/public/persisted_state';
import { Adapters } from '../../../../../../plugins/inspector/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getQueryService, getIndexPatterns } from '../../../../../../plugins/data/public/services';

export interface RequestHandlerParams {
searchSource: ISearchSource;
Expand All @@ -57,7 +57,7 @@ export interface RequestHandlerParams {
query?: Query;
filters?: esFilters.Filter[];
forceFetch: boolean;
queryFilter: QueryFilter;
filterManager: FilterManager;
uiState?: PersistedState;
partialRows?: boolean;
inspectorAdapters: Adapters;
Expand Down Expand Up @@ -90,7 +90,7 @@ const handleCourierRequest = async ({
partialRows,
metricsAtAllLevels,
inspectorAdapters,
queryFilter,
filterManager,
abortSignal,
}: RequestHandlerParams) => {
// Create a new search source that inherits the original search source
Expand Down Expand Up @@ -216,7 +216,7 @@ const handleCourierRequest = async ({
}

inspectorAdapters.data.setTabularLoader(
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, queryFilter),
() => buildTabularInspectorData((searchSource as any).tabifiedResponse, filterManager),
{ returnsFormattedValues: true }
);

Expand Down Expand Up @@ -259,10 +259,8 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
},
},
async fn(context, args, { inspectorAdapters, abortSignal }) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private: Function = $injector.get('Private');
const { indexPatterns } = npStart.plugins.data;
const queryFilter = Private(FilterBarQueryFilterProvider);
const indexPatterns = getIndexPatterns();
const { filterManager } = getQueryService();

const aggConfigsState = JSON.parse(args.aggConfigs);
const indexPattern = await indexPatterns.get(args.index);
Expand All @@ -283,7 +281,7 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
metricsAtAllLevels: args.metricsAtAllLevels,
partialRows: args.partialRows,
inspectorAdapters,
queryFilter,
filterManager,
abortSignal: (abortSignal as unknown) as AbortSignal,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setOverlays } from '../../../../../../../plugins/data/public/services';
import { OverlayStart } from 'kibana/public';

export const openModal = jest.fn();

jest.doMock('ui/new_platform', () => {
return {
npStart: {
core: {
overlays: {
openModal,
},
},
},
};
});
setOverlays(({
openModal,
} as unknown) as OverlayStart);
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
<ShardFailureModal
request={request}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
*/

import { handleResponse } from './handle_response';
import { toastNotifications } from 'ui/notify/toasts';

jest.mock('ui/notify/toasts', () => {
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 {
Expand All @@ -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', () => {
Expand All @@ -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'
);
});
Expand All @@ -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'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down Expand Up @@ -62,7 +63,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse)
</>
);

toastNotifications.addWarning({ title, text });
getNotifications().toasts.addWarning({ title, text });
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/data/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotificationsStart>(
'Notifications'
Expand All @@ -36,3 +37,7 @@ export const [getOverlays, setOverlays] = createGetterSetter<CoreStart['overlays
export const [getIndexPatterns, setIndexPatterns] = createGetterSetter<IndexPatternsContract>(
'IndexPatterns'
);

export const [getQueryService, setQueryService] = createGetterSetter<
DataPublicPluginStart['query']
>('Query');
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down