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/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/ui/public/index_patterns/get_routes.ts b/src/legacy/core_plugins/data/public/filter/filter_service.mock.ts similarity index 54% rename from src/legacy/ui/public/index_patterns/get_routes.ts rename to src/legacy/core_plugins/data/public/filter/filter_service.mock.ts index 52d42ea204532..bcd7ab7f40e6b 100644 --- a/src/legacy/ui/public/index_patterns/get_routes.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_service.mock.ts @@ -17,12 +17,31 @@ * 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)', +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.ts b/src/legacy/core_plugins/data/public/index.ts index db3663590b5ac..7aab6ddbf23c3 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -29,18 +29,40 @@ 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, + IndexPatternSelect, + IndexPatternsProvider, // LEGACY + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, + IndexPatternAlreadyExists, + IndexPatternMissingIndices, + NoDefaultIndexPattern, + NoDefinedIndexPatterns, + mockFields, + mockIndexPattern, +} from './index_patterns'; 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 79% 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 index e8e5f8c08278f..62d4983bfbf03 100644 --- 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 @@ -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/ui/public/index_patterns/errors.ts b/src/legacy/core_plugins/data/public/index_patterns/errors.ts similarity index 98% rename from src/legacy/ui/public/index_patterns/errors.ts rename to src/legacy/core_plugins/data/public/index_patterns/errors.ts index 31d632ae5c5dd..df7f26ad6673d 100644 --- a/src/legacy/ui/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/ui/public/index_patterns/_field.ts b/src/legacy/core_plugins/data/public/index_patterns/fields/field.ts similarity index 91% 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..7d19db5595ea6 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 { @@ -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/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/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..1644e23a163a6 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,5 @@ * under the License. */ -export { - ILLEGAL_CHARACTERS, - CONTAINS_SPACES, - validateIndexPattern, -} from './validate_index_pattern'; +export * from './field_list'; +export * from './field'; 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..496c4ba7b5b6f 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,4 @@ * under the License. */ -export { - IndexPatternsService, - IndexPatterns, - fixtures, - utils, - // types - IndexPatternsSetup, - IndexPattern, - StaticIndexPattern, - Field, - FieldType, -} from './index_patterns_service'; +export * from './index_patterns_service'; 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/fields_fetcher.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts similarity index 96% rename from src/legacy/ui/public/index_patterns/fields_fetcher.ts rename to src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts index ff1d9207e5092..c61df91cb8d1b 100644 --- a/src/legacy/ui/public/index_patterns/fields_fetcher.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts @@ -17,9 +17,10 @@ * under the License. */ +import { IndexPattern } from './index_pattern'; import { GetFieldsOptions, IndexPatternsApiClient } from './index_patterns_api_client'; -import { IndexPattern } from './_index_pattern'; +/** @internal */ export const createFieldsFetcher = ( indexPattern: IndexPattern, apiClient: IndexPatternsApiClient, 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/_flatten_hit.js b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/flatten_hit.js similarity index 79% 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 index f034b746bf803..b9d25dc0ccb41 100644 --- a/src/legacy/ui/public/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/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..31ff03d51f97a 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,9 @@ * under the License. */ -export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = ['\\', '/', '?', '"', '<', '>', '|']; -export const INDEX_PATTERN_ILLEGAL_CHARACTERS = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.concat( - ' ' -); +// @ts-ignore +export * from './flatten_hit'; +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 90% 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..b7fcb79da3269 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,20 @@ */ 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'; - -jest.mock('../../errors', () => ({ - SavedObjectNotFound: jest.fn(), - DuplicateField: jest.fn(), - IndexPatternMissingIndices: jest.fn(), -})); - -jest.mock('../errors', () => ({ - IndexPatternMissingIndices: jest.fn(), -})); +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 { IndexPattern } from './index_pattern'; -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,27 +41,27 @@ 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'); - -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; @@ -189,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); @@ -256,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/ui/public/index_patterns/_index_pattern.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.ts similarity index 96% 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..6a4cf6fe45390 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,15 @@ 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'; -// @ts-ignore -import { flattenHitWrapper } from './_flatten_hit'; + +import { IndexPatternMissingIndices } from '../errors'; +import { Field, FieldList, FieldType } from '../fields'; +import { createFieldsFetcher } from './_fields_fetcher'; +import { getRoutes } from '../utils'; +import { formatHitProvider } from './format_hit'; // @ts-ignore -import { formatHitProvider } from './_format_hit'; +import { flattenHitWrapper } from './flatten_hit'; +import { IndexPatternsApiClient } from './index_patterns_api_client'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -455,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.', @@ -505,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/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 96% 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..b121a7667c79b 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,11 +24,12 @@ 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(); @@ -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; 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 87% 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..bea4c6c489c9b 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,18 +17,8 @@ * under the License. */ -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(), -})); +import { http } from './index_patterns_api_client.test.mock'; +import { IndexPatternsApiClient } from './index_patterns_api_client'; describe('IndexPatternsApiClient', () => { it('uses the right URI to fetch fields for time patterns', async function () { 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/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 new file mode 100644 index 0000000000000..d4e5cc011d5f3 --- /dev/null +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.mock.ts @@ -0,0 +1,63 @@ +/* + * 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 { IndexPatternsService, IndexPatternsSetup } from '.'; +// @ts-ignore +import { flattenHitWrapper } from './index_patterns/flatten_hit'; + +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().mockImplementation(flattenHitWrapper), + formatHitProvider: jest.fn(), + indexPatterns: jest.fn() as any, + 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(), + }, + }; + + 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, +}; 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..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 @@ -16,25 +16,18 @@ * 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 { Field, FieldList, FieldType } from './fields'; +// @ts-ignore +import { createFlattenHitWrapper } from './index_patterns/flatten_hit'; +import { createIndexPatternSelect } from './components'; +import { + formatHitProvider, + IndexPattern, + IndexPatterns, + StaticIndexPattern, +} from './index_patterns'; export interface IndexPatternDependencies { uiSettings: UiSettingsClientContract; @@ -44,60 +37,75 @@ 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 { + FieldList, + flattenHitWrapper: createFlattenHitWrapper(), + formatHitProvider, indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), + 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, + }, }; } + public start() { + // nothing to do here yet + } + public stop() { // nothing to do here yet } } -// static exports +// static code -const constants = { +/** @public */ +export { IndexPatternSelect } from './components'; +export { IndexPatternsProvider } from './index_patterns'; +export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, -}; - -const fixtures = { + isFilterable, + validateIndexPattern, mockFields, mockIndexPattern, -}; +} 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/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/core_plugins/data/public/index_patterns/utils.ts b/src/legacy/core_plugins/data/public/index_patterns/utils.ts new file mode 100644 index 0000000000000..90a6554f399b8 --- /dev/null +++ b/src/legacy/core_plugins/data/public/index_patterns/utils.ts @@ -0,0 +1,166 @@ +/* + * 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, FieldType } from './fields'; +import { StaticIndexPattern } from './index_patterns'; + +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( + (chars: string[], char: string) => { + if (indexPattern.includes(char)) { + chars.push(char); + } + return chars; + }, + [] + ); + + return illegalCharacters; +} + +function indexPatternContainsSpaces(indexPattern: string): boolean { + return indexPattern.includes(' '); +} + +export function validateIndexPattern(indexPattern: string) { + const errors: Record = {}; + + const illegalCharacters = findIllegalCharacters(indexPattern); + + if (illegalCharacters.length) { + errors[ILLEGAL_CHARACTERS] = illegalCharacters; + } + + if (indexPatternContainsSpaces(indexPattern)) { + errors[CONTAINS_SPACES] = true; + } + + 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)', + }; +} + +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/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/query/query_bar/lib/fetch_index_patterns.ts b/src/legacy/core_plugins/data/public/query/query_bar/lib/fetch_index_patterns.ts index 5796623e31f53..cc7057d06c30c 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/lib/fetch_index_patterns.ts +++ b/src/legacy/core_plugins/data/public/query/query_bar/lib/fetch_index_patterns.ts @@ -19,8 +19,9 @@ import chrome from 'ui/chrome'; import { isEmpty } from 'lodash'; + import { UiSettingsClientContract } from 'src/core/public'; -import { utils as indexPatternUtils } from '../../../index_patterns'; +import { getFromSavedObject } from '../../../index_patterns'; export async function fetchIndexPatterns( indexPatternStrings: string[], @@ -49,7 +50,7 @@ export async function fetchIndexPatterns( ? exactMatches : [...exactMatches, await fetchDefaultIndexPattern(defaultIndex)]; - return allMatches.map(indexPatternUtils.getFromSavedObject); + return allMatches.map(getFromSavedObject); } const fetchDefaultIndexPattern = async (defaultIndex: string) => { diff --git a/src/legacy/ui/public/index_patterns/static_utils/index.ts b/src/legacy/core_plugins/data/public/query/query_service.mock.ts similarity index 52% rename from src/legacy/ui/public/index_patterns/static_utils/index.ts rename to src/legacy/core_plugins/data/public/query/query_service.mock.ts index 7131ea300b97c..19a00632ca192 100644 --- a/src/legacy/ui/public/index_patterns/static_utils/index.ts +++ b/src/legacy/core_plugins/data/public/query/query_service.mock.ts @@ -17,32 +17,35 @@ * under the License. */ -// @ts-ignore -import { get } from 'lodash'; -// @ts-ignore -import { KBN_FIELD_TYPES } from '../../../../utils/kbn_field_types'; -import { Field } from '../_field'; +import { QueryService, QuerySetup } from '.'; -const filterableTypes = KBN_FIELD_TYPES.filter((type: any) => type.filterable).map( - (type: any) => type.name -); +type QueryServiceClientContract = PublicMethodsOf; -export function isFilterable(field: Field): boolean { - return ( - field.name === '_id' || - field.scripted || - (field.searchable && filterableTypes.includes(field.type)) - ); -} +const createSetupContractMock = () => { + const setupContract: jest.Mocked = { + helpers: { + fromUser: jest.fn(), + toUser: jest.fn(), + getQueryLog: jest.fn(), + }, + }; -export function getFromSavedObject(savedObject: any) { - if (get(savedObject, 'attributes.fields') === undefined) { - return; - } + return setupContract; +}; - return { - id: savedObject.id, - fields: JSON.parse(savedObject.attributes.fields), - title: savedObject.attributes.title, +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/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/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/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..bd242aefc8f42 100644 --- a/src/legacy/ui/public/courier/courier.js +++ b/src/legacy/ui/public/courier/courier.js @@ -23,7 +23,6 @@ import { timefilter } from 'ui/timefilter'; import '../es'; import '../directives/listen'; -import '../index_patterns'; import { uiModules } from '../modules'; import { addFatalErrorCallback } from '../notify'; import '../promises'; diff --git a/src/legacy/ui/public/courier/search_source/__tests__/search_source.js b/src/legacy/ui/public/courier/search_source/__tests__/search_source.js index 8297c751da5fe..727463bc8b86b 100644 --- a/src/legacy/ui/public/courier/search_source/__tests__/search_source.js +++ b/src/legacy/ui/public/courier/search_source/__tests__/search_source.js @@ -45,8 +45,8 @@ describe('SearchSource', function () { SearchSource = Private(SearchSourceProvider); const IndexPattern = Private(StubIndexPatternProv); - indexPattern = new IndexPattern('test-*', null, []); - indexPattern2 = new IndexPattern('test2-*', null, []); + indexPattern = new IndexPattern('test-*', cfg => 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/validate/validate_index_pattern.test.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts similarity index 54% rename from src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts rename to src/legacy/ui/public/index_patterns/__mocks__/index.ts index cfd4049c1398d..9a8cf48ce7935 100644 --- a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.test.ts +++ b/src/legacy/ui/public/index_patterns/__mocks__/index.ts @@ -17,28 +17,35 @@ * under the License. */ -import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../constants'; +import { dataPluginMock } from '../../../../core_plugins/data/public/mocks'; -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); - }); +const dataSetup = dataPluginMock.createSetup(); - it('should not allow illegal characters', () => { - INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.forEach(char => { - const errors = validateIndexPattern(`pattern${char}`); - expect(errors[ILLEGAL_CHARACTERS]).toEqual([char]); - }); - }); +// mocks for stateful code +export const { FieldImpl } = dataSetup.indexPatterns!.__LEGACY; +export const { + FieldList, + flattenHitWrapper, + formatHitProvider, + indexPatterns, +} = dataSetup.indexPatterns!; - it('should return empty object when there are no errors', () => { - expect(validateIndexPattern('my-pattern-*')).toEqual({}); - }); -}); +// static code +export { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + isFilterable, + IndexPatternsProvider, // LEGACY + IndexPatternSelect, + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, + IndexPatternAlreadyExists, + IndexPatternMissingIndices, + NoDefaultIndexPattern, + NoDefinedIndexPatterns, + mockFields, + mockIndexPattern, +} from '../../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/fixtures/index.ts b/src/legacy/ui/public/index_patterns/fixtures/index.ts deleted file mode 100644 index 5c79d7f99f842..0000000000000 --- a/src/legacy/ui/public/index_patterns/fixtures/index.ts +++ /dev/null @@ -1,87 +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 { FieldType } from '../_field'; -import { StaticIndexPattern } from '../_index_pattern'; - -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/index.ts b/src/legacy/ui/public/index_patterns/index.ts index 51ba546ae4c80..75b03dc13bb62 100644 --- a/src/legacy/ui/public/index_patterns/index.ts +++ b/src/legacy/ui/public/index_patterns/index.ts @@ -17,31 +17,46 @@ * 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'; - -export { - INDEX_PATTERN_ILLEGAL_CHARACTERS, - INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, -} from './constants'; +/** + * 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 { validateIndexPattern, CONTAINS_SPACES, ILLEGAL_CHARACTERS } from './validate'; +import { setup as data } from '../../../core_plugins/data/public/legacy'; -export { getRoutes } from './get_routes'; -export { formatHitProvider } from './_format_hit'; -// @ts-ignore -export { flattenHitWrapper } from './_flatten_hit.js'; +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 { + CONTAINS_SPACES, + getFromSavedObject, + getRoutes, + isFilterable, + IndexPatternsProvider, // LEGACY + validateIndexPattern, + ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, IndexPatternAlreadyExists, IndexPatternMissingIndices, - NoDefinedIndexPatterns, NoDefaultIndexPattern, -} from './errors'; - -export { mockFields, mockIndexPattern } from './fixtures'; + NoDefinedIndexPatterns, + mockFields, + mockIndexPattern, +} from '../../../core_plugins/data/public'; -export { getFromSavedObject, isFilterable } from './static_utils'; +// types +export { + Field, + FieldType, + IndexPattern, + IndexPatterns, + StaticIndexPattern, +} from '../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts b/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts deleted file mode 100644 index cca38b7a33264..0000000000000 --- a/src/legacy/ui/public/index_patterns/validate/validate_index_pattern.ts +++ /dev/null @@ -1,57 +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'; - -export const ILLEGAL_CHARACTERS = 'ILLEGAL_CHARACTERS'; -export const CONTAINS_SPACES = 'CONTAINS_SPACES'; - -function findIllegalCharacters(indexPattern: string): string[] { - const illegalCharacters = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.reduce( - (chars: string[], char: string) => { - if (indexPattern.includes(char)) { - chars.push(char); - } - return chars; - }, - [] - ); - - return illegalCharacters; -} - -function indexPatternContainsSpaces(indexPattern: string): boolean { - return indexPattern.includes(' '); -} - -export function validateIndexPattern(indexPattern: string) { - const errors: Record = {}; - - const illegalCharacters = findIllegalCharacters(indexPattern); - - if (illegalCharacters.length) { - errors[ILLEGAL_CHARACTERS] = illegalCharacters; - } - - if (indexPatternContainsSpaces(indexPattern)) { - errors[CONTAINS_SPACES] = true; - } - - return errors; -} 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/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/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'; 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); 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/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/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, 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); 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": "关闭",