Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VisTypesRegistryProvider => VisualizationsPlugin interface - Draft #43459

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3e51172
swap registry with map
mattkime Aug 16, 2019
8b83c92
typescript fixes, add => register - reverting unneeded change
mattkime Aug 16, 2019
a80d5cf
fix create vis flow
mattkime Aug 19, 2019
bbae5cf
typescript
mattkime Aug 19, 2019
9754ae9
tslint fixes
mattkime Aug 20, 2019
1184ddf
Merge branch 'master' into visTypeRegisteryD18n
mattkime Aug 20, 2019
3463fff
typescript fixes
mattkime Aug 20, 2019
1679290
snap snap
mattkime Aug 20, 2019
716a010
fix: make pie chart available in functional tests
streamich Aug 22, 2019
15df0b8
typescript cleanup
mattkime Aug 22, 2019
8d35f1e
typescript fix
mattkime Aug 22, 2019
8237379
revert change mistake
mattkime Aug 22, 2019
aa6bd26
fix timelion
mattkime Aug 23, 2019
1e10abe
fix self_changing_vis plugin
mattkime Aug 23, 2019
c71cacf
Merge branch 'master' of github.com:elastic/kibana into visTypeRegist…
mattkime Aug 23, 2019
6376435
cleanup
mattkime Aug 26, 2019
2abfd84
Merge branch 'visTypeRegisteryD18n' of github.com:mattkime/kibana int…
mattkime Aug 26, 2019
9d7125d
Merge branch 'master' of github.com:elastic/kibana into visTypeRegist…
mattkime Aug 26, 2019
901c675
Revert "cleanup"
mattkime Aug 26, 2019
ed4fcdf
restore some cleanup
mattkime Aug 26, 2019
56c3e60
remove comment, import visType instead of creating var
mattkime Aug 26, 2019
1521dc1
import 'as' instead of assigning to var
mattkime Aug 26, 2019
0b118c7
Merge branch 'master' into visTypeRegisteryD18n
mattkime Aug 26, 2019
b71631e
revert commit to fix functional test
mattkime Aug 26, 2019
a8e2ade
revert mistaken commit
mattkime Aug 26, 2019
a42a3cc
Merge branch 'master' into visTypeRegisteryD18n
mattkime Aug 28, 2019
e1149e0
Merge branch 'master' into visTypeRegisteryD18n
mattkime Aug 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 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 { visFactory } from 'ui/vis/vis_factory';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
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 { visualizations } from '../../visualizations';

