diff --git a/src/legacy/core_plugins/markdown_vis/public/markdown_vis.js b/src/legacy/core_plugins/markdown_vis/public/markdown_vis.js
index 7842ad0bf523e..18afbb94eee05 100644
--- a/src/legacy/core_plugins/markdown_vis/public/markdown_vis.js
+++ b/src/legacy/core_plugins/markdown_vis/public/markdown_vis.js
@@ -19,7 +19,7 @@
import { MarkdownVisWrapper } from './markdown_vis_controller';
import { i18n } from '@kbn/i18n';
-import { VisFactoryProvider } from 'ui/vis/vis_factory';
+import { visFactory } from 'ui/vis/vis_factory';
import markdownVisParamsTemplate from './markdown_vis_params.html';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { DefaultEditorSize } from 'ui/vis/editor_size';
@@ -30,12 +30,10 @@ import { DefaultEditorSize } from 'ui/vis/editor_size';
// register the provider with the visTypes registry so that other know it exists
VisTypesRegistryProvider.register(MarkdownVisProvider);
-function MarkdownVisProvider(Private) {
- const VisFactory = Private(VisFactoryProvider);
-
+function MarkdownVisProvider() {
// return the visType object, which kibana will use to display and configure new
// Vis object of this type.
- return VisFactory.createReactVisualization({
+ return visFactory.createReactVisualization({
name: 'markdown',
title: 'Markdown',
isAccessible: true,
diff --git a/src/legacy/core_plugins/table_vis/public/table_vis.js b/src/legacy/core_plugins/table_vis/public/table_vis.js
index d9ccdca626a11..8e8d57f878f5d 100644
--- a/src/legacy/core_plugins/table_vis/public/table_vis.js
+++ b/src/legacy/core_plugins/table_vis/public/table_vis.js
@@ -27,7 +27,6 @@ import { Schemas } from 'ui/vis/editors/default/schemas';
import tableVisTemplate from './table_vis.html';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
-import { VisFiltersProvider } from 'ui/vis/vis_filters';
// we need to load the css ourselves
@@ -45,7 +44,6 @@ const legacyTableResponseHandler = legacyResponseHandlerProvider().handler;
// define the TableVisType
function TableVisTypeProvider(Private) {
const VisFactory = Private(VisFactoryProvider);
- const visFilters = Private(VisFiltersProvider);
// define the TableVisController which is used in the template
// by angular's ng-controller directive
@@ -112,11 +110,6 @@ function TableVisTypeProvider(Private) {
])
},
responseHandler: legacyTableResponseHandler,
- events: {
- filterBucket: {
- defaultAction: visFilters.filter,
- },
- },
hierarchicalData: function (vis) {
return Boolean(vis.params.showPartialRows || vis.params.showMetricsAtAllLevels);
}
diff --git a/src/legacy/ui/public/vis/__tests__/vis_types/base_vis_type.js b/src/legacy/ui/public/vis/__tests__/vis_types/base_vis_type.js
index 7590ff93d2b47..d2e545bde8241 100644
--- a/src/legacy/ui/public/vis/__tests__/vis_types/base_vis_type.js
+++ b/src/legacy/ui/public/vis/__tests__/vis_types/base_vis_type.js
@@ -19,15 +19,10 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
-import { BaseVisTypeProvider } from '../../vis_types/base_vis_type';
+import { BaseVisType } from '../../vis_types/base_vis_type';
describe('Base Vis Type', function () {
- let BaseVisType;
-
beforeEach(ngMock.module('kibana'));
- beforeEach(ngMock.inject(function (Private) {
- BaseVisType = Private(BaseVisTypeProvider);
- }));
describe('initialization', () => {
it('should throw if mandatory properties are missing', () => {
diff --git a/src/legacy/ui/public/vis/__tests__/vis_types/react_vis_type.js b/src/legacy/ui/public/vis/__tests__/vis_types/react_vis_type.js
index 99b485e8ef55d..b2478655d1cfe 100644
--- a/src/legacy/ui/public/vis/__tests__/vis_types/react_vis_type.js
+++ b/src/legacy/ui/public/vis/__tests__/vis_types/react_vis_type.js
@@ -19,12 +19,10 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
-import { ReactVisTypeProvider } from '../../vis_types/react_vis_type';
+import { ReactVisType } from '../../vis_types/react_vis_type';
describe('React Vis Type', function () {
- let ReactVisType;
-
const visConfig = {
name: 'test',
title: 'test',
@@ -35,9 +33,6 @@ describe('React Vis Type', function () {
};
beforeEach(ngMock.module('kibana'));
- beforeEach(ngMock.inject(function (Private) {
- ReactVisType = Private(ReactVisTypeProvider);
- }));
describe('initialization', () => {
it('should throw if component is not set', () => {
diff --git a/src/legacy/ui/public/vis/vis_factory.js b/src/legacy/ui/public/vis/vis_factory.js
index fba76f5af019b..9e764b2537d58 100644
--- a/src/legacy/ui/public/vis/vis_factory.js
+++ b/src/legacy/ui/public/vis/vis_factory.js
@@ -17,24 +17,26 @@
* under the License.
*/
-import { BaseVisTypeProvider, AngularVisTypeProvider, ReactVisTypeProvider, VislibVisTypeProvider } from './vis_types';
+import { BaseVisType, AngularVisTypeProvider, ReactVisType, VislibVisTypeProvider } from './vis_types';
+
+export const visFactory = {
+ createBaseVisualization: (config) => {
+ return new BaseVisType(config);
+ },
+ createReactVisualization: (config) => {
+ return new ReactVisType(config);
+ },
+};
export const VisFactoryProvider = (Private) => {
const AngularVisType = Private(AngularVisTypeProvider);
const VislibVisType = Private(VislibVisTypeProvider);
- const BaseVisType = Private(BaseVisTypeProvider);
- const ReactVisType = Private(ReactVisTypeProvider);
return {
- createBaseVisualization: (config) => {
- return new BaseVisType(config);
- },
+ ...visFactory,
createAngularVisualization: (config) => {
return new AngularVisType(config);
},
- createReactVisualization: (config) => {
- return new ReactVisType(config);
- },
createVislibVisualization: (config) => {
return new VislibVisType(config);
}
diff --git a/src/legacy/ui/public/vis/vis_filters/index.js b/src/legacy/ui/public/vis/vis_filters/index.js
index a31749947c6cb..9770052ec38b1 100644
--- a/src/legacy/ui/public/vis/vis_filters/index.js
+++ b/src/legacy/ui/public/vis/vis_filters/index.js
@@ -17,4 +17,4 @@
* under the License.
*/
-export { VisFiltersProvider, createFilter } from './vis_filters';
+export { VisFiltersProvider, createFilter, createFiltersFromEvent } from './vis_filters';
diff --git a/src/legacy/ui/public/vis/vis_filters/vis_filters.js b/src/legacy/ui/public/vis/vis_filters/vis_filters.js
index b7a62721e118c..72b79474cba18 100644
--- a/src/legacy/ui/public/vis/vis_filters/vis_filters.js
+++ b/src/legacy/ui/public/vis/vis_filters/vis_filters.js
@@ -19,7 +19,6 @@
import _ from 'lodash';
import { pushFilterBarFilters } from '../../filter_manager/push_filters';
-import { FilterBarQueryFilterProvider } from '../../filter_manager/query_filter';
import { onBrushEvent } from './brush_event';
/**
@@ -83,51 +82,49 @@ const createFilter = (aggConfigs, table, columnIndex, rowIndex, cellValue) => {
return filter;
};
-const VisFiltersProvider = (Private, getAppState) => {
- const queryFilter = Private(FilterBarQueryFilterProvider);
+
+const createFiltersFromEvent = (event) => {
+ const filters = [];
+ const dataPoints = event.data || [event];
+
+ dataPoints.filter(point => point).forEach(val => {
+ const { table, column, row, value } = val;
+ const filter = createFilter(event.aggConfigs, table, column, row, value);
+ if (filter) {
+ filter.forEach(f => {
+ if (event.negate) {
+ f.meta.negate = !f.meta.negate;
+ }
+ filters.push(f);
+ });
+ }
+ });
+
+ return filters;
+};
+
+const VisFiltersProvider = (getAppState, $timeout) => {
const pushFilters = (filters, simulate) => {
const appState = getAppState();
if (filters.length && !simulate) {
const flatFilters = _.flatten(filters);
- const deduplicatedFilters = flatFilters.filter((v, i) => i === flatFilters.findIndex(f => _.isEqual(v, f)));
+ const deduplicatedFilters = flatFilters.filter((v, i) => {
+ return i === flatFilters.findIndex(f => _.isEqual(v, f));
+ });
pushFilterBarFilters(appState, deduplicatedFilters);
+ // to trigger angular digest cycle, we can get rid of this once we have either new filterManager or actions API
+ $timeout(_.noop, 0);
}
};
- const filter = (event, { simulate = false } = {}) => {
- const dataPoints = event.data;
- const filters = [];
-
- dataPoints.filter(point => point).forEach(val => {
- const { table, column, row, value } = val;
- const filter = createFilter(event.aggConfigs, table, column, row, value);
- if (filter) {
- filter.forEach(f => {
- if (event.negate) {
- f.meta.negate = !f.meta.negate;
- }
- filters.push(f);
- });
- }
- });
-
- pushFilters(filters, simulate);
- return filters;
- };
-
- const addFilter = (event) => {
- const filter = createFilter(event.aggConfigs, event.table, event.column, event.row, event.value);
- queryFilter.addFilters(filter);
- };
return {
- addFilter,
- filter,
+ pushFilters,
brush: (event) => {
onBrushEvent(event, getAppState());
},
};
};
-export { VisFiltersProvider, createFilter };
+export { VisFiltersProvider, createFilter, createFiltersFromEvent };
diff --git a/src/legacy/ui/public/vis/vis_types/angular_vis_type.js b/src/legacy/ui/public/vis/vis_types/angular_vis_type.js
index 4613a0bcedce6..3ac936d13975b 100644
--- a/src/legacy/ui/public/vis/vis_types/angular_vis_type.js
+++ b/src/legacy/ui/public/vis/vis_types/angular_vis_type.js
@@ -17,12 +17,11 @@
* under the License.
*/
-import { BaseVisTypeProvider } from './base_vis_type';
+import { BaseVisType } from './base_vis_type';
import $ from 'jquery';
-export function AngularVisTypeProvider(Private, $compile, $rootScope) {
- const BaseVisType = Private(BaseVisTypeProvider);
+export function AngularVisTypeProvider($compile, $rootScope) {
class AngularVisController {
constructor(domeElement, vis) {
diff --git a/src/legacy/ui/public/vis/vis_types/base_vis_type.js b/src/legacy/ui/public/vis/vis_types/base_vis_type.js
index 2fa94ca3e860b..14d181365d884 100644
--- a/src/legacy/ui/public/vis/vis_types/base_vis_type.js
+++ b/src/legacy/ui/public/vis/vis_types/base_vis_type.js
@@ -18,75 +18,69 @@
*/
import _ from 'lodash';
-import { VisFiltersProvider } from '../vis_filters';
+import { createFiltersFromEvent } from '../vis_filters';
-export function BaseVisTypeProvider(Private) {
- const visFilters = Private(VisFiltersProvider);
+export class BaseVisType {
+ constructor(opts = {}) {
- class BaseVisType {
- constructor(opts = {}) {
-
- if (!opts.name) {
- throw('vis_type must define its name');
- }
- if (!opts.title) {
- throw('vis_type must define its title');
- }
- if (!opts.description) {
- throw('vis_type must define its description');
- }
- if (!opts.icon && !opts.image) {
- throw('vis_type must define its icon or image');
- }
- if (!opts.visualization) {
- throw('vis_type must define visualization controller');
- }
+ if (!opts.name) {
+ throw('vis_type must define its name');
+ }
+ if (!opts.title) {
+ throw('vis_type must define its title');
+ }
+ if (!opts.description) {
+ throw('vis_type must define its description');
+ }
+ if (!opts.icon && !opts.image) {
+ throw('vis_type must define its icon or image');
+ }
+ if (!opts.visualization) {
+ throw('vis_type must define visualization controller');
+ }
- const _defaults = {
- // name, title, description, icon, image
- visualization: null, // must be a class with render/resize/destroy methods
- visConfig: {
- defaults: {}, // default configuration
- },
- requestHandler: 'courier', // select one from registry or pass a function
- responseHandler: 'none',
- editor: 'default',
- editorConfig: {
- collections: {}, // collections used for configuration (list of positions, ...)
- },
- options: { // controls the visualize editor
- showTimePicker: true,
- showQueryBar: true,
- showFilterBar: true,
- showIndexSelection: true,
- hierarchicalData: false // we should get rid of this i guess ?
- },
- events: {
- filterBucket: {
- defaultAction: visFilters.addFilter,
- }
- },
- stage: 'production',
- feedbackMessage: '',
- hidden: false,
- };
+ const _defaults = {
+ // name, title, description, icon, image
+ visualization: null, // must be a class with render/resize/destroy methods
+ visConfig: {
+ defaults: {}, // default configuration
+ },
+ requestHandler: 'courier', // select one from registry or pass a function
+ responseHandler: 'none',
+ editor: 'default',
+ editorConfig: {
+ collections: {}, // collections used for configuration (list of positions, ...)
+ },
+ options: { // controls the visualize editor
+ showTimePicker: true,
+ showQueryBar: true,
+ showFilterBar: true,
+ showIndexSelection: true,
+ hierarchicalData: false // we should get rid of this i guess ?
+ },
+ events: {
+ filterBucket: {
+ defaultAction: createFiltersFromEvent,
+ }
+ },
+ stage: 'production',
+ feedbackMessage: '',
+ hidden: false,
+ };
- _.defaultsDeep(this, opts, _defaults);
+ _.defaultsDeep(this, opts, _defaults);
- this.requiresSearch = this.requestHandler !== 'none';
- }
+ this.requiresSearch = this.requestHandler !== 'none';
+ }
- shouldMarkAsExperimentalInUI() {
- return this.stage === 'experimental';
- }
+ shouldMarkAsExperimentalInUI() {
+ return this.stage === 'experimental';
+ }
- get schemas() {
- if (this.editorConfig && this.editorConfig.schemas) {
- return this.editorConfig.schemas;
- }
- return [];
+ get schemas() {
+ if (this.editorConfig && this.editorConfig.schemas) {
+ return this.editorConfig.schemas;
}
+ return [];
}
-
- return BaseVisType;
}
diff --git a/src/legacy/ui/public/vis/vis_types/index.js b/src/legacy/ui/public/vis/vis_types/index.js
index 8642fda2ffd01..b483d3a9adea2 100644
--- a/src/legacy/ui/public/vis/vis_types/index.js
+++ b/src/legacy/ui/public/vis/vis_types/index.js
@@ -17,9 +17,9 @@
* under the License.
*/
-import { BaseVisTypeProvider } from './base_vis_type';
+import { BaseVisType } from './base_vis_type';
import { AngularVisTypeProvider } from './angular_vis_type';
import { VislibVisTypeProvider } from './vislib_vis_type';
-import { ReactVisTypeProvider } from './react_vis_type';
+import { ReactVisType } from './react_vis_type';
-export { BaseVisTypeProvider, AngularVisTypeProvider, VislibVisTypeProvider, ReactVisTypeProvider };
+export { BaseVisType, AngularVisTypeProvider, VislibVisTypeProvider, ReactVisType };
diff --git a/src/legacy/ui/public/vis/vis_types/react_vis_type.js b/src/legacy/ui/public/vis/vis_types/react_vis_type.js
index 76e17666f91a6..29f809a65edda 100644
--- a/src/legacy/ui/public/vis/vis_types/react_vis_type.js
+++ b/src/legacy/ui/public/vis/vis_types/react_vis_type.js
@@ -21,54 +21,49 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import chrome from '../../chrome';
import { I18nContext } from '../../i18n';
-import { BaseVisTypeProvider } from './base_vis_type';
+import { BaseVisType } from './base_vis_type';
-export function ReactVisTypeProvider(Private) {
- const BaseVisType = Private(BaseVisTypeProvider);
- class ReactVisController {
- constructor(element, vis) {
- this.el = element;
- this.vis = vis;
- }
+class ReactVisController {
+ constructor(element, vis) {
+ this.el = element;
+ this.vis = vis;
+ }
- render(visData, visParams, updateStatus) {
- this.visData = visData;
+ render(visData, visParams, updateStatus) {
+ this.visData = visData;
- return new Promise((resolve) => {
- const Component = this.vis.type.visConfig.component;
- const config = chrome.getUiSettingsClient();
- render(
-
-
- , this.el);
- });
- }
+ return new Promise((resolve) => {
+ const Component = this.vis.type.visConfig.component;
+ const config = chrome.getUiSettingsClient();
+ render(
+
+
+ , this.el);
+ });
+ }
- destroy() {
- unmountComponentAtNode(this.el);
- }
+ destroy() {
+ unmountComponentAtNode(this.el);
}
+}
- class ReactVisType extends BaseVisType {
- constructor(opts) {
- super({
- ...opts,
- visualization: ReactVisController
- });
+export class ReactVisType extends BaseVisType {
+ constructor(opts) {
+ super({
+ ...opts,
+ visualization: ReactVisController
+ });
- if (!this.visConfig.component) {
- throw new Error('Missing component for ReactVisType');
- }
+ if (!this.visConfig.component) {
+ throw new Error('Missing component for ReactVisType');
}
}
-
- return ReactVisType;
}
diff --git a/src/legacy/ui/public/vis/vis_types/vislib_vis_type.js b/src/legacy/ui/public/vis/vis_types/vislib_vis_type.js
index 9d37583249772..2e664fadf9c0c 100644
--- a/src/legacy/ui/public/vis/vis_types/vislib_vis_type.js
+++ b/src/legacy/ui/public/vis/vis_types/vislib_vis_type.js
@@ -24,7 +24,7 @@ import 'plugins/kbn_vislib_vis_types/controls/heatmap_options';
import 'plugins/kbn_vislib_vis_types/controls/gauge_options';
import 'plugins/kbn_vislib_vis_types/controls/point_series';
import { CUSTOM_LEGEND_VIS_TYPES } from './vislib_vis_legend';
-import { BaseVisTypeProvider } from './base_vis_type';
+import { BaseVisType } from './base_vis_type';
import VislibProvider from '../../vislib';
import { VisFiltersProvider } from '../vis_filters';
import $ from 'jquery';
@@ -33,7 +33,6 @@ import { defaultsDeep } from 'lodash';
export function VislibVisTypeProvider(Private, $rootScope, $compile) {
const vislib = Private(VislibProvider);
const visFilters = Private(VisFiltersProvider);
- const BaseVisType = Private(BaseVisTypeProvider);
const legendClassName = {
top: 'visLib--legend-top',
@@ -127,9 +126,6 @@ export function VislibVisTypeProvider(Private, $rootScope, $compile) {
opts.responseHandlerConfig = { asAggConfigResults: true };
}
opts.events = defaultsDeep({}, opts.events, {
- filterBucket: {
- defaultAction: visFilters.filter,
- },
brush: {
defaultAction: visFilters.brush,
}
diff --git a/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.ts b/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.ts
index d1ddf2b7dd498..11ef49f2a0b7b 100644
--- a/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.ts
+++ b/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.ts
@@ -33,6 +33,8 @@ import { RenderCompleteHelper } from '../../render_complete';
import { AppState } from '../../state_management/app_state';
import { timefilter } from '../../timefilter';
import { RequestHandlerParams, Vis } from '../../vis';
+// @ts-ignore
+import { VisFiltersProvider } from '../../vis/vis_filters';
import { PipelineDataLoader } from './pipeline_data_loader';
import { visualizationLoader } from './visualization_loader';
import { VisualizeDataLoader } from './visualize_data_loader';
@@ -180,6 +182,7 @@ export class EmbeddedVisualizeHandler {
this.dataLoader = pipelineDataLoader
? new PipelineDataLoader(vis)
: new VisualizeDataLoader(vis, Private);
+ const visFilters: any = Private(VisFiltersProvider);
this.renderCompleteHelper = new RenderCompleteHelper(element);
this.inspectorAdapters = this.getActiveInspectorAdapters();
this.vis.openInspector = this.openInspector;
@@ -200,7 +203,8 @@ export class EmbeddedVisualizeHandler {
this.events$.subscribe(event => {
if (this.actions[event.name]) {
event.data.aggConfigs = getTableAggs(this.vis);
- this.actions[event.name](event.data);
+ const newFilters = this.actions[event.name](event.data) || [];
+ visFilters.pushFilters(newFilters);
}
});