diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ef8dbf2d25600..0bdddddab8de5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -7,6 +7,7 @@ /x-pack/plugins/discover_enhanced/ @elastic/kibana-app /x-pack/plugins/lens/ @elastic/kibana-app /x-pack/plugins/graph/ @elastic/kibana-app +/src/plugins/charts/ @elastic/kibana-app /src/plugins/dashboard/ @elastic/kibana-app /src/plugins/discover/ @elastic/kibana-app /src/plugins/input_control_vis/ @elastic/kibana-app diff --git a/src/plugins/data/common/search/index.ts b/src/plugins/data/common/search/index.ts index 061974d860246..2ee0db384cf06 100644 --- a/src/plugins/data/common/search/index.ts +++ b/src/plugins/data/common/search/index.ts @@ -20,6 +20,6 @@ export * from './aggs'; export * from './es_search'; export * from './expressions'; +export * from './search_source'; export * from './tabify'; export * from './types'; -export * from './es_search'; diff --git a/src/plugins/data/public/search/search_source/create_search_source.test.ts b/src/plugins/data/common/search/search_source/create_search_source.test.ts similarity index 96% rename from src/plugins/data/public/search/search_source/create_search_source.test.ts rename to src/plugins/data/common/search/search_source/create_search_source.test.ts index 6b6cfb0c9b1ca..dde5983fe73fb 100644 --- a/src/plugins/data/public/search/search_source/create_search_source.test.ts +++ b/src/plugins/data/common/search/search_source/create_search_source.test.ts @@ -19,9 +19,9 @@ import { createSearchSource as createSearchSourceFactory } from './create_search_source'; import { SearchSourceDependencies } from './search_source'; -import { IIndexPattern } from '../../../common/index_patterns'; +import { IIndexPattern } from '../../index_patterns'; import { IndexPatternsContract } from '../../index_patterns/index_patterns'; -import { Filter } from '../../../common/es_query/filters'; +import { Filter } from '../../es_query/filters'; import { BehaviorSubject } from 'rxjs'; describe('createSearchSource', () => { diff --git a/src/plugins/data/public/search/search_source/create_search_source.ts b/src/plugins/data/common/search/search_source/create_search_source.ts similarity index 100% rename from src/plugins/data/public/search/search_source/create_search_source.ts rename to src/plugins/data/common/search/search_source/create_search_source.ts diff --git a/src/plugins/data/public/search/search_source/extract_references.ts b/src/plugins/data/common/search/search_source/extract_references.ts similarity index 94% rename from src/plugins/data/public/search/search_source/extract_references.ts rename to src/plugins/data/common/search/search_source/extract_references.ts index f9987767a9688..72d93e41305d1 100644 --- a/src/plugins/data/public/search/search_source/extract_references.ts +++ b/src/plugins/data/common/search/search_source/extract_references.ts @@ -17,8 +17,8 @@ * under the License. */ -import { SavedObjectReference } from '../../../../../core/types'; -import { Filter } from '../../../common/es_query/filters'; +import { SavedObjectReference } from 'src/core/types'; +import { Filter } from '../../es_query/filters'; import { SearchSourceFields } from './types'; export const extractReferences = ( diff --git a/src/plugins/data/public/search/fetch/get_search_params.test.ts b/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts similarity index 93% rename from src/plugins/data/public/search/fetch/get_search_params.test.ts rename to src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts index 5e83e1f57bb6d..8778eb4fd559d 100644 --- a/src/plugins/data/public/search/fetch/get_search_params.test.ts +++ b/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts @@ -17,8 +17,9 @@ * under the License. */ +import { UI_SETTINGS } from '../../../constants'; +import { GetConfigFn } from '../../../types'; import { getSearchParams } from './get_search_params'; -import { GetConfigFn, UI_SETTINGS } from '../../../common'; function getConfigStub(config: any = {}): GetConfigFn { return (key) => config[key]; diff --git a/src/plugins/data/public/search/fetch/get_search_params.ts b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts similarity index 92% rename from src/plugins/data/public/search/fetch/get_search_params.ts rename to src/plugins/data/common/search/search_source/fetch/get_search_params.ts index ed87c4813951c..556fb4924da56 100644 --- a/src/plugins/data/public/search/fetch/get_search_params.ts +++ b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts @@ -17,7 +17,9 @@ * under the License. */ -import { UI_SETTINGS, ISearchRequestParams, GetConfigFn } from '../../../common'; +import { UI_SETTINGS } from '../../../constants'; +import { GetConfigFn } from '../../../types'; +import { ISearchRequestParams } from '../../index'; import { SearchRequest } from './types'; const sessionId = Date.now(); diff --git a/src/plugins/data/common/search/search_source/fetch/index.ts b/src/plugins/data/common/search/search_source/fetch/index.ts new file mode 100644 index 0000000000000..1b9a9677e4a99 --- /dev/null +++ b/src/plugins/data/common/search/search_source/fetch/index.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { getSearchParams, getSearchParamsFromRequest, getPreference } from './get_search_params'; +export { RequestFailure } from './request_error'; +export * from './types'; diff --git a/src/plugins/data/public/search/fetch/request_error.ts b/src/plugins/data/common/search/search_source/fetch/request_error.ts similarity index 95% rename from src/plugins/data/public/search/fetch/request_error.ts rename to src/plugins/data/common/search/search_source/fetch/request_error.ts index efaaafadf404e..ba5eb6f2897a9 100644 --- a/src/plugins/data/public/search/fetch/request_error.ts +++ b/src/plugins/data/common/search/search_source/fetch/request_error.ts @@ -18,7 +18,7 @@ */ import { SearchResponse } from 'elasticsearch'; -import { KbnError } from '../../../../kibana_utils/common'; +import { KbnError } from '../../../../../kibana_utils/common'; import { SearchError } from './types'; /** diff --git a/src/plugins/data/public/search/fetch/types.ts b/src/plugins/data/common/search/search_source/fetch/types.ts similarity index 97% rename from src/plugins/data/public/search/fetch/types.ts rename to src/plugins/data/common/search/search_source/fetch/types.ts index cdf10d8f1a1b0..30055f88012f2 100644 --- a/src/plugins/data/public/search/fetch/types.ts +++ b/src/plugins/data/common/search/search_source/fetch/types.ts @@ -18,8 +18,8 @@ */ import { SearchResponse } from 'elasticsearch'; -import { GetConfigFn } from '../../../common'; import { LegacyFetchHandlers } from '../legacy/types'; +import { GetConfigFn } from '../../../types'; /** * @internal diff --git a/src/plugins/data/public/search/search_source/filter_docvalue_fields.test.ts b/src/plugins/data/common/search/search_source/filter_docvalue_fields.test.ts similarity index 100% rename from src/plugins/data/public/search/search_source/filter_docvalue_fields.test.ts rename to src/plugins/data/common/search/search_source/filter_docvalue_fields.test.ts diff --git a/src/plugins/data/public/search/search_source/filter_docvalue_fields.ts b/src/plugins/data/common/search/search_source/filter_docvalue_fields.ts similarity index 100% rename from src/plugins/data/public/search/search_source/filter_docvalue_fields.ts rename to src/plugins/data/common/search/search_source/filter_docvalue_fields.ts diff --git a/src/plugins/data/public/search/search_source/index.ts b/src/plugins/data/common/search/search_source/index.ts similarity index 95% rename from src/plugins/data/public/search/search_source/index.ts rename to src/plugins/data/common/search/search_source/index.ts index 48c0338f7e981..70c9cfcee2348 100644 --- a/src/plugins/data/public/search/search_source/index.ts +++ b/src/plugins/data/common/search/search_source/index.ts @@ -23,3 +23,5 @@ export { SortDirection, EsQuerySortValue, SearchSourceFields } from './types'; export { injectReferences } from './inject_references'; export { extractReferences } from './extract_references'; export { parseSearchSourceJSON } from './parse_json'; +export * from './fetch'; +export * from './legacy'; diff --git a/src/plugins/data/public/search/search_source/inject_references.ts b/src/plugins/data/common/search/search_source/inject_references.ts similarity index 96% rename from src/plugins/data/public/search/search_source/inject_references.ts rename to src/plugins/data/common/search/search_source/inject_references.ts index 07f37c3c11275..81fafc6dcae06 100644 --- a/src/plugins/data/public/search/search_source/inject_references.ts +++ b/src/plugins/data/common/search/search_source/inject_references.ts @@ -17,8 +17,8 @@ * under the License. */ +import { SavedObjectReference } from 'src/core/types'; import { SearchSourceFields } from './types'; -import { SavedObjectReference } from '../../../../../core/types'; export const injectReferences = ( searchSourceFields: SearchSourceFields & { indexRefName: string }, diff --git a/src/plugins/data/public/search/legacy/call_client.test.ts b/src/plugins/data/common/search/search_source/legacy/call_client.test.ts similarity index 100% rename from src/plugins/data/public/search/legacy/call_client.test.ts rename to src/plugins/data/common/search/search_source/legacy/call_client.test.ts diff --git a/src/plugins/data/public/search/legacy/call_client.ts b/src/plugins/data/common/search/search_source/legacy/call_client.ts similarity index 93% rename from src/plugins/data/public/search/legacy/call_client.ts rename to src/plugins/data/common/search/search_source/legacy/call_client.ts index b87affdd59c54..cb6295dd701ee 100644 --- a/src/plugins/data/public/search/legacy/call_client.ts +++ b/src/plugins/data/common/search/search_source/legacy/call_client.ts @@ -18,10 +18,9 @@ */ import { SearchResponse } from 'elasticsearch'; -import { ISearchOptions } from 'src/plugins/data/common'; -import { FetchHandlers } from '../fetch'; +import { FetchHandlers, SearchRequest } from '../fetch'; import { defaultSearchStrategy } from './default_search_strategy'; -import { SearchRequest } from '../index'; +import { ISearchOptions } from '../../index'; export function callClient( searchRequests: SearchRequest[], diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts b/src/plugins/data/common/search/search_source/legacy/default_search_strategy.test.ts similarity index 67% rename from src/plugins/data/public/search/legacy/default_search_strategy.test.ts rename to src/plugins/data/common/search/search_source/legacy/default_search_strategy.test.ts index ad59e5c6c9625..3badd456bd72a 100644 --- a/src/plugins/data/public/search/legacy/default_search_strategy.test.ts +++ b/src/plugins/data/common/search/search_source/legacy/default_search_strategy.test.ts @@ -17,51 +17,50 @@ * under the License. */ -import { HttpStart } from 'src/core/public'; -import { coreMock } from '../../../../../core/public/mocks'; -import { getCallMsearch } from './call_msearch'; import { defaultSearchStrategy } from './default_search_strategy'; import { LegacyFetchHandlers, SearchStrategySearchParams } from './types'; import { BehaviorSubject } from 'rxjs'; const { search } = defaultSearchStrategy; -const msearchMock = jest.fn().mockResolvedValue({ body: { responses: [] } }); - -describe('defaultSearchStrategy', function () { - describe('search', function () { +describe('defaultSearchStrategy', () => { + describe('search', () => { let searchArgs: MockedKeys; - let http: jest.Mocked; beforeEach(() => { - msearchMock.mockClear(); - - http = coreMock.createStart().http; - http.post.mockResolvedValue(msearchMock); - searchArgs = { searchRequests: [ { index: { title: 'foo' }, + body: {}, }, ], getConfig: jest.fn(), onResponse: (req, res) => res, legacy: { - callMsearch: getCallMsearch({ http }), + callMsearch: jest.fn().mockResolvedValue(undefined), loadingCount$: new BehaviorSubject(0) as any, } as jest.Mocked, }; }); - test('calls http.post with the correct arguments', async () => { + test('calls callMsearch with the correct arguments', async () => { await search({ ...searchArgs }); - expect(http.post.mock.calls).toMatchInlineSnapshot(` + expect(searchArgs.legacy.callMsearch.mock.calls).toMatchInlineSnapshot(` Array [ Array [ - "/internal/_msearch", Object { - "body": "{\\"searches\\":[{\\"header\\":{\\"index\\":\\"foo\\"}}]}", + "body": Object { + "searches": Array [ + Object { + "body": Object {}, + "header": Object { + "index": "foo", + "preference": undefined, + }, + }, + ], + }, "signal": AbortSignal {}, }, ], diff --git a/src/plugins/data/public/search/legacy/default_search_strategy.ts b/src/plugins/data/common/search/search_source/legacy/default_search_strategy.ts similarity index 100% rename from src/plugins/data/public/search/legacy/default_search_strategy.ts rename to src/plugins/data/common/search/search_source/legacy/default_search_strategy.ts diff --git a/src/plugins/data/public/search/legacy/fetch_soon.test.ts b/src/plugins/data/common/search/search_source/legacy/fetch_soon.test.ts similarity index 96% rename from src/plugins/data/public/search/legacy/fetch_soon.test.ts rename to src/plugins/data/common/search/search_source/legacy/fetch_soon.test.ts index 7243ab158009a..81117513917c0 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.test.ts +++ b/src/plugins/data/common/search/search_source/legacy/fetch_soon.test.ts @@ -17,12 +17,13 @@ * under the License. */ -import { fetchSoon } from './fetch_soon'; -import { callClient } from './call_client'; -import { FetchHandlers } from '../fetch/types'; -import { SearchRequest } from '../index'; import { SearchResponse } from 'elasticsearch'; -import { GetConfigFn, UI_SETTINGS, ISearchOptions } from '../../../common'; +import { UI_SETTINGS } from '../../../constants'; +import { GetConfigFn } from '../../../types'; +import { FetchHandlers, SearchRequest } from '../fetch'; +import { ISearchOptions } from '../../index'; +import { callClient } from './call_client'; +import { fetchSoon } from './fetch_soon'; function getConfigStub(config: any = {}): GetConfigFn { return (key) => config[key]; diff --git a/src/plugins/data/public/search/legacy/fetch_soon.ts b/src/plugins/data/common/search/search_source/legacy/fetch_soon.ts similarity index 95% rename from src/plugins/data/public/search/legacy/fetch_soon.ts rename to src/plugins/data/common/search/search_source/legacy/fetch_soon.ts index 1c0573aa895d7..01ffc3876f6af 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.ts +++ b/src/plugins/data/common/search/search_source/legacy/fetch_soon.ts @@ -18,10 +18,10 @@ */ import { SearchResponse } from 'elasticsearch'; +import { UI_SETTINGS } from '../../../constants'; +import { FetchHandlers, SearchRequest } from '../fetch'; +import { ISearchOptions } from '../../index'; import { callClient } from './call_client'; -import { FetchHandlers } from '../fetch/types'; -import { SearchRequest } from '../index'; -import { UI_SETTINGS, ISearchOptions } from '../../../common'; /** * This function introduces a slight delay in the request process to allow multiple requests to queue diff --git a/src/plugins/data/common/search/search_source/legacy/index.ts b/src/plugins/data/common/search/search_source/legacy/index.ts new file mode 100644 index 0000000000000..26587b09ffd9e --- /dev/null +++ b/src/plugins/data/common/search/search_source/legacy/index.ts @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { fetchSoon } from './fetch_soon'; +export * from './types'; diff --git a/src/plugins/data/public/search/legacy/types.ts b/src/plugins/data/common/search/search_source/legacy/types.ts similarity index 95% rename from src/plugins/data/public/search/legacy/types.ts rename to src/plugins/data/common/search/search_source/legacy/types.ts index 740bc22a7485c..1a0a96a76a703 100644 --- a/src/plugins/data/public/search/legacy/types.ts +++ b/src/plugins/data/common/search/search_source/legacy/types.ts @@ -19,8 +19,7 @@ import { BehaviorSubject } from 'rxjs'; import { SearchResponse } from 'elasticsearch'; -import { FetchHandlers } from '../fetch'; -import { SearchRequest } from '..'; +import { FetchHandlers, SearchRequest } from '../fetch'; // @internal export interface LegacyFetchHandlers { diff --git a/src/plugins/data/public/search/search_source/migrate_legacy_query.ts b/src/plugins/data/common/search/search_source/migrate_legacy_query.ts similarity index 96% rename from src/plugins/data/public/search/search_source/migrate_legacy_query.ts rename to src/plugins/data/common/search/search_source/migrate_legacy_query.ts index 8d9b50d5a66b2..f271280170166 100644 --- a/src/plugins/data/public/search/search_source/migrate_legacy_query.ts +++ b/src/plugins/data/common/search/search_source/migrate_legacy_query.ts @@ -18,7 +18,7 @@ */ import { has } from 'lodash'; -import { Query } from 'src/plugins/data/public'; +import { Query } from '../../query/types'; /** * Creates a standardized query object from old queries that were either strings or pure ES query DSL diff --git a/src/plugins/data/public/search/search_source/mocks.ts b/src/plugins/data/common/search/search_source/mocks.ts similarity index 100% rename from src/plugins/data/public/search/search_source/mocks.ts rename to src/plugins/data/common/search/search_source/mocks.ts diff --git a/src/plugins/data/public/search/search_source/normalize_sort_request.test.ts b/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts similarity index 98% rename from src/plugins/data/public/search/search_source/normalize_sort_request.test.ts rename to src/plugins/data/common/search/search_source/normalize_sort_request.test.ts index 10004b87ca690..1899efbf3598d 100644 --- a/src/plugins/data/public/search/search_source/normalize_sort_request.test.ts +++ b/src/plugins/data/common/search/search_source/normalize_sort_request.test.ts @@ -19,7 +19,7 @@ import { normalizeSortRequest } from './normalize_sort_request'; import { SortDirection } from './types'; -import { IIndexPattern } from '../..'; +import { IIndexPattern } from '../../index_patterns'; describe('SearchSource#normalizeSortRequest', function () { const scriptedField = { diff --git a/src/plugins/data/public/search/search_source/normalize_sort_request.ts b/src/plugins/data/common/search/search_source/normalize_sort_request.ts similarity index 98% rename from src/plugins/data/public/search/search_source/normalize_sort_request.ts rename to src/plugins/data/common/search/search_source/normalize_sort_request.ts index 3ec0a13282d3e..e41c4482df9c9 100644 --- a/src/plugins/data/public/search/search_source/normalize_sort_request.ts +++ b/src/plugins/data/common/search/search_source/normalize_sort_request.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IIndexPattern } from '../..'; +import { IIndexPattern } from '../../index_patterns'; import { EsQuerySortValue, SortOptions } from './types'; export function normalizeSortRequest( diff --git a/src/plugins/data/public/search/search_source/parse_json.ts b/src/plugins/data/common/search/search_source/parse_json.ts similarity index 100% rename from src/plugins/data/public/search/search_source/parse_json.ts rename to src/plugins/data/common/search/search_source/parse_json.ts diff --git a/src/plugins/data/public/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts similarity index 97% rename from src/plugins/data/public/search/search_source/search_source.test.ts rename to src/plugins/data/common/search/search_source/search_source.test.ts index d9a9fb2f4fef3..74abd9238bc2b 100644 --- a/src/plugins/data/public/search/search_source/search_source.test.ts +++ b/src/plugins/data/common/search/search_source/search_source.test.ts @@ -18,12 +18,12 @@ */ import { Observable, BehaviorSubject } from 'rxjs'; -import { GetConfigFn } from 'src/plugins/data/common'; -import { SearchSource, SearchSourceDependencies } from './search_source'; -import { IndexPattern, SortDirection } from '../..'; -import { fetchSoon } from '../legacy'; +import { IndexPattern } from '../../index_patterns'; +import { GetConfigFn } from '../../types'; +import { fetchSoon } from './legacy'; +import { SearchSource, SearchSourceDependencies, SortDirection } from './'; -jest.mock('../legacy', () => ({ +jest.mock('./legacy', () => ({ fetchSoon: jest.fn().mockResolvedValue({}), })); diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts similarity index 99% rename from src/plugins/data/public/search/search_source/search_source.ts rename to src/plugins/data/common/search/search_source/search_source.ts index 4afee223454e4..d8a036ce970dd 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -75,9 +75,10 @@ import { map } from 'rxjs/operators'; import { normalizeSortRequest } from './normalize_sort_request'; import { filterDocvalueFields } from './filter_docvalue_fields'; import { fieldWildcardFilter } from '../../../../kibana_utils/common'; -import { IIndexPattern, ISearchGeneric } from '../..'; +import { IIndexPattern } from '../../index_patterns'; +import { ISearchGeneric } from '../..'; import { SearchSourceOptions, SearchSourceFields } from './types'; -import { FetchHandlers, RequestFailure, getSearchParamsFromRequest, SearchRequest } from '../fetch'; +import { FetchHandlers, RequestFailure, getSearchParamsFromRequest, SearchRequest } from './fetch'; import { getEsQueryConfig, @@ -87,7 +88,7 @@ import { ISearchOptions, } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; -import { fetchSoon } from '../legacy'; +import { fetchSoon } from './legacy'; import { extractReferences } from './extract_references'; /** @internal */ diff --git a/src/plugins/data/public/search/search_source/types.ts b/src/plugins/data/common/search/search_source/types.ts similarity index 100% rename from src/plugins/data/public/search/search_source/types.ts rename to src/plugins/data/common/search/search_source/types.ts diff --git a/src/plugins/data/common/search/types.ts b/src/plugins/data/common/search/types.ts index 7600bd9db6094..0a299b57275f8 100644 --- a/src/plugins/data/common/search/types.ts +++ b/src/plugins/data/common/search/types.ts @@ -17,6 +17,22 @@ * under the License. */ +import { Observable } from 'rxjs'; +import { IEsSearchRequest, IEsSearchResponse, ISearchOptions } from '../../common/search'; + +export type ISearch = ( + request: IKibanaSearchRequest, + options?: ISearchOptions +) => Observable; + +export type ISearchGeneric = < + SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest, + SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse +>( + request: SearchStrategyRequest, + options?: ISearchOptions +) => Observable; + export interface IKibanaSearchResponse { /** * Some responses may contain a unique id to identify the request this response came from. diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 26e72a82d4bb5..db8d9dba4e0c7 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -64,6 +64,7 @@ import { Required } from '@kbn/utility-types'; import * as Rx from 'rxjs'; import { SavedObject } from 'src/core/server'; import { SavedObject as SavedObject_3 } from 'src/core/public'; +import { SavedObjectReference as SavedObjectReference_2 } from 'src/core/types'; import { SavedObjectsClientContract } from 'src/core/public'; import { Search } from '@elastic/elasticsearch/api/requestParams'; import { SearchResponse } from 'elasticsearch'; @@ -651,13 +652,12 @@ export type ExistsFilter = Filter & { // @public (undocumented) export const expandShorthand: (sh: Record) => MappingObject; -// Warning: (ae-forgotten-export) The symbol "SavedObjectReference" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "extractReferences" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export const extractSearchSourceReferences: (state: SearchSourceFields) => [SearchSourceFields & { indexRefName?: string; -}, SavedObjectReference[]]; +}, SavedObjectReference_2[]]; // Warning: (ae-missing-release-tag) "FieldFormat" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1371,7 +1371,7 @@ export interface IndexPatternTypeMeta { // @public (undocumented) export const injectSearchSourceReferences: (searchSourceFields: SearchSourceFields & { indexRefName: string; -}, references: SavedObjectReference[]) => SearchSourceFields; +}, references: SavedObjectReference_2[]) => SearchSourceFields; // Warning: (ae-missing-release-tag) "InputTimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/src/plugins/data/public/search/expressions/esaggs.ts b/src/plugins/data/public/search/expressions/esaggs.ts index 50fbb114b39fd..9b89bd1dcbfa6 100644 --- a/src/plugins/data/public/search/expressions/esaggs.ts +++ b/src/plugins/data/public/search/expressions/esaggs.ts @@ -38,6 +38,7 @@ import { getRequestInspectorStats, getResponseInspectorStats, IAggConfigs, + ISearchSource, tabifyAggResponse, } from '../../../common/search'; @@ -48,7 +49,6 @@ import { getQueryService, getSearchService, } from '../../services'; -import { ISearchSource } from '../search_source'; import { buildTabularInspectorData } from './build_tabular_inspector_data'; import { serializeAggConfig } from './utils'; diff --git a/src/plugins/data/public/search/fetch/index.ts b/src/plugins/data/public/search/fetch/index.ts index 4b8511edfc26f..340a795d37bfb 100644 --- a/src/plugins/data/public/search/fetch/index.ts +++ b/src/plugins/data/public/search/fetch/index.ts @@ -17,8 +17,4 @@ * under the License. */ -export * from './types'; -export { getSearchParams, getSearchParamsFromRequest, getPreference } from './get_search_params'; - -export { RequestFailure } from './request_error'; export { handleResponse } from './handle_response'; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index c1af9699acbb2..fc3d71936a859 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -19,34 +19,31 @@ export * from './expressions'; +export { ISearchSetup, ISearchStart, ISearchStartSearchSource, SearchEnhancements } from './types'; + export { + ES_SEARCH_STRATEGY, + EsQuerySortValue, + extractReferences as extractSearchSourceReferences, + getSearchParamsFromRequest, + IEsSearchRequest, + IEsSearchResponse, + IKibanaSearchRequest, + IKibanaSearchResponse, + injectReferences as injectSearchSourceReferences, ISearch, ISearchGeneric, - ISearchSetup, - ISearchStart, - ISearchStartSearchSource, - SearchEnhancements, -} from './types'; - -export { IEsSearchResponse, IEsSearchRequest, ES_SEARCH_STRATEGY } from '../../common/search'; - -export { getEsPreference } from './es_search'; - -export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; - -export { SearchError, getSearchParamsFromRequest, SearchRequest } from './fetch'; - -export { ISearchSource, + parseSearchSourceJSON, + SearchError, + SearchRequest, SearchSource, SearchSourceDependencies, SearchSourceFields, - EsQuerySortValue, SortDirection, - extractReferences as extractSearchSourceReferences, - injectReferences as injectSearchSourceReferences, - parseSearchSourceJSON, -} from './search_source'; +} from '../../common/search'; + +export { getEsPreference } from './es_search'; export { SearchInterceptor, SearchInterceptorDeps } from './search_interceptor'; export { RequestTimeoutError } from './request_timeout_error'; diff --git a/src/plugins/data/public/search/legacy/call_msearch.test.ts b/src/plugins/data/public/search/legacy/call_msearch.test.ts new file mode 100644 index 0000000000000..da39bf521fe3d --- /dev/null +++ b/src/plugins/data/public/search/legacy/call_msearch.test.ts @@ -0,0 +1,54 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HttpStart } from 'src/core/public'; +import { coreMock } from '../../../../../core/public/mocks'; +import { getCallMsearch } from './call_msearch'; + +describe('callMsearch', () => { + const msearchMock = jest.fn().mockResolvedValue({ body: { responses: [] } }); + let http: jest.Mocked; + + beforeEach(() => { + msearchMock.mockClear(); + http = coreMock.createStart().http; + http.post.mockResolvedValue(msearchMock); + }); + + test('calls http.post with the correct arguments', async () => { + const searches = [{ header: { index: 'foo' }, body: {} }]; + const callMsearch = getCallMsearch({ http }); + await callMsearch({ + body: { searches }, + signal: new AbortController().signal, + }); + + expect(http.post.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + "/internal/_msearch", + Object { + "body": "{\\"searches\\":[{\\"header\\":{\\"index\\":\\"foo\\"},\\"body\\":{}}]}", + "signal": AbortSignal {}, + }, + ], + ] + `); + }); +}); diff --git a/src/plugins/data/public/search/legacy/call_msearch.ts b/src/plugins/data/public/search/legacy/call_msearch.ts index fd4f8a07919f8..6b2b9b4da020b 100644 --- a/src/plugins/data/public/search/legacy/call_msearch.ts +++ b/src/plugins/data/public/search/legacy/call_msearch.ts @@ -18,7 +18,7 @@ */ import { HttpStart } from 'src/core/public'; -import { LegacyFetchHandlers } from './types'; +import { LegacyFetchHandlers } from '../../../common/search/search_source'; /** * Wrapper for calling the internal msearch endpoint from the client. diff --git a/src/plugins/data/public/search/legacy/index.ts b/src/plugins/data/public/search/legacy/index.ts index 74e516f407e8c..08e5eab788e76 100644 --- a/src/plugins/data/public/search/legacy/index.ts +++ b/src/plugins/data/public/search/legacy/index.ts @@ -17,4 +17,4 @@ * under the License. */ -export { fetchSoon } from './fetch_soon'; +export * from './call_msearch'; diff --git a/src/plugins/data/public/search/mocks.ts b/src/plugins/data/public/search/mocks.ts index f4ed7d8b122b9..fdd6a90013413 100644 --- a/src/plugins/data/public/search/mocks.ts +++ b/src/plugins/data/public/search/mocks.ts @@ -19,9 +19,9 @@ import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks'; import { ISearchSetup, ISearchStart } from './types'; -import { searchSourceMock, createSearchSourceMock } from './search_source/mocks'; +import { searchSourceMock, createSearchSourceMock } from '../../common/search/search_source/mocks'; -export * from './search_source/mocks'; +export * from '../../common/search/search_source/mocks'; function createSetupContract(): jest.Mocked { return { diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index c41e1f78ee74e..d8937ed30e401 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -22,12 +22,16 @@ import { BehaviorSubject } from 'rxjs'; import { ISearchSetup, ISearchStart, SearchEnhancements } from './types'; import { handleResponse } from './fetch'; -import { getCallMsearch } from './legacy/call_msearch'; -import { createSearchSource, SearchSource, SearchSourceDependencies } from './search_source'; +import { + createSearchSource, + ISearchGeneric, + SearchSource, + SearchSourceDependencies, +} from '../../common/search'; +import { getCallMsearch } from './legacy'; import { AggsService, AggsStartDependencies } from './aggs'; import { IndexPatternsContract } from '../index_patterns/index_patterns'; import { ISearchInterceptor, SearchInterceptor } from './search_interceptor'; -import { ISearchGeneric } from './types'; import { SearchUsageCollector, createUsageCollector } from './collectors'; import { UsageCollectionSetup } from '../../../usage_collection/public'; import { esdsl, esRawResponse } from './expressions'; diff --git a/src/plugins/data/public/search/types.ts b/src/plugins/data/public/search/types.ts index 83a542269046f..6ae5d83499aa6 100644 --- a/src/plugins/data/public/search/types.ts +++ b/src/plugins/data/public/search/types.ts @@ -17,38 +17,18 @@ * under the License. */ -import { Observable } from 'rxjs'; import { PackageInfo } from 'kibana/server'; import { ISearchInterceptor } from './search_interceptor'; -import { ISearchSource, SearchSourceFields } from './search_source'; import { SearchUsageCollector } from './collectors'; import { AggsSetup, AggsSetupDependencies, AggsStartDependencies, AggsStart } from './aggs'; -import { - IKibanaSearchRequest, - IKibanaSearchResponse, - IEsSearchRequest, - IEsSearchResponse, - ISearchOptions, -} from '../../common/search'; +import { ISearchGeneric, ISearchSource, SearchSourceFields } from '../../common/search'; import { IndexPatternsContract } from '../../common/index_patterns/index_patterns'; import { UsageCollectionSetup } from '../../../usage_collection/public'; -export type ISearch = ( - request: IKibanaSearchRequest, - options?: ISearchOptions -) => Observable; - -export type ISearchGeneric = < - SearchStrategyRequest extends IEsSearchRequest = IEsSearchRequest, - SearchStrategyResponse extends IEsSearchResponse = IEsSearchResponse ->( - request: SearchStrategyRequest, - options?: ISearchOptions -) => Observable; - export interface SearchEnhancements { searchInterceptor: ISearchInterceptor; } + /** * The setup contract exposed by the Search plugin exposes the search strategy extension * point. diff --git a/src/plugins/visualizations/public/vis.test.ts b/src/plugins/visualizations/public/vis.test.ts index a0da8d83bed51..c271888b7c7a4 100644 --- a/src/plugins/visualizations/public/vis.test.ts +++ b/src/plugins/visualizations/public/vis.test.ts @@ -35,7 +35,7 @@ jest.mock('./services', () => { // eslint-disable-next-line const { BaseVisType } = require('./vis_types/base_vis_type'); // eslint-disable-next-line - const { SearchSource } = require('../../data/public/search/search_source'); + const { SearchSource } = require('../../data/common/search/search_source'); // eslint-disable-next-line const fixturesStubbedLogstashIndexPatternProvider = require('../../../fixtures/stubbed_logstash_index_pattern'); const visType = new BaseVisType({ diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx index 91adbcecaf897..077e07a89f788 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx @@ -118,6 +118,7 @@ export const QueryInput = ({ return ( void }) => ( - + {label} ); diff --git a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx index 365e430a460fa..50b8f4c6fc40b 100644 --- a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx @@ -126,6 +126,7 @@ export function PieToolbar(props: VisualizationToolbarProps & { * Adjusts the borders for groupings */ groupPosition?: 'none' | 'left' | 'center' | 'right'; + dataTestSubj?: string; }; export const ToolbarButton: React.FunctionComponent = ({ @@ -42,6 +43,7 @@ export const ToolbarButton: React.FunctionComponent = ({ size = 'm', hasArrow = true, groupPosition = 'none', + dataTestSubj = '', ...rest }) => { const classes = classNames( @@ -52,6 +54,7 @@ export const ToolbarButton: React.FunctionComponent = ({ ); return ( = ({ @@ -39,6 +40,7 @@ export const ToolbarPopover: React.FunctionComponent = ({ type, isDisabled = false, groupPosition, + buttonDataTestSubj, }) => { const [open, setOpen] = useState(false); @@ -60,6 +62,7 @@ export const ToolbarPopover: React.FunctionComponent = ({ hasArrow={false} isDisabled={isDisabled} groupPosition={groupPosition} + dataTestSubj={buttonDataTestSubj} > diff --git a/x-pack/plugins/lens/public/xy_visualization/axis_settings_popover.tsx b/x-pack/plugins/lens/public/xy_visualization/axis_settings_popover.tsx index 835f3e2cde769..45ec7098aa639 100644 --- a/x-pack/plugins/lens/public/xy_visualization/axis_settings_popover.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/axis_settings_popover.tsx @@ -73,7 +73,12 @@ export interface AxisSettingsPopoverProps { const popoverConfig = ( axis: AxesSettingsConfigKeys, isHorizontal: boolean -): { icon: IconType; groupPosition: ToolbarButtonProps['groupPosition']; popoverTitle: string } => { +): { + icon: IconType; + groupPosition: ToolbarButtonProps['groupPosition']; + popoverTitle: string; + buttonDataTestSubj: string; +} => { switch (axis) { case 'yLeft': return { @@ -86,6 +91,7 @@ const popoverConfig = ( : i18n.translate('xpack.lens.xyChart.leftAxisLabel', { defaultMessage: 'Left axis', }), + buttonDataTestSubj: 'lnsLeftAxisButton', }; case 'yRight': return { @@ -98,6 +104,7 @@ const popoverConfig = ( : i18n.translate('xpack.lens.xyChart.rightAxisLabel', { defaultMessage: 'Right axis', }), + buttonDataTestSubj: 'lnsRightAxisButton', }; case 'x': default: @@ -111,6 +118,8 @@ const popoverConfig = ( : i18n.translate('xpack.lens.xyChart.bottomAxisLabel', { defaultMessage: 'Bottom axis', }), + + buttonDataTestSubj: 'lnsBottomAxisButton', }; } }; @@ -143,6 +152,7 @@ export const AxisSettingsPopover: React.FunctionComponent diff --git a/x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx b/x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx index 4aa5bd62c05a5..c7781c2e1d50c 100644 --- a/x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/xy_config_panel.tsx @@ -208,6 +208,7 @@ export function XyToolbar(props: VisualizationToolbarProps) { isDisabled={!hasNonBarSeries} type="values" groupPosition="left" + buttonDataTestSubj="lnsMissingValuesButton" > ) { })} > { return { @@ -488,6 +490,7 @@ const ColorPicker = ({ const colorPicker = ( lns-empty-dimension', operation: 'avg', field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_splitDimensionPanel > lns-empty-dimension', operation: 'terms', field: 'ip', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.save(title, saveAsNew, redirectToOrigin); } diff --git a/x-pack/test/functional/apps/lens/dashboard.ts b/x-pack/test/functional/apps/lens/dashboard.ts index 4a68c9a8ff3f2..fa13d013ea115 100644 --- a/x-pack/test/functional/apps/lens/dashboard.ts +++ b/x-pack/test/functional/apps/lens/dashboard.ts @@ -51,7 +51,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await find.clickByButtonText('lnsXYvis'); await dashboardAddPanel.closeAddPanel(); await PageObjects.lens.goToTimeRange(); - await clickInChart(5, 5); // hardcoded position of bar + await clickInChart(5, 5); // hardcoded position of bar, depends heavy on data and charts implementation await retry.try(async () => { await testSubjects.click('applyFiltersPopoverButton'); @@ -68,5 +68,23 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const hasIpFilter = await filterBar.hasFilter('ip', '97.220.3.248'); expect(hasIpFilter).to.be(true); }); + it('should be able to add filters by clicking in pie chart', async () => { + await PageObjects.common.navigateToApp('dashboard'); + await PageObjects.dashboard.clickNewDashboard(); + await dashboardAddPanel.clickOpenAddPanel(); + await dashboardAddPanel.filterEmbeddableNames('lnsPieVis'); + await find.clickByButtonText('lnsPieVis'); + await dashboardAddPanel.closeAddPanel(); + + await PageObjects.lens.goToTimeRange(); + await clickInChart(5, 5); // hardcoded position of the slice, depends heavy on data and charts implementation + + await PageObjects.lens.assertExactText( + '[data-test-subj="embeddablePanelHeading-lnsPieVis"]', + 'lnsPieVis' + ); + const hasGeoDestFilter = await filterBar.hasFilter('geo.dest', 'LS'); + expect(hasGeoDestFilter).to.be(true); + }); }); } diff --git a/x-pack/test/functional/apps/lens/rollup.ts b/x-pack/test/functional/apps/lens/rollup.ts index f6882c8aed214..8e1dc231b6b1a 100644 --- a/x-pack/test/functional/apps/lens/rollup.ts +++ b/x-pack/test/functional/apps/lens/rollup.ts @@ -34,18 +34,21 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { operation: 'date_histogram', field: '@timestamp', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', operation: 'sum', field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_splitDimensionPanel > lns-empty-dimension', operation: 'terms', field: 'geo.src', }); + await PageObjects.lens.closeDimensionEditor(); expect(await find.allByCssSelector('.echLegendItem')).to.have.length(2); await PageObjects.lens.save('Afancilenstest'); diff --git a/x-pack/test/functional/apps/lens/smokescreen.ts b/x-pack/test/functional/apps/lens/smokescreen.ts index 8c4321d77acf4..42807a23cb13a 100644 --- a/x-pack/test/functional/apps/lens/smokescreen.ts +++ b/x-pack/test/functional/apps/lens/smokescreen.ts @@ -8,20 +8,12 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService, getPageObjects }: FtrProviderContext) { - const PageObjects = getPageObjects(['visualize', 'lens']); + const PageObjects = getPageObjects(['visualize', 'lens', 'common']); const find = getService('find'); const listingTable = getService('listingTable'); const testSubjects = getService('testSubjects'); describe('lens smokescreen tests', () => { - it('should allow editing saved visualizations', async () => { - await PageObjects.visualize.gotoVisualizationLandingPage(); - await listingTable.searchForItemWithName('Artistpreviouslyknownaslens'); - await PageObjects.lens.clickVisualizeListItemTitle('Artistpreviouslyknownaslens'); - await PageObjects.lens.goToTimeRange(); - await PageObjects.lens.assertMetric('Maximum of bytes', '19,986'); - }); - it('should allow creation of lens xy chart', async () => { await PageObjects.visualize.navigateToNewVisualization(); await PageObjects.visualize.clickVisType('lens'); @@ -32,18 +24,21 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { operation: 'date_histogram', field: '@timestamp', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', operation: 'avg', field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_splitDimensionPanel > lns-empty-dimension', operation: 'terms', field: '@message.raw', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.switchToVisualization('lnsDatatable'); await PageObjects.lens.removeDimension('lnsDatatable_column'); @@ -54,6 +49,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { operation: 'terms', field: 'ip', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.save('Afancilenstest'); @@ -70,8 +66,23 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { // legend item(s), so we're using a class selector here. expect(await find.allByCssSelector('.echLegendItem')).to.have.length(3); }); + it('should create an xy visualization with filters aggregation', async () => { + await PageObjects.visualize.gotoVisualizationLandingPage(); + await listingTable.searchForItemWithName('lnsXYvis'); + await PageObjects.lens.clickVisualizeListItemTitle('lnsXYvis'); + await PageObjects.lens.goToTimeRange(); + await PageObjects.lens.configureDimension({ + dimension: 'lnsXY_splitDimensionPanel > lns-dimensionTrigger', + operation: 'filters', + isPreviousIncompatible: true, + }); + await PageObjects.lens.addFilterToAgg(`geo.src : CN`); + + expect(await PageObjects.lens.getFiltersAggLabels()).to.eql([`ip : *`, `geo.src : CN`]); + expect(await find.allByCssSelector('.echLegendItem')).to.have.length(2); + }); - it('should allow seamless transition to and from table view', async () => { + it('should transition from metric to table to metric', async () => { await PageObjects.visualize.gotoVisualizationLandingPage(); await listingTable.searchForItemWithName('Artistpreviouslyknownaslens'); await PageObjects.lens.clickVisualizeListItemTitle('Artistpreviouslyknownaslens'); @@ -84,7 +95,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.lens.assertMetric('Maximum of bytes', '19,986'); }); - it('should switch from a multi-layer stacked bar to a multi-layer line chart', async () => { + it('should transition from a multi-layer stacked bar to a multi-layer line chart and correctly remove all layers', async () => { await PageObjects.visualize.navigateToNewVisualization(); await PageObjects.visualize.clickVisType('lens'); await PageObjects.lens.goToTimeRange(); @@ -95,22 +106,75 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { field: '@timestamp', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', operation: 'avg', field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.createLayer(); expect(await PageObjects.lens.hasChartSwitchWarning('line')).to.eql(false); await PageObjects.lens.switchToVisualization('line'); + await PageObjects.lens.configureDimension( + { + dimension: 'lnsXY_xDimensionPanel > lns-empty-dimension', + operation: 'terms', + field: 'geo.src', + }, + 1 + ); + + await PageObjects.lens.closeDimensionEditor(); + await PageObjects.lens.configureDimension( + { + dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', + operation: 'avg', + field: 'bytes', + }, + 1 + ); + await PageObjects.lens.closeDimensionEditor(); expect(await PageObjects.lens.getLayerCount()).to.eql(2); + await testSubjects.click('lnsLayerRemove'); + await testSubjects.click('lnsLayerRemove'); + await testSubjects.existOrFail('empty-workspace'); + }); + + it('should edit settings of xy line chart', async () => { + await PageObjects.visualize.gotoVisualizationLandingPage(); + await listingTable.searchForItemWithName('lnsXYvis'); + await PageObjects.lens.clickVisualizeListItemTitle('lnsXYvis'); + await PageObjects.lens.goToTimeRange(); + await testSubjects.click('lnsXY_splitDimensionPanel > indexPattern-dimension-remove'); + await PageObjects.lens.switchToVisualization('line'); + await PageObjects.lens.configureDimension({ + dimension: 'lnsXY_yDimensionPanel > lns-dimensionTrigger', + operation: 'max', + field: 'memory', + }); + await PageObjects.lens.editDimensionLabel('Test of label'); + await PageObjects.lens.editDimensionFormat('Percent'); + await PageObjects.lens.editDimensionColor('#ff0000'); + await PageObjects.lens.editMissingValues('Linear'); + + await PageObjects.lens.assertMissingValues('Linear'); + await PageObjects.lens.assertColor('#ff0000'); + + await testSubjects.existOrFail('indexPattern-dimension-formatDecimals'); + + await PageObjects.lens.closeDimensionEditor(); + + expect(await PageObjects.lens.getDimensionTriggerText('lnsXY_yDimensionPanel')).to.eql( + 'Test of label' + ); }); - it('should switch from a multi-layer stacked bar to donut chart using suggestions', async () => { + it('should transition from a multi-layer stacked bar to donut chart using suggestions', async () => { await PageObjects.visualize.navigateToNewVisualization(); await PageObjects.visualize.clickVisType('lens'); await PageObjects.lens.goToTimeRange(); @@ -121,12 +185,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { field: 'geo.dest', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', operation: 'avg', field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.createLayer(); await PageObjects.lens.configureDimension( @@ -138,6 +204,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { 1 ); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension( { dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension', @@ -146,6 +213,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }, 1 ); + + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.save('twolayerchart'); await testSubjects.click('lnsSuggestion-asDonut > lnsSuggestion'); @@ -158,7 +227,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); }); - it('should allow transition from line chart to donut chart and to bar chart', async () => { + it('should transition from line chart to donut chart and to bar chart', async () => { await PageObjects.visualize.gotoVisualizationLandingPage(); await listingTable.searchForItemWithName('lnsXYvis'); await PageObjects.lens.clickVisualizeListItemTitle('lnsXYvis'); @@ -185,7 +254,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); }); - it('should allow seamless transition from bar chart to line chart using layer chart switch', async () => { + it('should transition from bar chart to line chart using layer chart switch', async () => { await PageObjects.visualize.gotoVisualizationLandingPage(); await listingTable.searchForItemWithName('lnsXYvis'); await PageObjects.lens.clickVisualizeListItemTitle('lnsXYvis'); @@ -203,7 +272,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); }); - it('should allow seamless transition from pie chart to treemap chart', async () => { + it('should transition from pie chart to treemap chart', async () => { await PageObjects.visualize.gotoVisualizationLandingPage(); await listingTable.searchForItemWithName('lnsPieVis'); await PageObjects.lens.clickVisualizeListItemTitle('lnsPieVis'); @@ -221,7 +290,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); }); - it('should allow creating a pie chart and switching to datatable', async () => { + it('should create a pie chart and switch to datatable', async () => { await PageObjects.visualize.navigateToNewVisualization(); await PageObjects.visualize.clickVisType('lens'); await PageObjects.lens.goToTimeRange(); @@ -231,6 +300,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { operation: 'date_histogram', field: '@timestamp', }); + await PageObjects.lens.closeDimensionEditor(); await PageObjects.lens.configureDimension({ dimension: 'lnsPie_sizeByDimensionPanel > lns-empty-dimension', @@ -238,6 +308,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { field: 'bytes', }); + await PageObjects.lens.closeDimensionEditor(); expect(await PageObjects.lens.hasChartSwitchWarning('lnsDatatable')).to.eql(false); await PageObjects.lens.switchToVisualization('lnsDatatable'); diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts index e3c21085b92d3..a1e62afbe14c8 100644 --- a/x-pack/test/functional/page_objects/lens_page.ts +++ b/x-pack/test/functional/page_objects/lens_page.ts @@ -13,7 +13,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont const retry = getService('retry'); const find = getService('find'); const comboBox = getService('comboBox'); - const PageObjects = getPageObjects(['header', 'header', 'timePicker']); + const PageObjects = getPageObjects(['header', 'header', 'timePicker', 'common']); return logWrapper('lensPage', log, { /** @@ -85,19 +85,32 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont * @param layerIndex - the index of the layer */ async configureDimension( - opts: { dimension: string; operation: string; field: string }, + opts: { + dimension: string; + operation: string; + field?: string; + isPreviousIncompatible?: boolean; + }, layerIndex = 0 ) { await retry.try(async () => { await testSubjects.click(`lns-layerPanel-${layerIndex} > ${opts.dimension}`); await testSubjects.exists(`lns-indexPatternDimension-${opts.operation}`); }); + const operationSelector = opts.isPreviousIncompatible + ? `lns-indexPatternDimension-${opts.operation} incompatible` + : `lns-indexPatternDimension-${opts.operation}`; + await testSubjects.click(operationSelector); + + if (opts.field) { + const target = await testSubjects.find('indexPattern-dimension-field'); + await comboBox.openOptionsList(target); + await comboBox.setElement(target, opts.field); + } + }, - await testSubjects.click(`lns-indexPatternDimension-${opts.operation}`); - - const target = await testSubjects.find('indexPattern-dimension-field'); - await comboBox.openOptionsList(target); - await comboBox.setElement(target, opts.field); + // closes the dimension editor flyout + async closeDimensionEditor() { await testSubjects.click('lns-indexPattern-dimensionContainerTitle'); }, @@ -107,7 +120,17 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont async removeDimension(dimensionTestSubj: string) { await testSubjects.click(`${dimensionTestSubj} > indexPattern-dimension-remove`); }, - + /** + * adds new filter to filters agg + */ + async addFilterToAgg(queryString: string) { + await testSubjects.click('lns-newBucket-add'); + const queryInput = await testSubjects.find('indexPattern-filters-queryStringInput'); + await queryInput.type(queryString); + await PageObjects.common.pressEnterKey(); + await PageObjects.common.pressEnterKey(); + await PageObjects.common.sleep(1000); // give time for debounced components to rerender + }, /** * Save the current Lens visualization. */ @@ -141,10 +164,43 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont await testSubjects.click('lnsApp_saveAndReturnButton'); }, + async editDimensionLabel(label: string) { + await testSubjects.setValue('indexPattern-label-edit', label); + }, + async editDimensionFormat(format: string) { + const formatInput = await testSubjects.find('indexPattern-dimension-format'); + await comboBox.openOptionsList(formatInput); + await comboBox.setElement(formatInput, format); + }, + async editDimensionColor(color: string) { + const colorPickerInput = await testSubjects.find('colorPickerAnchor'); + await colorPickerInput.type(color); + await PageObjects.common.sleep(1000); // give time for debounced components to rerender + }, + async editMissingValues(option: string) { + await retry.try(async () => { + await testSubjects.click('lnsMissingValuesButton'); + await testSubjects.exists('lnsMissingValuesSelect'); + }); + await testSubjects.click('lnsMissingValuesSelect'); + const optionSelector = await find.byCssSelector(`#${option}`); + await optionSelector.click(); + }, + getTitle() { return testSubjects.getVisibleText('lns_ChartTitle'); }, + async getFiltersAggLabels() { + const labels = []; + const filters = await testSubjects.findAll('indexPattern-filters-existingFilterContainer'); + for (let i = 0; i < filters.length; i++) { + labels.push(await filters[i].getVisibleText()); + } + log.debug(`Found ${labels.length} filters on current page`); + return labels; + }, + /** * Uses the Lens visualization switcher to switch visualizations. * @@ -275,5 +331,13 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont await this.assertExactText('[data-test-subj="lns_metric_title"]', title); await this.assertExactText('[data-test-subj="lns_metric_value"]', count); }, + + async assertMissingValues(option: string) { + await this.assertExactText('[data-test-subj="lnsMissingValuesSelect"]', option); + }, + async assertColor(color: string) { + // TODO: target dimensionTrigger color element after merging https://github.com/elastic/kibana/pull/76871 + await testSubjects.getAttribute('colorPickerAnchor', color); + }, }); }