Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6f46c7a
improve test stability
Jul 9, 2020
b824176
Merge branch 'master' of github.com:elastic/kibana
Jul 9, 2020
995da7d
Merge branch 'master' of github.com:elastic/kibana
Jul 14, 2020
7b2a45c
Merge branch 'master' of github.com:elastic/kibana
Jul 15, 2020
c3a3822
Merge branch 'master' of github.com:elastic/kibana
Jul 16, 2020
5ce1d77
Merge branch 'master' of github.com:elastic/kibana
Jul 20, 2020
e5b2c84
Merge branch 'master' of github.com:elastic/kibana
Aug 3, 2020
7e767cb
Merge branch 'master' of github.com:elastic/kibana
Aug 5, 2020
5a3dfea
Merge branch 'master' of github.com:elastic/kibana
Aug 6, 2020
10847b1
Enhance pattern
Aug 6, 2020
2885c2d
fix tests
Aug 6, 2020
d8383db
fix test
Aug 6, 2020
0b95e19
Merge branch 'master' into data/enhance-pattern
elasticmachine Aug 10, 2020
f2871fa
Merge branch 'master' into data/enhance-pattern
elasticmachine Aug 11, 2020
89711dc
Merge branch 'master' of github.com:elastic/kibana into data/enhance-…
Aug 12, 2020
db23ed3
Rename enhance to __enhance
Aug 12, 2020
7138a91
Merge branch 'data/enhance-pattern' of github.com:lizozom/kibana into…
Aug 12, 2020
675a619
Deleted unnecessary attribute
Aug 12, 2020
c743e25
ISearchInterceptor interface
Aug 12, 2020
ce4463b
docs
Aug 12, 2020
ef12dfb
Clean up internal docs
Aug 12, 2020
73208e9
jest
Aug 12, 2020
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
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [DataPublicPluginSetup](./kibana-plugin-plugins-data-public.datapublicpluginsetup.md) &gt; [enhance](./kibana-plugin-plugins-data-public.datapublicpluginsetup.enhance.md)

## DataPublicPluginSetup.enhance property

<b>Signature:</b>

```typescript
enhance: (enhancements: DataPublicPluginEnhancements) => void;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface DataPublicPluginSetup
| Property | Type | Description |
| --- | --- | --- |
| [autocomplete](./kibana-plugin-plugins-data-public.datapublicpluginsetup.autocomplete.md) | <code>AutocompleteSetup</code> | |
| [enhance](./kibana-plugin-plugins-data-public.datapublicpluginsetup.enhance.md) | <code>(enhancements: DataPublicPluginEnhancements) =&gt; void</code> | |
| [fieldFormats](./kibana-plugin-plugins-data-public.datapublicpluginsetup.fieldformats.md) | <code>FieldFormatsSetup</code> | |
| [query](./kibana-plugin-plugins-data-public.datapublicpluginsetup.query.md) | <code>QuerySetup</code> | |
| [search](./kibana-plugin-plugins-data-public.datapublicpluginsetup.search.md) | <code>ISearchSetup</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchInterceptor](./kibana-plugin-plugins-data-public.searchinterceptor.md) &gt; [application](./kibana-plugin-plugins-data-public.searchinterceptor.application.md)

## SearchInterceptor.application property

<b>Signature:</b>

```typescript
protected application: CoreStart['application'];
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export declare class SearchInterceptor
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [abortController](./kibana-plugin-plugins-data-public.searchinterceptor.abortcontroller.md) | | <code>AbortController</code> | <code>abortController</code> used to signal all searches to abort. |
| [application](./kibana-plugin-plugins-data-public.searchinterceptor.application.md) | | <code>CoreStart['application']</code> | |
| [deps](./kibana-plugin-plugins-data-public.searchinterceptor.deps.md) | | <code>SearchInterceptorDeps</code> | |
| [getPendingCount$](./kibana-plugin-plugins-data-public.searchinterceptor.getpendingcount_.md) | | <code>() =&gt; Observable&lt;number&gt;</code> | Returns an <code>Observable</code> over the current number of pending searches. This could mean that one of the search requests is still in flight, or that it has only received partial responses. |
| [hideToast](./kibana-plugin-plugins-data-public.searchinterceptor.hidetoast.md) | | <code>() =&gt; void</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
http: CoreStart['http'];
http: CoreSetup['http'];
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface SearchInterceptorDeps

| Property | Type | Description |
| --- | --- | --- |
| [application](./kibana-plugin-plugins-data-public.searchinterceptordeps.application.md) | <code>ApplicationStart</code> | |
| [http](./kibana-plugin-plugins-data-public.searchinterceptordeps.http.md) | <code>CoreStart['http']</code> | |
| [toasts](./kibana-plugin-plugins-data-public.searchinterceptordeps.toasts.md) | <code>ToastsStart</code> | |
| [uiSettings](./kibana-plugin-plugins-data-public.searchinterceptordeps.uisettings.md) | <code>CoreStart['uiSettings']</code> | |
| [http](./kibana-plugin-plugins-data-public.searchinterceptordeps.http.md) | <code>CoreSetup['http']</code> | |
| [startServices](./kibana-plugin-plugins-data-public.searchinterceptordeps.startservices.md) | <code>Promise&lt;[CoreStart, any, unknown]&gt;</code> | |
| [toasts](./kibana-plugin-plugins-data-public.searchinterceptordeps.toasts.md) | <code>ToastsSetup</code> | |
| [uiSettings](./kibana-plugin-plugins-data-public.searchinterceptordeps.uisettings.md) | <code>CoreSetup['uiSettings']</code> | |
| [usageCollector](./kibana-plugin-plugins-data-public.searchinterceptordeps.usagecollector.md) | <code>SearchUsageCollector</code> | |

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) &gt; [application](./kibana-plugin-plugins-data-public.searchinterceptordeps.application.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) &gt; [startServices](./kibana-plugin-plugins-data-public.searchinterceptordeps.startservices.md)

## SearchInterceptorDeps.application property
## SearchInterceptorDeps.startServices property

<b>Signature:</b>

```typescript
application: ApplicationStart;
startServices: Promise<[CoreStart, any, unknown]>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
toasts: ToastsStart;
toasts: ToastsSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
uiSettings: CoreStart['uiSettings'];
uiSettings: CoreSetup['uiSettings'];
```
1 change: 1 addition & 0 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const createSetupContract = (): Setup => {
search: searchServiceMock.createSetupContract(),
fieldFormats: fieldFormatsServiceMock.createSetupContract(),
query: querySetupMock,
enhance: jest.fn(),
};
};

Expand Down
18 changes: 12 additions & 6 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
DataSetupDependencies,
DataStartDependencies,
InternalStartServices,
DataPublicPluginEnhancements,
} from './types';
import { AutocompleteService } from './autocomplete';
import { SearchService } from './search/search_service';
Expand Down Expand Up @@ -156,16 +157,21 @@ export class DataPublicPlugin
}))
);

const searchService = this.searchService.setup(core, {
expressions,
usageCollection,
getInternalStartServices,
packageInfo: this.packageInfo,
});

return {
autocomplete: this.autocomplete.setup(core),
search: this.searchService.setup(core, {
expressions,
usageCollection,
getInternalStartServices,
packageInfo: this.packageInfo,
}),
search: searchService,
fieldFormats: this.fieldFormatsService.setup(core),
query: queryService,
enhance: (enhancements: DataPublicPluginEnhancements) => {
searchService.enhance(enhancements.search);
},
};
}

