mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Split out PersistedState business logic from angular (#9687)
* - Remove angularization of PersistedState. - Provide the angularized version with PersistedStateProvider. - Use named exports - Es6-ify PersistedState class This pushes forward the first bullet point of #9686 * Address code review comments - Use single point of entry - Use injector instead of private - Use a new class (‘AngularizedPersistedState’) name instead of an arrow function * Remove extra import line
This commit is contained in:
parent
6fd728011c
commit
5f4cf32867
23 changed files with 184 additions and 162 deletions
|
@ -4,21 +4,19 @@ import noDigestPromises from 'test_utils/no_digest_promises';
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import errors from 'ui/errors';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import EventsProvider from 'ui/events';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
let PersistedState;
|
||||
let Events;
|
||||
|
||||
describe('Persisted State', function () {
|
||||
describe('Persisted State Provider', function () {
|
||||
noDigestPromises.activateForSuite();
|
||||
|
||||
beforeEach(function () {
|
||||
ngMock.module('kibana');
|
||||
|
||||
ngMock.inject(function (Private) {
|
||||
PersistedState = Private(PersistedStatePersistedStateProvider);
|
||||
Events = Private(EventsProvider);
|
||||
ngMock.inject(function ($injector) {
|
||||
PersistedState = $injector.get('PersistedState');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -30,11 +28,6 @@ describe('Persisted State', function () {
|
|||
expect(persistedState.get()).to.eql({});
|
||||
});
|
||||
|
||||
it('should be an event emitter', function () {
|
||||
persistedState = new PersistedState();
|
||||
expect(persistedState).to.be.an(Events);
|
||||
});
|
||||
|
||||
it('should create a state instance with data', function () {
|
||||
const val = { red: 'blue' };
|
||||
persistedState = new PersistedState(val);
|
2
src/ui/public/persisted_state/index.js
Normal file
2
src/ui/public/persisted_state/index.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
import './persisted_state.factory.js';
|
||||
export { PersistedState } from './persisted_state.js';
|
33
src/ui/public/persisted_state/persisted_state.factory.js
Normal file
33
src/ui/public/persisted_state/persisted_state.factory.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* @name AngularPersistedState
|
||||
*
|
||||
* Returns a PersistedState object which uses an EventEmitter instead of
|
||||
* the SimpleEmitter. The EventEmitter adds digest loops every time a handler is called
|
||||
* so it's preferable to use this variation when a callback modifies angular UI.
|
||||
*
|
||||
* TODO: The handlers themselves should really be responsible for triggering digest loops
|
||||
* as opposed to having an all or nothing situation. A nice goal would be to get rid
|
||||
* of the EventEmitter entirely and require handlers that need it to trigger a digest loop
|
||||
* themselves. We can even supply a service to wrap the callbacks in a function that
|
||||
* would call the callback, and finish with a $rootScope.$apply().
|
||||
*/
|
||||
|
||||
import EventsProvider from 'ui/events';
|
||||
import { PersistedState } from './persisted_state';
|
||||
import uiModules from 'ui/modules';
|
||||
|
||||
const module = uiModules.get('kibana');
|
||||
|
||||
module.factory('PersistedState', ($injector) => {
|
||||
const Private = $injector.get('Private');
|
||||
const Events = Private(EventsProvider);
|
||||
|
||||
// Extend PersistedState to override the EmitterClass class with
|
||||
// our Angular friendly version.
|
||||
return class AngularPersistedState extends PersistedState {
|
||||
constructor(value, path, parent, silent) {
|
||||
super(value, path, parent, silent, Events);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -8,63 +8,59 @@ import _ from 'lodash';
|
|||
import toPath from 'lodash/internal/toPath';
|
||||
import errors from 'ui/errors';
|
||||
import SimpleEmitter from 'ui/utils/simple_emitter';
|
||||
import EventsProvider from 'ui/events';
|
||||
|
||||
export default function (Private) {
|
||||
const Events = Private(EventsProvider);
|
||||
|
||||
function validateParent(parent, path) {
|
||||
if (path.length <= 0) {
|
||||
throw new errors.PersistedStateError('PersistedState child objects must contain a path');
|
||||
}
|
||||
|
||||
if (parent instanceof PersistedState) return;
|
||||
throw new errors.PersistedStateError('Parent object must be an instance of PersistedState');
|
||||
function prepSetParams(key, value, path) {
|
||||
// key must be the value, set the entire state using it
|
||||
if (_.isUndefined(value) && (_.isPlainObject(key) || path.length > 0)) {
|
||||
// setting entire tree, swap the key and value to write to the state
|
||||
value = key;
|
||||
key = undefined;
|
||||
}
|
||||
|
||||
function validateValue(value) {
|
||||
const msg = 'State value must be a plain object';
|
||||
if (!value) return;
|
||||
if (!_.isPlainObject(value)) throw new errors.PersistedStateError(msg);
|
||||
}
|
||||
// ensure the value being passed in is never mutated
|
||||
return {
|
||||
value: _.cloneDeep(value),
|
||||
key: key
|
||||
};
|
||||
}
|
||||
|
||||
function prepSetParams(key, value, path) {
|
||||
// key must be the value, set the entire state using it
|
||||
if (_.isUndefined(value) && (_.isPlainObject(key) || path.length > 0)) {
|
||||
// setting entire tree, swap the key and value to write to the state
|
||||
value = key;
|
||||
key = undefined;
|
||||
}
|
||||
export class PersistedState {
|
||||
|
||||
// ensure the value being passed in is never mutated
|
||||
return {
|
||||
value: _.cloneDeep(value),
|
||||
key: key
|
||||
};
|
||||
}
|
||||
|
||||
function parentDelegationMixin(from, to) {
|
||||
_.forOwn(from.prototype, function (method, methodName) {
|
||||
to.prototype[methodName] = function () {
|
||||
return from.prototype[methodName].apply(this._parent || this, arguments);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
_.class(PersistedState).inherits(Events);
|
||||
parentDelegationMixin(SimpleEmitter, PersistedState);
|
||||
parentDelegationMixin(Events, PersistedState);
|
||||
|
||||
function PersistedState(value, path, parent, silent) {
|
||||
PersistedState.Super.call(this);
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
* @param path
|
||||
* @param parent
|
||||
* @param silent
|
||||
* @param EmitterClass {SimpleEmitter} - a SimpleEmitter class that this class will extend. Can be used to
|
||||
* inherit a custom event emitter. For example, the EventEmitter is an "angular-ized" version
|
||||
* for angular components which automatically triggers a digest loop for every registered
|
||||
* handler. TODO: Get rid of the need for EventEmitter by wrapping handlers that require it
|
||||
* in a special function that will handler triggering the digest loop.
|
||||
*/
|
||||
constructor(value, path, parent, silent, EmitterClass = SimpleEmitter) {
|
||||
EmitterClass.call(this);
|
||||
|
||||
this._EmitterClass = EmitterClass;
|
||||
this._path = this._setPath(path);
|
||||
this._parent = parent || false;
|
||||
|
||||
_.forOwn(EmitterClass.prototype, (method, methodName) => {
|
||||
this[methodName] = function () {
|
||||
return EmitterClass.prototype[methodName].apply(this._parent || this, arguments);
|
||||
};
|
||||
});
|
||||
|
||||
// Some validations
|
||||
if (this._parent) {
|
||||
validateParent(this._parent, this._path);
|
||||
} else if (!this._path.length) {
|
||||
validateValue(value);
|
||||
if (this._path.length <= 0) {
|
||||
throw new errors.PersistedStateError('PersistedState child objects must contain a path');
|
||||
}
|
||||
if (!(this._parent instanceof PersistedState)) {
|
||||
throw new errors.PersistedStateError('Parent object must be an instance of PersistedState');
|
||||
}
|
||||
} else if (!this._path.length && value && !_.isPlainObject(value)) {
|
||||
throw new errors.PersistedStateError('State value must be a plain object');
|
||||
}
|
||||
|
||||
value = value || this._getDefault();
|
||||
|
@ -74,23 +70,23 @@ export default function (Private) {
|
|||
this._initialized = true; // used to track state changes
|
||||
}
|
||||
|
||||
PersistedState.prototype.get = function (key, def) {
|
||||
get(key, def) {
|
||||
return _.cloneDeep(this._get(key, def));
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.set = function (key, value) {
|
||||
set(key, value) {
|
||||
const params = prepSetParams(key, value, this._path);
|
||||
const val = this._set(params.key, params.value);
|
||||
this.emit('set');
|
||||
return val;
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.setSilent = function (key, value) {
|
||||
setSilent(key, value) {
|
||||
const params = prepSetParams(key, value, this._path);
|
||||
return this._set(params.key, params.value, true);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.reset = function (path) {
|
||||
reset(path) {
|
||||
const keyPath = this._getIndex(path);
|
||||
const origValue = _.get(this._defaultState, keyPath);
|
||||
const currentValue = _.get(this._mergedState, keyPath);
|
||||
|
@ -106,14 +102,14 @@ export default function (Private) {
|
|||
this._cleanPath(path, this._defaultChildState);
|
||||
|
||||
if (!_.isEqual(currentValue, origValue)) this.emit('change');
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.createChild = function (path, value, silent) {
|
||||
createChild(path, value, silent) {
|
||||
this._setChild(this._getIndex(path), value, this._parent || this);
|
||||
return new PersistedState(value, this._getIndex(path), this._parent || this, silent);
|
||||
};
|
||||
return new PersistedState(value, this._getIndex(path), this._parent || this, silent, this._EmitterClass);
|
||||
}
|
||||
|
||||
PersistedState.prototype.removeChild = function (path) {
|
||||
removeChild(path) {
|
||||
const origValue = _.get(this._defaultState, this._getIndex(path));
|
||||
|
||||
if (_.isUndefined(origValue)) {
|
||||
|
@ -121,35 +117,35 @@ export default function (Private) {
|
|||
} else {
|
||||
this.set(path, origValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.getChanges = function () {
|
||||
getChanges() {
|
||||
return _.cloneDeep(this._changedState);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.toJSON = function () {
|
||||
toJSON() {
|
||||
return this.get();
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.toString = function () {
|
||||
toString() {
|
||||
return JSON.stringify(this.toJSON());
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype.fromString = function (input) {
|
||||
fromString(input) {
|
||||
return this.set(JSON.parse(input));
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._getIndex = function (key) {
|
||||
_getIndex(key) {
|
||||
if (_.isUndefined(key)) return this._path;
|
||||
return (this._path || []).concat(toPath(key));
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._getPartialIndex = function (key) {
|
||||
_getPartialIndex(key) {
|
||||
const keyPath = this._getIndex(key);
|
||||
return keyPath.slice(this._path.length);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._cleanPath = function (path, stateTree) {
|
||||
_cleanPath(path, stateTree) {
|
||||
const partialPath = this._getPartialIndex(path);
|
||||
let remove = true;
|
||||
|
||||
|
@ -165,31 +161,31 @@ export default function (Private) {
|
|||
if (remove) delete stateVal[lastKey];
|
||||
if (Object.keys(stateVal).length > 0) remove = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._getDefault = function () {
|
||||
_getDefault() {
|
||||
const def = (this._hasPath()) ? undefined : {};
|
||||
return (this._parent ? this.get() : def);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._setPath = function (path) {
|
||||
_setPath(path) {
|
||||
const isString = _.isString(path);
|
||||
const isArray = _.isArray(path);
|
||||
|
||||
if (!isString && !isArray) return [];
|
||||
return (isString) ? [this._getIndex(path)] : path;
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._setChild = function (path, value, parent) {
|
||||
_setChild(path, value, parent) {
|
||||
parent._defaultChildState = parent._defaultChildState || {};
|
||||
_.set(parent._defaultChildState, path, value);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._hasPath = function () {
|
||||
_hasPath() {
|
||||
return this._path.length > 0;
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._get = function (key, def) {
|
||||
_get(key, def) {
|
||||
// delegate to parent instance
|
||||
if (this._parent) return this._parent._get(this._getIndex(key), def);
|
||||
|
||||
|
@ -199,9 +195,9 @@ export default function (Private) {
|
|||
}
|
||||
|
||||
return _.get(this._mergedState, this._getIndex(key), def);
|
||||
};
|
||||
}
|
||||
|
||||
PersistedState.prototype._set = function (key, value, silent, initialChildState) {
|
||||
_set(key, value, silent, initialChildState) {
|
||||
const self = this;
|
||||
let stateChanged = false;
|
||||
const initialState = !this._initialized;
|
||||
|
@ -272,7 +268,5 @@ export default function (Private) {
|
|||
if (!silent && stateChanged) this.emit('change');
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
return PersistedState;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,13 @@
|
|||
import _ from 'lodash';
|
||||
import modules from 'ui/modules';
|
||||
import StateManagementStateProvider from 'ui/state_management/state';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
const urlParam = '_a';
|
||||
|
||||
function AppStateProvider(Private, $rootScope, $location) {
|
||||
function AppStateProvider(Private, $rootScope, $location, $injector) {
|
||||
const State = Private(StateManagementStateProvider);
|
||||
const PersistedState = Private(PersistedStatePersistedStateProvider);
|
||||
const PersistedState = $injector.get('PersistedState');
|
||||
let persistedStates;
|
||||
let eventUnsubscribers;
|
||||
|
||||
|
|
|
@ -12,13 +12,12 @@ import _ from 'lodash';
|
|||
import AggTypesIndexProvider from 'ui/agg_types/index';
|
||||
import RegistryVisTypesProvider from 'ui/registry/vis_types';
|
||||
import VisAggConfigsProvider from 'ui/vis/agg_configs';
|
||||
import PersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import { PersistedState } from 'ui/persisted_state';
|
||||
|
||||
export default function VisFactory(Notifier, Private) {
|
||||
const aggTypes = Private(AggTypesIndexProvider);
|
||||
const visTypes = Private(RegistryVisTypesProvider);
|
||||
const AggConfigs = Private(VisAggConfigsProvider);
|
||||
const PersistedState = Private(PersistedStateProvider);
|
||||
|
||||
const notify = new Notifier({
|
||||
location: 'Vis'
|
||||
|
|
|
@ -8,7 +8,7 @@ import VislibLibAxisTitleProvider from 'ui/vislib/lib/axis/axis_title';
|
|||
import VislibLibAxisConfigProvider from 'ui/vislib/lib/axis/axis_config';
|
||||
import VislibLibVisConfigProvider from 'ui/vislib/lib/vis_config';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
describe('Vislib AxisTitle Class Test Suite', function () {
|
||||
let AxisTitle;
|
||||
|
@ -81,12 +81,12 @@ describe('Vislib AxisTitle Class Test Suite', function () {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
AxisTitle = Private(VislibLibAxisTitleProvider);
|
||||
AxisConfig = Private(VislibLibAxisConfigProvider);
|
||||
VisConfig = Private(VislibLibVisConfigProvider);
|
||||
Data = Private(VislibLibDataProvider);
|
||||
PersistedState = Private(PersistedStatePersistedStateProvider);
|
||||
PersistedState = $injector.get('PersistedState');
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'vis-wrapper');
|
||||
|
|
|
@ -7,7 +7,7 @@ import $ from 'jquery';
|
|||
import VislibLibChartTitleProvider from 'ui/vislib/lib/chart_title';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import VislibLibVisConfigProvider from 'ui/vislib/lib/vis_config';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
describe('Vislib ChartTitle Class Test Suite', function () {
|
||||
let ChartTitle;
|
||||
|
@ -77,11 +77,11 @@ describe('Vislib ChartTitle Class Test Suite', function () {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
ChartTitle = Private(VislibLibChartTitleProvider);
|
||||
Data = Private(VislibLibDataProvider);
|
||||
VisConfig = Private(VislibLibVisConfigProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
|
||||
el = d3.select('body').append('div')
|
||||
.attr('class', 'vis-wrapper')
|
||||
|
|
|
@ -7,7 +7,7 @@ import dataSeries from 'fixtures/vislib/mock_data/date_histogram/_series';
|
|||
import dataSeriesNeg from 'fixtures/vislib/mock_data/date_histogram/_series_neg';
|
||||
import dataStacked from 'fixtures/vislib/mock_data/stacked/_stacked';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
const seriesData = {
|
||||
'label': '',
|
||||
|
@ -106,9 +106,9 @@ describe('Vislib Data Class Test Suite', function () {
|
|||
let persistedState;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
Data = Private(VislibLibDataProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
}));
|
||||
|
||||
describe('Data Class (main)', function () {
|
||||
|
|
|
@ -8,7 +8,7 @@ import expect from 'expect.js';
|
|||
import data from 'fixtures/vislib/mock_data/date_histogram/_series';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
describe('Vislib Dispatch Class Test Suite', function () {
|
||||
|
||||
|
@ -26,9 +26,9 @@ describe('Vislib Dispatch Class Test Suite', function () {
|
|||
let SimpleEmitter;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.render(data, persistedState);
|
||||
SimpleEmitter = require('ui/utils/simple_emitter');
|
||||
}));
|
||||
|
@ -51,9 +51,9 @@ describe('Vislib Dispatch Class Test Suite', function () {
|
|||
let persistedState;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.on('brush', _.noop);
|
||||
vis.render(data, persistedState);
|
||||
}));
|
||||
|
@ -121,9 +121,9 @@ describe('Vislib Dispatch Class Test Suite', function () {
|
|||
let vis;
|
||||
let persistedState;
|
||||
ngMock.module('kibana');
|
||||
ngMock.inject(function (Private) {
|
||||
ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.on('someEvent', _.noop);
|
||||
vis.render(data, persistedState);
|
||||
|
||||
|
@ -140,9 +140,9 @@ describe('Vislib Dispatch Class Test Suite', function () {
|
|||
let vis;
|
||||
let persistedState;
|
||||
ngMock.module('kibana');
|
||||
ngMock.inject(function (Private) {
|
||||
ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.render(data, persistedState);
|
||||
vis.on('someEvent', _.noop);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import stackedSeries from 'fixtures/vislib/mock_data/date_histogram/_stacked_ser
|
|||
import $ from 'jquery';
|
||||
import VislibLibHandlerHandlerProvider from 'ui/vislib/lib/handler';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
const dateHistogramArray = [
|
||||
series,
|
||||
columns,
|
||||
|
@ -34,10 +34,10 @@ dateHistogramArray.forEach(function (data, i) {
|
|||
];
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
Handler = Private(VislibLibHandlerHandlerProvider);
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.render(data, persistedState);
|
||||
}));
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import stackedSeries from 'fixtures/vislib/mock_data/date_histogram/_stacked_ser
|
|||
import $ from 'jquery';
|
||||
import VislibLibLayoutLayoutProvider from 'ui/vislib/lib/layout/layout';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import VislibVisConfig from 'ui/vislib/lib/vis_config';
|
||||
|
||||
const dateHistogramArray = [
|
||||
|
@ -39,10 +39,10 @@ dateHistogramArray.forEach(function (data, i) {
|
|||
beforeEach(ngMock.module('kibana'));
|
||||
|
||||
beforeEach(function () {
|
||||
ngMock.inject(function (Private) {
|
||||
ngMock.inject(function (Private, $injector) {
|
||||
Layout = Private(VislibLibLayoutLayoutProvider);
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
VisConfig = Private(VislibVisConfig);
|
||||
vis.render(data, persistedState);
|
||||
numberOfCharts = vis.handler.charts.length;
|
||||
|
|
|
@ -3,7 +3,7 @@ import _ from 'lodash';
|
|||
import ngMock from 'ng_mock';
|
||||
import expect from 'expect.js';
|
||||
import VislibLibVisConfigProvider from 'ui/vislib/lib/vis_config';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
describe('Vislib VisConfig Class Test Suite', function () {
|
||||
let visConfig;
|
||||
|
@ -68,9 +68,9 @@ describe('Vislib VisConfig Class Test Suite', function () {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
const VisConfig = Private(VislibLibVisConfigProvider);
|
||||
const PersistedState = Private(PersistedStatePersistedStateProvider);
|
||||
const PersistedState = $injector.get('PersistedState');
|
||||
el = d3.select('body')
|
||||
.attr('class', 'vis-wrapper')
|
||||
.node();
|
||||
|
|
|
@ -5,7 +5,7 @@ import ngMock from 'ng_mock';
|
|||
import expect from 'expect.js';
|
||||
import $ from 'jquery';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import VislibLibAxisProvider from 'ui/vislib/lib/axis';
|
||||
import VislibVisConfig from 'ui/vislib/lib/vis_config';
|
||||
|
||||
|
@ -81,9 +81,9 @@ describe('Vislib xAxis Class Test Suite', function () {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
Data = Private(VislibLibDataProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
Axis = Private(VislibLibAxisProvider);
|
||||
VisConfig = Private(VislibVisConfig);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import ngMock from 'ng_mock';
|
|||
import expect from 'expect.js';
|
||||
import $ from 'jquery';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import VislibLibYAxisProvider from 'ui/vislib/lib/axis';
|
||||
import VislibVisConfig from 'ui/vislib/lib/vis_config';
|
||||
|
||||
|
@ -94,9 +94,9 @@ function createData(seriesData) {
|
|||
describe('Vislib yAxis Class Test Suite', function () {
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
Data = Private(VislibLibDataProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
YAxis = Private(VislibLibYAxisProvider);
|
||||
VisConfig = Private(VislibVisConfig);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import rows from 'fixtures/vislib/mock_data/date_histogram/_rows';
|
|||
import stackedSeries from 'fixtures/vislib/mock_data/date_histogram/_stacked_series';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
const dataArray = [
|
||||
series,
|
||||
|
@ -35,9 +35,9 @@ dataArray.forEach(function (data, i) {
|
|||
let numberOfCharts;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)();
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
secondVis = Private(FixturesVislibVisFixtureProvider)();
|
||||
}));
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import woahLotsOfVariables from 'fixtures/vislib/mock_data/date_histogram/_serie
|
|||
import notQuiteEnoughVariables from 'fixtures/vislib/mock_data/not_enough_data/_one_point';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
const dataTypesArray = {
|
||||
'series pos': require('fixtures/vislib/mock_data/date_histogram/_series'),
|
||||
'series pos neg': require('fixtures/vislib/mock_data/date_histogram/_series_pos_neg'),
|
||||
|
@ -31,9 +31,9 @@ _.forOwn(dataTypesArray, function (dataType, dataTypeName) {
|
|||
let persistedState;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)(visLibParams);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.on('brush', _.noop);
|
||||
vis.render(dataType, persistedState);
|
||||
}));
|
||||
|
|
|
@ -3,7 +3,7 @@ import expect from 'expect.js';
|
|||
import ngMock from 'ng_mock';
|
||||
import VislibVisProvider from 'ui/vislib/vis';
|
||||
import VislibLibDataProvider from 'ui/vislib/lib/data';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import VislibVisualizationsPieChartProvider from 'ui/vislib/visualizations/pie_chart';
|
||||
import VislibVisualizationsChartProvider from 'ui/vislib/visualizations/_chart';
|
||||
|
||||
|
@ -84,10 +84,10 @@ describe('Vislib _chart Test Suite', function () {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
Vis = Private(VislibVisProvider);
|
||||
Data = Private(VislibLibDataProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
PieChart = Private(VislibVisualizationsPieChartProvider);
|
||||
Chart = Private(VislibVisualizationsChartProvider);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import histogramRows from 'fixtures/vislib/mock_data/histogram/_rows';
|
|||
import stackedSeries from 'fixtures/vislib/mock_data/date_histogram/_stacked_series';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
// tuple, with the format [description, mode, data]
|
||||
const dataTypesArray = [
|
||||
|
@ -42,9 +42,9 @@ dataTypesArray.forEach(function (dataType, i) {
|
|||
};
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)(visLibParams);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.on('brush', _.noop);
|
||||
vis.render(data, persistedState);
|
||||
}));
|
||||
|
|
|
@ -11,7 +11,7 @@ import termsColumns from 'fixtures/vislib/mock_data/terms/_columns';
|
|||
import stackedSeries from 'fixtures/vislib/mock_data/date_histogram/_stacked_series';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
// tuple, with the format [description, mode, data]
|
||||
const dataTypesArray = [
|
||||
|
@ -53,9 +53,9 @@ describe('Vislib Heatmap Chart Test Suite', function () {
|
|||
}
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vislibVis = Private(FixturesVislibVisFixtureProvider);
|
||||
PersistedState = Private(PersistedStatePersistedStateProvider);
|
||||
PersistedState = $injector.get('PersistedState');
|
||||
generateVis();
|
||||
}));
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import rangeRows from 'fixtures/vislib/mock_data/range/_rows';
|
|||
import termSeries from 'fixtures/vislib/mock_data/terms/_series';
|
||||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
|
||||
const dataTypes = [
|
||||
['series pos', seriesPos],
|
||||
|
@ -34,7 +34,7 @@ describe('Vislib Line Chart', function () {
|
|||
let persistedState;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
const visLibParams = {
|
||||
type: 'line',
|
||||
addLegend: true,
|
||||
|
@ -43,7 +43,7 @@ describe('Vislib Line Chart', function () {
|
|||
};
|
||||
|
||||
vis = Private(FixturesVislibVisFixtureProvider)(visLibParams);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
vis.on('brush', _.noop);
|
||||
vis.render(data, persistedState);
|
||||
}));
|
||||
|
|
|
@ -6,7 +6,7 @@ import fixtures from 'fixtures/fake_hierarchical_data';
|
|||
import $ from 'jquery';
|
||||
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
|
||||
import VisProvider from 'ui/vis';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import AggResponseHierarchicalBuildHierarchicalDataProvider from 'ui/agg_response/hierarchical/build_hierarchical_data';
|
||||
|
||||
|
@ -74,11 +74,11 @@ describe('No global chart settings', function () {
|
|||
let data2;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
chart1 = Private(FixturesVislibVisFixtureProvider)(visLibParams1);
|
||||
chart2 = Private(FixturesVislibVisFixtureProvider)(visLibParams2);
|
||||
Vis = Private(VisProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
buildHierarchicalData = Private(AggResponseHierarchicalBuildHierarchicalDataProvider);
|
||||
|
||||
|
@ -169,10 +169,10 @@ aggArray.forEach(function (dataAgg, i) {
|
|||
let data;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
beforeEach(ngMock.inject(function (Private, $injector) {
|
||||
vis = Private(FixturesVislibVisFixtureProvider)(visLibParams);
|
||||
Vis = Private(VisProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
buildHierarchicalData = Private(AggResponseHierarchicalBuildHierarchicalDataProvider);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import VislibProvider from 'ui/vislib';
|
|||
import VislibVisProvider from 'ui/vislib/vis';
|
||||
import VisRenderbotProvider from 'ui/vis/renderbot';
|
||||
import VislibVisTypeVislibRenderbotProvider from 'ui/vislib_vis_type/vislib_renderbot';
|
||||
import PersistedStatePersistedStateProvider from 'ui/persisted_state/persisted_state';
|
||||
import 'ui/persisted_state';
|
||||
import AggResponseIndexProvider from 'ui/agg_response/index';
|
||||
import noDigestPromises from 'test_utils/no_digest_promises';
|
||||
|
||||
|
@ -30,7 +30,7 @@ describe('renderbot', function exportWrapper() {
|
|||
Vis = Private(VislibVisProvider);
|
||||
Renderbot = Private(VisRenderbotProvider);
|
||||
VislibRenderbot = Private(VislibVisTypeVislibRenderbotProvider);
|
||||
persistedState = new (Private(PersistedStatePersistedStateProvider))();
|
||||
persistedState = new ($injector.get('PersistedState'))();
|
||||
normalizeChartData = Private(AggResponseIndexProvider);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue