Skip to content

Commit

Permalink
Update index pattern and autocomplete refs. Make getters functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Mar 17, 2020
1 parent 09557bb commit bb30b0a
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/angular/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/index_pattern_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit bb30b0a

Please sign in to comment.