Skip to content

Commit

Permalink
Remove VisTypesRegistry (ui/registry/vis_types) (#46323) (#46893)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Sep 30, 2019
1 parent cb7a696 commit c07e407
Show file tree
Hide file tree
Showing 35 changed files with 193 additions and 382 deletions.
11 changes: 5 additions & 6 deletions src/legacy/core_plugins/input_control_vis/public/register_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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<VisualizeEmbeddableFactory> {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get<IPrivate>('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' }),
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
is-open="listingController.showNewVisModal"
on-close="listingController.closeNewVisModal"
vis-types-registry="listingController.visTypeRegistry"
vis-type-aliases="listingController.visTypeAliases"
></new-vis-modal>

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ 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';
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']);
Expand All @@ -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();

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

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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(),
});
};

Expand Down
Loading

0 comments on commit c07e407

Please sign in to comment.