Skip to content

Commit 7a518cf

Browse files
Merge branch 'master' into fixes-search-bar
2 parents bebf201 + 7d3fe58 commit 7a518cf

File tree

152 files changed

+2035
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+2035
-990
lines changed

.ci/Jenkinsfile_security_cypress

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ kibanaPipeline(timeoutMinutes: 180) {
1616
}
1717

1818
if (params.NOTIFY_ON_FAILURE) {
19-
kibanaPipeline.sendMail(to: 'gloria.delatorre@elastic.co')
19+
kibanaPipeline.sendMail(to: 'siem_dev_team@elastic.co')
2020
}
2121
}

src/plugins/data/public/ui/query_string_input/_query_bar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
&.kbnQueryBar__datePickerWrapper-isHidden {
6060
width: 0;
6161
overflow: hidden;
62+
max-width: 0;
6263
}
6364
}
6465
}

src/plugins/discover/public/application/angular/doc.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<div class="app-container">
22
<discover-doc
3-
es-client="esClient"
43
id="id"
54
index="index"
65
index-pattern-id="indexPatternId"

src/plugins/discover/public/application/angular/doc.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ app.directive('discoverDoc', function (reactDirective: any) {
3636
['index', { watchDepth: 'value' }],
3737
['indexPatternId', { watchDepth: 'reference' }],
3838
['indexPatternService', { watchDepth: 'reference' }],
39-
['esClient', { watchDepth: 'reference' }],
4039
],
4140
{ restrict: 'E' }
4241
);
@@ -51,10 +50,9 @@ app.config(($routeProvider: any) => {
5150
.when('/doc/:indexPattern/:index', {
5251
// have to be written as function expression, because it's not compiled in dev mode
5352
// eslint-disable-next-line object-shorthand
54-
controller: function ($scope: LazyScope, $route: any, es: any) {
53+
controller: function ($scope: LazyScope, $route: any) {
5554
timefilter.disableAutoRefreshSelector();
5655
timefilter.disableTimeRangeSelector();
57-
$scope.esClient = es;
5856
$scope.id = $route.current.params.id;
5957
$scope.index = $route.current.params.index;
6058
$scope.indexPatternId = $route.current.params.indexPattern;

src/plugins/discover/public/application/components/doc/doc.test.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import { throwError, of } from 'rxjs';
1920
import React from 'react';
2021
import { act } from 'react-dom/test-utils';
2122
import { mountWithIntl } from 'test_utils/enzyme_helpers';
2223
import { ReactWrapper } from 'enzyme';
2324
import { findTestSubject } from '@elastic/eui/lib/test';
2425
import { Doc, DocProps } from './doc';
2526

27+
const mockSearchApi = jest.fn();
28+
2629
jest.mock('../../../kibana_services', () => {
2730
let registry: any[] = [];
2831

@@ -31,6 +34,11 @@ jest.mock('../../../kibana_services', () => {
3134
metadata: {
3235
branch: 'test',
3336
},
37+
data: {
38+
search: {
39+
search: mockSearchApi,
40+
},
41+
},
3442
}),
3543
getDocViewsRegistry: () => ({
3644
addDocView(view: any) {
@@ -59,7 +67,7 @@ const waitForPromises = async () =>
5967
* this works but logs ugly error messages until we're using React 16.9
6068
* should be adapted when we upgrade
6169
*/
62-
async function mountDoc(search: () => void, update = false, indexPatternGetter: any = null) {
70+
async function mountDoc(update = false, indexPatternGetter: any = null) {
6371
const indexPattern = {
6472
getComputedFields: () => [],
6573
};
@@ -70,7 +78,6 @@ async function mountDoc(search: () => void, update = false, indexPatternGetter:
7078
const props = {
7179
id: '1',
7280
index: 'index1',
73-
esClient: { search } as any,
7481
indexPatternId: 'xyz',
7582
indexPatternService,
7683
} as DocProps;
@@ -88,32 +95,33 @@ async function mountDoc(search: () => void, update = false, indexPatternGetter:
8895

8996
describe('Test of <Doc /> of Discover', () => {
9097
test('renders loading msg', async () => {
91-
const comp = await mountDoc(jest.fn());
98+
const comp = await mountDoc();
9299
expect(findTestSubject(comp, 'doc-msg-loading').length).toBe(1);
93100
});
94101

95102
test('renders IndexPattern notFound msg', async () => {
96103
const indexPatternGetter = jest.fn(() => Promise.reject({ savedObjectId: '007' }));
97-
const comp = await mountDoc(jest.fn(), true, indexPatternGetter);
104+
const comp = await mountDoc(true, indexPatternGetter);
98105
expect(findTestSubject(comp, 'doc-msg-notFoundIndexPattern').length).toBe(1);
99106
});
100107

101108
test('renders notFound msg', async () => {
102-
const search = jest.fn(() => Promise.reject({ status: 404 }));
103-
const comp = await mountDoc(search, true);
109+
mockSearchApi.mockImplementation(() => throwError({ status: 404 }));
110+
const comp = await mountDoc(true);
104111
expect(findTestSubject(comp, 'doc-msg-notFound').length).toBe(1);
105112
});
106113

107114
test('renders error msg', async () => {
108-
const search = jest.fn(() => Promise.reject('whatever'));
109-
const comp = await mountDoc(search, true);
115+
mockSearchApi.mockImplementation(() => throwError({ error: 'something else' }));
116+
const comp = await mountDoc(true);
110117
expect(findTestSubject(comp, 'doc-msg-error').length).toBe(1);
111118
});
112119

113120
test('renders elasticsearch hit ', async () => {
114-
const hit = { hits: { total: 1, hits: [{ _id: 1, _source: { test: 1 } }] } };
115-
const search = jest.fn(() => Promise.resolve(hit));
116-
const comp = await mountDoc(search, true);
121+
mockSearchApi.mockImplementation(() =>
122+
of({ rawResponse: { hits: { total: 1, hits: [{ _id: 1, _source: { test: 1 } }] } } })
123+
);
124+
const comp = await mountDoc(true);
117125
expect(findTestSubject(comp, 'doc-hit').length).toBe(1);
118126
});
119127
});

src/plugins/discover/public/application/components/doc/doc.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ import { IndexPatternsContract } from 'src/plugins/data/public';
2323
import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search';
2424
import { getServices } from '../../../kibana_services';
2525
import { DocViewer } from '../doc_viewer/doc_viewer';
26-
import { ElasticSearchHit } from '../../doc_views/doc_views_types';
27-
28-
export interface ElasticSearchResult {
29-
hits: {
30-
hits: [ElasticSearchHit];
31-
max_score: number;
32-
};
33-
timed_out: boolean;
34-
took: number;
35-
shards: Record<string, unknown>;
36-
}
3726

3827
export interface DocProps {
3928
/**
@@ -53,12 +42,6 @@ export interface DocProps {
5342
* IndexPatternService to get a given index pattern by ID
5443
*/
5544
indexPatternService: IndexPatternsContract;
56-
/**
57-
* Client of ElasticSearch to use for the query
58-
*/
59-
esClient: {
60-
search: (payload: { index: string; body: Record<string, any> }) => Promise<ElasticSearchResult>;
61-
};
6245
}
6346

6447
export function Doc(props: DocProps) {

src/plugins/discover/public/application/components/doc/use_es_doc_search.test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
import { renderHook, act } from '@testing-library/react-hooks';
2020
import { buildSearchBody, useEsDocSearch, ElasticRequestState } from './use_es_doc_search';
2121
import { DocProps } from './doc';
22+
import { Observable } from 'rxjs';
23+
24+
const mockSearchResult = new Observable();
25+
26+
jest.mock('../../../kibana_services', () => ({
27+
getServices: () => ({
28+
data: {
29+
search: {
30+
search: jest.fn(() => {
31+
return mockSearchResult;
32+
}),
33+
},
34+
},
35+
}),
36+
}));
2237

2338
describe('Test of <Doc /> helper / hook', () => {
2439
test('buildSearchBody', () => {
@@ -53,7 +68,6 @@ describe('Test of <Doc /> helper / hook', () => {
5368
const props = {
5469
id: '1',
5570
index: 'index1',
56-
esClient: { search: jest.fn(() => new Promise(() => {})) },
5771
indexPatternId: 'xyz',
5872
indexPatternService,
5973
} as DocProps;

src/plugins/discover/public/application/components/doc/use_es_doc_search.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919
import { useEffect, useState } from 'react';
20-
import { IndexPattern } from '../../../kibana_services';
20+
import { IndexPattern, getServices } from '../../../kibana_services';
2121
import { DocProps } from './doc';
2222
import { ElasticSearchHit } from '../../doc_views/doc_views_types';
2323

@@ -53,7 +53,6 @@ export function buildSearchBody(id: string, indexPattern: IndexPattern): Record<
5353
* Custom react hook for querying a single doc in ElasticSearch
5454
*/
5555
export function useEsDocSearch({
56-
esClient,
5756
id,
5857
index,
5958
indexPatternId,
@@ -69,12 +68,18 @@ export function useEsDocSearch({
6968
const indexPatternEntity = await indexPatternService.get(indexPatternId);
7069
setIndexPattern(indexPatternEntity);
7170

72-
const { hits } = await esClient.search({
73-
index,
74-
body: buildSearchBody(id, indexPatternEntity),
75-
});
71+
const { rawResponse } = await getServices()
72+
.data.search.search({
73+
params: {
74+
index,
75+
body: buildSearchBody(id, indexPatternEntity),
76+
},
77+
})
78+
.toPromise();
7679

77-
if (hits && hits.hits && hits.hits[0]) {
80+
const hits = rawResponse.hits;
81+
82+
if (hits?.hits?.[0]) {
7883
setStatus(ElasticRequestState.Found);
7984
setHit(hits.hits[0]);
8085
} else {
@@ -91,6 +96,6 @@ export function useEsDocSearch({
9196
}
9297
}
9398
requestData();
94-
}, [esClient, id, index, indexPatternId, indexPatternService]);
99+
}, [id, index, indexPatternId, indexPatternService]);
95100
return [status, hit, indexPattern];
96101
}

src/plugins/discover/public/application/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/discover/public/application/components/json_code_block/json_code_block.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IndexPattern } from '../../../../../data/public';
2323

2424
it('returns the `JsonCodeEditor` component', () => {
2525
const props = {
26-
hit: { _index: 'test', _source: { test: 123 } },
26+
hit: { _index: 'test', _type: 'doc', _id: 'foo', _score: 1, _source: { test: 123 } },
2727
columns: [],
2828
indexPattern: {} as IndexPattern,
2929
filter: jest.fn(),

0 commit comments

Comments
 (0)