From 5bee0d4a33f8a39ea8f60b9a134937a1f78b043f Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 8 Aug 2019 14:28:38 -0600 Subject: [PATCH 01/14] Move ui/index_patterns files to data plugin. --- .../index_patterns/components/index.ts} | 4 +- .../components/index_pattern_select.tsx | 0 .../data}/public/index_patterns/errors.ts | 0 .../public/index_patterns/fields/field.ts} | 8 ++-- .../index_patterns/fields/field_list.ts} | 4 +- .../index_patterns/fields}/fields_fetcher.ts | 3 +- .../public/index_patterns/fields}/index.ts | 8 ++-- .../__tests__/_get_computed_fields.js | 2 +- .../index_patterns/_flatten_hit.js | 0 .../index_patterns/_pattern_cache.ts | 2 +- .../index_patterns/format_hit.ts} | 2 +- .../index_patterns/index_patterns}/index.ts | 8 ++-- .../index_patterns/index_pattern.test.js} | 28 +++++------ .../index_patterns/index_pattern.ts} | 14 +++--- .../index_patterns/index_patterns.test.js} | 10 ++-- .../index_patterns/index_patterns.ts | 4 +- .../index_patterns_api_client.test.js} | 4 +- .../index_patterns_api_client.test.mock.js} | 2 +- .../index_patterns_api_client.ts | 4 +- .../data/public/index_patterns/mocks.ts} | 4 +- .../data/public/index_patterns/utils.test.ts} | 44 +++++++++++++---- .../data/public/index_patterns/utils.ts} | 44 ++++++++++++++++- .../ui/public/index_patterns/get_routes.ts | 28 ----------- .../index_patterns/static_utils/index.ts | 48 ------------------- .../validate/validate_index_pattern.test.ts | 44 ----------------- 25 files changed, 127 insertions(+), 192 deletions(-) rename src/legacy/{ui/public/index_patterns/__tests__/index.js => core_plugins/data/public/index_patterns/components/index.ts} (91%) rename src/legacy/{ui => core_plugins/data}/public/index_patterns/components/index_pattern_select.tsx (100%) rename src/legacy/{ui => core_plugins/data}/public/index_patterns/errors.ts (100%) rename src/legacy/{ui/public/index_patterns/_field.ts => core_plugins/data/public/index_patterns/fields/field.ts} (94%) rename src/legacy/{ui/public/index_patterns/_field_list.ts => core_plugins/data/public/index_patterns/fields/field_list.ts} (92%) rename src/legacy/{ui/public/index_patterns => core_plugins/data/public/index_patterns/fields}/fields_fetcher.ts (91%) rename src/legacy/{ui/public/index_patterns/validate => core_plugins/data/public/index_patterns/fields}/index.ts (88%) rename src/legacy/{ui/public => core_plugins/data/public/index_patterns}/index_patterns/__tests__/_get_computed_fields.js (97%) rename src/legacy/{ui/public => core_plugins/data/public/index_patterns}/index_patterns/_flatten_hit.js (100%) rename src/legacy/{ui/public => core_plugins/data/public/index_patterns}/index_patterns/_pattern_cache.ts (96%) rename src/legacy/{ui/public/index_patterns/_format_hit.ts => core_plugins/data/public/index_patterns/index_patterns/format_hit.ts} (98%) rename src/legacy/{ui/public/index_patterns/constants => core_plugins/data/public/index_patterns/index_patterns}/index.ts (80%) rename src/legacy/{ui/public/index_patterns/__tests__/_index_pattern.test.js => core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js} (94%) rename src/legacy/{ui/public/index_patterns/_index_pattern.ts => core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts} (98%) rename src/legacy/{ui/public/index_patterns/__tests__/_index_patterns.test.js => core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.js} (88%) rename src/legacy/{ui/public => core_plugins/data/public/index_patterns}/index_patterns/index_patterns.ts (97%) rename src/legacy/{ui/public/index_patterns/__tests__/_index_patterns_api_client.test.js => core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js} (95%) rename src/legacy/{ui/public/index_patterns/__tests__/_index_patterns_api_client.test.mock.js => core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.js} (92%) rename src/legacy/{ui/public => core_plugins/data/public/index_patterns}/index_patterns/index_patterns_api_client.ts (95%) rename src/legacy/{ui/public/index_patterns/fixtures/index.ts => core_plugins/data/public/index_patterns/mocks.ts} (95%) rename src/legacy/{ui/public/index_patterns/static_utils/__tests__/index.js => core_plugins/data/public/index_patterns/utils.test.ts} (62%) rename src/legacy/{ui/public/index_patterns/validate/validate_index_pattern.ts => core_plugins/data/public/index_patterns/utils.ts} (55%) delete mode 100644 src/legacy/ui/public/index_patterns/get_routes.ts delete mode 100644 src/legacy/ui/public/index_patterns/static_utils/index.ts delete mode 100644 src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts diff --git a/src/legacy/ui/public/index_patterns/__tests__/index.js b/src/legacy/core_plugins/data/public/index_patterns/components/index.ts similarity index 91% rename from src/legacy/ui/public/index_patterns/__tests__/index.js rename to src/legacy/core_plugins/data/public/index_patterns/components/index.ts index 8aa6506bfe635..30dcb43557507 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/index.js +++ b/src/legacy/core_plugins/data/public/index_patterns/components/index.ts @@ -17,6 +17,4 @@ * under the License. */ -import './_get_computed_fields'; -describe('Index Patterns', function () { -}); +export * from './index_pattern_select'; diff --git a/src/legacy/ui/public/index_patterns/components/index_pattern_select.tsx b/src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx similarity index 100% rename from src/legacy/ui/public/index_patterns/components/index_pattern_select.tsx rename to src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx diff --git a/src/legacy/ui/public/index_patterns/errors.ts b/src/legacy/core_plugins/data/public/index_patterns/errors.ts similarity index 100% rename from src/legacy/ui/public/index_patterns/errors.ts rename to src/legacy/core_plugins/data/public/index_patterns/errors.ts diff --git a/src/legacy/ui/public/index_patterns/_field.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts similarity index 94% rename from src/legacy/ui/public/index_patterns/_field.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/field.ts index 34f1a55f7af1d..52a2d251c13d0 100644 --- a/src/legacy/ui/public/index_patterns/_field.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts @@ -24,12 +24,12 @@ import { fieldFormats } from 'ui/registry/field_formats'; import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; // @ts-ignore -import { FieldFormat } from '../../field_formats/field_format'; +import { getKbnFieldType } from '../../../../../utils/kbn_field_types'; // @ts-ignore -import { getKbnFieldType } from '../../../utils'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; // @ts-ignore -import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string'; -import { IndexPattern } from './_index_pattern'; +import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string'; +import { IndexPattern } from '../index_patterns'; export type FieldSpec = Record; export interface FieldType { diff --git a/src/legacy/ui/public/index_patterns/_field_list.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts similarity index 92% rename from src/legacy/ui/public/index_patterns/_field_list.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts index 40352012d32eb..d167714f76b16 100644 --- a/src/legacy/ui/public/index_patterns/_field_list.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field_list.ts @@ -18,8 +18,8 @@ */ import { IndexedArray } from 'ui/indexed_array'; -import { IndexPattern } from 'ui/index_patterns'; -import { Field, FieldSpec } from './_field'; +import { IndexPattern } from '../index_patterns'; +import { Field, FieldSpec } from './field'; export class FieldList extends IndexedArray { constructor(indexPattern: IndexPattern, specs: FieldSpec[], shortDotsEnable = false) { diff --git a/src/legacy/ui/public/index_patterns/fields_fetcher.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts similarity index 91% rename from src/legacy/ui/public/index_patterns/fields_fetcher.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts index ff1d9207e5092..df55e87d466f1 100644 --- a/src/legacy/ui/public/index_patterns/fields_fetcher.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts @@ -17,8 +17,7 @@ * under the License. */ -import { GetFieldsOptions, IndexPatternsApiClient } from './index_patterns_api_client'; -import { IndexPattern } from './_index_pattern'; +import { GetFieldsOptions, IndexPattern, IndexPatternsApiClient } from '../index_patterns'; export const createFieldsFetcher = ( indexPattern: IndexPattern, diff --git a/src/legacy/ui/public/index_patterns/validate/index.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts similarity index 88% rename from src/legacy/ui/public/index_patterns/validate/index.ts rename to src/legacy/core_plugins/data/public/index_patterns/fields/index.ts index 205dbb5bfe04d..14e109661cb89 100644 --- a/src/legacy/ui/public/index_patterns/validate/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts @@ -17,8 +17,6 @@ * under the License. */ -export { - ILLEGAL_CHARACTERS, - CONTAINS_SPACES, - validateIndexPattern, -} from './validate_index_pattern'; +export * from './field_list'; +export * from './field'; +export * from './fields_fetcher'; diff --git a/src/legacy/ui/public/index_patterns/__tests__/_get_computed_fields.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/__tests__/_get_computed_fields.js similarity index 97% rename from src/legacy/ui/public/index_patterns/__tests__/_get_computed_fields.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/__tests__/_get_computed_fields.js index 2c89c6bc27569..1a7675024167a 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/_get_computed_fields.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/__tests__/_get_computed_fields.js @@ -21,7 +21,7 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; -describe('get computed fields', function () { +describe('IndexPatterns#getComputedFields', function () { let indexPattern; let fn; diff --git a/src/legacy/ui/public/index_patterns/_flatten_hit.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_flatten_hit.js similarity index 100% rename from src/legacy/ui/public/index_patterns/_flatten_hit.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_flatten_hit.js diff --git a/src/legacy/ui/public/index_patterns/_pattern_cache.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts similarity index 96% rename from src/legacy/ui/public/index_patterns/_pattern_cache.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts index 56c19f625f10a..adc34e34f58e5 100644 --- a/src/legacy/ui/public/index_patterns/_pattern_cache.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_pattern_cache.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from './index'; +import { IndexPattern } from './index_pattern'; export interface PatternCache { get: (id: string) => IndexPattern; diff --git a/src/legacy/ui/public/index_patterns/_format_hit.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts similarity index 98% rename from src/legacy/ui/public/index_patterns/_format_hit.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts index 8f0243bc1924e..28797c28db834 100644 --- a/src/legacy/ui/public/index_patterns/_format_hit.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/format_hit.ts @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { IndexPattern } from './_index_pattern'; +import { IndexPattern } from './index_pattern'; const formattedCache = new WeakMap(); const partialFormattedCache = new WeakMap(); diff --git a/src/legacy/ui/public/index_patterns/constants/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts similarity index 80% rename from src/legacy/ui/public/index_patterns/constants/index.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts index 716e59c25309e..e5ae3b90108ec 100644 --- a/src/legacy/ui/public/index_patterns/constants/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts @@ -17,7 +17,7 @@ * under the License. */ -export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = ['\\', '/', '?', '"', '<', '>', '|']; -export const INDEX_PATTERN_ILLEGAL_CHARACTERS = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.concat( - ' ' -); +export * from './format_hit'; +export * from './index_pattern'; +export * from './index_patterns'; +export * from './index_patterns_api_client'; diff --git a/src/legacy/ui/public/index_patterns/__tests__/_index_pattern.test.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js similarity index 94% rename from src/legacy/ui/public/index_patterns/__tests__/_index_pattern.test.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js index 976a6ab86b9f2..c1724c1f184cb 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/_index_pattern.test.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js @@ -18,30 +18,26 @@ */ import _ from 'lodash'; -import { IndexedArray } from '../../indexed_array'; -import { IndexPattern } from '../_index_pattern'; -import { createFieldsFetcher } from '../fields_fetcher'; -import mockLogstashFields from '../../../../../fixtures/logstash_fields'; -import { stubbedSavedObjectIndexPattern } from '../../../../../fixtures/stubbed_saved_object_index_pattern'; +import mockLogstashFields from '../../../../../../fixtures/logstash_fields'; +import { stubbedSavedObjectIndexPattern } from '../../../../../../fixtures/stubbed_saved_object_index_pattern'; +import { IndexedArray } from 'ui/indexed_array'; -jest.mock('../../errors', () => ({ - SavedObjectNotFound: jest.fn(), - DuplicateField: jest.fn(), - IndexPatternMissingIndices: jest.fn(), -})); +import { createFieldsFetcher } from '../fields'; +import { IndexPattern } from './index_pattern'; jest.mock('../errors', () => ({ + SavedObjectNotFound: jest.fn(), + DuplicateField: jest.fn(), IndexPatternMissingIndices: jest.fn(), })); - -jest.mock('../../registry/field_formats', () => ({ +jest.mock('ui/registry/field_formats', () => ({ fieldFormats: { getDefaultInstance: jest.fn(), } })); -jest.mock('../../utils/mapping_setup', () => ({ +jest.mock('ui/utils/mapping_setup', () => ({ expandShorthand: jest.fn().mockImplementation(() => ({ id: true, title: true, @@ -51,21 +47,21 @@ jest.mock('../../utils/mapping_setup', () => ({ })) })); -jest.mock('../../notify', () => ({ +jest.mock('ui/notify', () => ({ toastNotifications: { addDanger: jest.fn(), addError: jest.fn(), } })); -jest.mock('../../saved_objects', () => { +jest.mock('ui/saved_objects', () => { return { findObjectByTitle: jest.fn(), }; }); let fields = []; -jest.mock('../fields_fetcher'); +jest.mock('../fields'); createFieldsFetcher.mockImplementation(() => ({ fetch: jest.fn().mockImplementation(() => { diff --git a/src/legacy/ui/public/index_patterns/_index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts similarity index 98% rename from src/legacy/ui/public/index_patterns/_index_pattern.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 777ed0b8dae16..5d0972d55598b 100644 --- a/src/legacy/ui/public/index_patterns/_index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -28,16 +28,14 @@ import { expandShorthand } from 'ui/utils/mapping_setup'; import { toastNotifications } from 'ui/notify'; import { findObjectByTitle } from 'ui/saved_objects'; import { SavedObjectsClientContract } from 'src/core/public'; -import { IndexPatternsApiClient } from './index_patterns_api_client'; -import { IndexPatternMissingIndices } from './errors'; -import { getRoutes } from './get_routes'; -import { FieldList } from './_field_list'; -import { createFieldsFetcher } from './fields_fetcher'; -import { Field, FieldType } from './_field'; + +import { IndexPatternMissingIndices } from '../errors'; +import { createFieldsFetcher, Field, FieldList, FieldType } from '../fields'; +import { getRoutes } from '../utils'; +import { formatHitProvider } from './format_hit'; // @ts-ignore import { flattenHitWrapper } from './_flatten_hit'; -// @ts-ignore -import { formatHitProvider } from './_format_hit'; +import { IndexPatternsApiClient } from './index_patterns_api_client'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; diff --git a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns.test.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.js similarity index 88% rename from src/legacy/ui/public/index_patterns/__tests__/_index_patterns.test.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.js index 54251347df2f7..039910e8d3b23 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns.test.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.js @@ -17,26 +17,26 @@ * under the License. */ -import { IndexPatterns } from '../index_patterns'; +import { IndexPatterns } from './index_patterns'; jest.mock('../errors', () => ({ IndexPatternMissingIndices: jest.fn(), })); -jest.mock('../../registry/field_formats', () => ({ +jest.mock('ui/registry/field_formats', () => ({ fieldFormats: { getDefaultInstance: jest.fn(), } })); -jest.mock('../../notify', () => ({ +jest.mock('ui/notify', () => ({ toastNotifications: { addDanger: jest.fn(), } })); -jest.mock('../_index_pattern', () => { +jest.mock('./index_pattern', () => { class IndexPattern { init = async () => { return this; @@ -48,7 +48,7 @@ jest.mock('../_index_pattern', () => { }; }); -jest.mock('../index_patterns_api_client', () => { +jest.mock('./index_patterns_api_client', () => { class IndexPatternsApiClient { getFieldsForWildcard = async () => ({}) } diff --git a/src/legacy/ui/public/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts similarity index 97% rename from src/legacy/ui/public/index_patterns/index_patterns.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts index daf81a66b9d40..cb9af2c909767 100644 --- a/src/legacy/ui/public/index_patterns/index_patterns.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -24,10 +24,10 @@ import { UiSettingsClientContract, } from 'src/core/public'; // @ts-ignore -import { fieldFormats } from '../registry/field_formats'; +import { fieldFormats } from 'ui/registry/field_formats'; -import { IndexPattern } from './_index_pattern'; import { createIndexPatternCache } from './_pattern_cache'; +import { IndexPattern } from './index_pattern'; import { IndexPatternsApiClient } from './index_patterns_api_client'; const indexPatternCache = createIndexPatternCache(); const apiClient = new IndexPatternsApiClient(); diff --git a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js similarity index 95% rename from src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js index 18d6250936383..dd3724ff202ae 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js @@ -17,8 +17,8 @@ * under the License. */ -import { http } from './_index_patterns_api_client.test.mock'; -import { IndexPatternsApiClient } from '../index_patterns_api_client'; +import { http } from './index_patterns_api_client.test.mock'; +import { IndexPatternsApiClient } from './index_patterns_api_client'; jest.mock('../../errors', () => ({ SavedObjectNotFound: jest.fn(), diff --git a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.mock.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.js similarity index 92% rename from src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.mock.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.js index 66de7bf3a7f21..a793fa6a25bea 100644 --- a/src/legacy/ui/public/index_patterns/__tests__/_index_patterns_api_client.test.mock.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.mock.js @@ -18,7 +18,7 @@ */ -import { setup } from '../../../../../test_utils/public/http_test_setup'; +import { setup } from '../../../../../../test_utils/public/http_test_setup'; export const { http } = setup(injectedMetadata => { injectedMetadata.getBasePath.mockReturnValue('/hola/daro/'); diff --git a/src/legacy/ui/public/index_patterns/index_patterns_api_client.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts similarity index 95% rename from src/legacy/ui/public/index_patterns/index_patterns_api_client.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts index ae71157aea829..4b0d7ec08347b 100644 --- a/src/legacy/ui/public/index_patterns/index_patterns_api_client.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts @@ -17,9 +17,9 @@ * under the License. */ -import { kfetch, KFetchQuery } from '../kfetch'; +import { kfetch, KFetchQuery } from 'ui/kfetch'; -import { IndexPatternMissingIndices } from './errors'; +import { IndexPatternMissingIndices } from '../errors'; function request(url: string, query: KFetchQuery) { return kfetch({ diff --git a/src/legacy/ui/public/index_patterns/fixtures/index.ts b/src/legacy/core_plugins/data/public/index_patterns/mocks.ts similarity index 95% rename from src/legacy/ui/public/index_patterns/fixtures/index.ts rename to src/legacy/core_plugins/data/public/index_patterns/mocks.ts index 5c79d7f99f842..8d8b28b5ef74a 100644 --- a/src/legacy/ui/public/index_patterns/fixtures/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/mocks.ts @@ -17,8 +17,8 @@ * under the License. */ -import { FieldType } from '../_field'; -import { StaticIndexPattern } from '../_index_pattern'; +import { FieldType } from './fields'; +import { StaticIndexPattern } from './index_patterns'; export const mockFields: FieldType[] = [ { diff --git a/src/legacy/ui/public/index_patterns/static_utils/__tests__/index.js b/src/legacy/core_plugins/data/public/index_patterns/utils.test.ts similarity index 62% rename from src/legacy/ui/public/index_patterns/static_utils/__tests__/index.js rename to src/legacy/core_plugins/data/public/index_patterns/utils.test.ts index 04503be6f7f78..1a186a6514763 100644 --- a/src/legacy/ui/public/index_patterns/static_utils/__tests__/index.js +++ b/src/legacy/core_plugins/data/public/index_patterns/utils.test.ts @@ -17,28 +17,53 @@ * under the License. */ -import expect from '@kbn/expect'; -import { isFilterable } from '../index'; +import { + CONTAINS_SPACES, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, + isFilterable, + validateIndexPattern, +} from './utils'; + +import { Field } from './fields'; const mockField = { name: 'foo', scripted: false, searchable: true, type: 'string', -}; +} as Field; + +describe('Index Pattern Utils', () => { + describe('Validation', () => { + it('should not allow space in the pattern', () => { + const errors = validateIndexPattern('my pattern'); + expect(errors[CONTAINS_SPACES]).toBe(true); + }); + + it('should not allow illegal characters', () => { + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.forEach(char => { + const errors = validateIndexPattern(`pattern${char}`); + expect(errors[ILLEGAL_CHARACTERS]).toEqual([char]); + }); + }); + + it('should return empty object when there are no errors', () => { + expect(validateIndexPattern('my-pattern-*')).toEqual({}); + }); + }); -describe('static utils', () => { describe('isFilterable', () => { describe('types', () => { it('should return true for filterable types', () => { ['string', 'number', 'date', 'ip', 'boolean'].forEach(type => { - expect(isFilterable({ ...mockField, type })).to.be(true); + expect(isFilterable({ ...mockField, type })).toBe(true); }); }); it('should return false for filterable types if the field is not searchable', () => { ['string', 'number', 'date', 'ip', 'boolean'].forEach(type => { - expect(isFilterable({ ...mockField, type, searchable: false })).to.be(false); + expect(isFilterable({ ...mockField, type, searchable: false })).toBe(false); }); }); @@ -52,18 +77,17 @@ describe('static utils', () => { 'unknown', 'conflict', ].forEach(type => { - expect(isFilterable({ ...mockField, type })).to.be(false); + expect(isFilterable({ ...mockField, type })).toBe(false); }); }); }); - it('should return true for scripted fields', () => { - expect(isFilterable({ ...mockField, scripted: true, searchable: false })).to.be(true); + expect(isFilterable({ ...mockField, scripted: true, searchable: false })).toBe(true); }); it('should return true for the _id field', () => { - expect(isFilterable({ ...mockField, name: '_id' })).to.be(true); + expect(isFilterable({ ...mockField, name: '_id' })).toBe(true); }); }); }); diff --git a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/utils.ts similarity index 55% rename from src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts rename to src/legacy/core_plugins/data/public/index_patterns/utils.ts index cca38b7a33264..297ac1daad1a6 100644 --- a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/utils.ts @@ -17,10 +17,18 @@ * under the License. */ -import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../constants'; +// @ts-ignore +import { get } from 'lodash'; +// @ts-ignore +import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types'; +import { Field } from './fields'; export const ILLEGAL_CHARACTERS = 'ILLEGAL_CHARACTERS'; export const CONTAINS_SPACES = 'CONTAINS_SPACES'; +export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = ['\\', '/', '?', '"', '<', '>', '|']; +export const INDEX_PATTERN_ILLEGAL_CHARACTERS = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.concat( + ' ' +); function findIllegalCharacters(indexPattern: string): string[] { const illegalCharacters = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.reduce( @@ -55,3 +63,37 @@ export function validateIndexPattern(indexPattern: string) { return errors; } + +const filterableTypes = KBN_FIELD_TYPES.filter((type: any) => type.filterable).map( + (type: any) => type.name +); + +export function isFilterable(field: Field): boolean { + return ( + field.name === '_id' || + field.scripted || + (field.searchable && filterableTypes.includes(field.type)) + ); +} + +export function getFromSavedObject(savedObject: any) { + if (get(savedObject, 'attributes.fields') === undefined) { + return; + } + + return { + id: savedObject.id, + fields: JSON.parse(savedObject.attributes.fields), + title: savedObject.attributes.title, + }; +} + +export function getRoutes() { + return { + edit: '/management/kibana/index_patterns/{{id}}', + addField: '/management/kibana/index_patterns/{{id}}/create-field', + indexedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:indexedFields)', + scriptedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:scriptedFields)', + sourceFilters: '/management/kibana/index_patterns/{{id}}?_a=(tab:sourceFilters)', + }; +} diff --git a/src/legacy/ui/public/index_patterns/get_routes.ts b/src/legacy/ui/public/index_patterns/get_routes.ts deleted file mode 100644 index 52d42ea204532..0000000000000 --- a/src/legacy/ui/public/index_patterns/get_routes.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 function getRoutes() { - return { - edit: '/management/kibana/index_patterns/{{id}}', - addField: '/management/kibana/index_patterns/{{id}}/create-field', - indexedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:indexedFields)', - scriptedFields: '/management/kibana/index_patterns/{{id}}?_a=(tab:scriptedFields)', - sourceFilters: '/management/kibana/index_patterns/{{id}}?_a=(tab:sourceFilters)', - }; -} diff --git a/src/legacy/ui/public/index_patterns/static_utils/index.ts b/src/legacy/ui/public/index_patterns/static_utils/index.ts deleted file mode 100644 index 7131ea300b97c..0000000000000 --- a/src/legacy/ui/public/index_patterns/static_utils/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ - -// @ts-ignore -import { get } from 'lodash'; -// @ts-ignore -import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types'; -import { Field } from '../_field'; - -const filterableTypes = KBN_FIELD_TYPES.filter((type: any) => type.filterable).map( - (type: any) => type.name -); - -export function isFilterable(field: Field): boolean { - return ( - field.name === '_id' || - field.scripted || - (field.searchable && filterableTypes.includes(field.type)) - ); -} - -export function getFromSavedObject(savedObject: any) { - if (get(savedObject, 'attributes.fields') === undefined) { - return; - } - - return { - id: savedObject.id, - fields: JSON.parse(savedObject.attributes.fields), - title: savedObject.attributes.title, - }; -} diff --git a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts b/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts deleted file mode 100644 index cfd4049c1398d..0000000000000 --- a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../constants'; - -import { - ILLEGAL_CHARACTERS, - CONTAINS_SPACES, - validateIndexPattern, -} from './validate_index_pattern'; - -describe('Index Pattern Validation', () => { - it('should not allow space in the pattern', () => { - const errors = validateIndexPattern('my pattern'); - expect(errors[CONTAINS_SPACES]).toBe(true); - }); - - it('should not allow illegal characters', () => { - INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.forEach(char => { - const errors = validateIndexPattern(`pattern${char}`); - expect(errors[ILLEGAL_CHARACTERS]).toEqual([char]); - }); - }); - - it('should return empty object when there are no errors', () => { - expect(validateIndexPattern('my-pattern-*')).toEqual({}); - }); -}); From 9b14ec886e3759d136fee9da388e26529e7dfc39 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 8 Aug 2019 16:28:26 -0600 Subject: [PATCH 02/14] Export updated service contract & re-export from ui/public. --- src/legacy/core_plugins/data/public/index.ts | 32 +++++-- .../data/public/index_patterns/errors.ts | 4 +- .../public/index_patterns/fields/index.ts | 1 - .../data/public/index_patterns/index.ts | 15 +--- .../_fields_fetcher.ts} | 4 +- .../index_patterns/index_pattern.ts | 3 +- .../index_patterns/index_patterns_service.ts | 90 +++++++++---------- src/legacy/ui/public/index_patterns/index.ts | 53 +++++++---- 8 files changed, 116 insertions(+), 86 deletions(-) rename src/legacy/core_plugins/data/public/index_patterns/{fields/fields_fetcher.ts => index_patterns/_fields_fetcher.ts} (90%) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index db3663590b5ac..639f299b7f1f1 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -29,18 +29,36 @@ export function plugin() { /** @public types */ export type DataSetup = DataSetup; export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions'; - -/** @public types */ -export { IndexPattern, IndexPatterns, StaticIndexPattern, Field } from './index_patterns'; -export { Query, QueryBar, QueryBarInput } from './query'; export { FilterBar, ApplyFiltersPopover } from './filter'; +export { + Field, + FieldType, + IndexPattern, + IndexPatterns, + StaticIndexPattern, +} from './index_patterns'; +export { Query, QueryBar, QueryBarInput } from './query'; export { SearchBar, SearchBarProps } from './search'; + +/** @public static code */ +export * from '../common'; export { FilterManager, FilterStateManager, uniqFilters, onlyDisabledFiltersChanged, } from './filter/filter_manager'; - -/** @public static code */ -export * from '../common'; +export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + isFilterable, + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, + IndexPatternAlreadyExists, + IndexPatternMissingIndices, + NoDefaultIndexPattern, + NoDefinedIndexPatterns, +} from './index_patterns'; \ No newline at end of file diff --git a/src/legacy/core_plugins/data/public/index_patterns/errors.ts b/src/legacy/core_plugins/data/public/index_patterns/errors.ts index 31d632ae5c5dd..df7f26ad6673d 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/errors.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/errors.ts @@ -16,9 +16,11 @@ * specific language governing permissions and limitations * under the License. */ + /* eslint-disable */ + // @ts-ignore -import { KbnError } from '../errors'; +import { KbnError } from 'ui/errors'; /** * when a mapping already exists for a field the user is attempting to add diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts index 14e109661cb89..1644e23a163a6 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/index.ts @@ -19,4 +19,3 @@ export * from './field_list'; export * from './field'; -export * from './fields_fetcher'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index.ts index ba211850d52f8..bbb2124d60d86 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index.ts @@ -17,15 +17,6 @@ * under the License. */ -export { - IndexPatternsService, - IndexPatterns, - fixtures, - utils, - // types - IndexPatternsSetup, - IndexPattern, - StaticIndexPattern, - Field, - FieldType, -} from './index_patterns_service'; +export * from './index_patterns_service'; + +export { mockFields, mockIndexPattern } from './mocks'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts similarity index 90% rename from src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts index df55e87d466f1..c61df91cb8d1b 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/fields_fetcher.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts @@ -17,8 +17,10 @@ * under the License. */ -import { GetFieldsOptions, IndexPattern, IndexPatternsApiClient } from '../index_patterns'; +import { IndexPattern } from './index_pattern'; +import { GetFieldsOptions, IndexPatternsApiClient } from './index_patterns_api_client'; +/** @internal */ export const createFieldsFetcher = ( indexPattern: IndexPattern, apiClient: IndexPatternsApiClient, diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 5d0972d55598b..117145d0edae1 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -30,7 +30,8 @@ import { findObjectByTitle } from 'ui/saved_objects'; import { SavedObjectsClientContract } from 'src/core/public'; import { IndexPatternMissingIndices } from '../errors'; -import { createFieldsFetcher, Field, FieldList, FieldType } from '../fields'; +import { Field, FieldList, FieldType } from '../fields'; +import { createFieldsFetcher } from './_fields_fetcher'; import { getRoutes } from '../utils'; import { formatHitProvider } from './format_hit'; // @ts-ignore diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 4ab08c2a60eb0..de65e35a05428 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -16,25 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -// @ts-ignore -import { mockFields, mockIndexPattern } from 'ui/index_patterns/fixtures'; -// @ts-ignore -import { INDEX_PATTERN_ILLEGAL_CHARACTERS } from 'ui/index_patterns/index'; -// @ts-ignore -import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/index_patterns/index'; -// @ts-ignore -import { IndexPatternSelect } from 'ui/index_patterns/index'; -// @ts-ignore -import { IndexPatterns } from 'ui/index_patterns/index'; -// @ts-ignore -import { validateIndexPattern } from 'ui/index_patterns/index'; - -import { isFilterable, getFromSavedObject } from 'ui/index_patterns/static_utils'; - -// IndexPattern, StaticIndexPattern, Field -import * as types from 'ui/index_patterns'; import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { IndexPatternSelect } from './components'; +import { Field, FieldList, FieldType } from './fields'; +import { + formatHitProvider, + IndexPattern, + IndexPatterns, + IndexPatternsProvider, + StaticIndexPattern, +} from './index_patterns'; export interface IndexPatternDependencies { uiSettings: UiSettingsClientContract; @@ -44,18 +36,22 @@ export interface IndexPatternDependencies { /** * Index Patterns Service * - * The `setup` method of this service returns the public contract for - * index patterns. Right now these APIs are simply imported from `ui/public` - * and re-exported here. Once the index patterns code actually moves to - * this plugin, the imports above can simply be updated to point to their - * corresponding local directory. - * * @internal */ export class IndexPatternsService { public setup({ uiSettings, savedObjectsClient }: IndexPatternDependencies) { return { - indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), + Field, + FieldList, + formatHitProvider, + // TODO: Remove Provider and replace with this + // IndexPatterns: new IndexPatterns(config, savedObjectsClient), + ui: { + IndexPatternSelect, + }, + __LEGACY: { + IndexPatternsProvider, + }, }; } @@ -64,40 +60,44 @@ export class IndexPatternsService { } } -// static exports +// static code -const constants = { +/** @public */ +export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, -}; - -const fixtures = { - mockFields, - mockIndexPattern, -}; + isFilterable, + validateIndexPattern, +} from './utils'; -const ui = { - IndexPatternSelect, -}; +/** @public */ +export { + IndexPatternAlreadyExists, + IndexPatternMissingIndices, + NoDefaultIndexPattern, + NoDefinedIndexPatterns, +} from './errors'; -const utils = { - getFromSavedObject, - isFilterable, -}; +// types -export { validateIndexPattern, constants, fixtures, ui, IndexPatterns, utils }; +/** @internal */ +export type IndexPatternsSetup = ReturnType; /** @public */ -export type IndexPatternsSetup = ReturnType; +export type IndexPattern = IndexPattern; /** @public */ -export type IndexPattern = types.IndexPattern; +export type IndexPatterns = IndexPatterns; /** @public */ -export type StaticIndexPattern = types.StaticIndexPattern; +export type StaticIndexPattern = StaticIndexPattern; /** @public */ -export type Field = types.Field; +export type Field = Field; /** @public */ -export type FieldType = types.FieldType; +export type FieldType = FieldType; diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 51ba546ae4c80..76bfcac57cced 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -17,31 +17,48 @@ * under the License. */ -export { IndexPatternSelect } from './components/index_pattern_select'; -export { Field, FieldType } from './_field'; -export { FieldList } from './_field_list'; -export { IndexPattern, StaticIndexPattern } from './_index_pattern'; -export { IndexPatterns, IndexPatternsProvider } from './index_patterns'; +/** + * Nothing to see here! + * + * Index Patterns have moved to the data plugin, and are being re-exported + * from ui/index_patterns for backwards compatibility. + */ -export { - INDEX_PATTERN_ILLEGAL_CHARACTERS, - INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, -} from './constants'; +import { setup as data } from '../../../core_plugins/data/public/legacy'; -export { validateIndexPattern, CONTAINS_SPACES, ILLEGAL_CHARACTERS } from './validate'; +// Field is only used in Discover. +// FieldList is only used as class in Index Patterns Management UI. +export const { Field, FieldList, formatHitProvider } = data.indexPatterns; +export const { IndexPatternsProvider } = data.indexPatterns.__LEGACY; -export { getRoutes } from './get_routes'; -export { formatHitProvider } from './_format_hit'; -// @ts-ignore -export { flattenHitWrapper } from './_flatten_hit.js'; +// ui components +export const { IndexPatternSelect } = data.indexPatterns.ui; +// static code export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + isFilterable, + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, IndexPatternAlreadyExists, IndexPatternMissingIndices, - NoDefinedIndexPatterns, NoDefaultIndexPattern, -} from './errors'; + NoDefinedIndexPatterns, +} from '../../../core_plugins/data/public'; + +// types +export { + FieldType, + IndexPattern, + IndexPatterns, + StaticIndexPattern, +} from '../../../core_plugins/data/public'; -export { mockFields, mockIndexPattern } from './fixtures'; +export const flattenHitWrapper = null; -export { getFromSavedObject, isFilterable } from './static_utils'; +export const mockFields = null; +export const mockIndexPattern = null; From 8244018ca05c1472bc72f8b6f8a282e691038068 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 8 Aug 2019 17:13:28 -0600 Subject: [PATCH 03/14] Fix broken import. --- .../public/index_patterns/index_patterns/index_patterns.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts index cb9af2c909767..b121a7667c79b 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -29,6 +29,7 @@ import { fieldFormats } from 'ui/registry/field_formats'; import { createIndexPatternCache } from './_pattern_cache'; import { IndexPattern } from './index_pattern'; import { IndexPatternsApiClient } from './index_patterns_api_client'; + const indexPatternCache = createIndexPatternCache(); const apiClient = new IndexPatternsApiClient(); @@ -124,7 +125,8 @@ export class IndexPatterns { // add angular service for backward compatibility // @ts-ignore -import { uiModules } from '../modules'; +// eslint-disable-next-line +import { uiModules } from 'ui/modules'; const module = uiModules.get('kibana/index_patterns'); let _service: any; From 2572ca584d596d346b2edc0198c32ba50834be5e Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 12 Aug 2019 22:30:39 -0600 Subject: [PATCH 04/14] Fix TS errors & create data service mocks. --- .../lib/filter_editor_utils.test.ts | 3 +- .../filter_editor/lib/filter_editor_utils.ts | 4 +- .../data/public/filter/filter_service.mock.ts | 47 +++++++++++++++++ .../data/public/filter/filter_service.ts | 7 ++- .../data/public/index_patterns/index.ts | 2 +- .../{_flatten_hit.js => flatten_hit.js} | 0 .../index_patterns/index_patterns/index.ts | 2 + .../index_patterns/index_pattern.ts | 2 +- ...ocks.ts => index_patterns_service.mock.ts} | 43 ++++++++++++++++ .../index_patterns/index_patterns_service.ts | 14 +++-- src/legacy/core_plugins/data/public/mocks.ts | 42 +++++++++++++++ src/legacy/core_plugins/data/public/plugin.ts | 2 +- .../query_bar/lib/fetch_index_patterns.ts | 5 +- .../data/public/query/query_service.mock.ts | 51 +++++++++++++++++++ .../data/public/query/query_service.ts | 4 ++ .../create_edit_field/create_edit_field.js | 4 +- .../ui/public/chrome/__mocks__/index.js | 5 +- src/legacy/ui/public/courier/courier.js | 12 ++--- .../public/index_patterns/__mocks__/index.ts | 50 ++++++++++++++++++ src/legacy/ui/public/index_patterns/index.ts | 19 ++++--- 20 files changed, 289 insertions(+), 29 deletions(-) create mode 100644 src/legacy/core_plugins/data/public/filter/filter_service.mock.ts rename src/legacy/core_plugins/data/public/index_patterns/index_patterns/{_flatten_hit.js => flatten_hit.js} (100%) rename src/legacy/core_plugins/data/public/index_patterns/{mocks.ts => index_patterns_service.mock.ts} (63%) create mode 100644 src/legacy/core_plugins/data/public/mocks.ts create mode 100644 src/legacy/core_plugins/data/public/query/query_service.mock.ts create mode 100644 src/legacy/ui/public/index_patterns/__mocks__/index.ts diff --git a/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.test.ts b/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.test.ts index 384fb68b79668..91d41708ce39b 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.test.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.test.ts @@ -18,7 +18,7 @@ */ import { FilterStateStore, toggleFilterNegated } from '@kbn/es-query'; -import { fixtures } from '../../../../index_patterns'; +import { mockFields, mockIndexPattern } from '../../../../index_patterns'; import { IndexPattern, Field } from '../../../../index'; import { buildFilter, @@ -57,7 +57,6 @@ jest.mock( { virtual: true } ); -const { mockFields, mockIndexPattern } = fixtures; const mockedFields = mockFields as Field[]; const mockedIndexPattern = mockIndexPattern as IndexPattern; diff --git a/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.ts index 3b7c8c1feb44a..5d36a221c886c 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_bar/filter_editor/lib/filter_editor_utils.ts @@ -33,7 +33,7 @@ import { } from '@kbn/es-query'; import { omit } from 'lodash'; import Ipv4Address from 'ui/utils/ipv4_address'; -import { Field, IndexPattern, utils as indexPatternUtils } from '../../../../index_patterns'; +import { Field, IndexPattern, isFilterable } from '../../../../index_patterns'; import { FILTER_OPERATORS, Operator } from './filter_operators'; export function getIndexPatternFromFilter( @@ -58,7 +58,7 @@ export function getQueryDslFromFilter(filter: Filter) { } export function getFilterableFields(indexPattern: IndexPattern) { - return indexPattern.fields.filter(indexPatternUtils.isFilterable); + return indexPattern.fields.filter(isFilterable); } export function getOperatorOptions(field: Field) { diff --git a/src/legacy/core_plugins/data/public/filter/filter_service.mock.ts b/src/legacy/core_plugins/data/public/filter/filter_service.mock.ts new file mode 100644 index 0000000000000..bcd7ab7f40e6b --- /dev/null +++ b/src/legacy/core_plugins/data/public/filter/filter_service.mock.ts @@ -0,0 +1,47 @@ +/* + * 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 { FilterService, FilterSetup } from '.'; + +type FilterServiceClientContract = PublicMethodsOf; + +const createSetupContractMock = () => { + const setupContract: jest.Mocked = { + filterManager: jest.fn() as any, + }; + + return setupContract; +}; + +const createMock = () => { + const mocked: jest.Mocked = { + setup: jest.fn(), + start: jest.fn(), + stop: jest.fn(), + }; + + mocked.setup.mockReturnValue(createSetupContractMock()); + return mocked; +}; + +export const filterServiceMock = { + create: createMock, + createSetupContract: createSetupContractMock, + createStartContract: createSetupContractMock, +}; diff --git a/src/legacy/core_plugins/data/public/filter/filter_service.ts b/src/legacy/core_plugins/data/public/filter/filter_service.ts index f56534490afc4..063b69c175b20 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_service.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_service.ts @@ -20,8 +20,9 @@ import { UiSettingsClientContract } from 'src/core/public'; import { IndexPatterns } from '../index_patterns'; import { FilterManager } from './filter_manager'; + /** - * FilterSearch Service + * Filter Service * @internal */ @@ -37,6 +38,10 @@ export class FilterService { }; } + public start() { + // nothing to do here yet + } + public stop() { // nothing to do here yet } diff --git a/src/legacy/core_plugins/data/public/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index.ts index bbb2124d60d86..bb4238e9997b7 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index.ts @@ -19,4 +19,4 @@ export * from './index_patterns_service'; -export { mockFields, mockIndexPattern } from './mocks'; +export { mockFields, mockIndexPattern } from './index_patterns_service.mock'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_flatten_hit.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js similarity index 100% rename from src/legacy/core_plugins/data/public/index_patterns/index_patterns/_flatten_hit.js rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts index e5ae3b90108ec..31ff03d51f97a 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index.ts @@ -17,6 +17,8 @@ * under the License. */ +// @ts-ignore +export * from './flatten_hit'; export * from './format_hit'; export * from './index_pattern'; export * from './index_patterns'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 117145d0edae1..0463cd6653edd 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -35,7 +35,7 @@ import { createFieldsFetcher } from './_fields_fetcher'; import { getRoutes } from '../utils'; import { formatHitProvider } from './format_hit'; // @ts-ignore -import { flattenHitWrapper } from './_flatten_hit'; +import { flattenHitWrapper } from './flatten_hit'; import { IndexPatternsApiClient } from './index_patterns_api_client'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; diff --git a/src/legacy/core_plugins/data/public/index_patterns/mocks.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts similarity index 63% rename from src/legacy/core_plugins/data/public/index_patterns/mocks.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index 8d8b28b5ef74a..9006e1b6f1dd3 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/mocks.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -17,9 +17,52 @@ * under the License. */ +// Legacy mocks - must be removed before migrating to new platform. +jest.mock('ui/chrome'); + +import { IndexPatternsService, IndexPatternsSetup } from '.'; import { FieldType } from './fields'; import { StaticIndexPattern } from './index_patterns'; +type IndexPatternsServiceClientContract = PublicMethodsOf; + +const createSetupContractMock = () => { + const setupContract: jest.Mocked = { + FieldList: {} as any, + flattenHitWrapper: jest.fn(), + formatHitProvider: jest.fn(), + IndexPatterns: jest.fn() as any, + ui: { + IndexPatternSelect: jest.fn(), + }, + __LEGACY: { + // For BWC we must temporarily export the class implementation of Field, + // which is only used externally by the Index Pattern UI. + FieldImpl: jest.fn(), + IndexPatternsProvider: jest.fn(), + }, + }; + + return setupContract; +}; + +const createMock = () => { + const mocked: jest.Mocked = { + setup: jest.fn(), + start: jest.fn(), + stop: jest.fn(), + }; + + mocked.setup.mockReturnValue(createSetupContractMock()); + return mocked; +}; + +export const indexPatternsServiceMock = { + create: createMock, + createSetupContract: createSetupContractMock, + createStartContract: createSetupContractMock, +}; + export const mockFields: FieldType[] = [ { name: 'machine.os', diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index de65e35a05428..f9e03f48533c8 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -20,6 +20,8 @@ import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { IndexPatternSelect } from './components'; import { Field, FieldList, FieldType } from './fields'; +// @ts-ignore +import { flattenHitWrapper } from './index_patterns/flatten_hit'; import { formatHitProvider, IndexPattern, @@ -41,20 +43,26 @@ export interface IndexPatternDependencies { export class IndexPatternsService { public setup({ uiSettings, savedObjectsClient }: IndexPatternDependencies) { return { - Field, FieldList, + flattenHitWrapper, formatHitProvider, - // TODO: Remove Provider and replace with this - // IndexPatterns: new IndexPatterns(config, savedObjectsClient), + IndexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), ui: { IndexPatternSelect, }, __LEGACY: { + // For BWC we must temporarily export the class implementation of Field, + // which is only used externally by the Index Pattern UI. + FieldImpl: Field, IndexPatternsProvider, }, }; } + public start() { + // nothing to do here yet + } + public stop() { // nothing to do here yet } diff --git a/src/legacy/core_plugins/data/public/mocks.ts b/src/legacy/core_plugins/data/public/mocks.ts new file mode 100644 index 0000000000000..0ca0b4947d538 --- /dev/null +++ b/src/legacy/core_plugins/data/public/mocks.ts @@ -0,0 +1,42 @@ +/* + * 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 { DataSetup } from '.'; +import { filterServiceMock } from './filter/filter_service.mock'; +import { indexPatternsServiceMock } from './index_patterns/index_patterns_service.mock'; +import { queryServiceMock } from './query/query_service.mock'; + +function createDataSetupMock() { + const mock: MockedKeys> = { + filter: filterServiceMock.createSetupContract(), + indexPatterns: indexPatternsServiceMock.createSetupContract(), + query: queryServiceMock.createSetupContract(), + }; + + return mock; +} + +function createDataStartMock() { + return {}; +} + +export const dataPluginMock = { + createSetup: createDataSetupMock, + createStart: createDataStartMock, +}; diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 34edb355d2ef8..6041b2d2928e2 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -82,7 +82,7 @@ export class DataPlugin implements Plugin { diff --git a/src/legacy/core_plugins/data/public/query/query_service.mock.ts b/src/legacy/core_plugins/data/public/query/query_service.mock.ts new file mode 100644 index 0000000000000..19a00632ca192 --- /dev/null +++ b/src/legacy/core_plugins/data/public/query/query_service.mock.ts @@ -0,0 +1,51 @@ +/* + * 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 { QueryService, QuerySetup } from '.'; + +type QueryServiceClientContract = PublicMethodsOf; + +const createSetupContractMock = () => { + const setupContract: jest.Mocked = { + helpers: { + fromUser: jest.fn(), + toUser: jest.fn(), + getQueryLog: jest.fn(), + }, + }; + + return setupContract; +}; + +const createMock = () => { + const mocked: jest.Mocked = { + setup: jest.fn(), + start: jest.fn(), + stop: jest.fn(), + }; + + mocked.setup.mockReturnValue(createSetupContractMock()); + return mocked; +}; + +export const queryServiceMock = { + create: createMock, + createSetupContract: createSetupContractMock, + createStartContract: createSetupContractMock, +}; diff --git a/src/legacy/core_plugins/data/public/query/query_service.ts b/src/legacy/core_plugins/data/public/query/query_service.ts index db04b3a29a212..114d8fdfd3878 100644 --- a/src/legacy/core_plugins/data/public/query/query_service.ts +++ b/src/legacy/core_plugins/data/public/query/query_service.ts @@ -35,6 +35,10 @@ export class QueryService { }; } + public start() { + // nothing to do here yet + } + public stop() { // nothing to do here yet } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js index b72a28d6f721c..f1294d6587e5b 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/create_edit_field/create_edit_field.js @@ -17,7 +17,9 @@ * under the License. */ -import { Field } from 'ui/index_patterns'; +import { setup as data } from '../../../../../../../data/public/legacy'; +const { FieldImpl: Field } = data.indexPatterns.__LEGACY; + import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors'; import { docTitle } from 'ui/doc_title'; import { KbnUrlProvider } from 'ui/url'; diff --git a/src/legacy/ui/public/chrome/__mocks__/index.js b/src/legacy/ui/public/chrome/__mocks__/index.js index ca603845eaf86..e8149970002a1 100644 --- a/src/legacy/ui/public/chrome/__mocks__/index.js +++ b/src/legacy/ui/public/chrome/__mocks__/index.js @@ -27,8 +27,11 @@ const uiSettingsClient = { }; const chrome = { + addBasePath: path => path ? path : 'test/base/path', + breadcrumbs: { + set: () => ({}), + }, getBasePath: () => '/test/base/path', - addBasePath: path => path, getInjected: jest.fn(), getUiSettingsClient: () => uiSettingsClient, getSavedObjectsClient: () => '', diff --git a/src/legacy/ui/public/courier/courier.js b/src/legacy/ui/public/courier/courier.js index 1f659933931ff..b383d71af7c7a 100644 --- a/src/legacy/ui/public/courier/courier.js +++ b/src/legacy/ui/public/courier/courier.js @@ -21,12 +21,12 @@ import _ from 'lodash'; import { timefilter } from 'ui/timefilter'; -import '../es'; -import '../directives/listen'; -import '../index_patterns'; -import { uiModules } from '../modules'; -import { addFatalErrorCallback } from '../notify'; -import '../promises'; +import 'ui/es'; +import 'ui/directives/listen'; +import 'ui/index_patterns'; +import { uiModules } from 'ui/modules'; +import { addFatalErrorCallback } from 'ui/notify'; +import 'ui/promises'; import { searchRequestQueue } from './search_request_queue'; import { FetchSoonProvider } from './fetch'; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts new file mode 100644 index 0000000000000..3ef07490e12b8 --- /dev/null +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -0,0 +1,50 @@ +/* + * 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 { dataPluginMock } from '../../../../core_plugins/data/public/mocks'; + +const createMock = () => { + const mock = { + setup: { + data: dataPluginMock.createSetup(), + }, + start: { + data: dataPluginMock.createStart(), + }, + }; + return mock; +}; + +createMock(); + +// static code +export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + isFilterable, + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, + IndexPatternAlreadyExists, + IndexPatternMissingIndices, + NoDefaultIndexPattern, + NoDefinedIndexPatterns, +} from '../../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 76bfcac57cced..011276dd3666c 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -26,9 +26,16 @@ import { setup as data } from '../../../core_plugins/data/public/legacy'; -// Field is only used in Discover. -// FieldList is only used as class in Index Patterns Management UI. -export const { Field, FieldList, formatHitProvider } = data.indexPatterns; +/* eslint-disable @kbn/eslint/no-restricted-paths */ +export { + mockFields, + mockIndexPattern, +} from '../../../core_plugins/data/public/index_patterns/index_patterns_service.mock'; +/* eslint-enable @kbn/eslint/no-restricted-paths */ + +// Field is only used as class in Index Patterns Management UI. +// FieldList is only used in discover. +export const { FieldList, flattenHitWrapper, formatHitProvider } = data.indexPatterns; export const { IndexPatternsProvider } = data.indexPatterns.__LEGACY; // ui components @@ -52,13 +59,9 @@ export { // types export { + Field, FieldType, IndexPattern, IndexPatterns, StaticIndexPattern, } from '../../../core_plugins/data/public'; - -export const flattenHitWrapper = null; - -export const mockFields = null; -export const mockIndexPattern = null; From 14063c557a698c8c58c46c5a9c20406240ca5d18 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 12 Aug 2019 22:31:01 -0600 Subject: [PATCH 05/14] Fix broken CCR & Rollup tests. --- .../auto_follow_pattern_add.test.js | 23 ++--------------- .../auto_follow_pattern_edit.test.js | 23 ++--------------- .../auto_follow_pattern_list.test.js | 13 +++++----- .../follower_index_add.test.js | 23 ++--------------- .../follower_index_edit.test.js | 23 ++--------------- .../follower_indices_list.test.js | 13 +++++----- .../__jest__/client_integration/home.test.js | 22 ++-------------- .../auto_follow_pattern_form.test.js | 13 ++-------- .../auto_follow_pattern_validators.test.js | 13 ++-------- .../job_create_clone.test.js | 18 +------------ .../job_create_date_histogram.test.js | 16 +----------- .../job_create_histogram.test.js | 16 +----------- .../job_create_logistics.test.js | 16 +----------- .../job_create_metrics.test.js | 16 +----------- .../job_create_review.test.js | 16 +----------- .../job_create_terms.test.js | 16 +----------- .../client_integration/job_list.test.js | 25 +------------------ .../client_integration/job_list_clone.test.js | 18 +------------ 18 files changed, 37 insertions(+), 286 deletions(-) diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_add.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_add.test.js index 258b2df79b5b8..476f01940d892 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_add.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_add.test.js @@ -7,27 +7,8 @@ import { setupEnvironment, pageHelpers, nextTick, getRandomString } from './helpers'; import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../src/legacy/ui/public/index_patterns'; -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path || 'api/cross_cluster_replication', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - } -})); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - const { validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/validate/validate_index_pattern'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES }; -}); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); const { setup } = pageHelpers.autoFollowPatternAdd; diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_edit.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_edit.test.js index f34dd8a14c936..9ef412883522a 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_edit.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_edit.test.js @@ -8,27 +8,8 @@ import { AutoFollowPatternForm } from '../../public/app/components/auto_follow_p import { setupEnvironment, pageHelpers, nextTick } from './helpers'; import { AUTO_FOLLOW_PATTERN_EDIT } from './helpers/constants'; -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path || 'api/cross_cluster_replication', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - } -})); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - const { validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/validate/validate_index_pattern'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES }; -}); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); const { setup } = pageHelpers.autoFollowPatternEdit; const { setup: setupAutoFollowPatternAdd } = pageHelpers.autoFollowPatternAdd; diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_list.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_list.test.js index 167d0799d8c48..8a6d382190945 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_list.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/auto_follow_pattern_list.test.js @@ -8,17 +8,18 @@ import { setupEnvironment, pageHelpers, nextTick, findTestSubject, getRandomStri import { getAutoFollowPatternClientMock } from '../../fixtures/auto_follow_pattern'; +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); + jest.mock('ui/chrome', () => ({ addBasePath: () => 'api/cross_cluster_replication', breadcrumbs: { set: () => {} }, + getUiSettingsClient: () => ({ + get: x => x, + getUpdate$: () => ({ subscribe: jest.fn() }), + }), })); -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - const { setup } = pageHelpers.autoFollowPatternList; describe('', () => { diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_add.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_add.test.js index 73cc1e217aaf0..d28d671fb2ace 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_add.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_add.test.js @@ -9,27 +9,8 @@ import { RemoteClustersFormField } from '../../public/app/components'; import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../src/legacy/ui/public/index_patterns'; -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path || 'api/cross_cluster_replication', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - } -})); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - const { validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/validate/validate_index_pattern'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES }; -}); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); const { setup } = pageHelpers.followerIndexAdd; const { setup: setupAutoFollowPatternAdd } = pageHelpers.autoFollowPatternAdd; diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_edit.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_edit.test.js index 0f118cb797044..5e74d923d3af5 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_edit.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_index_edit.test.js @@ -9,27 +9,8 @@ import { setupEnvironment, pageHelpers, nextTick } from './helpers'; import { FollowerIndexForm } from '../../public/app/components/follower_index_form/follower_index_form'; import { FOLLOWER_INDEX_EDIT } from './helpers/constants'; -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path || 'api/cross_cluster_replication', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - } -})); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - const { validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES } = - jest.requireActual('../../../../../../src/legacy/ui/public/index_patterns/validate/validate_index_pattern'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, validateIndexPattern, ILLEGAL_CHARACTERS, CONTAINS_SPACES }; -}); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); const { setup } = pageHelpers.followerIndexEdit; const { setup: setupFollowerIndexAdd } = pageHelpers.followerIndexAdd; diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_indices_list.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_indices_list.test.js index f3047206c77ba..6aef850672179 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_indices_list.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/follower_indices_list.test.js @@ -8,17 +8,18 @@ import { setupEnvironment, pageHelpers, nextTick, getRandomString } from './help import { getFollowerIndexMock } from '../../fixtures/follower_index'; +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); + jest.mock('ui/chrome', () => ({ addBasePath: () => 'api/cross_cluster_replication', breadcrumbs: { set: () => {} }, + getUiSettingsClient: () => ({ + get: x => x, + getUpdate$: () => ({ subscribe: jest.fn() }), + }), })); -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - const { setup } = pageHelpers.followerIndexList; describe('', () => { diff --git a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/home.test.js b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/home.test.js index cf6ccd80f461f..35ec99846990a 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/home.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/__jest__/client_integration/home.test.js @@ -7,26 +7,8 @@ import { setupEnvironment, pageHelpers, nextTick } from './helpers'; -jest.mock('ui/chrome', () => ({ - addBasePath: () => 'api/cross_cluster_replication', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - throw new Error(`Unexpected call to chrome.getInjected with key ${key}`); - } -})); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = - require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); const { setup } = pageHelpers.home; diff --git a/x-pack/legacy/plugins/cross_cluster_replication/public/app/components/auto_follow_pattern_form.test.js b/x-pack/legacy/plugins/cross_cluster_replication/public/app/components/auto_follow_pattern_form.test.js index 61ca7359efbda..f6cc9cb3742ea 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/public/app/components/auto_follow_pattern_form.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/public/app/components/auto_follow_pattern_form.test.js @@ -11,17 +11,8 @@ jest.mock('../services/auto_follow_pattern_validators', () => ({ validateLeaderIndexPattern: jest.fn(), })); -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/_index_pattern', () => ({ - IndexPattern: jest.fn(), -})); - -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/index_patterns', () => ({ - IndexPatterns: jest.fn(), -})); - -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/index_patterns_api_client', () => ({ - IndexPatternsApiClient: jest.fn(), -})); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); describe(' { describe('updateFormErrors()', () => { diff --git a/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/auto_follow_pattern_validators.test.js b/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/auto_follow_pattern_validators.test.js index be12bdecf56bc..f70caf2f8080b 100644 --- a/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/auto_follow_pattern_validators.test.js +++ b/x-pack/legacy/plugins/cross_cluster_replication/public/app/services/auto_follow_pattern_validators.test.js @@ -7,17 +7,8 @@ import { validateAutoFollowPattern } from './auto_follow_pattern_validators'; -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/_index_pattern', () => ({ - IndexPattern: jest.fn(), -})); - -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/index_patterns', () => ({ - IndexPatterns: jest.fn(), -})); - -jest.mock('../../../../../../../src/legacy/ui/public/index_patterns/index_patterns_api_client', () => ({ - IndexPatternsApiClient: jest.fn(), -})); +jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); describe('Auto-follow pattern validators', () => { describe('validateAutoFollowPattern()', () => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js index d80a06a441414..8a0b3159b34df 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js @@ -8,23 +8,7 @@ import { setupEnvironment, pageHelpers } from './helpers'; import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual( - '../../../../../../src/legacy/ui/public/index_patterns/constants' - ); - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js index c3d796795d16e..59814474396fe 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js @@ -9,21 +9,7 @@ import moment from 'moment-timezone'; import { setupEnvironment, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js index ac46498e77b8b..09417fa8ed307 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js @@ -7,21 +7,7 @@ import { setupEnvironment, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js index 8025d4f9bfe55..62de4612d4c09 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js @@ -9,21 +9,7 @@ import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../../../src/ import { setupEnvironment, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js index cfd4901e3a8be..2f26d2a7475de 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js @@ -7,21 +7,7 @@ import { setupEnvironment, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js index 261205542faa5..8ca736e62be7f 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js @@ -9,21 +9,7 @@ import { first } from 'lodash'; import { JOBS } from './helpers/constants'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path, - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js index a86e6f6602df5..78e8d9ec0c53a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js @@ -7,21 +7,7 @@ import { setupEnvironment, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js index a5e180c6caf1e..05272bf222612 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js @@ -9,30 +9,7 @@ import { setupEnvironment, pageHelpers, nextTick } from './helpers'; import { JOBS } from './helpers/constants'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual('../../../../../../src/legacy/ui/public/index_patterns/constants'); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: (path) => path ? path : 'api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: (key) => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {} - }; - } - throw new Error(`Unexpected call to chrome.getInjected with key ${key}`); - }, - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('../../public/crud_app/services', () => { const services = require.requireActual('../../public/crud_app/services'); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js index 10c8eecd04ad4..ce62f6c67ae03 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js @@ -10,23 +10,7 @@ import { getRouter } from '../../public/crud_app/services/routing'; import { CRUD_APP_BASE_PATH } from '../../public/crud_app/constants'; jest.mock('ui/new_platform'); - -jest.mock('ui/index_patterns', () => { - const { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } = require.requireActual( - '../../../../../../src/legacy/ui/public/index_patterns/constants' - ); // eslint-disable-line max-len - return { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE }; -}); - -jest.mock('ui/chrome', () => ({ - addBasePath: () => '/api/rollup', - breadcrumbs: { set: () => {} }, - getInjected: () => ({}), - getUiSettingsClient: () => ({}), - getSavedObjectsClient: () => ({}), -})); - -jest.mock('ui/timefilter', () => {}); +jest.mock('ui/index_patterns'); jest.mock('lodash/function/debounce', () => fn => fn); From b7807b7875f6cf43c0dc87155b09cd66bb561e54 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 13 Aug 2019 10:32:36 -0600 Subject: [PATCH 06/14] Update translation IDs. --- .../data/public/index_patterns/fields/field.ts | 4 ++-- .../public/index_patterns/index_patterns/index_pattern.ts | 4 ++-- x-pack/plugins/translations/translations/ja-JP.json | 8 ++++---- x-pack/plugins/translations/translations/zh-CN.json | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts index 52a2d251c13d0..7d19db5595ea6 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts @@ -98,11 +98,11 @@ export class Field implements FieldType { // find the type for this field, fallback to unknown type let type = getKbnFieldType(spec.type); if (spec.type && !type) { - const title = i18n.translate('common.ui.indexPattern.unknownFieldHeader', { + const title = i18n.translate('data.indexPatterns.unknownFieldHeader', { values: { type: spec.type }, defaultMessage: 'Unknown field type {type}', }); - const text = i18n.translate('common.ui.indexPattern.unknownFieldErrorMessage', { + const text = i18n.translate('data.indexPatterns.unknownFieldErrorMessage', { values: { name: spec.name, title: indexPattern.title }, defaultMessage: 'Field {name} in indexPattern {title} is using an unknown field type.', }); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts index 0463cd6653edd..6a4cf6fe45390 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts @@ -454,7 +454,7 @@ export class IndexPattern implements StaticIndexPattern { if (unresolvedCollision) { const message = i18n.translate( - 'common.ui.indexPattern.unableWriteLabel', + 'data.indexPatterns.unableWriteLabel', { defaultMessage: 'Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern.', @@ -504,7 +504,7 @@ export class IndexPattern implements StaticIndexPattern { } toastNotifications.addError(err, { - title: i18n.translate('common.ui.indexPattern.fetchFieldErrorTitle', { + title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields', }), }); diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index f571317d258a8..875dea48b5563 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -477,10 +477,6 @@ "common.ui.flotCharts.thuLabel": "木", "common.ui.flotCharts.tueLabel": "火", "common.ui.flotCharts.wedLabel": "水", - "common.ui.indexPattern.fetchFieldErrorTitle": "フィールドの取得中にエラーが発生", - "common.ui.indexPattern.unableWriteLabel": "インデックスパターンを書き込めません!このインデックスパターンへの最新の変更を取得するにな、ページを更新してください。", - "common.ui.indexPattern.unknownFieldErrorMessage": "インデックスパターン「{title}」のフィールド「{name}」が不明なフィールドタイプを使用しています。", - "common.ui.indexPattern.unknownFieldHeader": "不明なフィールドタイプ {type}", "common.ui.legacyBrowserMessage": "この Kibana インストレーションは、現在ご使用のブラウザが満たしていない厳格なセキュリティ要件が有効になっています。", "common.ui.legacyBrowserTitle": "ブラウザをアップグレードしてください", "common.ui.management.breadcrumb": "管理", @@ -784,6 +780,10 @@ "data.filter.options.pinAllFiltersButtonLabel": "すべてピン付け", "data.filter.options.unpinAllFiltersButtonLabel": "すべてのピンを外す", "data.filter.searchBar.changeAllFiltersTitle": "すべてのフィルターの変更", + "data.indexPatterns.fetchFieldErrorTitle": "フィールドの取得中にエラーが発生", + "data.indexPatterns.unableWriteLabel": "インデックスパターンを書き込めません!このインデックスパターンへの最新の変更を取得するにな、ページを更新してください。", + "data.indexPatterns.unknownFieldErrorMessage": "インデックスパターン「{title}」のフィールド「{name}」が不明なフィールドタイプを使用しています。", + "data.indexPatterns.unknownFieldHeader": "不明なフィールドタイプ {type}", "data.query.queryBar.kqlFullLanguageName": "Kibana クエリ言語", "data.query.queryBar.kqlLanguageName": "KQL", "data.query.queryBar.kqlOffLabel": "オフ", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 9c809d4b79763..86191707fe068 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -477,10 +477,6 @@ "common.ui.flotCharts.thuLabel": "周四", "common.ui.flotCharts.tueLabel": "周二", "common.ui.flotCharts.wedLabel": "周三", - "common.ui.indexPattern.fetchFieldErrorTitle": "提取字段时出错", - "common.ui.indexPattern.unableWriteLabel": "无法写入索引模式!请刷新页面以获取此索引模式的最新更改。", - "common.ui.indexPattern.unknownFieldErrorMessage": "indexPattern “{title}” 中的字段 “{name}” 使用未知字段类型。", - "common.ui.indexPattern.unknownFieldHeader": "未知字段类型 {type}", "common.ui.legacyBrowserMessage": "此 Kibana 安装启用了当前浏览器未满足的严格安全要求。", "common.ui.legacyBrowserTitle": "请升级您的浏览器", "common.ui.management.breadcrumb": "管理", @@ -784,6 +780,10 @@ "data.filter.options.pinAllFiltersButtonLabel": "全部固定", "data.filter.options.unpinAllFiltersButtonLabel": "全部取消固定", "data.filter.searchBar.changeAllFiltersTitle": "更改所有筛选", + "data.indexPatterns.fetchFieldErrorTitle": "提取字段时出错", + "data.indexPatterns.unableWriteLabel": "无法写入索引模式!请刷新页面以获取此索引模式的最新更改。", + "data.indexPatterns.unknownFieldErrorMessage": "indexPattern “{title}” 中的字段 “{name}” 使用未知字段类型。", + "data.indexPatterns.unknownFieldHeader": "未知字段类型 {type}", "data.query.queryBar.kqlFullLanguageName": "Kibana 查询语言", "data.query.queryBar.kqlLanguageName": "KQL", "data.query.queryBar.kqlOffLabel": "关闭", From dc14f4fd2b10c63ddd2c821f6a013554b1636ae6 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 13 Aug 2019 12:43:27 -0600 Subject: [PATCH 07/14] Update stubbed index pattern. --- src/fixtures/stubbed_logstash_index_pattern.js | 2 +- .../index_patterns/index_patterns_service.mock.ts | 12 +++++++----- .../public/index_patterns/index_patterns_service.ts | 2 +- src/legacy/core_plugins/data/public/plugin.ts | 2 +- .../courier/search_source/__tests__/search_source.js | 4 ++-- src/legacy/ui/public/index_patterns/index.ts | 2 +- .../public/saved_objects/__tests__/saved_object.js | 4 +++- src/test_utils/public/stub_index_pattern.js | 8 ++++++-- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/fixtures/stubbed_logstash_index_pattern.js b/src/fixtures/stubbed_logstash_index_pattern.js index 88dc5d708dc5f..dd0381c440bd6 100644 --- a/src/fixtures/stubbed_logstash_index_pattern.js +++ b/src/fixtures/stubbed_logstash_index_pattern.js @@ -40,7 +40,7 @@ export default function stubbedLogstashIndexPatternService(Private) { }; }); - const indexPattern = new StubIndexPattern('logstash-*', 'time', fields); + const indexPattern = new StubIndexPattern('logstash-*', cfg => cfg, 'time', fields); indexPattern.id = 'logstash-*'; return indexPattern; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index 9006e1b6f1dd3..15d2451c0c58f 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -17,9 +17,6 @@ * under the License. */ -// Legacy mocks - must be removed before migrating to new platform. -jest.mock('ui/chrome'); - import { IndexPatternsService, IndexPatternsSetup } from '.'; import { FieldType } from './fields'; import { StaticIndexPattern } from './index_patterns'; @@ -27,19 +24,24 @@ import { StaticIndexPattern } from './index_patterns'; type IndexPatternsServiceClientContract = PublicMethodsOf; const createSetupContractMock = () => { + // Legacy mock - must be removed before migrating to new platform. + // Included here because we only want to call `jest.mock` when somebody creates + // the mock for this contract. + jest.mock('ui/chrome'); + const setupContract: jest.Mocked = { FieldList: {} as any, flattenHitWrapper: jest.fn(), formatHitProvider: jest.fn(), - IndexPatterns: jest.fn() as any, + indexPatterns: jest.fn() as any, ui: { IndexPatternSelect: jest.fn(), }, __LEGACY: { + IndexPatternsProvider: jest.fn(), // For BWC we must temporarily export the class implementation of Field, // which is only used externally by the Index Pattern UI. FieldImpl: jest.fn(), - IndexPatternsProvider: jest.fn(), }, }; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index f9e03f48533c8..c0088a05b0c75 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -46,7 +46,7 @@ export class IndexPatternsService { FieldList, flattenHitWrapper, formatHitProvider, - IndexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), + indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), ui: { IndexPatternSelect, }, diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index 6041b2d2928e2..34edb355d2ef8 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -82,7 +82,7 @@ export class DataPlugin implements Plugin cfg, null, []); + indexPattern2 = new IndexPattern('test2-*', cfg => cfg, null, []); expect(indexPattern).to.not.be(indexPattern2); })); beforeEach(() => searchRequestQueue.removeAll()); diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 011276dd3666c..4e074ea62c216 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -34,7 +34,7 @@ export { /* eslint-enable @kbn/eslint/no-restricted-paths */ // Field is only used as class in Index Patterns Management UI. -// FieldList is only used in discover. +// FieldList is only used in discover and StubIndexPattern. export const { FieldList, flattenHitWrapper, formatHitProvider } = data.indexPatterns; export const { IndexPatternsProvider } = data.indexPatterns.__LEGACY; diff --git a/src/legacy/ui/public/saved_objects/__tests__/saved_object.js b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js index 64d030bd7c7ef..3af540b5b652c 100644 --- a/src/legacy/ui/public/saved_objects/__tests__/saved_object.js +++ b/src/legacy/ui/public/saved_objects/__tests__/saved_object.js @@ -23,7 +23,7 @@ import sinon from 'sinon'; import BluebirdPromise from 'bluebird'; import { SavedObjectProvider } from '../saved_object'; -import { IndexPattern } from '../../index_patterns'; +import StubIndexPatternProv from 'test_utils/stub_index_pattern'; import { SavedObjectsClientProvider } from '../saved_objects_client_provider'; import { InvalidJSONProperty } from '../../errors'; @@ -33,6 +33,7 @@ describe('Saved Object', function () { require('test_utils/no_digest_promises').activateForSuite(); let SavedObject; + let IndexPattern; let esDataStub; let savedObjectsClientStub; let window; @@ -97,6 +98,7 @@ describe('Saved Object', function () { beforeEach(ngMock.inject(function (es, Private, $window) { SavedObject = Private(SavedObjectProvider); + IndexPattern = Private(StubIndexPatternProv); esDataStub = es; savedObjectsClientStub = Private(SavedObjectsClientProvider); window = $window; diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 0fe07cab36328..67959b27d9e1a 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -18,8 +18,11 @@ */ import sinon from 'sinon'; +// TODO: We should not be importing from the data plugin directly here; this is only necessary +// because it is one of the few places that we need to access the IndexPattern class itself, rather +// than just the type. Doing this as a temporary measure; it will be left behind when migrating to NP. +import { IndexPattern } from '../../legacy/core_plugins/data/public/index_patterns/index_patterns'; import { - IndexPattern, FieldList, getRoutes, formatHitProvider, @@ -29,12 +32,13 @@ import { fieldFormats } from 'ui/registry/field_formats'; export default function () { - function StubIndexPattern(pattern, timeField, fields) { + function StubIndexPattern(pattern, getConfig, timeField, fields) { this.id = pattern; this.title = pattern; this.popularizeField = sinon.stub(); this.timeFieldName = timeField; this.isTimeBased = () => Boolean(this.timeFieldName); + this.getConfig = getConfig; this.getNonScriptedFields = sinon.spy(IndexPattern.prototype.getNonScriptedFields); this.getScriptedFields = sinon.spy(IndexPattern.prototype.getScriptedFields); this.getFieldByName = sinon.spy(IndexPattern.prototype.getFieldByName); From dcb1c5548d7e7a3767dddb73516ba40551aed5a1 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Tue, 13 Aug 2019 13:47:33 -0600 Subject: [PATCH 08/14] Revert changes to imports in courier. --- src/legacy/ui/public/courier/courier.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/legacy/ui/public/courier/courier.js b/src/legacy/ui/public/courier/courier.js index b383d71af7c7a..bd242aefc8f42 100644 --- a/src/legacy/ui/public/courier/courier.js +++ b/src/legacy/ui/public/courier/courier.js @@ -21,12 +21,11 @@ import _ from 'lodash'; import { timefilter } from 'ui/timefilter'; -import 'ui/es'; -import 'ui/directives/listen'; -import 'ui/index_patterns'; -import { uiModules } from 'ui/modules'; -import { addFatalErrorCallback } from 'ui/notify'; -import 'ui/promises'; +import '../es'; +import '../directives/listen'; +import { uiModules } from '../modules'; +import { addFatalErrorCallback } from '../notify'; +import '../promises'; import { searchRequestQueue } from './search_request_queue'; import { FetchSoonProvider } from './fetch'; From dd42901851e6577a0c97cb3c16f6f9f11883a7d9 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 15 Aug 2019 15:30:42 -0600 Subject: [PATCH 09/14] Move Provider to static export, add both static & prewired IndexPatternSelect components. --- src/legacy/core_plugins/data/public/index.ts | 4 ++- .../components/index_pattern_select.tsx | 34 +++++++++++++------ .../index_patterns_service.mock.ts | 5 +-- .../index_patterns/index_patterns_service.ts | 10 +++--- .../interpreter/public/functions/esaggs.ts | 7 ++-- .../public/functions/visualization.js | 2 +- .../public/index_patterns/__mocks__/index.ts | 2 ++ src/legacy/ui/public/index_patterns/index.ts | 14 ++++---- 8 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 639f299b7f1f1..8a8520e684124 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -53,6 +53,8 @@ export { getFromSavedObject, getRoutes, isFilterable, + IndexPatternSelect, + IndexPatternsProvider, // LEGACY validateIndexPattern, ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, @@ -61,4 +63,4 @@ export { IndexPatternMissingIndices, NoDefaultIndexPattern, NoDefinedIndexPatterns, -} from './index_patterns'; \ No newline at end of file +} from './index_patterns'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx b/src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx index e8e5f8c08278f..62d4983bfbf03 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx +++ b/src/legacy/core_plugins/data/public/index_patterns/components/index_pattern_select.tsx @@ -19,9 +19,9 @@ import _ from 'lodash'; import React, { Component } from 'react'; -import chrome from 'ui/chrome'; import { EuiComboBox } from '@elastic/eui'; +import { SavedObjectsClientContract, SimpleSavedObject } from '../../../../../../core/public'; interface IndexPatternSelectProps { onChange: (opt: any) => void; @@ -29,6 +29,7 @@ interface IndexPatternSelectProps { placeholder: string; fieldTypes: string[]; onNoIndexPatterns: () => void; + savedObjectsClient: SavedObjectsClientContract; } interface IndexPatternSelectState { @@ -38,8 +39,12 @@ interface IndexPatternSelectState { searchValue: string | undefined; } -const getIndexPatterns = async (search: string, fields: string[]) => { - const resp = await chrome.getSavedObjectsClient().find({ +const getIndexPatterns = async ( + client: SavedObjectsClientContract, + search: string, + fields: string[] +) => { + const resp = await client.find({ type: 'index-pattern', fields, search: `${search}*`, @@ -49,14 +54,22 @@ const getIndexPatterns = async (search: string, fields: string[]) => { return resp.savedObjects; }; -const getIndexPatternTitle = async (indexPatternId: string) => { - const savedObject = await chrome.getSavedObjectsClient().get('index-pattern', indexPatternId); +const getIndexPatternTitle = async ( + client: SavedObjectsClientContract, + indexPatternId: string +): Promise> => { + const savedObject = (await client.get('index-pattern', indexPatternId)) as SimpleSavedObject; if (savedObject.error) { throw new Error(`Unable to get index-pattern title: ${savedObject.error.message}`); } return savedObject.attributes.title; }; +// Takes in stateful runtime dependencies and pre-wires them to the component +export function createIndexPatternSelect(savedObjectsClient: SavedObjectsClientContract) { + return (props: any) => ; +} + export class IndexPatternSelect extends Component { private isMounted: boolean = false; state: IndexPatternSelectState; @@ -99,7 +112,7 @@ export class IndexPatternSelect extends Component { let indexPatternTitle; try { - indexPatternTitle = await getIndexPatternTitle(indexPatternId); + indexPatternTitle = await getIndexPatternTitle(this.props.savedObjectsClient, indexPatternId); } catch (err) { // index pattern no longer exists return; @@ -118,16 +131,16 @@ export class IndexPatternSelect extends Component { }; debouncedFetch = _.debounce(async (searchValue: string) => { - const { fieldTypes, onNoIndexPatterns } = this.props; + const { fieldTypes, onNoIndexPatterns, savedObjectsClient } = this.props; const savedObjectFields = ['title']; if (fieldTypes) { savedObjectFields.push('fields'); } - let savedObjects = await getIndexPatterns(searchValue, savedObjectFields); + let savedObjects = await getIndexPatterns(savedObjectsClient, searchValue, savedObjectFields); if (fieldTypes) { - savedObjects = savedObjects.filter(savedObject => { + savedObjects = savedObjects.filter((savedObject: SimpleSavedObject) => { try { const indexPatternFields = JSON.parse(savedObject.attributes.fields as any); return indexPatternFields.some((field: any) => { @@ -147,7 +160,7 @@ export class IndexPatternSelect extends Component { // We need this check to handle the case where search results come back in a different // order than they were sent out. Only load results for the most recent search. if (searchValue === this.state.searchValue) { - const options = savedObjects.map(indexPatternSavedObject => { + const options = savedObjects.map((indexPatternSavedObject: SimpleSavedObject) => { return { label: indexPatternSavedObject.attributes.title, value: indexPatternSavedObject.id, @@ -185,6 +198,7 @@ export class IndexPatternSelect extends Component { indexPatternId, // eslint-disable-line no-unused-vars placeholder, onNoIndexPatterns, // eslint-disable-line no-unused-vars + savedObjectsClient, // eslint-disable-line no-unused-vars ...rest } = this.props; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index 15d2451c0c58f..e14a19dcfc9f7 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -34,11 +34,8 @@ const createSetupContractMock = () => { flattenHitWrapper: jest.fn(), formatHitProvider: jest.fn(), indexPatterns: jest.fn() as any, - ui: { - IndexPatternSelect: jest.fn(), - }, + IndexPatternSelect: jest.fn(), __LEGACY: { - IndexPatternsProvider: jest.fn(), // For BWC we must temporarily export the class implementation of Field, // which is only used externally by the Index Pattern UI. FieldImpl: jest.fn(), diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index c0088a05b0c75..60a716ed4d73e 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -18,15 +18,14 @@ */ import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; -import { IndexPatternSelect } from './components'; import { Field, FieldList, FieldType } from './fields'; // @ts-ignore import { flattenHitWrapper } from './index_patterns/flatten_hit'; +import { createIndexPatternSelect } from './components'; import { formatHitProvider, IndexPattern, IndexPatterns, - IndexPatternsProvider, StaticIndexPattern, } from './index_patterns'; @@ -47,14 +46,11 @@ export class IndexPatternsService { flattenHitWrapper, formatHitProvider, indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), - ui: { - IndexPatternSelect, - }, + IndexPatternSelect: createIndexPatternSelect(savedObjectsClient), __LEGACY: { // For BWC we must temporarily export the class implementation of Field, // which is only used externally by the Index Pattern UI. FieldImpl: Field, - IndexPatternsProvider, }, }; } @@ -71,6 +67,8 @@ export class IndexPatternsService { // static code /** @public */ +export { IndexPatternSelect } from './components'; +export { IndexPatternsProvider } from './index_patterns'; export { CONTAINS_SPACES, getFromSavedObject, diff --git a/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts b/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts index 3bf414cf02211..5b58c3f3ed9bf 100644 --- a/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts +++ b/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts @@ -24,14 +24,13 @@ import { CourierRequestHandlerProvider } from 'ui/vis/request_handlers/courier'; // @ts-ignore import { AggConfigs } from 'ui/vis/agg_configs.js'; +import chrome from 'ui/chrome'; + // need to get rid of angular from these // @ts-ignore -import { IndexPatternsProvider } from 'ui/index_patterns'; -// @ts-ignore import { SearchSourceProvider } from 'ui/courier/search_source'; import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter'; - -import chrome from 'ui/chrome'; +import { IndexPatternsProvider } from '../../../data/public'; const courierRequestHandlerProvider = CourierRequestHandlerProvider; const courierRequestHandler = courierRequestHandlerProvider().handler; diff --git a/src/legacy/core_plugins/interpreter/public/functions/visualization.js b/src/legacy/core_plugins/interpreter/public/functions/visualization.js index 4ee4c0d6ed03a..0ba9c5f434474 100644 --- a/src/legacy/core_plugins/interpreter/public/functions/visualization.js +++ b/src/legacy/core_plugins/interpreter/public/functions/visualization.js @@ -23,7 +23,7 @@ import chrome from 'ui/chrome'; import { VisRequestHandlersRegistryProvider as RequestHandlersProvider } from 'ui/registry/vis_request_handlers'; import { VisResponseHandlersRegistryProvider as ResponseHandlerProvider } from 'ui/registry/vis_response_handlers'; import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; -import { IndexPatternsProvider } from 'ui/index_patterns'; +import { IndexPatternsProvider } from '../../../data/public'; import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter'; import { PersistedState } from 'ui/persisted_state'; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts index 3ef07490e12b8..5f01b5be44d72 100644 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -39,6 +39,8 @@ export { getFromSavedObject, getRoutes, isFilterable, + IndexPatternsProvider, // LEGACY + IndexPatternSelect, validateIndexPattern, ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 4e074ea62c216..737ed70300e49 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -33,13 +33,12 @@ export { } from '../../../core_plugins/data/public/index_patterns/index_patterns_service.mock'; /* eslint-enable @kbn/eslint/no-restricted-paths */ -// Field is only used as class in Index Patterns Management UI. -// FieldList is only used in discover and StubIndexPattern. -export const { FieldList, flattenHitWrapper, formatHitProvider } = data.indexPatterns; -export const { IndexPatternsProvider } = data.indexPatterns.__LEGACY; - -// ui components -export const { IndexPatternSelect } = data.indexPatterns.ui; +export const { + FieldList, // only used in Discover and StubIndexPattern + flattenHitWrapper, + formatHitProvider, + IndexPatternSelect, // only used in x-pack/plugin/maps and input control vis +} = data.indexPatterns; // static code export { @@ -47,6 +46,7 @@ export { getFromSavedObject, getRoutes, isFilterable, + IndexPatternsProvider, // LEGACY validateIndexPattern, ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, From 66f8beb315c5181e1d4eaf029f0fddf4cac40221 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 15 Aug 2019 16:49:07 -0600 Subject: [PATCH 10/14] Update ui/index_patterns mocks and fix broken jest tests. --- .../index_patterns/flatten_hit.js | 27 ++++++++++++++----- .../index_patterns_service.mock.ts | 4 ++- .../index_patterns/index_patterns_service.ts | 4 +-- .../public/index_patterns/__mocks__/index.ts | 21 +++++++-------- .../public/components/app/Home/Home.test.tsx | 2 ++ .../Main/__test__/UpdateBreadcrumbs.test.js | 2 ++ .../public/elasticsearch_geo_utils.test.js | 1 + 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js index f034b746bf803..b9d25dc0ccb41 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js @@ -19,8 +19,6 @@ import _ from 'lodash'; -const flattenedCache = new WeakMap(); - // Takes a hit, merges it with any stored/scripted fields, and with the metaFields // returns a flattened version @@ -84,15 +82,32 @@ function decorateFlattenedWrapper(hit, metaFields) { }; } -export function flattenHitWrapper(indexPattern, metaFields = {}) { - +/** + * This is wrapped by `createFlattenHitWrapper` in order to provide a single cache to be + * shared across all uses of this function. It is only exported here for use in mocks. + * + * @internal + */ +export function flattenHitWrapper(indexPattern, metaFields = {}, cache = new WeakMap()) { return function cachedFlatten(hit, deep = false) { const decorateFlattened = decorateFlattenedWrapper(hit, metaFields); - const cached = flattenedCache.get(hit); + const cached = cache.get(hit); const flattened = cached || flattenHit(indexPattern, hit, deep); if (!cached) { - flattenedCache.set(hit, { ...flattened }); + cache.set(hit, { ...flattened }); } return decorateFlattened(flattened); }; } + +/** + * This wraps `flattenHitWrapper` so one single cache can be provided for all uses of that + * function. The returned value of this function is what is included in the index patterns + * setup contract. + * + * @public + */ +export function createFlattenHitWrapper() { + const cache = new WeakMap(); + return _.partial(flattenHitWrapper, _, _, cache); +} diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index e14a19dcfc9f7..67d7d40c68c9c 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -20,6 +20,8 @@ import { IndexPatternsService, IndexPatternsSetup } from '.'; import { FieldType } from './fields'; import { StaticIndexPattern } from './index_patterns'; +// @ts-ignore +import { flattenHitWrapper } from './index_patterns/flatten_hit'; type IndexPatternsServiceClientContract = PublicMethodsOf; @@ -31,7 +33,7 @@ const createSetupContractMock = () => { const setupContract: jest.Mocked = { FieldList: {} as any, - flattenHitWrapper: jest.fn(), + flattenHitWrapper: jest.fn().mockImplementation(flattenHitWrapper), formatHitProvider: jest.fn(), indexPatterns: jest.fn() as any, IndexPatternSelect: jest.fn(), diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 60a716ed4d73e..3c5a8a14a8b69 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -20,7 +20,7 @@ import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; import { Field, FieldList, FieldType } from './fields'; // @ts-ignore -import { flattenHitWrapper } from './index_patterns/flatten_hit'; +import { createFlattenHitWrapper } from './index_patterns/flatten_hit'; import { createIndexPatternSelect } from './components'; import { formatHitProvider, @@ -43,7 +43,7 @@ export class IndexPatternsService { public setup({ uiSettings, savedObjectsClient }: IndexPatternDependencies) { return { FieldList, - flattenHitWrapper, + flattenHitWrapper: createFlattenHitWrapper(), formatHitProvider, indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), IndexPatternSelect: createIndexPatternSelect(savedObjectsClient), diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts index 5f01b5be44d72..fc137f9f5d87c 100644 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -19,19 +19,16 @@ import { dataPluginMock } from '../../../../core_plugins/data/public/mocks'; -const createMock = () => { - const mock = { - setup: { - data: dataPluginMock.createSetup(), - }, - start: { - data: dataPluginMock.createStart(), - }, - }; - return mock; -}; +const dataSetup = dataPluginMock.createSetup(); -createMock(); +// mocks for stateful code +export const { FieldImpl } = dataSetup.indexPatterns!.__LEGACY; +export const { + FieldList, + flattenHitWrapper, + formatHitProvider, + indexPatterns, +} = dataSetup.indexPatterns!; // static code export { diff --git a/x-pack/legacy/plugins/apm/public/components/app/Home/Home.test.tsx b/x-pack/legacy/plugins/apm/public/components/app/Home/Home.test.tsx index f186258a49f89..ee27bd4ff7afb 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Home/Home.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Home/Home.test.tsx @@ -9,6 +9,8 @@ import React from 'react'; import { Home } from '../Home'; jest.mock('ui/kfetch'); +jest.mock('ui/index_patterns'); +jest.mock('ui/new_platform'); describe('Home component', () => { it('should render', () => { diff --git a/x-pack/legacy/plugins/apm/public/components/app/Main/__test__/UpdateBreadcrumbs.test.js b/x-pack/legacy/plugins/apm/public/components/app/Main/__test__/UpdateBreadcrumbs.test.js index 20d747d32afae..1c6be1d68c30a 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Main/__test__/UpdateBreadcrumbs.test.js +++ b/x-pack/legacy/plugins/apm/public/components/app/Main/__test__/UpdateBreadcrumbs.test.js @@ -11,6 +11,8 @@ import { UpdateBreadcrumbs } from '../UpdateBreadcrumbs'; import * as hooks from '../../../../hooks/useCore'; jest.mock('ui/kfetch'); +jest.mock('ui/index_patterns'); +jest.mock('ui/new_platform'); const coreMock = { chrome: { diff --git a/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.test.js b/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.test.js index 14973a1e86297..ab025290127e1 100644 --- a/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.test.js +++ b/x-pack/legacy/plugins/maps/public/elasticsearch_geo_utils.test.js @@ -5,6 +5,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import { hitsToGeoJson, From 9ee5a9cb3617c8717225d64e65b6e03448633485 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Fri, 16 Aug 2019 10:53:24 -0600 Subject: [PATCH 11/14] Clean up index pattern jest test. --- .../index_patterns/index_pattern.test.js | 32 ++++++++----------- .../index_patterns_api_client.test.js | 10 ------ 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js index c1724c1f184cb..b7fcb79da3269 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.test.js @@ -21,16 +21,10 @@ import _ from 'lodash'; import mockLogstashFields from '../../../../../../fixtures/logstash_fields'; import { stubbedSavedObjectIndexPattern } from '../../../../../../fixtures/stubbed_saved_object_index_pattern'; import { IndexedArray } from 'ui/indexed_array'; +import { DuplicateField } from 'ui/errors'; -import { createFieldsFetcher } from '../fields'; import { IndexPattern } from './index_pattern'; -jest.mock('../errors', () => ({ - SavedObjectNotFound: jest.fn(), - DuplicateField: jest.fn(), - IndexPatternMissingIndices: jest.fn(), -})); - jest.mock('ui/registry/field_formats', () => ({ fieldFormats: { getDefaultInstance: jest.fn(), @@ -60,14 +54,14 @@ jest.mock('ui/saved_objects', () => { }; }); -let fields = []; -jest.mock('../fields'); - -createFieldsFetcher.mockImplementation(() => ({ - fetch: jest.fn().mockImplementation(() => { - return new Promise(resolve => resolve(fields)); - }), - every: jest.fn(), +let mockFieldsFetcherResponse = []; +jest.mock('./_fields_fetcher', () => ({ + createFieldsFetcher: jest.fn().mockImplementation(() => ({ + fetch: jest.fn().mockImplementation(() => { + return new Promise(resolve => resolve(mockFieldsFetcherResponse)); + }), + every: jest.fn(), + })) })); let object; @@ -185,14 +179,14 @@ describe('IndexPattern', () => { it('should fetch fields from the fieldsFetcher', async function () { expect(indexPattern.fields.length).toBeGreaterThan(2); - fields = [ + mockFieldsFetcherResponse = [ { name: 'foo' }, { name: 'bar' } ]; - await indexPattern.refreshFields(); - fields = []; + + mockFieldsFetcherResponse = []; const newFields = indexPattern.getNonScriptedFields(); expect(newFields).toHaveLength(2); @@ -252,7 +246,7 @@ describe('IndexPattern', () => { try { await indexPattern.addScriptedField(scriptedField.name, '\'new script\'', 'string'); } catch (e) { - expect(e).toEqual({}); + expect(e).toBeInstanceOf(DuplicateField); } }); }); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js index dd3724ff202ae..bea4c6c489c9b 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.js @@ -20,16 +20,6 @@ import { http } from './index_patterns_api_client.test.mock'; import { IndexPatternsApiClient } from './index_patterns_api_client'; -jest.mock('../../errors', () => ({ - SavedObjectNotFound: jest.fn(), - DuplicateField: jest.fn(), - IndexPatternMissingIndices: jest.fn(), -})); - -jest.mock('../errors', () => ({ - IndexPatternMissingIndices: jest.fn(), -})); - describe('IndexPatternsApiClient', () => { it('uses the right URI to fetch fields for time patterns', async function () { const fetchSpy = jest.spyOn(http, 'fetch').mockImplementation(() => ({})); From 5108a4b03004d5e265d724afd8e74f49eb7ef693 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Fri, 16 Aug 2019 11:04:20 -0600 Subject: [PATCH 12/14] Fix remaining jest tests. --- .../public/components/editor/controls_tab.test.js | 1 + .../public/components/editor/list_control_editor.test.js | 1 + .../public/components/editor/range_control_editor.test.js | 1 + src/legacy/ui/public/index_patterns/__mocks__/index.ts | 7 +++++++ .../ui/public/indices/validate/validate_index.test.js | 1 + .../ui/public/value_suggestions/value_suggestions.test.ts | 1 + 6 files changed, 12 insertions(+) diff --git a/src/legacy/core_plugins/input_control_vis/public/components/editor/controls_tab.test.js b/src/legacy/core_plugins/input_control_vis/public/components/editor/controls_tab.test.js index 6e193b60e46e0..27f37421b0e25 100644 --- a/src/legacy/core_plugins/input_control_vis/public/components/editor/controls_tab.test.js +++ b/src/legacy/core_plugins/input_control_vis/public/components/editor/controls_tab.test.js @@ -18,6 +18,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import React from 'react'; import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; diff --git a/src/legacy/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js b/src/legacy/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js index 6121a509e6f38..96c0802d3772a 100644 --- a/src/legacy/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js +++ b/src/legacy/core_plugins/input_control_vis/public/components/editor/list_control_editor.test.js @@ -18,6 +18,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import React from 'react'; import sinon from 'sinon'; diff --git a/src/legacy/core_plugins/input_control_vis/public/components/editor/range_control_editor.test.js b/src/legacy/core_plugins/input_control_vis/public/components/editor/range_control_editor.test.js index 4d8e4fbdf8dd0..5a698d65286ac 100644 --- a/src/legacy/core_plugins/input_control_vis/public/components/editor/range_control_editor.test.js +++ b/src/legacy/core_plugins/input_control_vis/public/components/editor/range_control_editor.test.js @@ -18,6 +18,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import React from 'react'; import sinon from 'sinon'; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts index fc137f9f5d87c..f5719ae1f0b9a 100644 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -47,3 +47,10 @@ export { NoDefaultIndexPattern, NoDefinedIndexPatterns, } from '../../../../core_plugins/data/public'; + +/* eslint-disable @kbn/eslint/no-restricted-paths */ +export { + mockFields, + mockIndexPattern, +} from '../../../../core_plugins/data/public/index_patterns/index_patterns_service.mock'; +/* eslint-enable @kbn/eslint/no-restricted-paths */ diff --git a/src/legacy/ui/public/indices/validate/validate_index.test.js b/src/legacy/ui/public/indices/validate/validate_index.test.js index f81ba9d4bcab5..62a6c8610fd40 100644 --- a/src/legacy/ui/public/indices/validate/validate_index.test.js +++ b/src/legacy/ui/public/indices/validate/validate_index.test.js @@ -18,6 +18,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../constants'; diff --git a/src/legacy/ui/public/value_suggestions/value_suggestions.test.ts b/src/legacy/ui/public/value_suggestions/value_suggestions.test.ts index d6ae193c4929d..d6d0a7dc003e6 100644 --- a/src/legacy/ui/public/value_suggestions/value_suggestions.test.ts +++ b/src/legacy/ui/public/value_suggestions/value_suggestions.test.ts @@ -18,6 +18,7 @@ */ jest.mock('ui/new_platform'); +jest.mock('ui/index_patterns'); import { mockFields, mockIndexPattern } from 'ui/index_patterns'; import { getSuggestionsProvider } from './value_suggestions'; From ea39d1e67f5037285e543d0ed09f602f4a2a2ddc Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Fri, 16 Aug 2019 16:20:29 -0600 Subject: [PATCH 13/14] Move fixtures from .mock file to utils and export as static. --- src/legacy/core_plugins/data/public/index.ts | 2 + .../data/public/index_patterns/index.ts | 2 - .../index_patterns_service.mock.ts | 66 ------------------ .../index_patterns/index_patterns_service.ts | 2 + .../data/public/index_patterns/utils.ts | 69 ++++++++++++++++++- .../public/index_patterns/__mocks__/index.ts | 7 +- src/legacy/ui/public/index_patterns/index.ts | 9 +-- 7 files changed, 75 insertions(+), 82 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 8a8520e684124..7aab6ddbf23c3 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -63,4 +63,6 @@ export { IndexPatternMissingIndices, NoDefaultIndexPattern, NoDefinedIndexPatterns, + mockFields, + mockIndexPattern, } from './index_patterns'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index.ts index bb4238e9997b7..496c4ba7b5b6f 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index.ts @@ -18,5 +18,3 @@ */ export * from './index_patterns_service'; - -export { mockFields, mockIndexPattern } from './index_patterns_service.mock'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index 67d7d40c68c9c..47961ba76f472 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -63,69 +63,3 @@ export const indexPatternsServiceMock = { createSetupContract: createSetupContractMock, createStartContract: createSetupContractMock, }; - -export const mockFields: FieldType[] = [ - { - name: 'machine.os', - esTypes: ['text'], - type: 'string', - aggregatable: false, - searchable: false, - filterable: true, - }, - { - name: 'machine.os.raw', - type: 'string', - esTypes: ['keyword'], - aggregatable: true, - searchable: true, - filterable: true, - }, - { - name: 'not.filterable', - type: 'string', - esTypes: ['text'], - aggregatable: true, - searchable: false, - filterable: false, - }, - { - name: 'bytes', - type: 'number', - esTypes: ['long'], - aggregatable: true, - searchable: true, - filterable: true, - }, - { - name: '@timestamp', - type: 'date', - esTypes: ['date'], - aggregatable: true, - searchable: true, - filterable: true, - }, - { - name: 'clientip', - type: 'ip', - esTypes: ['ip'], - aggregatable: true, - searchable: true, - filterable: true, - }, - { - name: 'bool.field', - type: 'boolean', - esTypes: ['boolean'], - aggregatable: true, - searchable: true, - filterable: true, - }, -]; - -export const mockIndexPattern: StaticIndexPattern = { - id: 'logstash-*', - fields: mockFields, - title: 'logstash-*', - timeFieldName: '@timestamp', -}; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 3c5a8a14a8b69..8ecca8fa94a14 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -78,6 +78,8 @@ export { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, isFilterable, validateIndexPattern, + mockFields, + mockIndexPattern, } from './utils'; /** @public */ diff --git a/src/legacy/core_plugins/data/public/index_patterns/utils.ts b/src/legacy/core_plugins/data/public/index_patterns/utils.ts index 297ac1daad1a6..90a6554f399b8 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/utils.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/utils.ts @@ -21,7 +21,8 @@ import { get } from 'lodash'; // @ts-ignore import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types'; -import { Field } from './fields'; +import { Field, FieldType } from './fields'; +import { StaticIndexPattern } from './index_patterns'; export const ILLEGAL_CHARACTERS = 'ILLEGAL_CHARACTERS'; export const CONTAINS_SPACES = 'CONTAINS_SPACES'; @@ -97,3 +98,69 @@ export function getRoutes() { sourceFilters: '/management/kibana/index_patterns/{{id}}?_a=(tab:sourceFilters)', }; } + +export const mockFields: FieldType[] = [ + { + name: 'machine.os', + esTypes: ['text'], + type: 'string', + aggregatable: false, + searchable: false, + filterable: true, + }, + { + name: 'machine.os.raw', + type: 'string', + esTypes: ['keyword'], + aggregatable: true, + searchable: true, + filterable: true, + }, + { + name: 'not.filterable', + type: 'string', + esTypes: ['text'], + aggregatable: true, + searchable: false, + filterable: false, + }, + { + name: 'bytes', + type: 'number', + esTypes: ['long'], + aggregatable: true, + searchable: true, + filterable: true, + }, + { + name: '@timestamp', + type: 'date', + esTypes: ['date'], + aggregatable: true, + searchable: true, + filterable: true, + }, + { + name: 'clientip', + type: 'ip', + esTypes: ['ip'], + aggregatable: true, + searchable: true, + filterable: true, + }, + { + name: 'bool.field', + type: 'boolean', + esTypes: ['boolean'], + aggregatable: true, + searchable: true, + filterable: true, + }, +]; + +export const mockIndexPattern: StaticIndexPattern = { + id: 'logstash-*', + fields: mockFields, + title: 'logstash-*', + timeFieldName: '@timestamp', +}; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts index f5719ae1f0b9a..9a8cf48ce7935 100644 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -46,11 +46,6 @@ export { IndexPatternMissingIndices, NoDefaultIndexPattern, NoDefinedIndexPatterns, -} from '../../../../core_plugins/data/public'; - -/* eslint-disable @kbn/eslint/no-restricted-paths */ -export { mockFields, mockIndexPattern, -} from '../../../../core_plugins/data/public/index_patterns/index_patterns_service.mock'; -/* eslint-enable @kbn/eslint/no-restricted-paths */ +} from '../../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 737ed70300e49..75b03dc13bb62 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -26,13 +26,6 @@ import { setup as data } from '../../../core_plugins/data/public/legacy'; -/* eslint-disable @kbn/eslint/no-restricted-paths */ -export { - mockFields, - mockIndexPattern, -} from '../../../core_plugins/data/public/index_patterns/index_patterns_service.mock'; -/* eslint-enable @kbn/eslint/no-restricted-paths */ - export const { FieldList, // only used in Discover and StubIndexPattern flattenHitWrapper, @@ -55,6 +48,8 @@ export { IndexPatternMissingIndices, NoDefaultIndexPattern, NoDefinedIndexPatterns, + mockFields, + mockIndexPattern, } from '../../../core_plugins/data/public'; // types From 75cf7324fe0aac48dac31babd22e728362017d59 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 19 Aug 2019 12:36:31 -0600 Subject: [PATCH 14/14] Fix tslint failure. --- .../data/public/index_patterns/index_patterns_service.mock.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts index 47961ba76f472..d4e5cc011d5f3 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -18,8 +18,6 @@ */ import { IndexPatternsService, IndexPatternsSetup } from '.'; -import { FieldType } from './fields'; -import { StaticIndexPattern } from './index_patterns'; // @ts-ignore import { flattenHitWrapper } from './index_patterns/flatten_hit';