diff --git a/src/legacy/core_plugins/input_control_vis/public/register_vis.js b/src/legacy/core_plugins/input_control_vis/public/register_vis.js index 50a8c4312171d..76320b331bb06 100644 --- a/src/legacy/core_plugins/input_control_vis/public/register_vis.js +++ b/src/legacy/core_plugins/input_control_vis/public/register_vis.js @@ -17,20 +17,19 @@ * under the License. */ -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; +import { visFactory } from 'ui/vis/vis_factory'; import { VisController } from './vis_controller'; import { ControlsTab } from './components/editor/controls_tab'; import { OptionsTab } from './components/editor/options_tab'; import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message'; import { Status } from 'ui/vis/update_status'; import { i18n } from '@kbn/i18n'; +import { setup as visualizations } from '../../visualizations/public/legacy'; -function InputControlVisProvider(Private) { - const VisFactory = Private(VisFactoryProvider); +function InputControlVisProvider() { // return the visType object, which kibana will use to display and configure new Vis object of this type. - return VisFactory.createBaseVisualization({ + return visFactory.createBaseVisualization({ name: 'input_control_vis', title: i18n.translate('inputControl.register.controlsTitle', { defaultMessage: 'Controls' @@ -76,7 +75,7 @@ function InputControlVisProvider(Private) { } // register the provider with the visTypes registry -VisTypesRegistryProvider.register(InputControlVisProvider); +visualizations.types.registerVisualization(InputControlVisProvider); // export the provider so that the visType can be required with Private() export default InputControlVisProvider; diff --git a/src/legacy/core_plugins/interpreter/public/functions/visualization.js b/src/legacy/core_plugins/interpreter/public/functions/visualization.js index e7dfbb78eb40a..7dceeaf684354 100644 --- a/src/legacy/core_plugins/interpreter/public/functions/visualization.js +++ b/src/legacy/core_plugins/interpreter/public/functions/visualization.js @@ -20,8 +20,9 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import chrome from 'ui/chrome'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { setup as data } from '../../../data/public/legacy'; +import { start as visualizations } from '../../../visualizations/public/legacy'; + import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter'; import { PersistedState } from 'ui/persisted_state'; @@ -64,13 +65,12 @@ export const visualization = () => ({ async fn(context, args, handlers) { const $injector = await chrome.dangerouslyGetActiveInjector(); const Private = $injector.get('Private'); - const visTypes = Private(VisTypesRegistryProvider); const { indexPatterns } = data.indexPatterns; const queryFilter = Private(FilterBarQueryFilterProvider); const visConfigParams = JSON.parse(args.visConfig); const schemas = JSON.parse(args.schemas); - const visType = visTypes.byName[args.type || 'histogram']; + const visType = visualizations.types.get(args.type || 'histogram'); const indexPattern = args.index ? await indexPatterns.get(args.index) : null; const uiStateParams = JSON.parse(args.uiState); diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js b/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js index 1a47cc5994fdb..b11f21a96f38d 100644 --- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js +++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/kbn_vislib_vis_types.js @@ -17,7 +17,7 @@ * under the License. */ -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; +import { setup as visualizations } from '../../visualizations/public/legacy'; import histogramVisTypeProvider from './histogram'; import lineVisTypeProvider from './line'; @@ -28,11 +28,11 @@ import horizontalBarVisTypeProvider from './horizontal_bar'; import gaugeVisTypeProvider from './gauge'; import goalVisTypeProvider from './goal'; -VisTypesRegistryProvider.register(histogramVisTypeProvider); -VisTypesRegistryProvider.register(lineVisTypeProvider); -VisTypesRegistryProvider.register(pieVisTypeProvider); -VisTypesRegistryProvider.register(areaVisTypeProvider); -VisTypesRegistryProvider.register(heatmapVisTypeProvider); -VisTypesRegistryProvider.register(horizontalBarVisTypeProvider); -VisTypesRegistryProvider.register(gaugeVisTypeProvider); -VisTypesRegistryProvider.register(goalVisTypeProvider); +visualizations.types.registerVisualization(histogramVisTypeProvider); +visualizations.types.registerVisualization(lineVisTypeProvider); +visualizations.types.registerVisualization(pieVisTypeProvider); +visualizations.types.registerVisualization(areaVisTypeProvider); +visualizations.types.registerVisualization(heatmapVisTypeProvider); +visualizations.types.registerVisualization(horizontalBarVisTypeProvider); +visualizations.types.registerVisualization(gaugeVisTypeProvider); +visualizations.types.registerVisualization(goalVisTypeProvider); diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js index c7373e9328bc6..775e9d1b2a5e6 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js @@ -32,7 +32,6 @@ import React from 'react'; import angular from 'angular'; import { FormattedMessage } from '@kbn/i18n/react'; import { toastNotifications } from 'ui/notify'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { docTitle } from 'ui/doc_title'; import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter'; import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory'; @@ -56,6 +55,7 @@ import { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_s import { getEditBreadcrumbs, getCreateBreadcrumbs } from '../breadcrumbs'; import { npStart } from 'ui/new_platform'; import { setup as data } from '../../../../../core_plugins/data/public/legacy'; +import { start as visualizations } from '../../../../visualizations/public/legacy'; const { savedQueryService } = data.search.services; @@ -64,8 +64,8 @@ uiRoutes template: editorTemplate, k7Breadcrumbs: getCreateBreadcrumbs, resolve: { - savedVis: function (savedVisualizations, redirectWhenMissing, $route, Private) { - const visTypes = Private(VisTypesRegistryProvider); + savedVis: function (savedVisualizations, redirectWhenMissing, $route) { + const visTypes = visualizations.types.all(); const visType = _.find(visTypes, { name: $route.current.params.type }); const shouldHaveIndex = visType.requiresSearch && visType.options.showIndexSelection; const hasIndex = $route.current.params.indexPattern || $route.current.params.savedSearchId; diff --git a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx b/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx index 21897cb6c0d15..52dcaaa05b94d 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.tsx @@ -43,9 +43,7 @@ import chrome from 'ui/chrome'; import { getVisualizeLoader } from 'ui/visualize/loader'; import { Legacy } from 'kibana'; -import { VisTypesRegistry, VisTypesRegistryProvider } from 'ui/registry/vis_types'; -import { IPrivate } from 'ui/private'; import { SavedObjectAttributes } from 'kibana/server'; import { npSetup } from 'ui/new_platform'; import { @@ -54,12 +52,14 @@ import { Container, EmbeddableOutput, } from '../../../../../../plugins/embeddable/public'; +import { start as visualizations } from '../../../../visualizations/public/legacy'; import { showNewVisModal } from '../wizard'; import { SavedVisualizations } from '../types'; import { DisabledLabEmbeddable } from './disabled_lab_embeddable'; import { getIndexPattern } from './get_index_pattern'; import { VisualizeEmbeddable, VisualizeInput, VisualizeOutput } from './visualize_embeddable'; import { VISUALIZE_EMBEDDABLE_TYPE } from './constants'; +import { TypesStart } from '../../../../visualizations/public/np_ready/types'; interface VisualizationAttributes extends SavedObjectAttributes { visState: string; @@ -72,17 +72,13 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory< VisualizationAttributes > { public readonly type = VISUALIZE_EMBEDDABLE_TYPE; - private readonly visTypes: VisTypesRegistry; + private readonly visTypes: TypesStart; static async createVisualizeEmbeddableFactory(): Promise { - const $injector = await chrome.dangerouslyGetActiveInjector(); - const Private = $injector.get('Private'); - const visTypes = Private(VisTypesRegistryProvider); - - return new VisualizeEmbeddableFactory(visTypes); + return new VisualizeEmbeddableFactory(visualizations.types); } - constructor(visTypes: VisTypesRegistry) { + constructor(visTypes: TypesStart) { super({ savedObjectMetaData: { name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }), @@ -92,21 +88,23 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory< return 'visualizeApp'; } return ( - visTypes.byName[JSON.parse(savedObject.attributes.visState).type].icon || 'visualizeApp' + visTypes.get(JSON.parse(savedObject.attributes.visState).type).icon || 'visualizeApp' ); }, getTooltipForSavedObject: savedObject => { if (!visTypes) { return ''; } - return `${savedObject.attributes.title} (${visTypes.byName[JSON.parse(savedObject.attributes.visState).type].title})`; + return `${savedObject.attributes.title} (${ + visTypes.get(JSON.parse(savedObject.attributes.visState).type).title + })`; }, showSavedObject: savedObject => { if (!visTypes) { return false; } const typeName: string = JSON.parse(savedObject.attributes.visState).type; - const visType = visTypes.byName[typeName]; + const visType = visTypes.get(typeName); if (!visType) { return false; } diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html b/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html index a35d75a3a68d2..edb7cccbd46a2 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html +++ b/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.html @@ -14,7 +14,6 @@ is-open="listingController.showNewVisModal" on-close="listingController.closeNewVisModal" vis-types-registry="listingController.visTypeRegistry" - vis-type-aliases="listingController.visTypeAliases" > diff --git a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js b/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js index d9f0af40587d3..e6c02bac54df4 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js +++ b/src/legacy/core_plugins/kibana/public/visualize/listing/visualize_listing.js @@ -21,7 +21,6 @@ import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_regis import 'ui/directives/kbn_href'; import { uiModules } from 'ui/modules'; import { timefilter } from 'ui/timefilter'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import chrome from 'ui/chrome'; import { wrapInI18nContext } from 'ui/i18n'; import { toastNotifications } from 'ui/notify'; @@ -29,7 +28,7 @@ import { SavedObjectsClientProvider } from 'ui/saved_objects'; import { VisualizeListingTable } from './visualize_listing_table'; import { NewVisModal } from '../wizard/new_vis_modal'; import { VisualizeConstants } from '../visualize_constants'; -import { setup as visualizationsSetup } from '../../../../visualizations/public/legacy'; +import { start as visualizations } from '../../../../visualizations/public/legacy'; import { i18n } from '@kbn/i18n'; const app = uiModules.get('app/visualize', ['ngRoute', 'react']); @@ -44,9 +43,6 @@ export function VisualizeListingController($injector, createNewVis) { const kbnUrl = $injector.get('kbnUrl'); const savedObjectClient = Private(SavedObjectsClientProvider); - this.visTypeRegistry = Private(VisTypesRegistryProvider); - this.visTypeAliases = visualizationsSetup.types.visTypeAliasRegistry.get(); - timefilter.disableAutoRefreshSelector(); timefilter.disableTimeRangeSelector(); @@ -81,6 +77,7 @@ export function VisualizeListingController($injector, createNewVis) { // TODO: Extract this into an external service. const services = Private(SavedObjectRegistryProvider).byLoaderPropertiesName; const visualizationService = services.visualizations; + this.visTypeRegistry = visualizations.types; this.fetchItems = filter => { const isLabsEnabled = config.get('visualize:enableLabs'); diff --git a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.js b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.js index f65802a9dca13..cc48cbe2cb1b9 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.js +++ b/src/legacy/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.js @@ -18,11 +18,10 @@ */ import './_saved_vis'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { uiModules } from 'ui/modules'; import { SavedObjectLoader, SavedObjectsClientProvider } from 'ui/saved_objects'; import { savedObjectManagementRegistry } from '../../management/saved_object_registry'; -import { setup as visualizationsSetup } from '../../../../visualizations/public/legacy'; +import { start as visualizations } from '../../../../visualizations/public/legacy'; import { createVisualizeEditUrl } from '../visualize_constants'; import { findListItems } from './find_list_items'; @@ -36,7 +35,7 @@ savedObjectManagementRegistry.register({ }); app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome) { - const visTypes = Private(VisTypesRegistryProvider); + const visTypes = visualizations.types; const savedObjectClient = Private(SavedObjectsClientProvider); const saveVisualizationLoader = new SavedObjectLoader( SavedVis, @@ -58,12 +57,12 @@ app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome) } // eslint-disable-line no-empty } - if (!typeName || !visTypes.byName[typeName]) { + if (!typeName || !visTypes.get(typeName)) { source.error = 'Unknown visualization type'; return source; } - source.type = visTypes.byName[typeName]; + source.type = visTypes.get(typeName); source.savedObjectType = 'visualization'; source.icon = source.type.icon; source.image = source.type.image; @@ -86,7 +85,7 @@ app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome) size, mapSavedObjectApiHits: this.mapSavedObjectApiHits.bind(this), savedObjectsClient: this.savedObjectsClient, - visTypes: visualizationsSetup.types.visTypeAliasRegistry.get(), + visTypes: visualizations.types.getAliases(), }); }; diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap b/src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap index 459d66e46a007..1ba42460f3c1a 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap +++ b/src/legacy/core_plugins/kibana/public/visualize/wizard/__snapshots__/new_vis_modal.test.tsx.snap @@ -108,38 +108,11 @@ exports[`NewVisModal filter for visualization types should render as expected 1` isOpen={true} onClose={[Function]} visTypesRegistry={ - Array [ - Object { - "hidden": false, - "name": "vis", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "production", - "title": "Vis Type 1", - "visualization": [Function], - }, - Object { - "hidden": false, - "name": "visExp", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "experimental", - "title": "Experimental Vis", - "visualization": [Function], - }, - Object { - "hidden": false, - "name": "visWithSearch", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "production", - "title": "Vis with search", - "visualization": [Function], - }, - ] + Object { + "all": [Function], + "get": [Function], + "getAliases": [Function], + } } > @@ -890,38 +863,11 @@ exports[`NewVisModal filter for visualization types should render as expected 1` @@ -1441,38 +1387,11 @@ exports[`NewVisModal should render as expected 1`] = ` isOpen={true} onClose={[Function]} visTypesRegistry={ - Array [ - Object { - "hidden": false, - "name": "vis", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "production", - "title": "Vis Type 1", - "visualization": [Function], - }, - Object { - "hidden": false, - "name": "visExp", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "experimental", - "title": "Experimental Vis", - "visualization": [Function], - }, - Object { - "hidden": false, - "name": "visWithSearch", - "requestHandler": "none", - "requiresSearch": false, - "responseHandler": "none", - "stage": "production", - "title": "Vis with search", - "visualization": [Function], - }, - ] + Object { + "all": [Function], + "get": [Function], + "getAliases": [Function], + } } > @@ -2214,38 +2133,11 @@ exports[`NewVisModal should render as expected 1`] = ` diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx b/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx index fbb3faf7b3564..00c60c7718262 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.test.tsx @@ -25,6 +25,7 @@ import { settingsGet } from './new_vis_modal.test.mocks'; import { NewVisModal } from './new_vis_modal'; import { VisType } from 'ui/vis'; +import { TypesStart } from '../../../../visualizations/public/np_ready/types'; describe('NewVisModal', () => { const defaultVisTypeParams = { @@ -37,7 +38,7 @@ describe('NewVisModal', () => { requestHandler: 'none', responseHandler: 'none', }; - const visTypes: VisType[] = [ + const _visTypes = [ { name: 'vis', title: 'Vis Type 1', stage: 'production', ...defaultVisTypeParams }, { name: 'visExp', title: 'Experimental Vis', stage: 'experimental', ...defaultVisTypeParams }, { @@ -47,6 +48,15 @@ describe('NewVisModal', () => { ...defaultVisTypeParams, }, ]; + const visTypes: TypesStart = { + get: (id: string) => { + return _visTypes.find(vis => vis.name === id) as VisType; + }, + all: () => { + return _visTypes as VisType[]; + }, + getAliases: () => [], + }; it('should render as expected', () => { const wrapper = mountWithIntl( diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx b/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx index 52815f6a0737e..1279157f6a974 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/wizard/new_vis_modal.tsx @@ -24,17 +24,16 @@ import { i18n } from '@kbn/i18n'; import chrome from 'ui/chrome'; import { VisType } from 'ui/vis'; -import { VisTypeAlias } from '../../../../visualizations/public'; import { VisualizeConstants } from '../visualize_constants'; import { SearchSelection } from './search_selection'; import { TypeSelection } from './type_selection'; +import { TypesStart } from '../../../../visualizations/public/np_ready/types'; interface TypeSelectionProps { isOpen: boolean; onClose: () => void; - visTypesRegistry: VisType[]; - visTypeAliases?: VisTypeAlias[]; + visTypesRegistry: TypesStart; editorParams?: string[]; } @@ -90,7 +89,6 @@ class NewVisModal extends React.Component ); diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx b/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx index 3b67330a9c969..2e43d3f78631c 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/wizard/show_new_vis.tsx @@ -21,15 +21,15 @@ import React from 'react'; import ReactDOM from 'react-dom'; import { I18nContext } from 'ui/i18n'; -import { VisType } from 'ui/vis'; import { NewVisModal } from './new_vis_modal'; +import { TypesStart } from '../../../../visualizations/public/np_ready/types'; interface ShowNewVisModalParams { editorParams?: string[]; } export function showNewVisModal( - visTypeRegistry: VisType[], + visTypeRegistry: TypesStart, { editorParams = [] }: ShowNewVisModalParams = {} ) { const container = document.createElement('div'); diff --git a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx b/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx index 3cea39925fa56..a4a37e6143f62 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx +++ b/src/legacy/core_plugins/kibana/public/visualize/wizard/type_selection/type_selection.tsx @@ -41,6 +41,7 @@ import { VisTypeAlias } from '../../../../../visualizations/public'; import { NewVisHelp } from './new_vis_help'; import { VisHelpText } from './vis_help_text'; import { VisTypeIcon } from './vis_type_icon'; +import { TypesStart } from '../../../../../visualizations/public/np_ready/types'; interface VisTypeListEntry extends VisType { highlighted: boolean; @@ -52,8 +53,7 @@ interface VisTypeAliasListEntry extends VisTypeAlias { interface TypeSelectionProps { onVisTypeSelected: (visType: VisType) => void; - visTypesRegistry: VisType[]; - visTypeAliases?: VisTypeAlias[]; + visTypesRegistry: TypesStart; showExperimental: boolean; } @@ -79,11 +79,7 @@ class TypeSelection extends React.Component @@ -167,11 +163,10 @@ class TypeSelection extends React.Component { - const types = visTypes.filter(type => { + const types = visTypes.all().filter(type => { // Filter out all lab visualizations if lab mode is not enabled if (!this.props.showExperimental && type.stage === 'experimental') { return false; @@ -185,7 +180,7 @@ class TypeSelection extends React.Component; if (!query) { diff --git a/src/legacy/core_plugins/region_map/public/__tests__/region_map_visualization.js b/src/legacy/core_plugins/region_map/public/__tests__/region_map_visualization.js index 2d70c2120d5f7..2e6b48ff89e28 100644 --- a/src/legacy/core_plugins/region_map/public/__tests__/region_map_visualization.js +++ b/src/legacy/core_plugins/region_map/public/__tests__/region_map_visualization.js @@ -87,6 +87,8 @@ describe('RegionMapsVisualizationTests', function () { ], }; + let visRegComplete = false; + beforeEach(ngMock.module('kibana')); let getManifestStub; @@ -106,7 +108,10 @@ describe('RegionMapsVisualizationTests', function () { uiSettings, }; - visualizationsSetup.types.registerVisualization(() => createRegionMapTypeDefinition(dependencies)); + if(!visRegComplete) { + visRegComplete = true; + visualizationsSetup.types.registerVisualization(() => createRegionMapTypeDefinition(dependencies)); + } Vis = Private(visModule.VisProvider); RegionMapsVisualization = createRegionMapVisualization(dependencies); diff --git a/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js b/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js index 17162278b1e20..a0ae604eb4659 100644 --- a/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js +++ b/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js @@ -60,6 +60,7 @@ mockRawData(); const THRESHOLD = 0.45; const PIXEL_DIFF = 64; +let visRegComplete = false; describe('CoordinateMapsVisualizationTest', function () { let domNode; @@ -84,7 +85,11 @@ describe('CoordinateMapsVisualizationTest', function () { $injector, }; - visualizationsSetup.types.registerVisualization(() => createTileMapTypeDefinition(dependencies)); + if(!visRegComplete) { + visRegComplete = true; + visualizationsSetup.types.registerVisualization(() => createTileMapTypeDefinition(dependencies)); + } + Vis = Private(visModule.VisProvider); CoordinateMapsVisualization = createTileMapVisualization(dependencies); diff --git a/src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis.js b/src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis.js index f5fb6312d2b0a..7f626df6a4ea3 100644 --- a/src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis.js +++ b/src/legacy/core_plugins/vis_type_metric/public/__tests__/metric_vis.js @@ -24,7 +24,6 @@ import expect from '@kbn/expect'; import { VisProvider } from 'ui/vis'; import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern'; -import { setup as visualizationsSetup } from '../../../visualizations/public/legacy'; import { createMetricVisTypeDefinition } from '../metric_vis_type'; describe('metric_vis - createMetricVisTypeDefinition', () => { @@ -37,9 +36,6 @@ describe('metric_vis - createMetricVisTypeDefinition', () => { setup = () => { const Vis = Private(VisProvider); const metricVisType = createMetricVisTypeDefinition(); - - visualizationsSetup.types.registerVisualization(() => metricVisType); - const indexPattern = Private(LogstashIndexPatternStubProvider); indexPattern.stubSetFieldFormat('ip', 'url', { diff --git a/src/legacy/core_plugins/vis_type_table/public/__tests__/table_vis_controller.js b/src/legacy/core_plugins/vis_type_table/public/__tests__/table_vis_controller.js index f04c953f070ae..94c8fec650dcf 100644 --- a/src/legacy/core_plugins/vis_type_table/public/__tests__/table_vis_controller.js +++ b/src/legacy/core_plugins/vis_type_table/public/__tests__/table_vis_controller.js @@ -43,19 +43,22 @@ describe('Table Vis - Controller', async function () { let tabifiedResponse; let legacyDependencies; + ngMock.inject(function ($injector) { + Private = $injector.get('Private'); + legacyDependencies = { + // eslint-disable-next-line new-cap + createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, + }; + + visualizationsSetup.types.registerVisualization(() => + createTableVisTypeDefinition(legacyDependencies) + ); + }); + beforeEach(ngMock.module('kibana', 'kibana/table_vis')); beforeEach( ngMock.inject(function ($injector) { Private = $injector.get('Private'); - legacyDependencies = { - // eslint-disable-next-line new-cap - createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, - }; - - visualizationsSetup.types.registerVisualization(() => - createTableVisTypeDefinition(legacyDependencies) - ); - $rootScope = $injector.get('$rootScope'); $compile = $injector.get('$compile'); fixtures = require('fixtures/fake_hierarchical_data'); diff --git a/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table.js b/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table.js index 323201ded73a3..4dad6bf5e44a0 100644 --- a/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table.js +++ b/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table.js @@ -99,16 +99,18 @@ describe('Table Vis - AggTable Directive', function () { ); }; + ngMock.inject(function (Private) { + legacyDependencies = { + // eslint-disable-next-line new-cap + createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, + }; + + visualizationsSetup.types.registerVisualization(() => createTableVisTypeDefinition(legacyDependencies)); + }); + beforeEach(ngMock.module('kibana')); beforeEach( ngMock.inject(function ($injector, Private, config) { - legacyDependencies = { - // eslint-disable-next-line new-cap - createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, - }; - - visualizationsSetup.types.registerVisualization(() => createTableVisTypeDefinition(legacyDependencies)); - tableAggResponse = legacyResponseHandlerProvider().handler; indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); Vis = Private(VisProvider); diff --git a/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table_group.js b/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table_group.js index 77a0ee5221b95..e8359e37d6186 100644 --- a/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table_group.js +++ b/src/legacy/core_plugins/vis_type_table/public/agg_table/__tests__/agg_table_group.js @@ -26,17 +26,12 @@ import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logsta import { VisProvider } from 'ui/vis'; import { tabifyAggResponse } from 'ui/agg_response/tabify'; -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { createTableVisTypeDefinition } from '../../table_vis_type'; -import { setup as visualizationsSetup } from '../../../../visualizations/public/legacy'; - describe('Table Vis - AggTableGroup Directive', function () { let $rootScope; let $compile; let Vis; let indexPattern; let tableAggResponse; - let legacyDependencies; const tabifiedData = {}; const init = () => { @@ -61,12 +56,16 @@ describe('Table Vis - AggTableGroup Directive', function () { beforeEach(ngMock.module('kibana')); beforeEach( ngMock.inject(function ($injector, Private) { + // this is provided in table_vis_controller.js + // tech debt that will be resolved through further deangularization and moving tests to jest + /* legacyDependencies = { // eslint-disable-next-line new-cap createAngularVisualization: VisFactoryProvider(Private).createAngularVisualization, }; visualizationsSetup.types.registerVisualization(() => createTableVisTypeDefinition(legacyDependencies)); + */ tableAggResponse = legacyResponseHandlerProvider().handler; indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); diff --git a/src/legacy/core_plugins/vis_type_vega/public/__tests__/vega_visualization.js b/src/legacy/core_plugins/vis_type_vega/public/__tests__/vega_visualization.js index 9c46dfb9451fa..1bd68774ab071 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/__tests__/vega_visualization.js +++ b/src/legacy/core_plugins/vis_type_vega/public/__tests__/vega_visualization.js @@ -55,6 +55,7 @@ describe('VegaVisualizations', () => { let vis; let imageComparator; let vegaVisualizationDependencies; + let visRegComplete = false; beforeEach(ngMock.module('kibana')); beforeEach( @@ -65,9 +66,12 @@ describe('VegaVisualizations', () => { uiSettings: $injector.get('config'), }; - visualizationsSetup.types.registerVisualization(() => - createVegaTypeDefinition(vegaVisualizationDependencies) - ); + if(!visRegComplete) { + visRegComplete = true; + visualizationsSetup.types.registerVisualization(() => + createVegaTypeDefinition(vegaVisualizationDependencies) + ); + } Vis = Private(visModule.VisProvider); diff --git a/src/legacy/core_plugins/visualizations/public/index.ts b/src/legacy/core_plugins/visualizations/public/index.ts index eb93bb9b419eb..997f18cbd5146 100644 --- a/src/legacy/core_plugins/visualizations/public/index.ts +++ b/src/legacy/core_plugins/visualizations/public/index.ts @@ -41,8 +41,7 @@ export type Vis = types.Vis; export type VisParams = types.VisParams; export type VisProvider = types.VisProvider; export type VisState = types.VisState; -export { VisualizationController, VisType } from 'ui/vis/vis_types/vis_type'; -export { VisTypesRegistry } from 'ui/registry/vis_types'; +export { VisualizationController } from 'ui/vis/vis_types/vis_type'; export { Status } from 'ui/vis/update_status'; /** diff --git a/src/legacy/core_plugins/visualizations/public/legacy.ts b/src/legacy/core_plugins/visualizations/public/legacy.ts index c589c7eed0be1..088563a1970c3 100644 --- a/src/legacy/core_plugins/visualizations/public/legacy.ts +++ b/src/legacy/core_plugins/visualizations/public/legacy.ts @@ -38,12 +38,6 @@ import { PluginInitializerContext } from 'src/core/public'; import { npSetup, npStart } from 'ui/new_platform'; // @ts-ignore import { VisFiltersProvider, createFilter } from 'ui/vis/vis_filters'; -// @ts-ignore -import { VisProvider as Vis } from 'ui/vis/index.js'; -// @ts-ignore -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; -import chrome from 'ui/chrome'; import { plugin } from '.'; @@ -53,15 +47,6 @@ export const setup = pluginInstance.setup(npSetup.core, { __LEGACY: { VisFiltersProvider, createFilter, - - Vis, - VisFactoryProvider, - VisTypesRegistryProvider, - }, -}); -export const start = pluginInstance.start(npStart.core, { - __LEGACY: { - VisTypesRegistryProvider, - chrome, }, }); +export const start = pluginInstance.start(npStart.core); diff --git a/src/legacy/core_plugins/visualizations/public/mocks.ts b/src/legacy/core_plugins/visualizations/public/mocks.ts index 4c14d0e54646d..11dccbb173755 100644 --- a/src/legacy/core_plugins/visualizations/public/mocks.ts +++ b/src/legacy/core_plugins/visualizations/public/mocks.ts @@ -17,8 +17,6 @@ * under the License. */ -import chrome from 'ui/chrome'; - jest.mock('ui/vis/vis_filters'); jest.mock('ui/vis/default_feedback_message'); jest.mock('ui/vis/index.js'); @@ -30,7 +28,6 @@ import { VisFiltersProvider, createFilter } from 'ui/vis/vis_filters'; import { VisProvider as Vis } from 'ui/vis/index.js'; // @ts-ignore import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; jest.mock('./types/vis_type_alias_registry'); import { PluginInitializerContext } from 'src/core/public'; @@ -44,19 +41,16 @@ const createSetupContract = (): VisualizationsSetup => ({ createFilter: jest.fn(), }, types: { - Vis, - VisFactoryProvider: jest.fn(), registerVisualization: jest.fn(), - visTypeAliasRegistry: { - add: jest.fn(), - get: jest.fn(), - }, + registerAlias: jest.fn(), }, }); const createStartContract = (): VisualizationsStart => ({ types: { get: jest.fn(), + all: jest.fn(), + getAliases: jest.fn(), }, }); @@ -67,19 +61,9 @@ const createInstance = async () => { __LEGACY: { VisFiltersProvider, createFilter, - - Vis, - VisFactoryProvider, - VisTypesRegistryProvider, }, }); - const doStart = () => - plugin.start(coreMock.createStart(), { - __LEGACY: { - VisTypesRegistryProvider, - chrome, - }, - }); + const doStart = () => plugin.start(coreMock.createStart()); return { plugin, diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/index.ts b/src/legacy/core_plugins/visualizations/public/np_ready/index.ts index 38b6a32125358..f43550676e1b2 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/index.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/index.ts @@ -36,7 +36,7 @@ export type VisualizationsSetup = VisualizationsSetup; export type VisualizationsStart = VisualizationsStart; /** @public types */ -export { VisTypeAlias } from './types'; +export { VisTypeAlias, VisType } from './types'; export function plugin(initializerContext: PluginInitializerContext) { return new VisualizationsPlugin(initializerContext); diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/plugin.ts b/src/legacy/core_plugins/visualizations/public/np_ready/plugin.ts index 6d09b0249775b..0e77c3ce88385 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/plugin.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/plugin.ts @@ -30,17 +30,6 @@ interface VisualizationsPluginSetupDependencies { __LEGACY: { VisFiltersProvider: any; createFilter: any; - - Vis: any; - VisFactoryProvider: any; - VisTypesRegistryProvider: any; - }; -} - -interface VisualizationsPluginStartDependencies { - __LEGACY: { - VisTypesRegistryProvider: any; - chrome: any; }; } @@ -69,41 +58,27 @@ export interface VisualizationsStart { */ export class VisualizationsPlugin implements - Plugin< - VisualizationsSetup, - VisualizationsStart, - VisualizationsPluginSetupDependencies, - VisualizationsPluginStartDependencies - > { + Plugin { private readonly filters: FiltersService = new FiltersService(); private readonly types: TypesService = new TypesService(); constructor(initializerContext: PluginInitializerContext) {} public setup(core: CoreSetup, { __LEGACY }: VisualizationsPluginSetupDependencies) { - const { - VisFiltersProvider, - createFilter, - Vis, - VisFactoryProvider, - VisTypesRegistryProvider, - } = __LEGACY; + const { VisFiltersProvider, createFilter } = __LEGACY; return { filters: this.filters.setup({ VisFiltersProvider, createFilter, }), - types: this.types.setup({ Vis, VisFactoryProvider, VisTypesRegistryProvider }), + types: this.types.setup(), }; } - public async start(core: CoreStart, { __LEGACY }: VisualizationsPluginStartDependencies) { - const { chrome, VisTypesRegistryProvider } = __LEGACY; - const $injector = await chrome.dangerouslyGetActiveInjector(); - const Private: any = $injector.get('Private'); + public start(core: CoreStart) { return { - types: this.types.start({ VisTypesRegistryProvider, Private }), + types: this.types.start(), }; } diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/types/types_service.ts b/src/legacy/core_plugins/visualizations/public/np_ready/types/types_service.ts index 608fcfa37f414..37971491e61a4 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/types/types_service.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/types/types_service.ts @@ -17,41 +17,59 @@ * under the License. */ +import { IconType } from '@elastic/eui'; import { visTypeAliasRegistry, VisTypeAlias } from './vis_type_alias_registry'; -interface SetupDependencies { - Vis: any; - VisFactoryProvider: any; - VisTypesRegistryProvider: any; -} +export interface VisType { + name: string; + title: string; + description?: string; + visualization: any; + isAccessible?: boolean; + requestHandler: string; + responseHandler: string; + icon?: IconType; + image?: string; + stage: 'experimental' | 'production'; + requiresSearch: boolean; + hidden: boolean; -interface StartDependencies { - VisTypesRegistryProvider: any; - Private: any; + // Since we haven't typed everything here yet, we basically "any" the rest + // of that interface. This should be removed as soon as this type definition + // has been completed. But that way we at least have typing for a couple of + // properties on that type. + [key: string]: any; } + /** * Vis Types Service * * @internal */ export class TypesService { - public setup({ Vis, VisFactoryProvider, VisTypesRegistryProvider }: SetupDependencies) { + private types: Record = {}; + public setup() { return { - Vis, - VisFactoryProvider, - registerVisualization: (registerFn: () => any) => { - VisTypesRegistryProvider.register(registerFn); + registerVisualization: (registerFn: () => VisType) => { + const visDefinition = registerFn(); + if (this.types[visDefinition.name]) { + throw new Error('type already exists!'); + } + this.types[visDefinition.name] = visDefinition; }, - visTypeAliasRegistry, + registerAlias: visTypeAliasRegistry.add, }; } - public start({ VisTypesRegistryProvider, Private }: StartDependencies) { - const visTypes = Private(VisTypesRegistryProvider); + public start() { return { get: (visualization: string) => { - return visTypes.byName[visualization]; + return this.types[visualization]; + }, + all: () => { + return [...Object.values(this.types)]; }, + getAliases: visTypeAliasRegistry.get, }; } diff --git a/src/legacy/ui/public/registry/vis_types.ts b/src/legacy/ui/public/registry/vis_types.ts deleted file mode 100644 index 7f4c2e96eee44..0000000000000 --- a/src/legacy/ui/public/registry/vis_types.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 { VisType } from '../vis'; -import { uiRegistry, UIRegistry } from './_registry'; - -interface VisTypesRegistryAccessors { - byName: { [typeName: string]: VisType }; -} - -export type VisTypesRegistry = UIRegistry & VisTypesRegistryAccessors; - -export const VisTypesRegistryProvider = uiRegistry({ - name: 'visTypes', - index: ['name'], - order: ['title'], -}); diff --git a/src/legacy/ui/public/vis/__tests__/_vis.js b/src/legacy/ui/public/vis/__tests__/_vis.js index 8e09ea211945b..9ecfd90b29fe5 100644 --- a/src/legacy/ui/public/vis/__tests__/_vis.js +++ b/src/legacy/ui/public/vis/__tests__/_vis.js @@ -22,7 +22,7 @@ import ngMock from 'ng_mock'; import expect from '@kbn/expect'; import { VisProvider } from '..'; import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; -import { VisTypesRegistryProvider } from '../../registry/vis_types'; +import { start as visualizations } from '../../../../core_plugins/visualizations/public/legacy'; describe('Vis Class', function () { let indexPattern; @@ -45,7 +45,7 @@ describe('Vis Class', function () { beforeEach(ngMock.inject(function (Private) { Vis = Private(VisProvider); indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); - visTypes = Private(VisTypesRegistryProvider); + visTypes = visualizations.types; })); beforeEach(function () { @@ -57,7 +57,7 @@ describe('Vis Class', function () { expect(vis.aggs.aggs).to.have.length(3); expect(vis).to.have.property('type'); - expect(vis.type).to.eql(visTypes.byName.pie); + expect(vis.type).to.eql(visTypes.get('pie')); expect(vis).to.have.property('params'); expect(vis.params).to.have.property('isDonut', true); @@ -87,7 +87,7 @@ describe('Vis Class', function () { it('should set the state to defaults', function () { const vis = new Vis(indexPattern); expect(vis).to.have.property('type'); - expect(vis.type).to.eql(visTypes.byName.histogram); + expect(vis.type).to.eql(visTypes.get('histogram')); expect(vis).to.have.property('aggs'); expect(vis.aggs.aggs).to.have.length(1); expect(vis).to.have.property('params'); diff --git a/src/legacy/ui/public/vis/vis.js b/src/legacy/ui/public/vis/vis.js index c12c639a3e826..b3f032ae98d62 100644 --- a/src/legacy/ui/public/vis/vis.js +++ b/src/legacy/ui/public/vis/vis.js @@ -30,16 +30,16 @@ import { EventEmitter } from 'events'; import _ from 'lodash'; import '../render_complete/directive'; -import { VisTypesRegistryProvider } from '../registry/vis_types'; import { AggConfigs } from '../agg_types/agg_configs'; import { PersistedState } from '../persisted_state'; import { updateVisualizationConfig } from './vis_update'; import { SearchSourceProvider } from '../courier/search_source'; +import { start as visualizations } from '../../../core_plugins/visualizations/public/legacy'; import '../directives/bind'; export function VisProvider(Private, getAppState) { - const visTypes = Private(VisTypesRegistryProvider); + const visTypes = visualizations.types; const SearchSource = Private(SearchSourceProvider); class Vis extends EventEmitter { @@ -75,7 +75,7 @@ export function VisProvider(Private, getAppState) { this.title = state.title || ''; const type = state.type || this.type; if (_.isString(type)) { - this.type = visTypes.byName[type]; + this.type = visTypes.get(type); if (!this.type) { throw new Error(`Invalid type "${type}"`); } diff --git a/src/legacy/ui/public/vis/vis_types/vis_type.ts b/src/legacy/ui/public/vis/vis_types/vis_type.ts index 547a89e385a4b..9d06409fda622 100644 --- a/src/legacy/ui/public/vis/vis_types/vis_type.ts +++ b/src/legacy/ui/public/vis/vis_types/vis_type.ts @@ -17,9 +17,9 @@ * under the License. */ -import { IconType } from '@elastic/eui'; import { Status } from '../update_status'; import { Vis } from '..'; +export { VisType } from '../../../../core_plugins/visualizations/public'; export declare class VisualizationController { constructor(element: HTMLElement, vis: Vis); @@ -27,24 +27,3 @@ export declare class VisualizationController { public destroy(): void; public isLoaded?(): Promise | void; } - -export interface VisType { - name: string; - title: string; - description?: string; - visualization: typeof VisualizationController; - isAccessible?: boolean; - requestHandler: string; - responseHandler: string; - icon?: IconType; - image?: string; - stage: 'experimental' | 'production'; - requiresSearch: boolean; - hidden: boolean; - - // Since we haven't typed everything here yet, we basically "any" the rest - // of that interface. This should be removed as soon as this type definition - // has been completed. But that way we at least have typing for a couple of - // properties on that type. - [key: string]: any; -} diff --git a/src/legacy/ui/public/visualize/components/visualization_chart.tsx b/src/legacy/ui/public/visualize/components/visualization_chart.tsx index 452a80863b796..06e44a4fd6e1c 100644 --- a/src/legacy/ui/public/visualize/components/visualization_chart.tsx +++ b/src/legacy/ui/public/visualize/components/visualization_chart.tsx @@ -119,7 +119,8 @@ class VisualizationChart extends React.Component { if (onInit) { // In case the visualization implementation has an isLoaded function, we // call that and wait for the result to resolve (in case it was a promise). - const visLoaded = this.visualization.isLoaded && this.visualization.isLoaded(); + const visLoaded = + this.visualization && this.visualization.isLoaded && this.visualization.isLoaded(); Promise.resolve(visLoaded).then(onInit); } diff --git a/src/legacy/ui/public/visualize/loader/vis.js b/src/legacy/ui/public/visualize/loader/vis.js index 00ea5d1550df3..39acf795a9372 100644 --- a/src/legacy/ui/public/visualize/loader/vis.js +++ b/src/legacy/ui/public/visualize/loader/vis.js @@ -29,11 +29,13 @@ import { EventEmitter } from 'events'; import _ from 'lodash'; -import { VisTypesRegistryProvider } from '../../registry/vis_types'; import { PersistedState } from '../../persisted_state'; -export function VisProvider(Private, indexPatterns, getAppState) { - const visTypes = Private(VisTypesRegistryProvider); +import { start as visualizations } from '../../../../core_plugins/visualizations/public/legacy'; + + +export function VisProvider(indexPatterns, getAppState) { + const visTypes = visualizations.types; class Vis extends EventEmitter { constructor(visState = { type: 'histogram' }) { @@ -65,7 +67,7 @@ export function VisProvider(Private, indexPatterns, getAppState) { this.title = state.title || ''; const type = state.type || this.type; if (_.isString(type)) { - this.type = visTypes.byName[type]; + this.type = visTypes.get(type); if (!this.type) { throw new Error(`Invalid type "${type}"`); } diff --git a/test/plugin_functional/plugins/kbn_tp_custom_visualizations/public/self_changing_vis/self_changing_vis.js b/test/plugin_functional/plugins/kbn_tp_custom_visualizations/public/self_changing_vis/self_changing_vis.js index 2bf3ab9085949..daa493c727fd0 100644 --- a/test/plugin_functional/plugins/kbn_tp_custom_visualizations/public/self_changing_vis/self_changing_vis.js +++ b/test/plugin_functional/plugins/kbn_tp_custom_visualizations/public/self_changing_vis/self_changing_vis.js @@ -17,16 +17,16 @@ * under the License. */ -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; +import { visFactory } from 'ui/vis/vis_factory'; import { SelfChangingEditor } from './self_changing_editor'; import { SelfChangingComponent } from './self_changing_components'; -function SelfChangingVisType(Private) { - const VisFactory = Private(VisFactoryProvider); +import { setup as visualizations } from '../../../../../../src/legacy/core_plugins/visualizations/public/legacy'; - return VisFactory.createReactVisualization({ +function SelfChangingVisType() { + + return visFactory.createReactVisualization({ name: 'self_changing_vis', title: 'Self Changing Vis', icon: 'visControls', @@ -50,4 +50,4 @@ function SelfChangingVisType(Private) { }); } -VisTypesRegistryProvider.register(SelfChangingVisType); +visualizations.types.registerVisualization(SelfChangingVisType); diff --git a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts index 5ac5c49eca9b1..701c351b8b149 100644 --- a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts +++ b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import { visualizations } from '../../../../../src/legacy/core_plugins/visualizations/public'; import { BASE_APP_URL, getEditPath } from '../common'; -visualizations.types.visTypeAliasRegistry.add({ +visualizations.types.registerAlias({ aliasUrl: BASE_APP_URL, name: 'lens', isPromoted: true, diff --git a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js index 8a103a554f7f2..3708957159f61 100644 --- a/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js +++ b/x-pack/legacy/plugins/maps/public/register_vis_type_alias.js @@ -8,7 +8,7 @@ import { setup as visualizationsSetup } from '../../../../../src/legacy/core_plu import { i18n } from '@kbn/i18n'; import { APP_ID, APP_ICON, MAP_BASE_URL } from '../common/constants'; -visualizationsSetup.types.visTypeAliasRegistry.add({ +visualizationsSetup.types.registerAlias({ aliasUrl: MAP_BASE_URL, name: APP_ID, title: i18n.translate('xpack.maps.visTypeAlias.title', {