function InputControlVisProvider(Private) {
const VisFactory = Private(VisFactoryProvider);

const InputControlVisProvider =
// return the visType object, which kibana will use to display and configure new Vis object of this type.
return VisFactory.createBaseVisualization({
visFactory.createBaseVisualization({
name: 'input_control_vis',
title: i18n.translate('inputControl.register.controlsTitle', {
defaultMessage: 'Controls'
Expand Down Expand Up @@ -73,7 +72,6 @@ function InputControlVisProvider(Private) {
requestHandler: 'none',
responseHandler: 'none',
});
}

// register the provider with the visTypes registry
VisTypesRegistryProvider.register(InputControlVisProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ export const visualization = () => ({
const Private = $injector.get('Private');
const requestHandlers = Private(RequestHandlersProvider);
const responseHandlers = Private(ResponseHandlerProvider);
const visTypes = Private(VisTypesRegistryProvider);
const visTypes = VisTypesRegistryProvider;
const indexPatterns = Private(IndexPatternsProvider);
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 = visTypes.get(args.type || 'histogram');
const requestHandler = getHandler(requestHandlers, visType.requestHandler);
const responseHandler = getHandler(responseHandlers, visType.responseHandler);
const indexPattern = args.index ? await indexPatterns.get(args.index) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import chrome from 'ui/chrome';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';

import histogramVisTypeProvider from './histogram';
Expand All @@ -28,11 +29,18 @@ 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);
async function registerItems() {
const $injector = await chrome.dangerouslyGetActiveInjector();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppisljar chrome.dangerouslyGetActiveInjector(); doesn't return in the browser tests and some 80 tests fail. Perhaps we need an alternative way of registering these - what the best way to do it for a karma test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm ... interesting .... i had a feeling we did this in other places that were tested by karma and it was working, will try to look into it later today if time allows.

const Private = $injector.get('Private');

VisTypesRegistryProvider.register(histogramVisTypeProvider(Private));
VisTypesRegistryProvider.register(lineVisTypeProvider(Private));
VisTypesRegistryProvider.register(pieVisTypeProvider(Private));
VisTypesRegistryProvider.register(areaVisTypeProvider(Private));
VisTypesRegistryProvider.register(heatmapVisTypeProvider(Private));
VisTypesRegistryProvider.register(horizontalBarVisTypeProvider(Private));
VisTypesRegistryProvider.register(gaugeVisTypeProvider(Private));
VisTypesRegistryProvider.register(goalVisTypeProvider(Private));
}

registerItems();
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ uiRoutes
template: editorTemplate,
k7Breadcrumbs: getCreateBreadcrumbs,
resolve: {
savedVis: function (savedVisualizations, redirectWhenMissing, $route, Private) {
const visTypes = Private(VisTypesRegistryProvider);
const visType = _.find(visTypes, { name: $route.current.params.type });
savedVis: function (savedVisualizations, redirectWhenMissing, $route) {
const visTypes = VisTypesRegistryProvider;
const visType = visTypes.get($route.current.params.type);
const shouldHaveIndex = visType.requiresSearch && visType.options.showIndexSelection;
const hasIndex = $route.current.params.indexPattern || $route.current.params.savedSearchId;
if (shouldHaveIndex && !hasIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ 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 {
EmbeddableFactory,
Expand All @@ -79,41 +78,41 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
VisualizationAttributes
> {
public readonly type = VISUALIZE_EMBEDDABLE_TYPE;
private readonly visTypes: VisTypesRegistry;

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(() => VisTypesRegistryProvider.getAll());
}

constructor(visTypes: VisTypesRegistry) {
constructor(private readonly getVisTypesRegistry: () => VisTypesRegistry) {
super({
savedObjectMetaData: {
name: i18n.translate('kbn.visualize.savedObjectName', { defaultMessage: 'Visualization' }),
type: 'visualization',
getIconForSavedObject: savedObject => {
const visTypes = getVisTypesRegistry();
if (!visTypes) {
return 'visualizeApp';
} else {
const visStateType = visTypes.get(JSON.parse(savedObject.attributes.visState).type);
return visStateType ? visStateType.icon : 'visualizeApp';
}
return (
visTypes.byName[JSON.parse(savedObject.attributes.visState).type].icon || 'visualizeApp'
);
},
getTooltipForSavedObject: savedObject => {
const visTypes = getVisTypesRegistry();
if (!visTypes) {
return '';
}
return `${savedObject.attributes.title} (${visTypes.byName[JSON.parse(savedObject.attributes.visState).type].title})`;
const visStateType = visTypes.get(JSON.parse(savedObject.attributes.visState).type);
return `${savedObject.attributes.title} (
${visStateType ? visStateType.title : ''})`;
},
showSavedObject: savedObject => {
const visTypes = getVisTypesRegistry();
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 All @@ -124,8 +123,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
},
},
});

this.visTypes = visTypes;
}

public isEditable() {
Expand Down Expand Up @@ -179,10 +176,13 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
}

public async create() {
const visTypes = getVisTypesRegistry();
// TODO: This is a bit of a hack to preserve the original functionality. Ideally we will clean this up
// to allow for in place creation of visualizations without having to navigate away to a new URL.
if (this.visTypes) {
showNewVisModal(this.visTypes, {

// TODO: This now seems redundant as `visTypes` will always be truthy.
if (visTypes) {
showNewVisModal(visTypes, {
editorParams: ['addToDashboard'],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function VisualizeListingController($injector, createNewVis) {
const config = $injector.get('config');
const kbnUrl = $injector.get('kbnUrl');

this.visTypeRegistry = Private(VisTypesRegistryProvider);
this.visTypeRegistry = VisTypesRegistryProvider.getAll();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as well as every place we read from the registry

this.visTypeAliases = visualizations.types.visTypeAliasRegistry.get();

timefilter.disableAutoRefreshSelector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ savedObjectManagementRegistry.register({
});

app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome) {
const visTypes = Private(VisTypesRegistryProvider);
const visTypes = VisTypesRegistryProvider;

const savedObjectClient = Private(SavedObjectsClientProvider);
const saveVisualizationLoader = new SavedObjectLoader(SavedVis, kbnUrl, chrome, savedObjectClient);
Expand All @@ -48,12 +48,12 @@ app.service('savedVisualizations', function (SavedVis, Private, kbnUrl, chrome)
catch (e) { /* missing typename handled below */ } // 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.icon = source.type.icon;
return source;
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading