Skip to content

Commit

Permalink
Fix _timestamp and arrays in advanced settings, add test for value type
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Mar 4, 2015
1 parent cde5f15 commit 2263d22
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/kibana/components/index_patterns/_flatten_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ define(function (require) {
}
});

return hit.$$_flattened = _.merge(source, fields, _.pick(hit, self.metaFields));
return hit.$$_flattened = _.merge(source, fields, _.pick(hit, self.metaFields), _.pick(hit.fields, self.metaFields));
};
});
4 changes: 3 additions & 1 deletion src/kibana/plugins/settings/sections/advanced/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
define(function (require) {
var _ = require('lodash');
var configDefaults = require('components/config/defaults');
var getValType = require('plugins/settings/sections/advanced/lib/get_val_type');


require('plugins/settings/sections/advanced/advanced_row');

Expand Down Expand Up @@ -38,7 +40,7 @@ define(function (require) {
var conf = {
name: name,
defVal: def.value,
type: (def.type || _.isArray(val) || typeof val),
type: getValType(def, val),
description: def.description,
value: val,
};
Expand Down
22 changes: 22 additions & 0 deletions src/kibana/plugins/settings/sections/advanced/lib/get_val_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define(function (require) {
var _ = require('lodash');

/**
* @param {object} advanced setting definition object
* @param {?} current value of the setting
* @returns {string} the type to use for determining the display and editor
*/
function getValType(def, value) {
if (def.type) {
return def.type;
}

if (_.isArray(value) || _.isArray(def.value)) {
return 'array';
}

return (typeof def.value);
}

return getValType;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
define(function (require) {
var getValType = require('plugins/settings/sections/advanced/lib/get_val_type');
describe('Settings', function () {
describe('Advanced', function () {
describe('getValType(def, val)', function () {
it('should be a function', function () {
expect(getValType).to.be.a(Function);
});

it('should return the explicitly defined type of a setting', function () {
expect(getValType({type: 'string'})).to.be('string');
expect(getValType({type: 'json'})).to.be('json');
expect(getValType({type: 'string', value: 5})).to.be('string');
});

it('should return array if the value is an Array and there is no defined type', function () {
expect(getValType({type: 'string'}, [1, 2, 3])).to.be('string');
expect(getValType({type: 'json', value: [1, 2, 3]})).to.be('json');

expect(getValType({value: 'someString'}, [1, 2, 3])).to.be('array');
expect(getValType({value: [1, 2, 3]}, 'someString')).to.be('array');

});

it('should return the type of the default value if there is no type and it is not an array', function () {
expect(getValType({value: 'someString'})).to.be('string');
expect(getValType({value: 'someString'}, 42)).to.be('string');
});
});
});
});
});

0 comments on commit 2263d22

Please sign in to comment.