-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3259 from rashidkpc/fix/_timestamp_missing
Fix _timestamp in doc tables + arrays in advanced settings
- Loading branch information
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/kibana/plugins/settings/sections/advanced/lib/get_val_type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/unit/specs/plugins/settings/sections/advanced/lib/get_val_type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |