From bb30b0aca95837dea03a6928c564a584579942da Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 17:11:38 -0600 Subject: [PATCH] Update index pattern and autocomplete refs. Make getters functions --- .../legacy/plugins/maps/public/angular/map_controller.js | 4 ++-- .../plugins/maps/public/components/geo_field_with_index.ts | 2 +- .../layer_panel/filter_editor/filter_editor.js | 4 ++-- .../layer_panel/join_editor/resources/join.js | 4 ++-- .../layer_panel/join_editor/resources/join_expression.js | 7 +++++-- .../maps/public/embeddable/map_embeddable_factory.js | 4 ++-- x-pack/legacy/plugins/maps/public/index_pattern_util.js | 4 ++-- x-pack/legacy/plugins/maps/public/kibana_services.js | 4 ++-- .../sources/es_geo_grid_source/create_source_editor.js | 4 ++-- .../sources/es_geo_grid_source/update_source_editor.js | 4 ++-- .../sources/es_pew_pew_source/create_source_editor.js | 4 ++-- .../sources/es_pew_pew_source/update_source_editor.js | 4 ++-- .../sources/es_search_source/create_source_editor.js | 4 ++-- .../sources/es_search_source/update_source_editor.js | 6 +++--- .../maps/public/layers/sources/es_term_source.test.js | 1 - 15 files changed, 31 insertions(+), 29 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/angular/map_controller.js b/x-pack/legacy/plugins/maps/public/angular/map_controller.js index fc45c0446445c..519ba0b1e3d96 100644 --- a/x-pack/legacy/plugins/maps/public/angular/map_controller.js +++ b/x-pack/legacy/plugins/maps/public/angular/map_controller.js @@ -15,7 +15,7 @@ import { i18n } from '@kbn/i18n'; import { capabilities } from 'ui/capabilities'; import { render, unmountComponentAtNode } from 'react-dom'; import { uiModules } from 'ui/modules'; -import { getTimeFilter, indexPatternService, getInspector } from '../kibana_services'; +import { getTimeFilter, getIndexPatternService, getInspector } from '../kibana_services'; import { Provider } from 'react-redux'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { createMapStore } from '../../../../../plugins/maps/public/reducers/store'; @@ -396,7 +396,7 @@ app.controller( const indexPatterns = []; const getIndexPatternPromises = nextIndexPatternIds.map(async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); indexPatterns.push(indexPattern); } catch (err) { // unable to fetch index pattern diff --git a/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts b/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts index 863e0adda8fb2..3962da23bd073 100644 --- a/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts +++ b/x-pack/legacy/plugins/maps/public/components/geo_field_with_index.ts @@ -7,7 +7,7 @@ // Maps can contain geo fields from multiple index patterns. GeoFieldWithIndex is used to: // 1) Combine the geo field along with associated index pattern state. -// 2) Package asynchronously looked up state via indexPatternService to avoid +// 2) Package asynchronously looked up state via getIndexPatternService() to avoid // PITA of looking up async state in downstream react consumers. export type GeoFieldWithIndex = { geoFieldName: string; diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js index 94e855fc6708f..5bdba953788c7 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js @@ -22,7 +22,7 @@ import { import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; import { npStart } from 'ui/new_platform'; @@ -49,7 +49,7 @@ export class FilterEditor extends Component { const indexPatterns = []; const getIndexPatternPromises = indexPatternIds.map(async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); indexPatterns.push(indexPattern); } catch (err) { // unable to fetch index pattern diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index c2c9f333a675c..0df6bd40d1a31 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -14,7 +14,7 @@ import { WhereExpression } from './where_expression'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; import { indexPatterns } from '../../../../../../../../../src/plugins/data/public'; -import { indexPatternService } from '../../../../kibana_services'; +import { getIndexPatternService } from '../../../../kibana_services'; export class Join extends Component { state = { @@ -39,7 +39,7 @@ export class Join extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js index fb77857f731b9..f7edcf6e85e25 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join_expression.js @@ -19,7 +19,10 @@ import { i18n } from '@kbn/i18n'; import { SingleFieldSelect } from '../../../../components/single_field_select'; import { FormattedMessage } from '@kbn/i18n/react'; import { getTermsFields } from '../../../../index_pattern_util'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../../kibana_services'; +import { + getIndexPatternService, + getIndexPatternSelectComponent, +} from '../../../../kibana_services'; export class JoinExpression extends Component { state = { @@ -40,7 +43,7 @@ export class JoinExpression extends Component { _onRightSourceChange = async indexPatternId => { try { - const indexPattern = await indexPatternService.get(indexPatternId); + const indexPattern = await getIndexPatternService().get(indexPatternId); this.props.onRightSourceChange({ indexPatternId, indexPatternTitle: indexPattern.title, diff --git a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js index af86e5bf7e903..fcbae894dffa4 100644 --- a/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js +++ b/x-pack/legacy/plugins/maps/public/embeddable/map_embeddable_factory.js @@ -14,7 +14,7 @@ import { } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { setup } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { MapEmbeddable } from './map_embeddable'; -import { indexPatternService } from '../kibana_services'; +import { getIndexPatternService } from '../kibana_services'; import { createMapPath, MAP_SAVED_OBJECT_TYPE, APP_ICON } from '../../common/constants'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -78,7 +78,7 @@ export class MapEmbeddableFactory extends EmbeddableFactory { const promises = queryableIndexPatternIds.map(async indexPatternId => { try { - return await indexPatternService.get(indexPatternId); + return await getIndexPatternService().get(indexPatternId); } catch (error) { // Unable to load index pattern, better to not throw error so map embeddable can render // Error will be surfaced by map embeddable since it too will be unable to locate the index pattern diff --git a/x-pack/legacy/plugins/maps/public/index_pattern_util.js b/x-pack/legacy/plugins/maps/public/index_pattern_util.js index 7aa87ab32cdf5..30a0a6826db83 100644 --- a/x-pack/legacy/plugins/maps/public/index_pattern_util.js +++ b/x-pack/legacy/plugins/maps/public/index_pattern_util.js @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { indexPatternService } from './kibana_services'; +import { getIndexPatternService } from './kibana_services'; import { indexPatterns } from '../../../../../src/plugins/data/public'; import { ES_GEO_FIELD_TYPE } from '../common/constants'; export async function getIndexPatternsFromIds(indexPatternIds = []) { const promises = []; indexPatternIds.forEach(id => { - const indexPatternPromise = indexPatternService.get(id); + const indexPatternPromise = getIndexPatternService().get(id); if (indexPatternPromise) { promises.push(indexPatternPromise); } diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 77a28c3d08bf4..3b0f501dc0f60 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -13,11 +13,11 @@ export { SearchSource } from '../../../../../src/plugins/data/public'; let indexPatternService; export const setIndexPatternService = dataIndexPatterns => (indexPatternService = dataIndexPatterns); -export const getIndexPatternService = indexPatternService; +export const getIndexPatternService = () => indexPatternService; let autocompleteService; export const setAutocompleteService = dataAutoComplete => (autocompleteService = dataAutoComplete); -export const getAutocompleteService = autocompleteService; +export const getAutocompleteService = () => autocompleteService; let licenseId; export const setLicenseId = latestLicenseId => (licenseId = latestLicenseId); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js index 25ef628c4589f..148683269ef78 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js @@ -10,7 +10,7 @@ import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; import { RENDER_AS } from '../../../../common/constants'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; +import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout'; import { i18n } from '@kbn/i18n'; @@ -89,7 +89,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js index 7b91e6ddb55d5..269c2a8b8633a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js @@ -8,7 +8,7 @@ import React, { Fragment, Component } from 'react'; import { RENDER_AS } from '../../../../common/constants'; import { MetricsEditor } from '../../../components/metrics_editor'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { ResolutionEditor } from './resolution_editor'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -33,7 +33,7 @@ export class UpdateSourceEditor extends Component { async _loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js index 6e8d383cb0160..a4af1a3c19c83 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/create_source_editor.js @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react'; import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; -import { indexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; +import { getIndexPatternService, getIndexPatternSelectComponent } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -70,7 +70,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js index ff00f472e9edf..ce1f53c33ba53 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_pew_pew_source/update_source_editor.js @@ -7,7 +7,7 @@ import React, { Component, Fragment } from 'react'; import { MetricsEditor } from '../../../components/metrics_editor'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -30,7 +30,7 @@ export class UpdateSourceEditor extends Component { async _loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js index 2ac68a73e12db..895ad12f107d9 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/create_source_editor.js @@ -11,7 +11,7 @@ import { EuiFormRow, EuiSpacer, EuiSwitch, EuiCallOut } from '@elastic/eui'; import { SingleFieldSelect } from '../../../components/single_field_select'; import { - indexPatternService, + getIndexPatternService, getIndexPatternSelectComponent, getHttp, } from '../../../kibana_services'; @@ -99,7 +99,7 @@ export class CreateSourceEditor extends Component { let indexPattern; try { - indexPattern = await indexPatternService.get(indexPatternId); + indexPattern = await getIndexPatternService().get(indexPatternId); } catch (err) { // index pattern no longer exists return; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js index 52702c1f4ecc7..b1fc9713f98c4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/update_source_editor.js @@ -18,7 +18,7 @@ import { import { SingleFieldSelect } from '../../../components/single_field_select'; import { TooltipSelector } from '../../../components/tooltip_selector'; -import { indexPatternService } from '../../../kibana_services'; +import { getIndexPatternService } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; import { getTermsFields, getSourceFields } from '../../../index_pattern_util'; import { ValidatedRange } from '../../../components/validated_range'; @@ -60,7 +60,7 @@ export class UpdateSourceEditor extends Component { async loadIndexSettings() { try { - const indexPattern = await indexPatternService.get(this.props.indexPatternId); + const indexPattern = await getIndexPatternService().get(this.props.indexPatternId); const { maxInnerResultWindow } = await loadIndexSettings(indexPattern.title); if (this._isMounted) { this.setState({ maxInnerResultWindow }); @@ -73,7 +73,7 @@ export class UpdateSourceEditor extends Component { async loadFields() { let indexPattern; try { - indexPattern = await indexPatternService.get(this.props.indexPatternId); + indexPattern = await getIndexPatternService().get(this.props.indexPatternId); } catch (err) { if (this._isMounted) { this.setState({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js index 890b1e3aaac1f..14ffd068df465 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.test.js @@ -8,7 +8,6 @@ import { ESTermSource, extractPropertiesMap } from './es_term_source'; jest.mock('ui/new_platform'); jest.mock('../vector_layer', () => {}); -jest.mock('ui/timefilter', () => {}); const indexPatternTitle = 'myIndex'; const termFieldName = 'myTermField';