Skip to content

Commit

Permalink
Separate class\type definitions from plugin instance setup (elastic#3…
Browse files Browse the repository at this point in the history
…8894) (elastic#39039)

* Separate class\type defenitions from plugin instance setup in shim plugin definition
This helps avoiding circular dependency issues that were obsereved in filter-manager branch (due to code starting to use the data plugin).

* typescript fun
  • Loading branch information
Liza Katz authored Jun 16, 2019
1 parent 0f9374a commit e1d73f4
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 31 deletions.
14 changes: 4 additions & 10 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
// and handled by the platform itself in the setup method
// of the ExpressionExectorService
// @ts-ignore
import { getInterpreter } from 'plugins/interpreter/interpreter';
// @ts-ignore
import { renderersRegistry } from 'plugins/interpreter/registries';
import { ExpressionsService, ExpressionsSetup } from './expressions';
import { SearchService, SearchSetup } from './search';
import { QueryService, QuerySetup } from './query';
import { FilterService, FilterSetup } from './filter';
import { IndexPatternsService, IndexPatternsSetup } from './index_patterns';

class DataPlugin {
export class DataPlugin {
// Exposed services, sorted alphabetically
private readonly expressions: ExpressionsService;
private readonly filter: FilterService;
Expand All @@ -48,6 +46,9 @@ class DataPlugin {
}

public setup(): DataSetup {
// TODO: this is imported here to avoid circular imports.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { getInterpreter } = require('plugins/interpreter/interpreter');
return {
expressions: this.expressions.setup({
interpreter: {
Expand All @@ -71,13 +72,6 @@ class DataPlugin {
}
}

/**
* We export data here so that users importing from 'plugins/data'
* will automatically receive the response value of the `setup` contract, mimicking
* the data that will eventually be injected by the new platform.
*/
export const data = new DataPlugin().setup();

/** @public */
export interface DataSetup {
expressions: ExpressionsSetup;
Expand Down
27 changes: 27 additions & 0 deletions src/legacy/core_plugins/data/public/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { DataPlugin } from './index';

/**
* We export data here so that users importing from 'plugins/data'
* will automatically receive the response value of the `setup` contract, mimicking
* the data that will eventually be injected by the new platform.
*/
export const data = new DataPlugin().setup();
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/context/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from './query';
import { timefilter } from 'ui/timefilter';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
data.filter.loadLegacyDirectives();

const module = uiModules.get('apps/context', [
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { DashboardListing, EMPTY_FILTER } from './listing/dashboard_listing';
import { uiModules } from 'ui/modules';
import 'ui/capabilities/route_setup';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
data.search.loadLegacyDirectives();
data.filter.loadLegacyDirectives();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../breadcrumbs';
import { buildVislibDimensions } from 'ui/visualize/loader/pipeline_helpers/build_pipeline';
import 'ui/capabilities/route_setup';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
data.search.loadLegacyDirectives();

const fetchStatuses = {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { VisualizeConstants } from './visualize_constants';
import { FeatureCatalogueRegistryProvider, FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';
import { getLandingBreadcrumbs, getWizardStep1Breadcrumbs } from './breadcrumbs';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
data.search.loadLegacyDirectives();
data.filter.loadLegacyDirectives();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import uuid from 'uuid';
import { IconSelect } from './icon_select';
import { YesNo } from './yes_no';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBarInput } = data.query.ui;
import { getDefaultQueryLanguage } from './lib/get_default_query_language';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '@elastic/eui';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
const lessC = less(window, { env: 'production' });
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';

import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from '@elastic/eui';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { Storage } from 'ui/storage';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { getDefaultQueryLanguage } from '../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
const localStorage = new Storage(window.localStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
EuiSpacer,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { Storage } from 'ui/storage';
import { getDefaultQueryLanguage } from './lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createSelectHandler } from '../lib/create_select_handler';
import { GroupBySelect } from './group_by_select';
import PropTypes from 'prop-types';
import React from 'react';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBarInput } = data.query.ui;
import { Storage } from 'ui/storage';
import { htmlIdGenerator, EuiFlexGroup, EuiFlexItem, EuiFormRow } from '@elastic/eui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { collectionActions } from '../lib/collection_actions';
import { AddDeleteButtons } from '../add_delete_buttons';
import { ColorPicker } from '../color_picker';
import uuid from 'uuid';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBarInput } = data.query.ui;
import { Storage } from 'ui/storage';
import { EuiFieldText, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
import { Storage } from 'ui/storage';
import { getDefaultQueryLanguage } from '../../lib/get_default_query_language';
const { QueryBarInput } = data.query.ui;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createSelectHandler } from '../../lib/create_select_handler';
import { YesNo } from '../../yes_no';
import { createTextHandler } from '../../lib/create_text_handler';
import { IndexPattern } from '../../index_pattern';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBarInput } = data.query.ui;
import { Storage } from 'ui/storage';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/agg_types/buckets/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { i18n } from '@kbn/i18n';

import chrome from 'ui/chrome';
import { buildEsQuery } from '@kbn/es-query';
import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';

const { getQueryLog } = data.query.helpers;
const config = chrome.getUiSettingsClient();
Expand Down
6 changes: 4 additions & 2 deletions src/legacy/ui/public/agg_types/controls/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { AggConfig } from 'ui/vis';
import { Query, data } from 'plugins/data';
// @ts-ignore
import { data } from 'plugins/data/setup';
import { Query } from 'plugins/data';

const { QueryBarInput } = data.query.ui;

Expand Down Expand Up @@ -104,7 +106,7 @@ function FilterRow({
query={value}
indexPatterns={[agg.getIndexPattern()]}
appName="filtersAgg"
onChange={query => onChangeValue(id, query, customLabel)}
onChange={(query: Query) => onChangeValue(id, query, customLabel)}
disableAutoFocus={!autoFocus}
data-test-subj={dataTestSubj}
bubbleSubmitEvent={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';
import { indexPatternService } from '../../../kibana_services';
import { Storage } from 'ui/storage';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
const { QueryBar } = data.query.ui;

const settings = chrome.getUiSettingsClient();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import mapTemplate from './angular/map.html';
import { MapListing } from './shared/components/map_listing';
import { recentlyAccessed } from 'ui/persisted_log';

import { data } from 'plugins/data';
import { data } from 'plugins/data/setup';
data.query.loadLegacyDirectives();

const app = uiModules.get('app/maps', ['ngRoute', 'react']);
Expand Down

0 comments on commit e1d73f4

Please sign in to comment.