mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Update the raw property when removing items from an indexed array. Closes #4381
This commit is contained in:
parent
932eba08c9
commit
c3358005d9
4 changed files with 29 additions and 8 deletions
|
@ -42,7 +42,7 @@ define(function (require) {
|
|||
var fields = indexPattern.fields;
|
||||
var field = self.field.toActualField();
|
||||
|
||||
_.remove(fields, { name: field.name });
|
||||
fields.remove({ name: field.name });
|
||||
fields.push(field);
|
||||
|
||||
if (!self.selectedFormatId) {
|
||||
|
|
|
@ -136,6 +136,19 @@ define(function (require) {
|
|||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove items from this based on a predicate
|
||||
* @param {function|object|string} predicate - the predicate used to decide what is removed
|
||||
* @param {object} context - this binding for predicate
|
||||
* @return {array} - the removed data
|
||||
*/
|
||||
IndexedArray.prototype.remove = function (predicate, context) {
|
||||
var out = _.remove(this, predicate, context);
|
||||
_.remove(this.raw, predicate, context);
|
||||
this._clearIndices();
|
||||
return out;
|
||||
};
|
||||
|
||||
/**
|
||||
* provide a hook for the JSON serializer
|
||||
* @return {array} - a plain, vanilla array with our same data
|
||||
|
|
|
@ -84,12 +84,6 @@ define(function (require) {
|
|||
return buckets;
|
||||
},
|
||||
|
||||
remove: _.wrap(_.remove, function (remove, arr, predicate, cntx) {
|
||||
var out = remove.call(this, arr, predicate, cntx);
|
||||
if (arr._clearIndices) arr._clearIndices();
|
||||
return out;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Remove or add a value to an array based on it's presense in the
|
||||
* array initially.
|
||||
|
|
|
@ -104,6 +104,20 @@ define(function (require) {
|
|||
expect(sumOfGroups).to.eql(expectedCount);
|
||||
});
|
||||
|
||||
it('removes items based on a predicate', function () {
|
||||
var reg = new IndexedArray({
|
||||
group: ['group'],
|
||||
order: ['id'],
|
||||
initialSet: users
|
||||
});
|
||||
|
||||
reg.remove({name: 'John'});
|
||||
|
||||
expect(_.eq(reg.raw, reg.slice(0))).to.be(true);
|
||||
expect(reg.length).to.be(3);
|
||||
expect(reg[0].name).to.be('Anon');
|
||||
});
|
||||
|
||||
it('updates indices after values are re-ordered', function () {
|
||||
var rawUsers = users.slice(0);
|
||||
|
||||
|
@ -137,4 +151,4 @@ define(function (require) {
|
|||
|
||||
require('specs/utils/indexed_array/_path_getter')();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue