From e1d73f46e80132d2c887794585f73db73a5031f6 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Sun, 16 Jun 2019 10:49:27 +0300 Subject: [PATCH] Separate class\type definitions from plugin instance setup (#38894) (#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 --- src/legacy/core_plugins/data/public/index.ts | 14 +++------- src/legacy/core_plugins/data/public/setup.ts | 27 +++++++++++++++++++ .../core_plugins/kibana/public/context/app.js | 2 +- .../kibana/public/dashboard/index.js | 2 +- .../public/discover/controllers/discover.js | 2 +- .../kibana/public/visualize/index.js | 2 +- .../public/components/annotations_editor.js | 2 +- .../public/components/panel_config/gauge.js | 2 +- .../components/panel_config/markdown.js | 2 +- .../public/components/panel_config/metric.js | 2 +- .../public/components/panel_config/table.js | 2 +- .../components/panel_config/timeseries.js | 2 +- .../public/components/panel_config/top_n.js | 2 +- .../public/components/series_config.js | 2 +- .../public/components/splits/filter.js | 2 +- .../public/components/splits/filter_items.js | 2 +- .../components/vis_types/table/config.js | 2 +- .../components/vis_types/timeseries/config.js | 2 +- .../ui/public/agg_types/buckets/filters.js | 2 +- .../ui/public/agg_types/controls/filter.tsx | 6 +++-- .../filter_editor/filter_editor.js | 2 +- x-pack/plugins/maps/public/index.js | 2 +- 22 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 src/legacy/core_plugins/data/public/setup.ts diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index a00e01804723c..679a835a0477e 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -22,8 +22,6 @@ // 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'; @@ -31,7 +29,7 @@ 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; @@ -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: { @@ -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; diff --git a/src/legacy/core_plugins/data/public/setup.ts b/src/legacy/core_plugins/data/public/setup.ts new file mode 100644 index 0000000000000..6329d2931ecdb --- /dev/null +++ b/src/legacy/core_plugins/data/public/setup.ts @@ -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(); diff --git a/src/legacy/core_plugins/kibana/public/context/app.js b/src/legacy/core_plugins/kibana/public/context/app.js index 60af9db918280..59184c8f7f8e5 100644 --- a/src/legacy/core_plugins/kibana/public/context/app.js +++ b/src/legacy/core_plugins/kibana/public/context/app.js @@ -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', [ diff --git a/src/legacy/core_plugins/kibana/public/dashboard/index.js b/src/legacy/core_plugins/kibana/public/dashboard/index.js index 1fac69157c697..a1ea66c0e841a 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/index.js +++ b/src/legacy/core_plugins/kibana/public/dashboard/index.js @@ -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(); diff --git a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js index 977fb8091c6a9..112894dce9272 100644 --- a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js @@ -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 = { diff --git a/src/legacy/core_plugins/kibana/public/visualize/index.js b/src/legacy/core_plugins/kibana/public/visualize/index.js index 26b6af9899b76..ae2bae73253c1 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/index.js +++ b/src/legacy/core_plugins/kibana/public/visualize/index.js @@ -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(); diff --git a/src/legacy/core_plugins/metrics/public/components/annotations_editor.js b/src/legacy/core_plugins/metrics/public/components/annotations_editor.js index 5f405951b8939..ce70b6d32df6a 100644 --- a/src/legacy/core_plugins/metrics/public/components/annotations_editor.js +++ b/src/legacy/core_plugins/metrics/public/components/annotations_editor.js @@ -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'; diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js b/src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js index d52848e68c30c..6abfc93269faa 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/gauge.js @@ -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'; diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js b/src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js index c2b22308dbcb8..2794fa55ff1d7 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/markdown.js @@ -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); diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/metric.js b/src/legacy/core_plugins/metrics/public/components/panel_config/metric.js index bfac22e2f2eeb..cd8402dc07cd9 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/metric.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/metric.js @@ -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); diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/table.js b/src/legacy/core_plugins/metrics/public/components/panel_config/table.js index 210b8e10a95d9..0ba0b20d593b0 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/table.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/table.js @@ -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); diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js b/src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js index 4c4649a9d8bcd..aacc444390375 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/timeseries.js @@ -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); diff --git a/src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js b/src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js index ef75a3e51eac4..5fd2026e45f1d 100644 --- a/src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js +++ b/src/legacy/core_plugins/metrics/public/components/panel_config/top_n.js @@ -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); diff --git a/src/legacy/core_plugins/metrics/public/components/series_config.js b/src/legacy/core_plugins/metrics/public/components/series_config.js index 10d18fe07e221..8b333e420508b 100644 --- a/src/legacy/core_plugins/metrics/public/components/series_config.js +++ b/src/legacy/core_plugins/metrics/public/components/series_config.js @@ -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; diff --git a/src/legacy/core_plugins/metrics/public/components/splits/filter.js b/src/legacy/core_plugins/metrics/public/components/splits/filter.js index baadc99e76d15..73dd2b2225be9 100644 --- a/src/legacy/core_plugins/metrics/public/components/splits/filter.js +++ b/src/legacy/core_plugins/metrics/public/components/splits/filter.js @@ -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'; diff --git a/src/legacy/core_plugins/metrics/public/components/splits/filter_items.js b/src/legacy/core_plugins/metrics/public/components/splits/filter_items.js index 33af1ab497a3f..941ada2b3018a 100644 --- a/src/legacy/core_plugins/metrics/public/components/splits/filter_items.js +++ b/src/legacy/core_plugins/metrics/public/components/splits/filter_items.js @@ -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'; diff --git a/src/legacy/core_plugins/metrics/public/components/vis_types/table/config.js b/src/legacy/core_plugins/metrics/public/components/vis_types/table/config.js index 901b3a2e08061..a3c7037190ab0 100644 --- a/src/legacy/core_plugins/metrics/public/components/vis_types/table/config.js +++ b/src/legacy/core_plugins/metrics/public/components/vis_types/table/config.js @@ -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; diff --git a/src/legacy/core_plugins/metrics/public/components/vis_types/timeseries/config.js b/src/legacy/core_plugins/metrics/public/components/vis_types/timeseries/config.js index 6403e2dbbd224..ec91b96a85998 100644 --- a/src/legacy/core_plugins/metrics/public/components/vis_types/timeseries/config.js +++ b/src/legacy/core_plugins/metrics/public/components/vis_types/timeseries/config.js @@ -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 { diff --git a/src/legacy/ui/public/agg_types/buckets/filters.js b/src/legacy/ui/public/agg_types/buckets/filters.js index 87b275abef277..ee1a81b3ed2d5 100644 --- a/src/legacy/ui/public/agg_types/buckets/filters.js +++ b/src/legacy/ui/public/agg_types/buckets/filters.js @@ -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(); diff --git a/src/legacy/ui/public/agg_types/controls/filter.tsx b/src/legacy/ui/public/agg_types/controls/filter.tsx index 54e68cf913c35..4653123130ed4 100644 --- a/src/legacy/ui/public/agg_types/controls/filter.tsx +++ b/src/legacy/ui/public/agg_types/controls/filter.tsx @@ -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; @@ -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} diff --git a/x-pack/plugins/maps/public/components/layer_panel/filter_editor/filter_editor.js b/x-pack/plugins/maps/public/components/layer_panel/filter_editor/filter_editor.js index 14a302c66e847..1e3617ff076a7 100644 --- a/x-pack/plugins/maps/public/components/layer_panel/filter_editor/filter_editor.js +++ b/x-pack/plugins/maps/public/components/layer_panel/filter_editor/filter_editor.js @@ -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(); diff --git a/x-pack/plugins/maps/public/index.js b/x-pack/plugins/maps/public/index.js index 414496a057af6..9096d677b8c3e 100644 --- a/x-pack/plugins/maps/public/index.js +++ b/x-pack/plugins/maps/public/index.js @@ -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']);