Skip to content

Commit

Permalink
partly removing angular from visFilters and visFactory (#38643) (#38901)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Jun 14, 2019
1 parent abd7ba9 commit 717c7f2
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 180 deletions.
8 changes: 3 additions & 5 deletions src/legacy/core_plugins/markdown_vis/public/markdown_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/legacy/core_plugins/table_vis/public/table_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand Down
20 changes: 11 additions & 9 deletions src/legacy/ui/public/vis/vis_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vis/vis_filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { VisFiltersProvider, createFilter } from './vis_filters';
export { VisFiltersProvider, createFilter, createFiltersFromEvent } from './vis_filters';
61 changes: 29 additions & 32 deletions src/legacy/ui/public/vis/vis_filters/vis_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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 };
5 changes: 2 additions & 3 deletions src/legacy/ui/public/vis/vis_types/angular_vis_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
118 changes: 56 additions & 62 deletions src/legacy/ui/public/vis/vis_types/base_vis_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions src/legacy/ui/public/vis/vis_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Loading

0 comments on commit 717c7f2

Please sign in to comment.