forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
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 elastic#4924 from epixa/4684-unknown-settings
Allow modifying unknown/custom advanced settings
- Loading branch information
Showing
9 changed files
with
200 additions
and
34 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
src/plugins/kibana/public/settings/sections/advanced/advanced_row.html
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
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
27 changes: 27 additions & 0 deletions
27
src/plugins/kibana/public/settings/sections/advanced/lib/__tests__/get_editor_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,27 @@ | ||
|
||
var getEditorType = require('plugins/kibana/settings/sections/advanced/lib/get_editor_type'); | ||
var expect = require('expect.js'); | ||
|
||
describe('Settings', function () { | ||
describe('Advanced', function () { | ||
describe('getEditorType(conf)', function () { | ||
context('when given type has a named editor', function () { | ||
it('returns that named editor', function () { | ||
expect(getEditorType({ type: 'json' })).to.equal('json'); | ||
expect(getEditorType({ type: 'array' })).to.equal('array'); | ||
expect(getEditorType({ type: 'boolean' })).to.equal('boolean'); | ||
expect(getEditorType({ type: 'select' })).to.equal('select'); | ||
}); | ||
}); | ||
|
||
context('when given a type of number, string, null, or undefined', function () { | ||
it('returns "normal"', function () { | ||
expect(getEditorType({ type: 'number' })).to.equal('normal'); | ||
expect(getEditorType({ type: 'string' })).to.equal('normal'); | ||
expect(getEditorType({ type: 'null' })).to.equal('normal'); | ||
expect(getEditorType({ type: 'undefined' })).to.equal('normal'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
src/plugins/kibana/public/settings/sections/advanced/lib/__tests__/to_editable_config.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,86 @@ | ||
|
||
var toEditableConfig = require('plugins/kibana/settings/sections/advanced/lib/to_editable_config'); | ||
var expect = require('expect.js'); | ||
|
||
describe('Settings', function () { | ||
describe('Advanced', function () { | ||
describe('toEditableConfig(def, name, value)', function () { | ||
it('sets name', function () { | ||
expect(invoke({ name: 'who' }).name).to.equal('who'); | ||
}); | ||
|
||
it('sets value', function () { | ||
expect(invoke({ value: 'what' }).value).to.equal('what'); | ||
}); | ||
|
||
it('sets type', function () { | ||
expect(invoke({ value: 'what' }).type).to.be('string'); | ||
expect(invoke({ value: 0 }).type).to.be('number'); | ||
expect(invoke({ value: [] }).type).to.be('array'); | ||
}); | ||
|
||
context('when given a setting definition object', function () { | ||
var def; | ||
beforeEach(function () { | ||
def = { | ||
value: 'the original', | ||
description: 'the one and only', | ||
options: 'all the options' | ||
}; | ||
}); | ||
|
||
it('is not marked as custom', function () { | ||
expect(invoke({ def }).isCustom).to.be.false; | ||
}); | ||
|
||
it('sets a default value', function () { | ||
expect(invoke({ def }).defVal).to.equal(def.value); | ||
}); | ||
|
||
it('sets a description', function () { | ||
expect(invoke({ def }).description).to.equal(def.description); | ||
}); | ||
|
||
it('sets options', function () { | ||
expect(invoke({ def }).options).to.equal(def.options); | ||
}); | ||
|
||
context('that contains a type', function () { | ||
it('sets that type', function () { | ||
def.type = 'something'; | ||
expect(invoke({ def }).type).to.equal(def.type); | ||
}); | ||
}); | ||
|
||
context('that contains a value of type array', function () { | ||
it('sets type to array', function () { | ||
def.value = []; | ||
expect(invoke({ def }).type).to.equal('array'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when not given a setting definition object', function () { | ||
it('is marked as custom', function () { | ||
expect(invoke().isCustom).to.be.true; | ||
}); | ||
|
||
it('sets defVal to undefined', function () { | ||
expect(invoke().defVal).to.be.undefined; | ||
}); | ||
|
||
it('sets description to undefined', function () { | ||
expect(invoke().description).to.be.undefined; | ||
}); | ||
|
||
it('sets options to undefined', function () { | ||
expect(invoke().options).to.be.undefined; | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function invoke({ def = false, name = 'woah', value = 'forreal' } = {}) { | ||
return toEditableConfig(def, name, value); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/plugins/kibana/public/settings/sections/advanced/lib/get_editor_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,17 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
var NAMED_EDITORS = ['json', 'array', 'boolean', 'select']; | ||
var NORMAL_EDITOR = ['number', 'string', 'null', 'undefined']; | ||
|
||
/** | ||
* @param {object} advanced setting configuration object | ||
* @returns {string} the editor type to use when editing value | ||
*/ | ||
function getEditorType(conf) { | ||
if (_.contains(NAMED_EDITORS, conf.type)) return conf.type; | ||
if (_.contains(NORMAL_EDITOR, conf.type)) return 'normal'; | ||
} | ||
|
||
return getEditorType; | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/plugins/kibana/public/settings/sections/advanced/lib/to_editable_config.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,39 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var getValType = require('./get_val_type'); | ||
var getEditorType = require('./get_editor_type'); | ||
|
||
/** | ||
* @param {object} advanced setting definition object | ||
* @param {object} name of setting | ||
* @param {object} current value of setting | ||
* @returns {object} the editable config object | ||
*/ | ||
function toEditableConfig(def, name, value) { | ||
var isCustom = !def; | ||
if (isCustom) def = {}; | ||
|
||
var conf = { | ||
name, | ||
value, | ||
isCustom, | ||
readonly: !!def.readonly, | ||
defVal: def.value, | ||
type: getValType(def, value), | ||
description: def.description, | ||
options: def.options | ||
}; | ||
|
||
var editor = getEditorType(conf); | ||
conf.json = editor === 'json'; | ||
conf.select = editor === 'select'; | ||
conf.bool = editor === 'boolean'; | ||
conf.array = editor === 'array'; | ||
conf.normal = editor === 'normal'; | ||
conf.tooComplex = !editor; | ||
|
||
return conf; | ||
} | ||
|
||
return toEditableConfig; | ||
}); |
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