Expand Down
24 changes: 15 additions & 9 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { $Values } from '@kbn/utility-types';
import _ from 'lodash';
import { Action } from 'history';
import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';
import { ApplicationStart } from 'kibana/public';
import { Assign } from '@kbn/utility-types';
import { BehaviorSubject } from 'rxjs';
import Boom from 'boom';
import { Component } from 'react';
import { CoreSetup } from 'src/core/public';
import { CoreSetup as CoreSetup_2 } from 'kibana/public';
import { CoreStart } from 'kibana/public';
import { CoreStart as CoreStart_2 } from 'src/core/public';
import { Ensure } from '@kbn/utility-types';
Expand Down Expand Up @@ -65,7 +65,7 @@ import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/ex
import { Subscription } from 'rxjs';
import { Toast } from 'kibana/public';
import { ToastInputFields } from 'src/core/public/notifications';
import { ToastsStart } from 'kibana/public';
import { ToastsSetup } from 'kibana/public';
import { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestParams } from '@elastic/elasticsearch/lib/Transport';
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport';
Expand Down Expand Up @@ -226,6 +226,10 @@ export interface DataPublicPluginSetup {
//
// (undocumented)
autocomplete: AutocompleteSetup;
// Warning: (ae-forgotten-export) The symbol "DataPublicPluginEnhancements" needs to be exported by the entry point index.d.ts
//
// (undocumented)
enhance: (enhancements: DataPublicPluginEnhancements) => void;
// Warning: (ae-forgotten-export) The symbol "FieldFormatsSetup" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -1651,6 +1655,8 @@ export class SearchInterceptor {
constructor(deps: SearchInterceptorDeps, requestTimeout?: number | undefined);
protected abortController: AbortController;
// (undocumented)
protected application: CoreStart['application'];
// (undocumented)
protected readonly deps: SearchInterceptorDeps;
getPendingCount$: () => Observable<number>;
// (undocumented)
Expand Down Expand Up @@ -1678,13 +1684,13 @@ export class SearchInterceptor {
// @public (undocumented)
export interface SearchInterceptorDeps {
// (undocumented)
application: ApplicationStart;
http: CoreSetup_2['http'];
// (undocumented)
http: CoreStart['http'];
startServices: Promise<[CoreStart, any, unknown]>;
// (undocumented)
toasts: ToastsStart;
toasts: ToastsSetup;
// (undocumented)
uiSettings: CoreStart['uiSettings'];
uiSettings: CoreSetup_2['uiSettings'];
// Warning: (ae-forgotten-export) The symbol "SearchUsageCollector" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -1915,9 +1921,9 @@ export const UI_SETTINGS: {
// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:398:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:45:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:54:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:55:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:63:5 - (ae-forgotten-export) The symbol "IndexPatternSelectProps" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:59:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:60:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:68:5 - (ae-forgotten-export) The symbol "IndexPatternSelectProps" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
9 changes: 8 additions & 1 deletion src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export * from './aggs';
export * from './expressions';
export * from './tabify';

export { ISearch, ISearchOptions, ISearchGeneric, ISearchSetup, ISearchStart } from './types';
export {
ISearch,
ISearchOptions,
ISearchGeneric,
ISearchSetup,
ISearchStart,
SearchEnhancements,
} from './types';

export { IEsSearchResponse, IEsSearchRequest, ES_SEARCH_STRATEGY } from '../../common/search';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export * from './search_source/mocks';
function createSetupContract(): jest.Mocked<ISearchSetup> {
return {
aggs: searchAggsSetupMock(),
enhance: jest.fn(),
};
}

function createStartContract(): jest.Mocked<ISearchStart> {
return {
aggs: searchAggsStartMock(),
setInterceptor: jest.fn(),
search: jest.fn(),
searchSource: searchSourceMock,
__LEGACY: {
Expand Down
28 changes: 14 additions & 14 deletions src/plugins/data/public/search/search_interceptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@
* under the License.
*/

import { CoreStart } from '../../../../core/public';
import { CoreSetup } from '../../../../core/public';
import { coreMock } from '../../../../core/public/mocks';
import { IEsSearchRequest } from '../../common/search';
import { SearchInterceptor } from './search_interceptor';
import { AbortError } from '../../common';

let searchInterceptor: SearchInterceptor;
let mockCoreStart: MockedKeys<CoreStart>;
let mockCoreSetup: MockedKeys<CoreSetup>;

const flushPromises = () => new Promise((resolve) => setImmediate(resolve));
jest.useFakeTimers();

describe('SearchInterceptor', () => {
beforeEach(() => {
mockCoreStart = coreMock.createStart();
mockCoreSetup = coreMock.createSetup();
searchInterceptor = new SearchInterceptor(
{
toasts: mockCoreStart.notifications.toasts,
application: mockCoreStart.application,
uiSettings: mockCoreStart.uiSettings,
http: mockCoreStart.http,
toasts: mockCoreSetup.notifications.toasts,
startServices: mockCoreSetup.getStartServices(),
uiSettings: mockCoreSetup.uiSettings,
http: mockCoreSetup.http,
},
1000
);
Expand All @@ -46,7 +46,7 @@ describe('SearchInterceptor', () => {
describe('search', () => {
test('Observable should resolve if fetch is successful', async () => {
const mockResponse: any = { result: 200 };
mockCoreStart.http.fetch.mockResolvedValueOnce(mockResponse);
mockCoreSetup.http.fetch.mockResolvedValueOnce(mockResponse);
const mockRequest: IEsSearchRequest = {
params: {},
};
Expand All @@ -58,7 +58,7 @@ describe('SearchInterceptor', () => {

test('Observable should fail if fetch has an error', async () => {
const mockResponse: any = { result: 500 };
mockCoreStart.http.fetch.mockRejectedValueOnce(mockResponse);
mockCoreSetup.http.fetch.mockRejectedValueOnce(mockResponse);
const mockRequest: IEsSearchRequest = {
params: {},
};
Expand All @@ -72,7 +72,7 @@ describe('SearchInterceptor', () => {
});

test('Observable should fail if fetch times out (test merged signal)', async () => {
mockCoreStart.http.fetch.mockImplementationOnce((options: any) => {
mockCoreSetup.http.fetch.mockImplementationOnce((options: any) => {
return new Promise((resolve, reject) => {
options.signal.addEventListener('abort', () => {
reject(new AbortError());
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('SearchInterceptor', () => {

test('Observable should fail if user aborts (test merged signal)', async () => {
const abortController = new AbortController();
mockCoreStart.http.fetch.mockImplementationOnce((options: any) => {
mockCoreSetup.http.fetch.mockImplementationOnce((options: any) => {
return new Promise((resolve, reject) => {
options.signal.addEventListener('abort', () => {
reject(new AbortError());
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('SearchInterceptor', () => {

const error = (e: any) => {
expect(e).toBeInstanceOf(AbortError);
expect(mockCoreStart.http.fetch).not.toBeCalled();
expect(mockCoreSetup.http.fetch).not.toBeCalled();
done();
};
response.subscribe({ error });
Expand All @@ -150,7 +150,7 @@ describe('SearchInterceptor', () => {
pendingCount$.subscribe(pendingNext);

const mockResponse: any = { result: 200 };
mockCoreStart.http.fetch.mockResolvedValue(mockResponse);
mockCoreSetup.http.fetch.mockResolvedValue(mockResponse);
const mockRequest: IEsSearchRequest = {
params: {},
};
Expand All @@ -169,7 +169,7 @@ describe('SearchInterceptor', () => {
pendingCount$.subscribe(pendingNext);

const mockResponse: any = { result: 500 };
mockCoreStart.http.fetch.mockRejectedValue(mockResponse);
mockCoreSetup.http.fetch.mockRejectedValue(mockResponse);
const mockRequest: IEsSearchRequest = {
params: {},
};
Expand Down
18 changes: 12 additions & 6 deletions src/plugins/data/public/search/search_interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { BehaviorSubject, throwError, timer, Subscription, defer, from, Observable } from 'rxjs';
import { finalize, filter } from 'rxjs/operators';
import { ApplicationStart, Toast, ToastsStart, CoreStart } from 'kibana/public';
import { Toast, CoreStart, ToastsSetup, CoreSetup } from 'kibana/public';
import { getCombinedSignal, AbortError } from '../../common/utils';
import { IEsSearchRequest, IEsSearchResponse } from '../../common/search';
import { ISearchOptions } from './types';
Expand All @@ -29,10 +29,10 @@ import { SearchUsageCollector } from './collectors';
const LONG_QUERY_NOTIFICATION_DELAY = 10000;

export interface SearchInterceptorDeps {
toasts: ToastsStart;
application: ApplicationStart;
http: CoreStart['http'];
uiSettings: CoreStart['uiSettings'];
toasts: ToastsSetup;
http: CoreSetup['http'];
uiSettings: CoreSetup['uiSettings'];
startServices: Promise<[CoreStart, any, unknown]>;
usageCollector?: SearchUsageCollector;
}

Expand Down Expand Up @@ -62,6 +62,8 @@ export class SearchInterceptor {
*/
protected longRunningToast?: Toast;

protected application!: CoreStart['application'];

/**
* This class should be instantiated with a `requestTimeout` corresponding with how many ms after
* requests are initiated that they should automatically cancel.
Expand All @@ -75,6 +77,10 @@ export class SearchInterceptor {
) {
this.deps.http.addLoadingCountSource(this.pendingCount$);

this.deps.startServices.then(([coreStart]) => {
this.application = coreStart.application;
});

// When search requests go out, a notification is scheduled allowing users to continue the
// request past the timeout. When all search requests complete, we remove the notification.
this.getPendingCount$()
Expand Down Expand Up @@ -172,7 +178,7 @@ export class SearchInterceptor {
{
title: 'Your query is taking awhile',
text: getLongQueryNotification({
application: this.deps.application,
application: this.application,
}),
},
{
Expand Down
Loading