diff --git a/src/legacy/core_plugins/data/public/index_patterns/static.ts b/src/legacy/core_plugins/data/public/index_patterns/static.ts deleted file mode 100644 index d0e15330e04c2..0000000000000 --- a/src/legacy/core_plugins/data/public/index_patterns/static.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -export const foo = () => false; -export { - // types - IndexPatternsSetup, - StaticIndexPattern, - StaticIndexPatternField, - Field, -} from './index_patterns_service'; diff --git a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header/helpers.tsx b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header/helpers.tsx index d98d16e971761..ddf960091d476 100644 --- a/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header/helpers.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/doc_table/components/table_header/helpers.tsx @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + import { IndexPattern } from 'ui/index_patterns'; // @ts-ignore import { shortenDottedString } from '../../../../../common/utils/shorten_dotted_string'; diff --git a/src/legacy/core_plugins/kibana_react/public/search_bar/components/search_bar.test.tsx b/src/legacy/core_plugins/kibana_react/public/search_bar/components/search_bar.test.tsx index ceaa72dae758b..bd00e35a40491 100644 --- a/src/legacy/core_plugins/kibana_react/public/search_bar/components/search_bar.test.tsx +++ b/src/legacy/core_plugins/kibana_react/public/search_bar/components/search_bar.test.tsx @@ -20,6 +20,7 @@ import React from 'react'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; import { SearchBar } from './search_bar'; +import { IndexPattern } from 'ui/index_patterns'; jest.mock('../../../../data/public', () => { return { diff --git a/src/legacy/ui/public/index_patterns/_field.ts b/src/legacy/ui/public/index_patterns/_field.ts index 8ae4f0c0ac42c..d4017a1e43e26 100644 --- a/src/legacy/ui/public/index_patterns/_field.ts +++ b/src/legacy/ui/public/index_patterns/_field.ts @@ -44,6 +44,8 @@ export interface FieldType { aggregatable?: boolean; filterable?: boolean; searchable?: boolean; + sortable?: boolean; + visualizable?: boolean; readFromDocValues?: boolean; scripted?: boolean; parent?: string; @@ -64,6 +66,8 @@ export class Field implements FieldType { aggregatable?: boolean; filterable?: boolean; searchable?: boolean; + sortable?: boolean; + visualizable?: boolean; scripted?: boolean; parent?: string; subType?: string; diff --git a/src/legacy/ui/public/index_patterns/_field_list.ts b/src/legacy/ui/public/index_patterns/_field_list.ts index 2342db5c1df89..0fc945dbab608 100644 --- a/src/legacy/ui/public/index_patterns/_field_list.ts +++ b/src/legacy/ui/public/index_patterns/_field_list.ts @@ -22,7 +22,7 @@ import { IndexPattern } from 'ui/index_patterns/_index_pattern'; import { Field, FieldSpec } from './_field'; export class FieldList extends IndexedArray { - constructor(indexPattern: IndexPattern, specs: FieldSpec[], shortDotsEnable: boolean = false) { + constructor(indexPattern: IndexPattern, specs: FieldSpec[], shortDotsEnable = false) { super({ index: ['name'], group: ['type'], diff --git a/src/legacy/ui/public/index_patterns/_get.js b/src/legacy/ui/public/index_patterns/_get.js deleted file mode 100644 index b3c723d09890d..0000000000000 --- a/src/legacy/ui/public/index_patterns/_get.js +++ /dev/null @@ -1,69 +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 _ from 'lodash'; - -export function indexPatternsGetProvider(savedObjectsClient) { - - // many places may require the id list, so we will cache it separately - // didn't incorporate with the indexPattern cache to prevent id collisions. - let cachedIdPromise; - - const get = function (field) { - if (field === 'id' && cachedIdPromise) { - // return a clone of the cached response - return cachedIdPromise.then(function (cachedResp) { - return _.clone(cachedResp); - }); - } - - const promise = savedObjectsClient.find({ - type: 'index-pattern', - fields: [], - perPage: 10000 - }).then(resp => { - return resp.savedObjects.map(obj => _.get(obj, field)); - }); - - if (field === 'id') { - cachedIdPromise = promise; - } - - // ensure that the response stays pristine by cloning it here too - return promise.then(function (resp) { - return _.clone(resp); - }); - }; - - const retFunction = (field) => { - const getter = get.bind(get, field); - if (field === 'id') { - getter.clearCache = function () { - cachedIdPromise = null; - }; - } - return getter; - }; - - retFunction.multiple = async fields => { - return (await savedObjectsClient.find({ type: 'index-pattern', fields, perPage: 10000 })).savedObjects; - }; - - return retFunction; -} diff --git a/src/legacy/ui/public/index_patterns/_index_pattern.ts b/src/legacy/ui/public/index_patterns/_index_pattern.ts index 95cf7045a4186..09623f75442ed 100644 --- a/src/legacy/ui/public/index_patterns/_index_pattern.ts +++ b/src/legacy/ui/public/index_patterns/_index_pattern.ts @@ -59,16 +59,6 @@ export interface StaticIndexPattern { timeFieldName?: string; } -export const createIndexPatternMock = (params: Record): StaticIndexPattern => { - return { - ...params, - id: params.id || 'testIndexPattern', - title: params.title || 'testIndexPattern', - type: params.type, - fields: params.fields || [], - }; -}; - export class IndexPattern implements StaticIndexPattern { [key: string]: any; @@ -354,7 +344,7 @@ export class IndexPattern implements StaticIndexPattern { return this.fields.byName[this.timeFieldName]; } - getFieldByName(name: string) { + getFieldByName(name: string): Field | void { if (!this.fields || !this.fields.byName) return; return this.fields.byName[name]; } diff --git a/src/legacy/ui/public/index_patterns/_pattern_cache.ts b/src/legacy/ui/public/index_patterns/_pattern_cache.ts index a846fcd5d9f9b..56c19f625f10a 100644 --- a/src/legacy/ui/public/index_patterns/_pattern_cache.ts +++ b/src/legacy/ui/public/index_patterns/_pattern_cache.ts @@ -17,9 +17,11 @@ * under the License. */ +import { IndexPattern } from './index'; + export interface PatternCache { - get: (id: string) => any; - set: (id: string, value: any) => any; + get: (id: string) => IndexPattern; + set: (id: string, value: Promise) => Promise; clear: (id: string) => void; clearAll: () => void; } diff --git a/src/legacy/ui/public/index_patterns/index_patterns.ts b/src/legacy/ui/public/index_patterns/index_patterns.ts index 055cff0ca97a5..6f22c1c2a73ea 100644 --- a/src/legacy/ui/public/index_patterns/index_patterns.ts +++ b/src/legacy/ui/public/index_patterns/index_patterns.ts @@ -41,7 +41,7 @@ export class IndexPatterns { this.savedObjectsClient = savedObjectsClient; } - private async loadSavedObjects() { + private async refreshSavedObjectsCache() { this.savedObjectsCache = (await this.savedObjectsClient.find({ type: 'index-pattern', fields: [], @@ -51,7 +51,7 @@ export class IndexPatterns { getIds = async (refresh: boolean) => { if (!this.savedObjectsCache || refresh) { - await this.loadSavedObjects(); + await this.refreshSavedObjectsCache(); } if (this.savedObjectsCache) { return this.savedObjectsCache.map(obj => _.get(obj, 'id')); @@ -60,7 +60,7 @@ export class IndexPatterns { getTitles = async (refresh: boolean) => { if (!this.savedObjectsCache || refresh) { - await this.loadSavedObjects(); + await this.refreshSavedObjectsCache(); } if (this.savedObjectsCache) { return this.savedObjectsCache.map(obj => _.get(obj, 'attributes.title')); @@ -69,7 +69,7 @@ export class IndexPatterns { getFields = async (fields: string[], refresh: boolean) => { if (!this.savedObjectsCache || refresh) { - await this.loadSavedObjects(); + await this.refreshSavedObjectsCache(); } if (this.savedObjectsCache) { return this.savedObjectsCache.map(obj => { @@ -105,7 +105,7 @@ export class IndexPatterns { return cache || indexPatternCache.set(id, this.make(id)); }; - make = (id?: string) => { + make = (id?: string): Promise => { return new IndexPattern( id, (cfg: any) => this.config.get(cfg),