diff --git a/src/legacy/core_plugins/data/public/filter/filter_manager/filter_manager.test.ts b/src/legacy/core_plugins/data/public/filter/filter_manager/filter_manager.test.ts index 2bb12de316417..a6700dc37e8d8 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_manager/filter_manager.test.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_manager/filter_manager.test.ts @@ -64,7 +64,10 @@ describe('filter_manager', () => { appStateStub = new StubState(); globalStateStub = new StubState(); indexPatterns = new StubIndexPatterns(); - filterManager = new FilterManager(indexPatterns as IndexPatterns, setupMock.uiSettings); + filterManager = new FilterManager( + (indexPatterns as unknown) as IndexPatterns, + setupMock.uiSettings + ); readyFilters = getFiltersArray(); // FilterStateManager is tested indirectly. diff --git a/src/legacy/core_plugins/data/public/filter/filter_manager/filter_state_manager.test.ts b/src/legacy/core_plugins/data/public/filter/filter_manager/filter_state_manager.test.ts index 4232d08549ddc..a4345018aa830 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_manager/filter_state_manager.test.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_manager/filter_state_manager.test.ts @@ -53,7 +53,10 @@ describe('filter_state_manager', () => { appStateStub = new StubState(); globalStateStub = new StubState(); const indexPatterns = new StubIndexPatterns(); - filterManager = new FilterManager(indexPatterns as IndexPatterns, setupMock.uiSettings); + filterManager = new FilterManager( + (indexPatterns as unknown) as IndexPatterns, + setupMock.uiSettings + ); }); describe('app_state_undefined', () => { diff --git a/src/legacy/core_plugins/data/public/filter/filter_manager/test_helpers/stub_index_pattern.ts b/src/legacy/core_plugins/data/public/filter/filter_manager/test_helpers/stub_index_pattern.ts index 9a4f457fa9f91..4047260b69501 100644 --- a/src/legacy/core_plugins/data/public/filter/filter_manager/test_helpers/stub_index_pattern.ts +++ b/src/legacy/core_plugins/data/public/filter/filter_manager/test_helpers/stub_index_pattern.ts @@ -18,7 +18,7 @@ */ export class StubIndexPatterns { - async get(index: any) { + async get(index: string) { return { fields: { byName: {}, diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 7f745e1646284..9c95ef7a82ab8 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -54,7 +54,6 @@ export { getRoutes, isFilterable, IndexPatternSelect, - IndexPatternsProvider, // LEGACY validateIndexPattern, ILLEGAL_CHARACTERS, INDEX_PATTERN_ILLEGAL_CHARACTERS, diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts index 014a2bbd83702..f47cd000b7ba0 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/_fields_fetcher.ts @@ -18,12 +18,12 @@ */ import { IndexPattern } from './index_pattern'; -import { GetFieldsOptions, IndexPatternsApiClient } from './index_patterns_api_client'; +import { GetFieldsOptions, IIndexPatternsApiClient } from './index_patterns_api_client'; /** @internal */ export const createFieldsFetcher = ( indexPattern: IndexPattern, - apiClient: IndexPatternsApiClient, + apiClient: IIndexPatternsApiClient, metaFields: string ) => { const fieldFetcher = { diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx index ec1005bdce261..2bb05c5d32934 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_pattern.tsx @@ -39,7 +39,7 @@ import { createFieldsFetcher } from './_fields_fetcher'; import { getRoutes } from '../utils'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; -import { IndexPatternsApiClient } from './index_patterns_api_client'; +import { IIndexPatternsApiClient } from './index_patterns_api_client'; const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3; const type = 'index-pattern'; @@ -113,7 +113,7 @@ export class IndexPattern implements StaticIndexPattern { id: string | undefined, getConfig: any, savedObjectsClient: SavedObjectsClientContract, - apiClient: IndexPatternsApiClient, + apiClient: IIndexPatternsApiClient, patternCache: any ) { this.id = id; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts index 8fc5c89e5d17c..9330fb312c225 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts @@ -19,7 +19,11 @@ // eslint-disable-next-line max-classes-per-file import { IndexPatterns } from './index_patterns'; -import { SavedObjectsClientContract, UiSettingsClientContract } from 'kibana/public'; +import { + SavedObjectsClientContract, + UiSettingsClientContract, + HttpServiceBase, +} from 'kibana/public'; jest.mock('../errors', () => ({ IndexPatternMissingIndices: jest.fn(), @@ -65,12 +69,9 @@ describe('IndexPatterns', () => { beforeEach(() => { const savedObjectsClient = {} as SavedObjectsClientContract; const uiSettings = {} as UiSettingsClientContract; + const http = {} as HttpServiceBase; - indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient); - }); - - test('does not cache gets without an id', () => { - expect(indexPatterns.get()).not.toBe(indexPatterns.get()); + indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http); }); test('does cache gets for the same id', () => { diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts index b121a7667c79b..d4435b6bdd66c 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -22,6 +22,7 @@ import { SavedObjectsClientContract, SimpleSavedObject, UiSettingsClientContract, + HttpServiceBase, } from 'src/core/public'; // @ts-ignore import { fieldFormats } from 'ui/registry/field_formats'; @@ -31,7 +32,6 @@ import { IndexPattern } from './index_pattern'; import { IndexPatternsApiClient } from './index_patterns_api_client'; const indexPatternCache = createIndexPatternCache(); -const apiClient = new IndexPatternsApiClient(); export class IndexPatterns { fieldFormats: fieldFormats; @@ -39,8 +39,15 @@ export class IndexPatterns { private config: UiSettingsClientContract; private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array>> | null; + private apiClient: IndexPatternsApiClient; + + constructor( + config: UiSettingsClientContract, + savedObjectsClient: SavedObjectsClientContract, + http: HttpServiceBase + ) { + this.apiClient = new IndexPatternsApiClient(http); - constructor(config: UiSettingsClientContract, savedObjectsClient: SavedObjectsClientContract) { this.config = config; this.savedObjectsClient = savedObjectsClient; } @@ -105,9 +112,7 @@ export class IndexPatterns { return null; }; - get = (id?: string) => { - if (!id) return this.make(); - + get = (id: string) => { const cache = indexPatternCache.get(id); return cache || indexPatternCache.set(id, this.make(id)); }; @@ -117,27 +122,8 @@ export class IndexPatterns { id, (cfg: any) => this.config.get(cfg), this.savedObjectsClient, - apiClient, + this.apiClient, indexPatternCache ).init(); }; } - -// add angular service for backward compatibility -// @ts-ignore -// eslint-disable-next-line -import { uiModules } from 'ui/modules'; - -const module = uiModules.get('kibana/index_patterns'); -let _service: any; -module.service('indexPatterns', function(chrome: any) { - if (!_service) - _service = new IndexPatterns(chrome.getUiSettingsClient(), chrome.getSavedObjectsClient()); - return _service; -}); - -export const IndexPatternsProvider = (chrome: any) => { - if (!_service) - _service = new IndexPatterns(chrome.getUiSettingsClient(), chrome.getSavedObjectsClient()); - return _service; -}; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts index 944108e1501f1..7af31006ab372 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts @@ -20,21 +20,13 @@ import { http } from './index_patterns_api_client.test.mock'; import { IndexPatternsApiClient } from './index_patterns_api_client'; -const requestData = { - credentials: 'same-origin', - headers: { 'Content-Type': 'application/json' }, - method: 'GET', - prependBasePath: true, - query: {}, -}; - describe('IndexPatternsApiClient', () => { let fetchSpy: jest.Mock; let indexPatternsApiClient: IndexPatternsApiClient; beforeEach(() => { fetchSpy = jest.spyOn(http, 'fetch').mockImplementation(() => Promise.resolve({})); - indexPatternsApiClient = new IndexPatternsApiClient(); + indexPatternsApiClient = new IndexPatternsApiClient(http); }); test('uses the right URI to fetch fields for time patterns', async function() { @@ -42,7 +34,7 @@ describe('IndexPatternsApiClient', () => { await indexPatternsApiClient.getFieldsForTimePattern(); - expect(fetchSpy).toHaveBeenCalledWith(expectedPath, requestData); + expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); }); test('uses the right URI to fetch fields for wildcard', async function() { @@ -50,7 +42,7 @@ describe('IndexPatternsApiClient', () => { await indexPatternsApiClient.getFieldsForWildcard(); - expect(fetchSpy).toHaveBeenCalledWith(expectedPath, requestData); + expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); }); test('uses the right URI to fetch fields for wildcard given a type', async function() { @@ -58,6 +50,6 @@ describe('IndexPatternsApiClient', () => { await indexPatternsApiClient.getFieldsForWildcard({ type: 'rollup' }); - expect(fetchSpy).toHaveBeenCalledWith(expectedPath, requestData); + expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); }); }); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts index 4b0d7ec08347b..c0e8516a75bb3 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts @@ -17,24 +17,9 @@ * under the License. */ -import { kfetch, KFetchQuery } from 'ui/kfetch'; - +import { HttpServiceBase } from 'src/core/public'; import { IndexPatternMissingIndices } from '../errors'; -function request(url: string, query: KFetchQuery) { - return kfetch({ - method: 'GET', - pathname: url, - query, - }).catch(resp => { - if (resp.body.statusCode === 404 && resp.body.statuscode === 'no_matching_indices') { - throw new IndexPatternMissingIndices(resp.body.message); - } - - throw new Error(resp.body.message || resp.body.error || `${resp.body.statusCode} Response`); - }); -} - const API_BASE_URL: string = `/api/index_patterns/`; export interface GetFieldsOptions { @@ -45,8 +30,28 @@ export interface GetFieldsOptions { metaFields?: string; } +export type IIndexPatternsApiClient = PublicMethodsOf; + export class IndexPatternsApiClient { - constructor() {} + private http: HttpServiceBase; + + constructor(http: HttpServiceBase) { + this.http = http; + } + + private _request(url: string, query: any) { + return this.http + .fetch(url, { + query, + }) + .catch((resp: any) => { + if (resp.body.statusCode === 404 && resp.body.statuscode === 'no_matching_indices') { + throw new IndexPatternMissingIndices(resp.body.message); + } + + throw new Error(resp.body.message || resp.body.error || `${resp.body.statusCode} Response`); + }); + } _getUrl(path: string[]) { return ( @@ -63,11 +68,11 @@ export class IndexPatternsApiClient { const url = this._getUrl(['_fields_for_time_pattern']); - return request(url, { + return this._request(url, { pattern, look_back: lookBack, meta_fields: metaFields, - }).then(resp => resp.fields); + }).then((resp: any) => resp.fields); } getFieldsForWildcard(options: GetFieldsOptions = {}) { @@ -91,6 +96,6 @@ export class IndexPatternsApiClient { }; } - return request(url, query).then(resp => resp.fields); + return this._request(url, query).then((resp: any) => resp.fields); } } 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 5f8a66f733c42..84fb65d0f2303 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 @@ -17,7 +17,11 @@ * under the License. */ -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { + UiSettingsClientContract, + SavedObjectsClientContract, + HttpServiceBase, +} from 'src/core/public'; import { Field, FieldList, FieldType } from './fields'; import { createFlattenHitWrapper } from './index_patterns'; import { createIndexPatternSelect } from './components'; @@ -31,6 +35,7 @@ import { export interface IndexPatternDependencies { uiSettings: UiSettingsClientContract; savedObjectsClient: SavedObjectsClientContract; + http: HttpServiceBase; } /** @@ -39,12 +44,12 @@ export interface IndexPatternDependencies { * @internal */ export class IndexPatternsService { - public setup({ uiSettings, savedObjectsClient }: IndexPatternDependencies) { + public setup({ uiSettings, savedObjectsClient, http }: IndexPatternDependencies) { return { FieldList, flattenHitWrapper: createFlattenHitWrapper(), formatHitProvider, - indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient), + indexPatterns: new IndexPatterns(uiSettings, savedObjectsClient, http), IndexPatternSelect: createIndexPatternSelect(savedObjectsClient), __LEGACY: { // For BWC we must temporarily export the class implementation of Field, @@ -67,7 +72,6 @@ export class IndexPatternsService { /** @public */ export { IndexPatternSelect } from './components'; -export { IndexPatternsProvider } from './index_patterns'; export { CONTAINS_SPACES, getFromSavedObject, diff --git a/src/legacy/core_plugins/data/public/plugin.ts b/src/legacy/core_plugins/data/public/plugin.ts index f63f569534d86..ee4ecd9841095 100644 --- a/src/legacy/core_plugins/data/public/plugin.ts +++ b/src/legacy/core_plugins/data/public/plugin.ts @@ -66,12 +66,13 @@ export class DataPlugin implements Plugin Promise.resolve([])); const mockAutocompleteProvider = jest.fn(() => mockGetAutocompleteSuggestions); export const mockGetAutocompleteProvider = jest.fn(() => mockAutocompleteProvider); -const mockKfetch = jest.fn(() => createKfetch(setup().http)); export const mockFetchIndexPatterns = jest .fn() @@ -56,9 +52,6 @@ export const mockFetchIndexPatterns = jest jest.mock('ui/persisted_log', () => ({ PersistedLog: mockPersistedLogFactory, })); -jest.mock('ui/kfetch', () => ({ - kfetch: mockKfetch, -})); jest.mock('../lib/fetch_index_patterns', () => ({ fetchIndexPatterns: mockFetchIndexPatterns, diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.tsx index fa9bad78625c0..e66d71b9b08b4 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.test.tsx @@ -95,6 +95,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -113,6 +114,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -132,6 +134,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -153,6 +156,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -175,6 +179,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -201,6 +206,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -226,6 +232,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); @@ -256,6 +263,7 @@ describe('QueryBarInput', () => { intl={null as any} uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} /> ); expect(mockFetchIndexPatterns).toHaveBeenCalledWith( diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx index d9f66467b09bd..de48de47a6a0c 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_input.tsx @@ -30,9 +30,12 @@ import { } from 'ui/autocomplete_providers'; import { debounce, compact, isEqual, omit } from 'lodash'; import { PersistedLog } from 'ui/persisted_log'; -import { kfetch } from 'ui/kfetch'; import { Storage } from 'ui/storage'; -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { + UiSettingsClientContract, + SavedObjectsClientContract, + HttpServiceBase, +} from 'src/core/public'; import { IndexPattern, StaticIndexPattern } from '../../../index_patterns'; import { Query } from '../index'; import { fromUser, matchPairs, toUser } from '../lib'; @@ -45,6 +48,7 @@ interface Props { uiSettings: UiSettingsClientContract; indexPatterns: Array; savedObjectsClient: SavedObjectsClientContract; + http: HttpServiceBase; store: Storage; intl: InjectedIntl; query: Query; @@ -359,9 +363,7 @@ export class QueryBarInputUI extends Component { // Send telemetry info every time the user opts in or out of kuery // As a result it is important this function only ever gets called in the // UI component's change handler. - kfetch({ - pathname: '/api/kibana/kql_opt_in_telemetry', - method: 'POST', + this.props.http.post('/api/kibana/kql_opt_in_telemetry', { body: JSON.stringify({ opt_in: language === 'kuery' }), }); diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx index cab3c06781390..c48a3ea719813 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.test.tsx @@ -109,6 +109,7 @@ describe('QueryBarTopRowTopRow', () => { intl={null as any} onChange={noop} isDirty={false} + http={startMock.http} /> ); @@ -131,6 +132,7 @@ describe('QueryBarTopRowTopRow', () => { intl={null as any} onChange={noop} isDirty={false} + http={startMock.http} /> ); @@ -145,6 +147,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} store={createMockStorage()} intl={null as any} @@ -163,6 +166,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} store={createMockStorage()} intl={null as any} @@ -182,6 +186,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} screenTitle={'Another Screen'} store={createMockStorage()} @@ -205,6 +210,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} screenTitle={'Another Screen'} indexPatterns={[mockIndexPattern]} @@ -227,6 +233,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} screenTitle={'Another Screen'} indexPatterns={[mockIndexPattern]} @@ -249,6 +256,7 @@ describe('QueryBarTopRowTopRow', () => { onSubmit={noop} onChange={noop} isDirty={false} + http={startMock.http} appName={'discover'} screenTitle={'Another Screen'} store={createMockStorage()} diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx index 40dd218108fa0..5a1a7030b7119 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/query_bar_top_row.tsx @@ -33,7 +33,11 @@ import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react'; import { documentationLinks } from 'ui/documentation_links'; import { Toast, toastNotifications } from 'ui/notify'; import { PersistedLog } from 'ui/persisted_log'; -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { + UiSettingsClientContract, + SavedObjectsClientContract, + HttpServiceBase, +} from 'src/core/public'; import { IndexPattern } from '../../../index_patterns'; import { QueryBarInput } from './query_bar_input'; @@ -68,6 +72,7 @@ interface Props { isDirty: boolean; uiSettings: UiSettingsClientContract; savedObjectsClient: SavedObjectsClientContract; + http: HttpServiceBase; } interface State { @@ -214,6 +219,7 @@ export class QueryBarTopRowUI extends Component { persistedLog={this.persistedLog} uiSettings={this.props.uiSettings} savedObjectsClient={this.props.savedObjectsClient} + http={this.props.http} /> ); diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx index 342388740a99c..f4de88c25dd85 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.test.tsx @@ -101,6 +101,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} /> ); @@ -117,6 +118,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} showDatePicker={false} /> ); @@ -134,6 +136,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} filters={[]} onFiltersUpdated={noop} showDatePicker={false} @@ -153,6 +156,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} showFilterBar={false} filters={[]} onFiltersUpdated={noop} @@ -173,6 +177,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} screenTitle={'test screen'} store={createMockStorage()} onQuerySubmit={noop} @@ -193,6 +198,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} screenTitle={'test screen'} store={createMockStorage()} onQuerySubmit={noop} @@ -214,6 +220,7 @@ describe('SearchBar', () => { appName={'test'} indexPatterns={[mockIndexPattern]} intl={null as any} + http={startMock.http} screenTitle={'test screen'} store={createMockStorage()} onQuerySubmit={noop} diff --git a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx index b41200e7a2f39..5f7a8ffaa6313 100644 --- a/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx +++ b/src/legacy/core_plugins/data/public/search/search_bar/components/search_bar.tsx @@ -26,7 +26,12 @@ import { Storage } from 'ui/storage'; import { get, isEqual } from 'lodash'; import { toastNotifications } from 'ui/notify'; -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; + +import { + UiSettingsClientContract, + SavedObjectsClientContract, + HttpServiceBase, +} from 'src/core/public'; import { IndexPattern, Query, FilterBar } from '../../../../../data/public'; import { QueryBarTopRow } from '../../../query'; import { SavedQuery, SavedQueryAttributes } from '../index'; @@ -50,6 +55,7 @@ export interface SearchBarProps { uiSettings: UiSettingsClientContract; savedObjectsClient: SavedObjectsClientContract; indexPatterns?: IndexPattern[]; + http: HttpServiceBase; // Query bar showQueryBar?: boolean; showQueryInput?: boolean; @@ -368,6 +374,7 @@ class SearchBarUI extends Component { if (this.shouldRenderQueryBar()) { queryBar = ( { @@ -49,12 +49,14 @@ export const initLegacyModule = once((): void => { } child.setAttribute('ui-settings', 'uiSettings'); + child.setAttribute('http', 'http'); // Append helper directive elem.append(child); const linkFn = ($scope: any) => { $scope.uiSettings = npSetup.core.uiSettings; + $scope.http = npSetup.core.http; }; return linkFn; @@ -64,6 +66,7 @@ export const initLegacyModule = once((): void => { .directive('filterBarHelper', (reactDirective: any) => { return reactDirective(wrapInI18nContext(FilterBar), [ ['uiSettings', { watchDepth: 'reference' }], + ['http', { watchDepth: 'reference' }], ['onFiltersUpdated', { watchDepth: 'reference' }], ['indexPatterns', { watchDepth: 'collection' }], ['filters', { watchDepth: 'collection' }], @@ -98,4 +101,16 @@ export const initLegacyModule = once((): void => { }, }; }); + + const module = uiModules.get('kibana/index_patterns'); + let _service: any; + module.service('indexPatterns', function(chrome: any) { + if (!_service) + _service = new IndexPatterns( + npStart.core.uiSettings, + npStart.core.savedObjects.client, + npStart.core.http + ); + return _service; + }); }); diff --git a/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts b/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts index 904332ff4b846..eb24d59f9ca74 100644 --- a/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts +++ b/src/legacy/core_plugins/interpreter/public/functions/esaggs.ts @@ -44,14 +44,14 @@ import { RequestHandlerParams } from '../../../../ui/public/visualize/loader/emb import { tabifyAggResponse } from '../../../../ui/public/agg_response/tabify/tabify'; import { KibanaContext, KibanaDatatable } from '../../common'; import { ExpressionFunction, KibanaDatatableColumn } from '../../types'; -import { IndexPatternsProvider } from '../../../data/public'; +import { setup as data } from '../../../data/public/legacy'; const name = 'esaggs'; type Context = KibanaContext | null; interface Arguments { - index: string | null; + index: string; metricsAtAllLevels: boolean; partialRows: boolean; includeFormatHints: boolean; @@ -221,8 +221,7 @@ export const esaggs = (): ExpressionFunction ({ const $injector = await chrome.dangerouslyGetActiveInjector(); const Private = $injector.get('Private'); const visTypes = Private(VisTypesRegistryProvider); - const indexPatterns = Private(IndexPatternsProvider); + const { indexPatterns } = data.indexPatterns; const queryFilter = Private(FilterBarQueryFilterProvider); const visConfigParams = JSON.parse(args.visConfig); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/create_index_pattern_wizard.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/create_index_pattern_wizard.test.js index 20e2fb779abeb..ca03f6221266d 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/create_index_pattern_wizard.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/create_index_pattern_wizard.test.js @@ -181,7 +181,7 @@ describe('CreateIndexPatternWizard', () => { ...services, config: { get, set }, indexPatterns: { - get: () => ({ + make: () => ({ create, }), clearCache: clear, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/create_index_pattern_wizard.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/create_index_pattern_wizard.js index 021b42c9f59f7..a1f302dc87f6c 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/create_index_pattern_wizard.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/create_index_pattern_wizard.js @@ -121,7 +121,7 @@ export class CreateIndexPatternWizard extends Component { const { services } = this.props; const { indexPattern } = this.state; - const emptyPattern = await services.indexPatterns.get(); + const emptyPattern = await services.indexPatterns.make(); Object.assign(emptyPattern, { id: indexPatternId, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/lib/resolve_saved_objects.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/lib/resolve_saved_objects.js index eeb5fb778b707..0cf079efb6923 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/lib/resolve_saved_objects.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/lib/resolve_saved_objects.js @@ -52,7 +52,7 @@ function addJsonFieldToIndexPattern(target, sourceString, fieldName, indexName) } async function importIndexPattern(doc, indexPatterns, overwriteAll, confirmModalPromise) { // TODO: consolidate this is the code in create_index_pattern_wizard.js - const emptyPattern = await indexPatterns.get(); + const emptyPattern = await indexPatterns.make(); const { title, timeFieldName, diff --git a/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.test.tsx b/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.test.tsx index 91c8cf55f05e7..3e31cbd0d84c1 100644 --- a/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.test.tsx +++ b/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.test.tsx @@ -97,6 +97,7 @@ describe('TopNavMenu', () => { name="test" uiSettings={startMock.uiSettings} savedObjectsClient={startMock.savedObjects.client} + http={startMock.http} showSearchBar={true} /> ); diff --git a/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.tsx b/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.tsx index 0ca18d5ebacc3..f69b843d9c767 100644 --- a/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.tsx +++ b/src/legacy/core_plugins/kibana_react/public/top_nav_menu/top_nav_menu.tsx @@ -57,10 +57,11 @@ export function TopNavMenu(props: Props) { function renderSearchBar() { // Validate presense of all required fields - if (!props.showSearchBar || !props.savedObjectsClient) return; + if (!props.showSearchBar || !props.savedObjectsClient || !props.http) return; return ( { // Pass in storage const localStorage = new Storage(window.localStorage); + child.setAttribute('http', 'http'); child.setAttribute('store', 'store'); child.setAttribute('ui-settings', 'uiSettings'); child.setAttribute('saved-objects-client', 'savedObjectsClient'); @@ -54,7 +56,8 @@ module.directive('kbnTopNav', () => { const linkFn = ($scope, _, $attr) => { $scope.store = localStorage; - $scope.uiSettings = chrome.getUiSettingsClient(); + $scope.http = npSetup.core.http; + $scope.uiSettings = npSetup.core.uiSettings; $scope.savedObjectsClient = chrome.getSavedObjectsClient(); // Watch config changes @@ -100,6 +103,7 @@ module.directive('kbnTopNavHelper', (reactDirective) => { ['savedObjectsClient', { watchDepth: 'reference' }], ['intl', { watchDepth: 'reference' }], ['store', { watchDepth: 'reference' }], + ['http', { watchDepth: 'reference' }], ['onQuerySubmit', { watchDepth: 'reference' }], ['onFiltersUpdated', { watchDepth: 'reference' }], diff --git a/src/legacy/ui/public/vis/editors/default/controls/filter.tsx b/src/legacy/ui/public/vis/editors/default/controls/filter.tsx index 4d210d1269a7a..39211b7f88c85 100644 --- a/src/legacy/ui/public/vis/editors/default/controls/filter.tsx +++ b/src/legacy/ui/public/vis/editors/default/controls/filter.tsx @@ -112,6 +112,7 @@ function FilterRow({ languageSwitcherPopoverAnchorPosition="leftDown" store={localStorage} uiSettings={npStart.core.uiSettings} + http={npStart.core.http} savedObjectsClient={npStart.core.savedObjects.client} /> diff --git a/x-pack/legacy/plugins/graph/public/app.js b/x-pack/legacy/plugins/graph/public/app.js index 172c59bfeeeac..5a4eb48c79bd8 100644 --- a/x-pack/legacy/plugins/graph/public/app.js +++ b/x-pack/legacy/plugins/graph/public/app.js @@ -16,7 +16,7 @@ import 'uiExports/fieldFormats'; import 'uiExports/savedObjectTypes'; import 'ui/autoload/all'; -// TODO: remove ui imports completely (move to plugins) +// TODO: remove ui imports completely (move tDelete o plugins) import 'ui/kbn_top_nav'; import 'ui/directives/saved_object_finder'; import 'ui/directives/input_focus'; @@ -26,7 +26,7 @@ import { uiModules } from 'ui/modules'; import uiRoutes from 'ui/routes'; import { addAppRedirectMessageToUrl, fatalError, toastNotifications } from 'ui/notify'; import { formatAngularHttpError } from 'ui/notify/lib'; -import { IndexPatternsProvider } from 'ui/index_patterns'; +import { setup as data } from '../../../../../src/legacy/core_plugins/data/public/legacy'; import { SavedObjectsClientProvider } from 'ui/saved_objects'; import { KibanaParsedUrl } from 'ui/url/kibana_parsed_url'; import { npStart } from 'ui/new_platform'; @@ -143,7 +143,6 @@ uiRoutes }, //Copied from example found in wizard.js ( Kibana TODO - can't - // IndexPatternsProvider abstract these implementation details better?) indexPatterns: function (Private) { const savedObjectsClient = Private(SavedObjectsClientProvider); @@ -154,7 +153,7 @@ uiRoutes }).then(response => response.savedObjects); }, GetIndexPatternProvider: function (Private) { - return Private(IndexPatternsProvider); + return data.indexPatterns.indexPatterns; }, SavedWorkspacesProvider: function (Private) { return Private(SavedWorkspacesProvider); diff --git a/x-pack/legacy/plugins/ml/public/data_frame/pages/data_frame_new_pivot/components/step_create/step_create_form.tsx b/x-pack/legacy/plugins/ml/public/data_frame/pages/data_frame_new_pivot/components/step_create/step_create_form.tsx index 7c13d0addece9..ab6abb5c53226 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame/pages/data_frame_new_pivot/components/step_create/step_create_form.tsx +++ b/x-pack/legacy/plugins/ml/public/data_frame/pages/data_frame_new_pivot/components/step_create/step_create_form.tsx @@ -140,7 +140,7 @@ export const StepCreateForm: SFC = React.memo( const indexPatternName = transformConfig.dest.index; try { - const newIndexPattern = await kibanaContext.indexPatterns.get(); + const newIndexPattern = await kibanaContext.indexPatterns.make(); Object.assign(newIndexPattern, { id: '', diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts index 418eb75290e1e..b83a43c3ffa86 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.ts @@ -134,7 +134,7 @@ export const useCreateAnalyticsForm = () => { const indexPatternName = destinationIndex; try { - const newIndexPattern = await kibanaContext.indexPatterns.get(); + const newIndexPattern = await kibanaContext.indexPatterns.make(); Object.assign(newIndexPattern, { id: '', @@ -235,17 +235,19 @@ export const useCreateAnalyticsForm = () => { // able to identify outliers if there are no numeric fields present. const ids = await kibanaContext.indexPatterns.getIds(true); const indexPatternsWithNumericFields: IndexPatternTitle[] = []; - ids.forEach(async id => { - const indexPattern = await kibanaContext.indexPatterns.get(id); - if ( - indexPattern.fields - .filter(f => !OMIT_FIELDS.includes(f.name)) - .map(f => f.type) - .includes('number') - ) { - indexPatternsWithNumericFields.push(indexPattern.title); - } - }); + ids + .filter(f => !!f) + .forEach(async id => { + const indexPattern = await kibanaContext.indexPatterns.get(id!); + if ( + indexPattern.fields + .filter(f => !OMIT_FIELDS.includes(f.name)) + .map(f => f.type) + .includes('number') + ) { + indexPatternsWithNumericFields.push(indexPattern.title); + } + }); setIndexPatternTitles({ indexPatternTitles, indexPatternsWithNumericFields }); } catch (e) { addRequestMessage({ diff --git a/x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/import_view/import_view.js b/x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/import_view/import_view.js index 2ce6f69fa9c47..c1ffcad948adb 100644 --- a/x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/import_view/import_view.js +++ b/x-pack/legacy/plugins/ml/public/datavisualizer/file_based/components/import_view/import_view.js @@ -548,7 +548,7 @@ export class ImportView extends Component { async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFieldName, kibanaConfig) { try { - const emptyPattern = await indexPatterns.get(); + const emptyPattern = await indexPatterns.make(); Object.assign(emptyPattern, { id: '', diff --git a/x-pack/legacy/plugins/security/public/views/management/edit_role/index.js b/x-pack/legacy/plugins/security/public/views/management/edit_role/index.js index 1abb299c99390..efb15d72248d3 100644 --- a/x-pack/legacy/plugins/security/public/views/management/edit_role/index.js +++ b/x-pack/legacy/plugins/security/public/views/management/edit_role/index.js @@ -13,8 +13,7 @@ import template from 'plugins/security/views/management/edit_role/edit_role.html import 'plugins/security/services/shield_user'; import 'plugins/security/services/shield_role'; import 'plugins/security/services/shield_indices'; - -import { IndexPatternsProvider } from 'ui/index_patterns'; +import { setup as data } from '../../../../../../../../src/legacy/core_plugins/data/public/legacy'; import { xpackInfo } from 'plugins/xpack_main/services/xpack_info'; import { SpacesManager } from '../../../../../spaces/public/lib'; import { ROLES_PATH, CLONE_ROLES_PATH, EDIT_ROLES_PATH } from '../management_urls'; @@ -75,8 +74,8 @@ const routeDefinition = (action) => ({ return ShieldUser.query().$promise .then(users => _.map(users, 'username')); }, - indexPatterns(Private) { - const indexPatterns = Private(IndexPatternsProvider); + indexPatterns() { + const { indexPatterns } = data.indexPatterns; return indexPatterns.getTitles(); }, spaces(spacesEnabled) {