From 5a4b1f6b9caf6de4db42eac1ace6d949d08b17e2 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 28 Jun 2017 13:17:31 -0600 Subject: [PATCH 01/15] move field formatters to common --- .../field_format/__tests__/field_format.js} | 19 ++-- .../common/field_format}/content_types.js | 4 +- .../common/field_format}/field_format.js | 2 +- .../field_format/types/__tests__/boolean.js | 60 ++++++++++++ .../field_format/types/__tests__/color.js | 75 ++++++++++++++ .../field_format/types/__tests__/date.js | 46 +++++++++ .../field_format/types/__tests__/duration.js | 46 +++++++++ .../common/field_format/types/__tests__/ip.js | 20 ++++ .../field_format/types/__tests__/string.js | 60 ++++++++++++ .../field_format/types/__tests__/truncate.js | 34 +++++++ .../field_format/types/__tests__/url.js | 85 ++++++++++++++++ .../common/field_format}/types/_numeral.js | 2 +- .../common/field_format}/types/_source.html | 0 .../common/field_format}/types/boolean.js | 4 +- .../common/field_format}/types/bytes.js | 2 +- .../common/field_format}/types/color.js | 4 +- .../field_format}/types/color_default.js | 0 .../kibana/common/field_format}/types/date.js | 2 +- .../common/field_format}/types/duration.js | 2 +- .../kibana/common/field_format}/types/ip.js | 2 +- .../common/field_format}/types/number.js | 2 +- .../common/field_format}/types/percent.js | 2 +- .../common/field_format}/types/source.js | 10 +- .../common/field_format}/types/string.js | 6 +- .../common/field_format}/types/truncate.js | 3 +- .../kibana/common/field_format}/types/url.js | 4 +- .../highlight/__tests__/highlight_html.js | 0 .../highlight/__tests__/highlight_request.js | 0 .../kibana/common}/highlight/highlight.js | 0 .../common}/highlight/highlight_html.js | 3 +- .../common}/highlight/highlight_request.js | 0 .../common}/highlight/highlight_tags.js | 0 .../kibana/common}/highlight/html_tags.js | 0 .../utils/__tests__/aggressive_parse.js | 3 +- .../utils/__tests__/as_pretty_string.js | 2 +- .../utils/__tests__/shorten_dotted_string.js | 2 +- .../kibana/common}/utils/aggressive_parse.js | 0 .../kibana/common}/utils/as_pretty_string.js | 0 .../kibana/common}/utils/no_white_space.js | 0 .../common}/utils/shorten_dotted_string.js | 0 src/ui/public/agg_types/buckets/range.js | 2 +- src/ui/public/autoload/modules.js | 1 - .../public/courier/data_source/_abstract.js | 2 +- .../public/courier/fetch/strategy/search.js | 3 +- .../public/doc_table/components/table_row.js | 4 +- .../__tests__/_boolean.js | 0 .../__tests__/_color.js | 0 .../__tests__/_conformance.js | 2 +- .../__tests__/_date.js | 0 .../__tests__/_duration.js | 0 .../__tests__/_ip.js | 0 .../__tests__/_source.js | 0 .../__tests__/_string.js | 0 .../__tests__/_truncate.js | 0 .../__tests__/_url.js | 0 .../__tests__/index.js | 0 src/ui/public/field_format/register.js | 26 +++++ .../editors/color/color.js | 2 +- src/ui/public/filters/short_dots.js | 2 +- src/ui/public/index_patterns/_field.js | 2 +- .../_field_format/__tests__/content_types.js | 98 ------------------- src/ui/public/stringify/register.js | 26 ----- src/ui/ui_exports.js | 1 + 63 files changed, 499 insertions(+), 178 deletions(-) rename src/{ui/public/index_patterns/__tests__/_field_format.js => core_plugins/kibana/common/field_format/__tests__/field_format.js} (93%) rename src/{ui/public/index_patterns/_field_format => core_plugins/kibana/common/field_format}/content_types.js (92%) rename src/{ui/public/index_patterns/_field_format => core_plugins/kibana/common/field_format}/field_format.js (97%) create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/color.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/date.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/duration.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/ip.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/string.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js create mode 100644 src/core_plugins/kibana/common/field_format/types/__tests__/url.js rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/_numeral.js (93%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/_source.html (100%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/boolean.js (82%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/bytes.js (66%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/color.js (91%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/color_default.js (100%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/date.js (94%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/duration.js (97%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/ip.js (84%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/number.js (66%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/percent.js (89%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/source.js (76%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/string.js (84%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/truncate.js (86%) rename src/{ui/public/stringify => core_plugins/kibana/common/field_format}/types/url.js (95%) rename src/{ui/public => core_plugins/kibana/common}/highlight/__tests__/highlight_html.js (100%) rename src/{ui/public => core_plugins/kibana/common}/highlight/__tests__/highlight_request.js (100%) rename src/{ui/public => core_plugins/kibana/common}/highlight/highlight.js (100%) rename src/{ui/public => core_plugins/kibana/common}/highlight/highlight_html.js (93%) rename src/{ui/public => core_plugins/kibana/common}/highlight/highlight_request.js (100%) rename src/{ui/public => core_plugins/kibana/common}/highlight/highlight_tags.js (100%) rename src/{ui/public => core_plugins/kibana/common}/highlight/html_tags.js (100%) rename src/{ui/public => core_plugins/kibana/common}/utils/__tests__/aggressive_parse.js (97%) rename src/{ui/public => core_plugins/kibana/common}/utils/__tests__/as_pretty_string.js (92%) rename src/{ui/public => core_plugins/kibana/common}/utils/__tests__/shorten_dotted_string.js (86%) rename src/{ui/public => core_plugins/kibana/common}/utils/aggressive_parse.js (100%) rename src/{ui/public => core_plugins/kibana/common}/utils/as_pretty_string.js (100%) rename src/{ui/public => core_plugins/kibana/common}/utils/no_white_space.js (100%) rename src/{ui/public => core_plugins/kibana/common}/utils/shorten_dotted_string.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_boolean.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_color.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_conformance.js (97%) rename src/ui/public/{stringify => field_format}/__tests__/_date.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_duration.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_ip.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_source.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_string.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_truncate.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/_url.js (100%) rename src/ui/public/{stringify => field_format}/__tests__/index.js (100%) create mode 100644 src/ui/public/field_format/register.js delete mode 100644 src/ui/public/index_patterns/_field_format/__tests__/content_types.js delete mode 100644 src/ui/public/stringify/register.js diff --git a/src/ui/public/index_patterns/__tests__/_field_format.js b/src/core_plugins/kibana/common/field_format/__tests__/field_format.js similarity index 93% rename from src/ui/public/index_patterns/__tests__/_field_format.js rename to src/core_plugins/kibana/common/field_format/__tests__/field_format.js index 6a9b21a592ca5..c25a55f95f278 100644 --- a/src/ui/public/index_patterns/__tests__/_field_format.js +++ b/src/core_plugins/kibana/common/field_format/__tests__/field_format.js @@ -1,23 +1,20 @@ import _ from 'lodash'; import expect from 'expect.js'; -import { asPrettyString } from 'ui/utils/as_pretty_string'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { asPrettyString } from '../../utils/as_pretty_string'; +import { FieldFormat } from '../field_format'; describe('FieldFormat class', function () { let TestFormat; beforeEach(function () { - - TestFormat = function (params) { - TestFormat.Super.call(this, params); + TestFormat = class _TestFormat extends FieldFormat { + static id = 'test-format'; + static title = 'Test Format'; + _convert(val) { + return asPrettyString(val); + } }; - - TestFormat.id = 'test-format'; - TestFormat.title = 'Test Format'; - TestFormat.prototype._convert = asPrettyString; - - _.class(TestFormat).inherits(FieldFormat); }); describe('params', function () { diff --git a/src/ui/public/index_patterns/_field_format/content_types.js b/src/core_plugins/kibana/common/field_format/content_types.js similarity index 92% rename from src/ui/public/index_patterns/_field_format/content_types.js rename to src/core_plugins/kibana/common/field_format/content_types.js index cc9661b32d96f..78f2e3d1aec6d 100644 --- a/src/ui/public/index_patterns/_field_format/content_types.js +++ b/src/core_plugins/kibana/common/field_format/content_types.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { asPrettyString } from 'ui/utils/as_pretty_string'; -import { getHighlightHtml } from 'ui/highlight'; +import { asPrettyString } from '../utils/as_pretty_string'; +import { getHighlightHtml } from '../highlight/highlight_html'; const types = { html: function (format, convert) { diff --git a/src/ui/public/index_patterns/_field_format/field_format.js b/src/core_plugins/kibana/common/field_format/field_format.js similarity index 97% rename from src/ui/public/index_patterns/_field_format/field_format.js rename to src/core_plugins/kibana/common/field_format/field_format.js index d6c497c483425..7b43a27d3d2e4 100644 --- a/src/ui/public/index_patterns/_field_format/field_format.js +++ b/src/core_plugins/kibana/common/field_format/field_format.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { contentTypesSetup } from 'ui/index_patterns/_field_format/content_types'; +import { contentTypesSetup } from './content_types'; export function FieldFormat(params) { // give the constructor a more appropriate name diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js b/src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js new file mode 100644 index 0000000000000..0d8a1810160dd --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js @@ -0,0 +1,60 @@ +import expect from 'expect.js'; +import { stringifyBoolean } from '../boolean'; + +describe('Boolean Format', function () { + + let boolean; + beforeEach(() => { + const BoolFormat = stringifyBoolean(); + boolean = new BoolFormat(); + }); + + [ + { + input: 0, + expected: 'false' + }, + { + input: 'no', + expected: 'false' + }, + { + input: false, + expected: 'false' + }, + { + input: 'false', + expected: 'false' + }, + { + input: 1, + expected: 'true' + }, + { + input: 'yes', + expected: 'true' + }, + { + input: true, + expected: 'true' + }, + { + input: 'true', + expected: 'true' + }, + { + input: ' True ',//should handle trailing and mixed case + expected: 'true' + } + ].forEach((test)=> { + it(`convert ${test.input} to boolean`, ()=> { + expect(boolean.convert(test.input)).to.be(test.expected); + }); + }); + + it('does not convert non-boolean values, instead returning original value', ()=> { + const s = 'non-boolean value!!'; + expect(boolean.convert(s)).to.be(s); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/color.js b/src/core_plugins/kibana/common/field_format/types/__tests__/color.js new file mode 100644 index 0000000000000..6db886fcf7bd8 --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/color.js @@ -0,0 +1,75 @@ +import expect from 'expect.js'; +import { stringifyColor } from '../color'; + +describe('Color Format', function () { + let ColorFormat; + + beforeEach(() => { + ColorFormat = stringifyColor(); + }); + + describe('field is a number', () => { + it('should add colors if the value is in range', function () { + const colorer = new ColorFormat({ + fieldType: 'number', + colors: [{ + range: '100:150', + text: 'blue', + background: 'yellow' + }] + }); + expect(colorer.convert(99, 'html')).to.eql('99'); + expect(colorer.convert(100, 'html')).to.eql( + '100' + ); + expect(colorer.convert(150, 'html')).to.eql( + '150' + ); + expect(colorer.convert(151, 'html')).to.eql('151'); + }); + + it('should not convert invalid ranges', function () { + const colorer = new ColorFormat({ + fieldType: 'number', + colors: [{ + range: '100150', + text: 'blue', + background: 'yellow' + }] + }); + expect(colorer.convert(99, 'html')).to.eql('99'); + }); + }); + + describe('field is a string', () => { + it('should add colors if the regex matches', function () { + const colorer = new ColorFormat({ + fieldType: 'string', + colors: [{ + regex: 'A.*', + text: 'blue', + background: 'yellow' + }] + }); + + const converter = colorer.getConverterFor('html'); + expect(converter('B', 'html')).to.eql('B'); + expect(converter('AAA', 'html')).to.eql( + 'AAA' + ); + expect(converter('AB', 'html')).to.eql( + 'AB' + ); + expect(converter('a', 'html')).to.eql('a'); + + expect(converter('B', 'html')).to.eql('B'); + expect(converter('AAA', 'html')).to.eql( + 'AAA' + ); + expect(converter('AB', 'html')).to.eql( + 'AB' + ); + expect(converter('a', 'html')).to.eql('a'); + }); + }); +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/date.js b/src/core_plugins/kibana/common/field_format/types/__tests__/date.js new file mode 100644 index 0000000000000..1d3acf98d4c4f --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/date.js @@ -0,0 +1,46 @@ +import expect from 'expect.js'; +import moment from 'moment-timezone'; +import { stringifyDate } from '../date'; + +describe('Date Format', function () { + let convert; + let mockConfig; + + beforeEach(function () { + mockConfig = {}; + mockConfig.dateFormat = 'MMMM Do YYYY, HH:mm:ss.SSS'; + mockConfig['dateFormat:tz'] = 'Browser'; + const getConfig = (key) => mockConfig[key]; + + const DateFormat = stringifyDate(); + const date = new DateFormat({}, getConfig); + + convert = date.convert.bind(date); + }); + + it('decoding an undefined or null date should return an empty string', function () { + expect(convert(null)).to.be('-'); + expect(convert(undefined)).to.be('-'); + }); + + it('should clear the memoization cache after changing the date', function () { + function setDefaultTimezone() { + moment.tz.setDefault(mockConfig['dateFormat:tz']); + } + const time = 1445027693942; + + mockConfig['dateFormat:tz'] = 'America/Chicago'; + setDefaultTimezone(); + const chicagoTime = convert(time); + + mockConfig['dateFormat:tz'] = 'America/Phoenix'; + setDefaultTimezone(); + const phoenixTime = convert(time); + + expect(chicagoTime).not.to.equal(phoenixTime); + }); + + it('should parse date math values', function () { + expect(convert('2015-01-01||+1M/d')).to.be('January 1st 2015, 00:00:00.000'); + }); +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/duration.js b/src/core_plugins/kibana/common/field_format/types/__tests__/duration.js new file mode 100644 index 0000000000000..622d4b18e9ad2 --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/duration.js @@ -0,0 +1,46 @@ +import expect from 'expect.js'; +import { stringifyDuration } from '../duration'; + +describe('Duration Format', function () { + let DurationFormat; + + beforeEach(function () { + DurationFormat = stringifyDuration(); + }); + + test({ inputFormat: 'seconds', outputFormat: 'humanize' }) + (-60, 'minus a minute') + (60, 'a minute') + (125, '2 minutes'); + + test({ inputFormat: 'minutes', outputFormat: 'humanize' }) + (-60, 'minus an hour') + (60, 'an hour') + (125, '2 hours'); + + test({ inputFormat: 'minutes', outputFormat: 'asHours' }) // outputPrecision defaults to: 2 + (-60, '-1.00') + (60, '1.00') + (125, '2.08'); + + test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 0 }) + (-60, '-60') + (60, '60') + (125, '125'); + + test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 2 }) + (-60, '-60.00') + (-32.333, '-32.33') + (60, '60.00') + (125, '125.00'); + + function test({ inputFormat, outputFormat, outputPrecision }) { + return function testFixture(input, output) { + it(`should format ${input} ${inputFormat} through ${outputFormat}${outputPrecision ? `, ${outputPrecision} decimals` : ''}`, () => { + const duration = new DurationFormat({ inputFormat, outputFormat, outputPrecision }); + expect(duration.convert(input)).to.eql(output); + }); + return testFixture; + }; + } +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/ip.js b/src/core_plugins/kibana/common/field_format/types/__tests__/ip.js new file mode 100644 index 0000000000000..0eaf0ff126c09 --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/ip.js @@ -0,0 +1,20 @@ +import expect from 'expect.js'; +import { stringifyIp } from '../ip'; + +describe('IP Address Format', function () { + let ip; + beforeEach(function () { + const IpFormat = stringifyIp(); + ip = new IpFormat(); + }); + + it('converts a value from a decimal to a string', function () { + expect(ip.convert(1186489492)).to.be('70.184.100.148'); + }); + + it('converts null and undefined to -', function () { + expect(ip.convert(null)).to.be('-'); + expect(ip.convert(undefined)).to.be('-'); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/string.js b/src/core_plugins/kibana/common/field_format/types/__tests__/string.js new file mode 100644 index 0000000000000..694f4792fa9da --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/string.js @@ -0,0 +1,60 @@ +import expect from 'expect.js'; +import { stringifyString } from '../string'; + +describe('String Format', function () { + + let StringFormat; + + beforeEach(function () { + StringFormat = stringifyString(); + }); + + it('convert a string to lower case', function () { + const string = new StringFormat({ + transform: 'lower' + }); + expect(string.convert('Kibana')).to.be('kibana'); + }); + + it('convert a string to upper case', function () { + const string = new StringFormat({ + transform: 'upper' + }); + expect(string.convert('Kibana')).to.be('KIBANA'); + }); + +// TODO fix base64 encoded to not use window.atob +/* + it('decode a base64 string', function () { + const string = new StringFormat({ + transform: 'base64' + }); + expect(string.convert('Zm9vYmFy')).to.be('foobar'); + }); +*/ + + it('convert a string to title case', function () { + const string = new StringFormat({ + transform: 'title' + }); + expect(string.convert('PLEASE DO NOT SHOUT')).to.be('Please Do Not Shout'); + expect(string.convert('Mean, variance and standard_deviation.')).to.be('Mean, Variance And Standard_deviation.'); + expect(string.convert('Stay CALM!')).to.be('Stay Calm!'); + }); + + it('convert a string to short case', function () { + const string = new StringFormat({ + transform: 'short' + }); + expect(string.convert('dot.notated.string')).to.be('d.n.string'); + }); + + it('convert a string to unknown transform case', function () { + const string = new StringFormat({ + transform: 'unknown_transform' + }); + const value = 'test test test'; + expect(string.convert(value)).to.be(value); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js b/src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js new file mode 100644 index 0000000000000..cbec58d90dc44 --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js @@ -0,0 +1,34 @@ +import expect from 'expect.js'; +import { stringifyTruncate } from '../truncate'; + +describe('String Truncate Format', function () { + let Truncate; + + beforeEach(function () { + Truncate = stringifyTruncate(); + }); + + it('truncate large string', function () { + const truncate = new Truncate({ fieldLength: 4 }); + + expect(truncate.convert('This is some text')).to.be('This...'); + }); + + it('does not truncate large string when field length is not a string', function () { + const truncate = new Truncate({ fieldLength: 'not number' }); + + expect(truncate.convert('This is some text')).to.be('This is some text'); + }); + + it('does not truncate large string when field length is null', function () { + const truncate = new Truncate({ fieldLength: null }); + + expect(truncate.convert('This is some text')).to.be('This is some text'); + }); + + it('does not truncate large string when field length larger than the text', function () { + const truncate = new Truncate({ fieldLength: 100000 }); + + expect(truncate.convert('This is some text')).to.be('This is some text'); + }); +}); diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/url.js b/src/core_plugins/kibana/common/field_format/types/__tests__/url.js new file mode 100644 index 0000000000000..7335dfdcd0489 --- /dev/null +++ b/src/core_plugins/kibana/common/field_format/types/__tests__/url.js @@ -0,0 +1,85 @@ +import expect from 'expect.js'; +import { stringifyUrl } from '../url'; + +describe('Url Format', function () { + + let Url; + + beforeEach(function () { + Url = stringifyUrl(); + }); + + it('ouputs a simple tab by default', function () { + const url = new Url(); + + expect(url.convert('http://elastic.co', 'html')) + .to.be('http://elastic.co'); + }); + + it('outputs an if type === "img"', function () { + const url = new Url({ type: 'img' }); + + expect(url.convert('http://elastic.co', 'html')) + .to.be('A dynamically-specified image located at http://elastic.co'); + }); + + describe('url template', function () { + it('accepts a template', function () { + const url = new Url({ urlTemplate: 'url: {{ value }}' }); + expect(url.convert('url', 'html')) + .to.be('url: url'); + }); + + it('only outputs the url if the contentType === "text"', function () { + const url = new Url(); + expect(url.convert('url', 'text')).to.be('url'); + }); + }); + + describe('label template', function () { + it('accepts a template', function () { + const url = new Url({ labelTemplate: 'extension: {{ value }}' }); + expect(url.convert('php', 'html')) + .to.be('extension: php'); + }); + + it('uses the label template for text formating', function () { + const url = new Url({ labelTemplate: 'external {{value }}' }); + expect(url.convert('url', 'text')).to.be('external url'); + }); + + it('can use the raw value', function () { + const url = new Url({ + labelTemplate: 'external {{value}}' + }); + expect(url.convert('url?', 'text')).to.be('external url?'); + }); + + it('can use the url', function () { + const url = new Url({ + urlTemplate: 'http://google.com/{{value}}', + labelTemplate: 'external {{url}}' + }); + expect(url.convert('url?', 'text')).to.be('external http://google.com/url%3F'); + }); + }); + + describe('templating', function () { + it('ignores unknown variables', function () { + const url = new Url({ urlTemplate: '{{ not really a var }}' }); + expect(url.convert('url', 'text')).to.be(''); + }); + + it('does not allow executing code in variable expressions', function () { + const url = new Url({ urlTemplate: '{{ (__dirname = true) && value }}' }); + expect(url.convert('url', 'text')).to.be(''); + }); + + describe('', function () { + it('does not get values from the prototype chain', function () { + const url = new Url({ urlTemplate: '{{ toString }}' }); + expect(url.convert('url', 'text')).to.be(''); + }); + }); + }); +}); diff --git a/src/ui/public/stringify/types/_numeral.js b/src/core_plugins/kibana/common/field_format/types/_numeral.js similarity index 93% rename from src/ui/public/stringify/types/_numeral.js rename to src/core_plugins/kibana/common/field_format/types/_numeral.js index 197c1b44e96c7..0c6ea362ab9de 100644 --- a/src/ui/public/stringify/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_format/types/_numeral.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import numeral from 'numeral'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; const numeralInst = numeral(); diff --git a/src/ui/public/stringify/types/_source.html b/src/core_plugins/kibana/common/field_format/types/_source.html similarity index 100% rename from src/ui/public/stringify/types/_source.html rename to src/core_plugins/kibana/common/field_format/types/_source.html diff --git a/src/ui/public/stringify/types/boolean.js b/src/core_plugins/kibana/common/field_format/types/boolean.js similarity index 82% rename from src/ui/public/stringify/types/boolean.js rename to src/core_plugins/kibana/common/field_format/types/boolean.js index fb91800a396da..4b9a6ffaa9e31 100644 --- a/src/ui/public/stringify/types/boolean.js +++ b/src/core_plugins/kibana/common/field_format/types/boolean.js @@ -1,5 +1,5 @@ -import { asPrettyString } from 'ui/utils/as_pretty_string'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { asPrettyString } from '../../utils/as_pretty_string'; +import { FieldFormat } from '../field_format'; export function stringifyBoolean() { diff --git a/src/ui/public/stringify/types/bytes.js b/src/core_plugins/kibana/common/field_format/types/bytes.js similarity index 66% rename from src/ui/public/stringify/types/bytes.js rename to src/core_plugins/kibana/common/field_format/types/bytes.js index 53214e7483cfe..46fbe2e8196e9 100644 --- a/src/ui/public/stringify/types/bytes.js +++ b/src/core_plugins/kibana/common/field_format/types/bytes.js @@ -1,4 +1,4 @@ -import { Numeral } from 'ui/stringify/types/_numeral'; +import { Numeral } from './_numeral'; export function stringifyBytes() { return Numeral.factory({ diff --git a/src/ui/public/stringify/types/color.js b/src/core_plugins/kibana/common/field_format/types/color.js similarity index 91% rename from src/ui/public/stringify/types/color.js rename to src/core_plugins/kibana/common/field_format/types/color.js index bd3d64d2a4493..d83a75f803e1a 100644 --- a/src/ui/public/stringify/types/color.js +++ b/src/core_plugins/kibana/common/field_format/types/color.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import { asPrettyString } from 'ui/utils/as_pretty_string'; +import { asPrettyString } from '../../utils/as_pretty_string'; import { DEFAULT_COLOR } from './color_default'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; export function stringifyColor() { diff --git a/src/ui/public/stringify/types/color_default.js b/src/core_plugins/kibana/common/field_format/types/color_default.js similarity index 100% rename from src/ui/public/stringify/types/color_default.js rename to src/core_plugins/kibana/common/field_format/types/color_default.js diff --git a/src/ui/public/stringify/types/date.js b/src/core_plugins/kibana/common/field_format/types/date.js similarity index 94% rename from src/ui/public/stringify/types/date.js rename to src/core_plugins/kibana/common/field_format/types/date.js index 2fa1e5bbfdd69..80d2cbc7f9e33 100644 --- a/src/ui/public/stringify/types/date.js +++ b/src/core_plugins/kibana/common/field_format/types/date.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import moment from 'moment'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; export function stringifyDate() { diff --git a/src/ui/public/stringify/types/duration.js b/src/core_plugins/kibana/common/field_format/types/duration.js similarity index 97% rename from src/ui/public/stringify/types/duration.js rename to src/core_plugins/kibana/common/field_format/types/duration.js index 4051fc99da5d7..7b45ce07eaea1 100644 --- a/src/ui/public/stringify/types/duration.js +++ b/src/core_plugins/kibana/common/field_format/types/duration.js @@ -1,5 +1,5 @@ import moment from 'moment'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; export function stringifyDuration() { const ratioToSeconds = { diff --git a/src/ui/public/stringify/types/ip.js b/src/core_plugins/kibana/common/field_format/types/ip.js similarity index 84% rename from src/ui/public/stringify/types/ip.js rename to src/core_plugins/kibana/common/field_format/types/ip.js index a9cfd09978f97..a934001762a06 100644 --- a/src/ui/public/stringify/types/ip.js +++ b/src/core_plugins/kibana/common/field_format/types/ip.js @@ -1,4 +1,4 @@ -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; export function stringifyIp() { diff --git a/src/ui/public/stringify/types/number.js b/src/core_plugins/kibana/common/field_format/types/number.js similarity index 66% rename from src/ui/public/stringify/types/number.js rename to src/core_plugins/kibana/common/field_format/types/number.js index ccb1d62026974..b4d7a478f3466 100644 --- a/src/ui/public/stringify/types/number.js +++ b/src/core_plugins/kibana/common/field_format/types/number.js @@ -1,4 +1,4 @@ -import { Numeral } from 'ui/stringify/types/_numeral'; +import { Numeral } from './_numeral'; export function stringifyNumber() { return Numeral.factory({ diff --git a/src/ui/public/stringify/types/percent.js b/src/core_plugins/kibana/common/field_format/types/percent.js similarity index 89% rename from src/ui/public/stringify/types/percent.js rename to src/core_plugins/kibana/common/field_format/types/percent.js index 84fee934e8338..d2e35c69a98db 100644 --- a/src/ui/public/stringify/types/percent.js +++ b/src/core_plugins/kibana/common/field_format/types/percent.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { Numeral } from 'ui/stringify/types/_numeral'; +import { Numeral } from './_numeral'; export function stringifyPercent() { return Numeral.factory({ diff --git a/src/ui/public/stringify/types/source.js b/src/core_plugins/kibana/common/field_format/types/source.js similarity index 76% rename from src/ui/public/stringify/types/source.js rename to src/core_plugins/kibana/common/field_format/types/source.js index 802478f1949e5..0d07f152f17fa 100644 --- a/src/ui/public/stringify/types/source.js +++ b/src/core_plugins/kibana/common/field_format/types/source.js @@ -1,11 +1,11 @@ import _ from 'lodash'; -import { noWhiteSpace } from 'ui/utils/no_white_space'; -import { toJson } from 'ui/utils/aggressive_parse'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; -import { shortenDottedString } from 'ui/utils/shorten_dotted_string'; +import { noWhiteSpace } from '../../utils/no_white_space'; +import { toJson } from '../../utils/aggressive_parse'; +import { FieldFormat } from '../field_format'; +import { shortenDottedString } from '../../utils/shorten_dotted_string'; export function stringifySource() { - const template = _.template(noWhiteSpace(require('ui/stringify/types/_source.html'))); + const template = _.template(noWhiteSpace(require('./_source.html'))); class SourceFormat extends FieldFormat { constructor(params, getConfig) { diff --git a/src/ui/public/stringify/types/string.js b/src/core_plugins/kibana/common/field_format/types/string.js similarity index 84% rename from src/ui/public/stringify/types/string.js rename to src/core_plugins/kibana/common/field_format/types/string.js index 1fa073191769f..a64ff4d35b8e6 100644 --- a/src/ui/public/stringify/types/string.js +++ b/src/core_plugins/kibana/common/field_format/types/string.js @@ -1,6 +1,6 @@ -import { asPrettyString } from 'ui/utils/as_pretty_string'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; -import { shortenDottedString } from 'ui/utils/shorten_dotted_string'; +import { asPrettyString } from '../../utils/as_pretty_string'; +import { FieldFormat } from '../field_format'; +import { shortenDottedString } from '../../utils/shorten_dotted_string'; export function stringifyString() { diff --git a/src/ui/public/stringify/types/truncate.js b/src/core_plugins/kibana/common/field_format/types/truncate.js similarity index 86% rename from src/ui/public/stringify/types/truncate.js rename to src/core_plugins/kibana/common/field_format/types/truncate.js index 64fa438a14511..c3e0780e8ed19 100644 --- a/src/ui/public/stringify/types/truncate.js +++ b/src/core_plugins/kibana/common/field_format/types/truncate.js @@ -1,6 +1,5 @@ import _ from 'lodash'; - -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../field_format'; export function stringifyTruncate() { const omission = '...'; diff --git a/src/ui/public/stringify/types/url.js b/src/core_plugins/kibana/common/field_format/types/url.js similarity index 95% rename from src/ui/public/stringify/types/url.js rename to src/core_plugins/kibana/common/field_format/types/url.js index 3e8a63a9e2cfc..5ecdf97346aa8 100644 --- a/src/ui/public/stringify/types/url.js +++ b/src/core_plugins/kibana/common/field_format/types/url.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; -import { getHighlightHtml } from 'ui/highlight'; +import { FieldFormat } from '../field_format'; +import { getHighlightHtml } from '../../highlight/highlight_html'; export function stringifyUrl() { diff --git a/src/ui/public/highlight/__tests__/highlight_html.js b/src/core_plugins/kibana/common/highlight/__tests__/highlight_html.js similarity index 100% rename from src/ui/public/highlight/__tests__/highlight_html.js rename to src/core_plugins/kibana/common/highlight/__tests__/highlight_html.js diff --git a/src/ui/public/highlight/__tests__/highlight_request.js b/src/core_plugins/kibana/common/highlight/__tests__/highlight_request.js similarity index 100% rename from src/ui/public/highlight/__tests__/highlight_request.js rename to src/core_plugins/kibana/common/highlight/__tests__/highlight_request.js diff --git a/src/ui/public/highlight/highlight.js b/src/core_plugins/kibana/common/highlight/highlight.js similarity index 100% rename from src/ui/public/highlight/highlight.js rename to src/core_plugins/kibana/common/highlight/highlight.js diff --git a/src/ui/public/highlight/highlight_html.js b/src/core_plugins/kibana/common/highlight/highlight_html.js similarity index 93% rename from src/ui/public/highlight/highlight_html.js rename to src/core_plugins/kibana/common/highlight/highlight_html.js index 022eff7b8cf11..e2bc333fe84dc 100644 --- a/src/ui/public/highlight/highlight_html.js +++ b/src/core_plugins/kibana/common/highlight/highlight_html.js @@ -1,11 +1,10 @@ import _ from 'lodash'; -import angular from 'angular'; import { highlightTags } from './highlight_tags'; import { htmlTags } from './html_tags'; export function getHighlightHtml(fieldValue, highlights) { let highlightHtml = (typeof fieldValue === 'object') - ? angular.toJson(fieldValue) + ? JSON.stringify(fieldValue) : fieldValue; _.each(highlights, function (highlight) { diff --git a/src/ui/public/highlight/highlight_request.js b/src/core_plugins/kibana/common/highlight/highlight_request.js similarity index 100% rename from src/ui/public/highlight/highlight_request.js rename to src/core_plugins/kibana/common/highlight/highlight_request.js diff --git a/src/ui/public/highlight/highlight_tags.js b/src/core_plugins/kibana/common/highlight/highlight_tags.js similarity index 100% rename from src/ui/public/highlight/highlight_tags.js rename to src/core_plugins/kibana/common/highlight/highlight_tags.js diff --git a/src/ui/public/highlight/html_tags.js b/src/core_plugins/kibana/common/highlight/html_tags.js similarity index 100% rename from src/ui/public/highlight/html_tags.js rename to src/core_plugins/kibana/common/highlight/html_tags.js diff --git a/src/ui/public/utils/__tests__/aggressive_parse.js b/src/core_plugins/kibana/common/utils/__tests__/aggressive_parse.js similarity index 97% rename from src/ui/public/utils/__tests__/aggressive_parse.js rename to src/core_plugins/kibana/common/utils/__tests__/aggressive_parse.js index 75b3a53024da8..49f25ed69af86 100644 --- a/src/ui/public/utils/__tests__/aggressive_parse.js +++ b/src/core_plugins/kibana/common/utils/__tests__/aggressive_parse.js @@ -1,7 +1,8 @@ import _ from 'lodash'; import expect from 'expect.js'; import sinon from 'sinon'; -import * as aggressiveParse from 'ui/utils/aggressive_parse'; +import * as aggressiveParse from '../aggressive_parse'; + describe('aggressiveParse', () => { let object; diff --git a/src/ui/public/utils/__tests__/as_pretty_string.js b/src/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js similarity index 92% rename from src/ui/public/utils/__tests__/as_pretty_string.js rename to src/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js index 003234f75a879..786863560efc1 100644 --- a/src/ui/public/utils/__tests__/as_pretty_string.js +++ b/src/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js @@ -1,5 +1,5 @@ import expect from 'expect.js'; -import { asPrettyString } from 'ui/utils/as_pretty_string'; +import { asPrettyString } from '../as_pretty_string'; describe('asPrettyString', () => { diff --git a/src/ui/public/utils/__tests__/shorten_dotted_string.js b/src/core_plugins/kibana/common/utils/__tests__/shorten_dotted_string.js similarity index 86% rename from src/ui/public/utils/__tests__/shorten_dotted_string.js rename to src/core_plugins/kibana/common/utils/__tests__/shorten_dotted_string.js index dea2efc252bed..231c0b2d77a0e 100644 --- a/src/ui/public/utils/__tests__/shorten_dotted_string.js +++ b/src/core_plugins/kibana/common/utils/__tests__/shorten_dotted_string.js @@ -1,5 +1,5 @@ import expect from 'expect.js'; -import { shortenDottedString } from 'ui/utils/shorten_dotted_string'; +import { shortenDottedString } from '../shorten_dotted_string'; describe('shortenDottedString', () => { diff --git a/src/ui/public/utils/aggressive_parse.js b/src/core_plugins/kibana/common/utils/aggressive_parse.js similarity index 100% rename from src/ui/public/utils/aggressive_parse.js rename to src/core_plugins/kibana/common/utils/aggressive_parse.js diff --git a/src/ui/public/utils/as_pretty_string.js b/src/core_plugins/kibana/common/utils/as_pretty_string.js similarity index 100% rename from src/ui/public/utils/as_pretty_string.js rename to src/core_plugins/kibana/common/utils/as_pretty_string.js diff --git a/src/ui/public/utils/no_white_space.js b/src/core_plugins/kibana/common/utils/no_white_space.js similarity index 100% rename from src/ui/public/utils/no_white_space.js rename to src/core_plugins/kibana/common/utils/no_white_space.js diff --git a/src/ui/public/utils/shorten_dotted_string.js b/src/core_plugins/kibana/common/utils/shorten_dotted_string.js similarity index 100% rename from src/ui/public/utils/shorten_dotted_string.js rename to src/core_plugins/kibana/common/utils/shorten_dotted_string.js diff --git a/src/ui/public/agg_types/buckets/range.js b/src/ui/public/agg_types/buckets/range.js index 549e5e3482456..2a9ea4741947e 100644 --- a/src/ui/public/agg_types/buckets/range.js +++ b/src/ui/public/agg_types/buckets/range.js @@ -1,6 +1,6 @@ import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type'; import { AggTypesBucketsCreateFilterRangeProvider } from 'ui/agg_types/buckets/create_filter/range'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../../../../core_plugins/kibana/common/field_format/field_format'; import { RangeKeyProvider } from './range_key'; import rangesTemplate from 'ui/agg_types/controls/ranges.html'; diff --git a/src/ui/public/autoload/modules.js b/src/ui/public/autoload/modules.js index 2a659b06b653f..dbef161838620 100644 --- a/src/ui/public/autoload/modules.js +++ b/src/ui/public/autoload/modules.js @@ -24,7 +24,6 @@ import 'ui/modals'; import 'ui/state_management/app_state'; import 'ui/state_management/global_state'; import 'ui/storage'; -import 'ui/stringify/register'; import 'ui/style_compile'; import 'ui/timefilter'; import 'ui/timepicker'; diff --git a/src/ui/public/courier/data_source/_abstract.js b/src/ui/public/courier/data_source/_abstract.js index cf5760ef3c0af..065c7252b357b 100644 --- a/src/ui/public/courier/data_source/_abstract.js +++ b/src/ui/public/courier/data_source/_abstract.js @@ -8,7 +8,7 @@ import { ErrorHandlersProvider } from '../_error_handlers'; import { FetchProvider } from '../fetch'; import { DecorateQueryProvider } from './_decorate_query'; import { FieldWildcardProvider } from '../../field_wildcard'; -import { getHighlightRequest } from '../../highlight'; +import { getHighlightRequest } from '../../../../core_plugins/kibana/common/highlight'; import { migrateFilter } from './_migrate_filter'; export function AbstractDataSourceProvider(Private, Promise, PromiseEmitter, config) { diff --git a/src/ui/public/courier/fetch/strategy/search.js b/src/ui/public/courier/fetch/strategy/search.js index 314523ae5917a..e64ed44a156e0 100644 --- a/src/ui/public/courier/fetch/strategy/search.js +++ b/src/ui/public/courier/fetch/strategy/search.js @@ -1,7 +1,6 @@ import _ from 'lodash'; import angular from 'angular'; - -import { toJson } from 'ui/utils/aggressive_parse'; +import { toJson } from '../../../../../core_plugins/kibana/common/utils/aggressive_parse'; export function SearchStrategyProvider(Private, Promise, timefilter, kbnIndex, sessionId) { diff --git a/src/ui/public/doc_table/components/table_row.js b/src/ui/public/doc_table/components/table_row.js index 6ba4827162311..dcf9c45787cca 100644 --- a/src/ui/public/doc_table/components/table_row.js +++ b/src/ui/public/doc_table/components/table_row.js @@ -1,13 +1,11 @@ import _ from 'lodash'; import $ from 'jquery'; import rison from 'rison-node'; -import 'ui/highlight'; -import 'ui/highlight/highlight_tags'; import 'ui/doc_viewer'; import 'ui/filters/trust_as_html'; import 'ui/filters/short_dots'; import './table_row.less'; -import { noWhiteSpace } from 'ui/utils/no_white_space'; +import { noWhiteSpace } from '../../../../core_plugins/kibana/common/utils/no_white_space'; import openRowHtml from 'ui/doc_table/components/table_row/open.html'; import detailsHtml from 'ui/doc_table/components/table_row/details.html'; import { uiModules } from 'ui/modules'; diff --git a/src/ui/public/stringify/__tests__/_boolean.js b/src/ui/public/field_format/__tests__/_boolean.js similarity index 100% rename from src/ui/public/stringify/__tests__/_boolean.js rename to src/ui/public/field_format/__tests__/_boolean.js diff --git a/src/ui/public/stringify/__tests__/_color.js b/src/ui/public/field_format/__tests__/_color.js similarity index 100% rename from src/ui/public/stringify/__tests__/_color.js rename to src/ui/public/field_format/__tests__/_color.js diff --git a/src/ui/public/stringify/__tests__/_conformance.js b/src/ui/public/field_format/__tests__/_conformance.js similarity index 97% rename from src/ui/public/stringify/__tests__/_conformance.js rename to src/ui/public/field_format/__tests__/_conformance.js index 2a41ea6e01e22..4ee3e73f80ad0 100644 --- a/src/ui/public/stringify/__tests__/_conformance.js +++ b/src/ui/public/field_format/__tests__/_conformance.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import expect from 'expect.js'; import ngMock from 'ng_mock'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../../../../core_plugins/kibana/common/field_format/field_format'; let fieldFormats; let config; diff --git a/src/ui/public/stringify/__tests__/_date.js b/src/ui/public/field_format/__tests__/_date.js similarity index 100% rename from src/ui/public/stringify/__tests__/_date.js rename to src/ui/public/field_format/__tests__/_date.js diff --git a/src/ui/public/stringify/__tests__/_duration.js b/src/ui/public/field_format/__tests__/_duration.js similarity index 100% rename from src/ui/public/stringify/__tests__/_duration.js rename to src/ui/public/field_format/__tests__/_duration.js diff --git a/src/ui/public/stringify/__tests__/_ip.js b/src/ui/public/field_format/__tests__/_ip.js similarity index 100% rename from src/ui/public/stringify/__tests__/_ip.js rename to src/ui/public/field_format/__tests__/_ip.js diff --git a/src/ui/public/stringify/__tests__/_source.js b/src/ui/public/field_format/__tests__/_source.js similarity index 100% rename from src/ui/public/stringify/__tests__/_source.js rename to src/ui/public/field_format/__tests__/_source.js diff --git a/src/ui/public/stringify/__tests__/_string.js b/src/ui/public/field_format/__tests__/_string.js similarity index 100% rename from src/ui/public/stringify/__tests__/_string.js rename to src/ui/public/field_format/__tests__/_string.js diff --git a/src/ui/public/stringify/__tests__/_truncate.js b/src/ui/public/field_format/__tests__/_truncate.js similarity index 100% rename from src/ui/public/stringify/__tests__/_truncate.js rename to src/ui/public/field_format/__tests__/_truncate.js diff --git a/src/ui/public/stringify/__tests__/_url.js b/src/ui/public/field_format/__tests__/_url.js similarity index 100% rename from src/ui/public/stringify/__tests__/_url.js rename to src/ui/public/field_format/__tests__/_url.js diff --git a/src/ui/public/stringify/__tests__/index.js b/src/ui/public/field_format/__tests__/index.js similarity index 100% rename from src/ui/public/stringify/__tests__/index.js rename to src/ui/public/field_format/__tests__/index.js diff --git a/src/ui/public/field_format/register.js b/src/ui/public/field_format/register.js new file mode 100644 index 0000000000000..56e800472efd9 --- /dev/null +++ b/src/ui/public/field_format/register.js @@ -0,0 +1,26 @@ +import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; +import { stringifyUrl } from '../../../core_plugins/kibana/common/field_format/types/url'; +import { stringifyBytes } from '../../../core_plugins/kibana/common/field_format/types/bytes'; +import { stringifyDate } from '../../../core_plugins/kibana/common/field_format/types/date'; +import { stringifyDuration } from '../../../core_plugins/kibana/common/field_format/types/duration'; +import { stringifyIp } from '../../../core_plugins/kibana/common/field_format/types/ip'; +import { stringifyNumber } from '../../../core_plugins/kibana/common/field_format/types/number'; +import { stringifyPercent } from '../../../core_plugins/kibana/common/field_format/types/percent'; +import { stringifyString } from '../../../core_plugins/kibana/common/field_format/types/string'; +import { stringifySource } from '../../../core_plugins/kibana/common/field_format/types/source'; +import { stringifyColor } from '../../../core_plugins/kibana/common/field_format/types/color'; +import { stringifyTruncate } from '../../../core_plugins/kibana/common/field_format/types/truncate'; +import { stringifyBoolean } from '../../../core_plugins/kibana/common/field_format/types/boolean'; + +RegistryFieldFormatsProvider.register(stringifyUrl); +RegistryFieldFormatsProvider.register(stringifyBytes); +RegistryFieldFormatsProvider.register(stringifyDate); +RegistryFieldFormatsProvider.register(stringifyDuration); +RegistryFieldFormatsProvider.register(stringifyIp); +RegistryFieldFormatsProvider.register(stringifyNumber); +RegistryFieldFormatsProvider.register(stringifyPercent); +RegistryFieldFormatsProvider.register(stringifyString); +RegistryFieldFormatsProvider.register(stringifySource); +RegistryFieldFormatsProvider.register(stringifyColor); +RegistryFieldFormatsProvider.register(stringifyTruncate); +RegistryFieldFormatsProvider.register(stringifyBoolean); diff --git a/src/ui/public/field_format_editor/editors/color/color.js b/src/ui/public/field_format_editor/editors/color/color.js index 864eeb88f45da..6d08817e4c461 100644 --- a/src/ui/public/field_format_editor/editors/color/color.js +++ b/src/ui/public/field_format_editor/editors/color/color.js @@ -1,6 +1,6 @@ import './color.less'; import colorTemplate from './color.html'; -import { DEFAULT_COLOR } from 'ui/stringify/types/color_default'; +import { DEFAULT_COLOR } from '../../../../../core_plugins/kibana/common/field_format/types/color_default'; export function colorEditor() { return { diff --git a/src/ui/public/filters/short_dots.js b/src/ui/public/filters/short_dots.js index 17a01411d7747..5cdb69d0a1be4 100644 --- a/src/ui/public/filters/short_dots.js +++ b/src/ui/public/filters/short_dots.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { shortenDottedString } from 'ui/utils/shorten_dotted_string'; +import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string'; import { uiModules } from 'ui/modules'; // Shorts dot notated strings // eg: foo.bar.baz becomes f.b.baz diff --git a/src/ui/public/index_patterns/_field.js b/src/ui/public/index_patterns/_field.js index 90fc680341f77..8401621161926 100644 --- a/src/ui/public/index_patterns/_field.js +++ b/src/ui/public/index_patterns/_field.js @@ -1,5 +1,5 @@ import { ObjDefine } from 'ui/utils/obj_define'; -import { FieldFormat } from 'ui/index_patterns/_field_format/field_format'; +import { FieldFormat } from '../../../core_plugins/kibana/common/field_format/field_format'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; import { getKbnFieldType } from '../../../utils'; diff --git a/src/ui/public/index_patterns/_field_format/__tests__/content_types.js b/src/ui/public/index_patterns/_field_format/__tests__/content_types.js deleted file mode 100644 index 825864b7abebf..0000000000000 --- a/src/ui/public/index_patterns/_field_format/__tests__/content_types.js +++ /dev/null @@ -1,98 +0,0 @@ -import angular from 'angular'; -import $ from 'jquery'; -import ngMock from 'ng_mock'; -import sinon from 'sinon'; -import expect from 'expect.js'; -import { escape } from 'lodash'; - -import { contentTypesSetup } from '../content_types'; - -describe('index_patterns/_field_format/content_types', () => { - - let render; - const callMe = sinon.stub(); - afterEach(() => callMe.reset()); - - function getAllContents(node) { - return [...node.childNodes].reduce((acc, child) => { - return acc.concat(child, getAllContents(child)); - }, []); - } - - angular.module('testApp', []) - .directive('testDirective', () => ({ - restrict: 'EACM', - link: callMe - })); - - beforeEach(ngMock.module('testApp')); - beforeEach(ngMock.inject(($injector) => { - const $rootScope = $injector.get('$rootScope'); - const $compile = $injector.get('$compile'); - - $rootScope.callMe = callMe; - - render = (convert) => { - const $el = $('
'); - const { html } = contentTypesSetup({ _convert: { html: convert } }); - $compile($el.html(html(` - -
- {{callMe()}} - - - `)))($rootScope); - return $el; - }; - })); - - it('no element directive', () => { - const $el = render(value => ` - ${escape(value)} - `); - - expect($el.find('test-directive')).to.have.length(1); - sinon.assert.notCalled(callMe); - }); - - it('no attribute directive', () => { - const $el = render(value => ` -
${escape(value)}
- `); - - expect($el.find('[test-directive]')).to.have.length(1); - sinon.assert.notCalled(callMe); - }); - - it('no comment directive', () => { - const $el = render(value => ` - -
${escape(value)}
- `); - - const comments = getAllContents($el.get(0)) - .filter(node => node.nodeType === 8); - - expect(comments).to.have.length(1); - expect(comments[0].textContent).to.contain('test-directive'); - sinon.assert.notCalled(callMe); - }); - - it('no class directive', () => { - const $el = render(value => ` -
${escape(value)}
- `); - - expect($el.find('.test-directive')).to.have.length(1); - sinon.assert.notCalled(callMe); - }); - - it('no interpolation', () => { - const $el = render(value => ` -
${escape(value)}
- `); - - expect($el.find('.foo')).to.have.length(1); - sinon.assert.notCalled(callMe); - }); -}); diff --git a/src/ui/public/stringify/register.js b/src/ui/public/stringify/register.js deleted file mode 100644 index 305d1484a8cc0..0000000000000 --- a/src/ui/public/stringify/register.js +++ /dev/null @@ -1,26 +0,0 @@ -import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { stringifyUrl } from 'ui/stringify/types/url'; -import { stringifyBytes } from 'ui/stringify/types/bytes'; -import { stringifyDate } from 'ui/stringify/types/date'; -import { stringifyDuration } from 'ui/stringify/types/duration'; -import { stringifyIp } from 'ui/stringify/types/ip'; -import { stringifyNumber } from 'ui/stringify/types/number'; -import { stringifyPercent } from 'ui/stringify/types/percent'; -import { stringifyString } from 'ui/stringify/types/string'; -import { stringifySource } from 'ui/stringify/types/source'; -import { stringifyColor } from 'ui/stringify/types/color'; -import { stringifyTruncate } from 'ui/stringify/types/truncate'; -import { stringifyBoolean } from 'ui/stringify/types/boolean'; - -RegistryFieldFormatsProvider.register(stringifyUrl); -RegistryFieldFormatsProvider.register(stringifyBytes); -RegistryFieldFormatsProvider.register(stringifyDate); -RegistryFieldFormatsProvider.register(stringifyDuration); -RegistryFieldFormatsProvider.register(stringifyIp); -RegistryFieldFormatsProvider.register(stringifyNumber); -RegistryFieldFormatsProvider.register(stringifyPercent); -RegistryFieldFormatsProvider.register(stringifyString); -RegistryFieldFormatsProvider.register(stringifySource); -RegistryFieldFormatsProvider.register(stringifyColor); -RegistryFieldFormatsProvider.register(stringifyTruncate); -RegistryFieldFormatsProvider.register(stringifyBoolean); diff --git a/src/ui/ui_exports.js b/src/ui/ui_exports.js index 3808037de9711..5c0e6a9b2907a 100644 --- a/src/ui/ui_exports.js +++ b/src/ui/ui_exports.js @@ -10,6 +10,7 @@ export default class UiExports { this.navLinks = new UiNavLinkCollection(this); this.apps = new UiAppCollection(this); this.aliases = { + fieldFormats: ['ui/field_format/register'], fieldFormatEditors: ['ui/field_format_editor/register'] }; this.urlBasePath = urlBasePath; From f7b5205f4cd0da4889241b2f5f7276b49e8e1e7b Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 29 Jun 2017 12:13:46 -0600 Subject: [PATCH 02/15] expose fieldFormats on server --- .../__tests__/field_format.js | 0 .../field_formats/__tests__/field_formats.js | 38 ++++++++++++++++ .../content_types.js | 0 .../field_format.js | 0 .../common/field_formats/field_formats.js | 45 +++++++++++++++++++ .../types/__tests__/boolean.js | 0 .../types/__tests__/color.js | 0 .../types/__tests__/date.js | 0 .../types/__tests__/duration.js | 0 .../types/__tests__/ip.js | 0 .../types/__tests__/string.js | 0 .../types/__tests__/truncate.js | 0 .../types/__tests__/url.js | 0 .../types/_numeral.js | 2 +- .../types/_source.html | 0 .../types/boolean.js | 0 .../types/bytes.js | 0 .../types/color.js | 0 .../types/color_default.js | 0 .../types/date.js | 0 .../types/duration.js | 0 .../types/ip.js | 0 .../types/number.js | 0 .../types/percent.js | 0 .../types/source.js | 0 .../types/string.js | 0 .../types/truncate.js | 0 .../types/url.js | 0 src/core_plugins/kibana/index.js | 4 ++ .../field_formats}/__tests__/_boolean.js | 0 .../public/field_formats}/__tests__/_color.js | 0 .../field_formats}/__tests__/_conformance.js | 2 +- .../public/field_formats}/__tests__/_date.js | 0 .../field_formats}/__tests__/_duration.js | 0 .../public/field_formats}/__tests__/_ip.js | 0 .../field_formats}/__tests__/_source.js | 0 .../field_formats}/__tests__/_string.js | 0 .../field_formats}/__tests__/_truncate.js | 0 .../public/field_formats}/__tests__/_url.js | 0 .../public/field_formats}/__tests__/index.js | 0 .../kibana/public/field_formats/register.js | 26 +++++++++++ .../kibana/server/register_field_formats.js | 27 +++++++++++ src/ui/field_formats_mixin.js | 5 +++ src/ui/index.js | 3 ++ src/ui/public/agg_types/buckets/range.js | 2 +- src/ui/public/field_format/register.js | 26 ----------- .../editors/color/color.js | 2 +- src/ui/public/index_patterns/_field.js | 2 +- src/ui/ui_exports.js | 1 - 49 files changed, 153 insertions(+), 32 deletions(-) rename src/core_plugins/kibana/common/{field_format => field_formats}/__tests__/field_format.js (100%) create mode 100644 src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js rename src/core_plugins/kibana/common/{field_format => field_formats}/content_types.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/field_format.js (100%) create mode 100644 src/core_plugins/kibana/common/field_formats/field_formats.js rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/boolean.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/color.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/date.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/duration.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/ip.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/string.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/truncate.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/__tests__/url.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/_numeral.js (96%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/_source.html (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/boolean.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/bytes.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/color.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/color_default.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/date.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/duration.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/ip.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/number.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/percent.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/source.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/string.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/truncate.js (100%) rename src/core_plugins/kibana/common/{field_format => field_formats}/types/url.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_boolean.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_color.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_conformance.js (97%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_date.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_duration.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_ip.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_source.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_string.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_truncate.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/_url.js (100%) rename src/{ui/public/field_format => core_plugins/kibana/public/field_formats}/__tests__/index.js (100%) create mode 100644 src/core_plugins/kibana/public/field_formats/register.js create mode 100644 src/core_plugins/kibana/server/register_field_formats.js create mode 100644 src/ui/field_formats_mixin.js delete mode 100644 src/ui/public/field_format/register.js diff --git a/src/core_plugins/kibana/common/field_format/__tests__/field_format.js b/src/core_plugins/kibana/common/field_formats/__tests__/field_format.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/__tests__/field_format.js rename to src/core_plugins/kibana/common/field_formats/__tests__/field_format.js diff --git a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js new file mode 100644 index 0000000000000..ede32b5571423 --- /dev/null +++ b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js @@ -0,0 +1,38 @@ +import expect from 'expect.js'; +import { FieldFormatsService } from '../field_formats'; +import { stringifyNumber } from '../types/number'; + +describe('FieldFormatsService', function () { + + const NumberFormat = stringifyNumber(); + const config = {}; + config['format:defaultTypeMap'] = { + 'ip': { 'id': 'ip', 'params': {} }, + 'date': { 'id': 'date', 'params': {} }, + 'number': { 'id': 'number', 'params': {} }, + 'boolean': { 'id': 'boolean', 'params': {} }, + '_source': { 'id': '_source', 'params': {} }, + '_default_': { 'id': 'string', 'params': {} } + }; + config['format:number:defaultPattern'] = '0,0.[000]'; + const getConfig = (key) => config[key]; + + let fieldFormats; + beforeEach(function () { + fieldFormats = new FieldFormatsService; + }); + + it('registered FieldFormats are accessible via getType method', function () { + fieldFormats.register(NumberFormat); + const Type = fieldFormats.getType('number'); + expect(Type.id).to.be('number'); + }); + + it('getDefaultInstance returns default FieldFormat instance for fieldType', function () { + fieldFormats.register(NumberFormat); + const instance = fieldFormats.getDefaultInstance('number', getConfig); + expect(instance.type.id).to.be('number'); + expect(instance.convert('0.33333')).to.be('0.333'); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_format/content_types.js b/src/core_plugins/kibana/common/field_formats/content_types.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/content_types.js rename to src/core_plugins/kibana/common/field_formats/content_types.js diff --git a/src/core_plugins/kibana/common/field_format/field_format.js b/src/core_plugins/kibana/common/field_formats/field_format.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/field_format.js rename to src/core_plugins/kibana/common/field_formats/field_format.js diff --git a/src/core_plugins/kibana/common/field_formats/field_formats.js b/src/core_plugins/kibana/common/field_formats/field_formats.js new file mode 100644 index 0000000000000..9040f90dab49f --- /dev/null +++ b/src/core_plugins/kibana/common/field_formats/field_formats.js @@ -0,0 +1,45 @@ +export class FieldFormatsService { + constructor() { + this.fieldFormats = new Map(); + } + + /** + * Get the id of the default type for this field type + * using the format:defaultTypeMap config map + * + * @param {String} fieldType - the field type + * @param {Func} getConfig + * @return {String} + */ + getDefaultConfig(fieldType, getConfig) { + const defaultMap = getConfig('format:defaultTypeMap'); + return defaultMap[fieldType] || defaultMap._default_; + } + + /** + * Get the default fieldFormat instance for a field type. + * + * @param {String} fieldType + * @param {Func} getConfig + * @return {FieldFormat} + */ + getDefaultInstance(fieldType, getConfig) { + const conf = this.getDefaultConfig(fieldType, getConfig); + const FieldFormat = this.fieldFormats.get(conf.id); + return new FieldFormat(conf.params, getConfig); + } + + /** + * Get a FieldFormat type (class) by it's id. + * + * @param {String} fieldFormatId - the FieldFormat id + * @return {FieldFormat} + */ + getType(fieldFormatId) { + return this.fieldFormats.get(fieldFormatId); + } + + register(FieldFormat) { + this.fieldFormats.set(FieldFormat.id, FieldFormat); + } +} diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/boolean.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/color.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/color.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/color.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/color.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/date.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/date.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/date.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/date.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/duration.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/duration.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/ip.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/ip.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/string.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/string.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/string.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/truncate.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js diff --git a/src/core_plugins/kibana/common/field_format/types/__tests__/url.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/url.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/__tests__/url.js rename to src/core_plugins/kibana/common/field_formats/types/__tests__/url.js diff --git a/src/core_plugins/kibana/common/field_format/types/_numeral.js b/src/core_plugins/kibana/common/field_formats/types/_numeral.js similarity index 96% rename from src/core_plugins/kibana/common/field_format/types/_numeral.js rename to src/core_plugins/kibana/common/field_formats/types/_numeral.js index 0c6ea362ab9de..fa0c1abd4a961 100644 --- a/src/core_plugins/kibana/common/field_format/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_formats/types/_numeral.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import numeral from 'numeral'; +import numeral from '@spalger/numeral'; import { FieldFormat } from '../field_format'; const numeralInst = numeral(); diff --git a/src/core_plugins/kibana/common/field_format/types/_source.html b/src/core_plugins/kibana/common/field_formats/types/_source.html similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/_source.html rename to src/core_plugins/kibana/common/field_formats/types/_source.html diff --git a/src/core_plugins/kibana/common/field_format/types/boolean.js b/src/core_plugins/kibana/common/field_formats/types/boolean.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/boolean.js rename to src/core_plugins/kibana/common/field_formats/types/boolean.js diff --git a/src/core_plugins/kibana/common/field_format/types/bytes.js b/src/core_plugins/kibana/common/field_formats/types/bytes.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/bytes.js rename to src/core_plugins/kibana/common/field_formats/types/bytes.js diff --git a/src/core_plugins/kibana/common/field_format/types/color.js b/src/core_plugins/kibana/common/field_formats/types/color.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/color.js rename to src/core_plugins/kibana/common/field_formats/types/color.js diff --git a/src/core_plugins/kibana/common/field_format/types/color_default.js b/src/core_plugins/kibana/common/field_formats/types/color_default.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/color_default.js rename to src/core_plugins/kibana/common/field_formats/types/color_default.js diff --git a/src/core_plugins/kibana/common/field_format/types/date.js b/src/core_plugins/kibana/common/field_formats/types/date.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/date.js rename to src/core_plugins/kibana/common/field_formats/types/date.js diff --git a/src/core_plugins/kibana/common/field_format/types/duration.js b/src/core_plugins/kibana/common/field_formats/types/duration.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/duration.js rename to src/core_plugins/kibana/common/field_formats/types/duration.js diff --git a/src/core_plugins/kibana/common/field_format/types/ip.js b/src/core_plugins/kibana/common/field_formats/types/ip.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/ip.js rename to src/core_plugins/kibana/common/field_formats/types/ip.js diff --git a/src/core_plugins/kibana/common/field_format/types/number.js b/src/core_plugins/kibana/common/field_formats/types/number.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/number.js rename to src/core_plugins/kibana/common/field_formats/types/number.js diff --git a/src/core_plugins/kibana/common/field_format/types/percent.js b/src/core_plugins/kibana/common/field_formats/types/percent.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/percent.js rename to src/core_plugins/kibana/common/field_formats/types/percent.js diff --git a/src/core_plugins/kibana/common/field_format/types/source.js b/src/core_plugins/kibana/common/field_formats/types/source.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/source.js rename to src/core_plugins/kibana/common/field_formats/types/source.js diff --git a/src/core_plugins/kibana/common/field_format/types/string.js b/src/core_plugins/kibana/common/field_formats/types/string.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/string.js rename to src/core_plugins/kibana/common/field_formats/types/string.js diff --git a/src/core_plugins/kibana/common/field_format/types/truncate.js b/src/core_plugins/kibana/common/field_formats/types/truncate.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/truncate.js rename to src/core_plugins/kibana/common/field_formats/types/truncate.js diff --git a/src/core_plugins/kibana/common/field_format/types/url.js b/src/core_plugins/kibana/common/field_formats/types/url.js similarity index 100% rename from src/core_plugins/kibana/common/field_format/types/url.js rename to src/core_plugins/kibana/common/field_formats/types/url.js diff --git a/src/core_plugins/kibana/index.js b/src/core_plugins/kibana/index.js index 5320cb084deae..aa991d09e874d 100644 --- a/src/core_plugins/kibana/index.js +++ b/src/core_plugins/kibana/index.js @@ -10,6 +10,7 @@ import { importApi } from './server/routes/api/import'; import { exportApi } from './server/routes/api/export'; import scripts from './server/routes/api/scripts'; import { registerSuggestionsApi } from './server/routes/api/suggestions'; +import { registerFieldFormats } from './server/register_field_formats'; import * as systemApi from './server/lib/system_api'; import handleEsError from './server/lib/handle_es_error'; import mappings from './mappings.json'; @@ -33,6 +34,7 @@ export default function (kibana) { uiExports: { hacks: ['plugins/kibana/dev_tools/hacks/hide_empty_tools'], + fieldFormats: ['plugins/kibana/field_formats/register'], app: { id: 'kibana', title: 'Kibana', @@ -135,10 +137,12 @@ export default function (kibana) { importApi(server); exportApi(server); registerSuggestionsApi(server); + registerFieldFormats(server); server.expose('systemApi', systemApi); server.expose('handleEsError', handleEsError); server.expose('injectVars', injectVars); + } }); } diff --git a/src/ui/public/field_format/__tests__/_boolean.js b/src/core_plugins/kibana/public/field_formats/__tests__/_boolean.js similarity index 100% rename from src/ui/public/field_format/__tests__/_boolean.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_boolean.js diff --git a/src/ui/public/field_format/__tests__/_color.js b/src/core_plugins/kibana/public/field_formats/__tests__/_color.js similarity index 100% rename from src/ui/public/field_format/__tests__/_color.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_color.js diff --git a/src/ui/public/field_format/__tests__/_conformance.js b/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js similarity index 97% rename from src/ui/public/field_format/__tests__/_conformance.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js index 4ee3e73f80ad0..2488edf2e105d 100644 --- a/src/ui/public/field_format/__tests__/_conformance.js +++ b/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import expect from 'expect.js'; import ngMock from 'ng_mock'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { FieldFormat } from '../../../../core_plugins/kibana/common/field_format/field_format'; +import { FieldFormat } from '../../../common/field_formats/field_format'; let fieldFormats; let config; diff --git a/src/ui/public/field_format/__tests__/_date.js b/src/core_plugins/kibana/public/field_formats/__tests__/_date.js similarity index 100% rename from src/ui/public/field_format/__tests__/_date.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_date.js diff --git a/src/ui/public/field_format/__tests__/_duration.js b/src/core_plugins/kibana/public/field_formats/__tests__/_duration.js similarity index 100% rename from src/ui/public/field_format/__tests__/_duration.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_duration.js diff --git a/src/ui/public/field_format/__tests__/_ip.js b/src/core_plugins/kibana/public/field_formats/__tests__/_ip.js similarity index 100% rename from src/ui/public/field_format/__tests__/_ip.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_ip.js diff --git a/src/ui/public/field_format/__tests__/_source.js b/src/core_plugins/kibana/public/field_formats/__tests__/_source.js similarity index 100% rename from src/ui/public/field_format/__tests__/_source.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_source.js diff --git a/src/ui/public/field_format/__tests__/_string.js b/src/core_plugins/kibana/public/field_formats/__tests__/_string.js similarity index 100% rename from src/ui/public/field_format/__tests__/_string.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_string.js diff --git a/src/ui/public/field_format/__tests__/_truncate.js b/src/core_plugins/kibana/public/field_formats/__tests__/_truncate.js similarity index 100% rename from src/ui/public/field_format/__tests__/_truncate.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_truncate.js diff --git a/src/ui/public/field_format/__tests__/_url.js b/src/core_plugins/kibana/public/field_formats/__tests__/_url.js similarity index 100% rename from src/ui/public/field_format/__tests__/_url.js rename to src/core_plugins/kibana/public/field_formats/__tests__/_url.js diff --git a/src/ui/public/field_format/__tests__/index.js b/src/core_plugins/kibana/public/field_formats/__tests__/index.js similarity index 100% rename from src/ui/public/field_format/__tests__/index.js rename to src/core_plugins/kibana/public/field_formats/__tests__/index.js diff --git a/src/core_plugins/kibana/public/field_formats/register.js b/src/core_plugins/kibana/public/field_formats/register.js new file mode 100644 index 0000000000000..6a0b6b9fb1e36 --- /dev/null +++ b/src/core_plugins/kibana/public/field_formats/register.js @@ -0,0 +1,26 @@ +import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; +import { stringifyUrl } from '../../common/field_formats/types/url'; +import { stringifyBytes } from '../../common/field_formats/types/bytes'; +import { stringifyDate } from '../../common/field_formats/types/date'; +import { stringifyDuration } from '../../common/field_formats/types/duration'; +import { stringifyIp } from '../../common/field_formats/types/ip'; +import { stringifyNumber } from '../../common/field_formats/types/number'; +import { stringifyPercent } from '../../common/field_formats/types/percent'; +import { stringifyString } from '../../common/field_formats/types/string'; +import { stringifySource } from '../../common/field_formats/types/source'; +import { stringifyColor } from '../../common/field_formats/types/color'; +import { stringifyTruncate } from '../../common/field_formats/types/truncate'; +import { stringifyBoolean } from '../../common/field_formats/types/boolean'; + +RegistryFieldFormatsProvider.register(stringifyUrl); +RegistryFieldFormatsProvider.register(stringifyBytes); +RegistryFieldFormatsProvider.register(stringifyDate); +RegistryFieldFormatsProvider.register(stringifyDuration); +RegistryFieldFormatsProvider.register(stringifyIp); +RegistryFieldFormatsProvider.register(stringifyNumber); +RegistryFieldFormatsProvider.register(stringifyPercent); +RegistryFieldFormatsProvider.register(stringifyString); +RegistryFieldFormatsProvider.register(stringifySource); +RegistryFieldFormatsProvider.register(stringifyColor); +RegistryFieldFormatsProvider.register(stringifyTruncate); +RegistryFieldFormatsProvider.register(stringifyBoolean); diff --git a/src/core_plugins/kibana/server/register_field_formats.js b/src/core_plugins/kibana/server/register_field_formats.js new file mode 100644 index 0000000000000..c326b846c19af --- /dev/null +++ b/src/core_plugins/kibana/server/register_field_formats.js @@ -0,0 +1,27 @@ +import { stringifyUrl } from '../common/field_formats/types/url'; +import { stringifyBytes } from '../common/field_formats/types/bytes'; +import { stringifyDate } from '../common/field_formats/types/date'; +import { stringifyDuration } from '../common/field_formats/types/duration'; +import { stringifyIp } from '../common/field_formats/types/ip'; +import { stringifyNumber } from '../common/field_formats/types/number'; +import { stringifyPercent } from '../common/field_formats/types/percent'; +import { stringifyString } from '../common/field_formats/types/string'; +//import { stringifySource } from '../common/field_formats/types/source'; +import { stringifyColor } from '../common/field_formats/types/color'; +import { stringifyTruncate } from '../common/field_formats/types/truncate'; +import { stringifyBoolean } from '../common/field_formats/types/boolean'; + +export function registerFieldFormats(server) { + server.fieldFormats.register(stringifyUrl()); + server.fieldFormats.register(stringifyBytes()); + server.fieldFormats.register(stringifyDate()); + server.fieldFormats.register(stringifyDuration()); + server.fieldFormats.register(stringifyIp()); + server.fieldFormats.register(stringifyNumber()); + server.fieldFormats.register(stringifyPercent()); + server.fieldFormats.register(stringifyString()); + //server.fieldFormats.register(stringifySource()); + server.fieldFormats.register(stringifyColor()); + server.fieldFormats.register(stringifyTruncate()); + server.fieldFormats.register(stringifyBoolean()); +} diff --git a/src/ui/field_formats_mixin.js b/src/ui/field_formats_mixin.js new file mode 100644 index 0000000000000..cea4c28fe8f5e --- /dev/null +++ b/src/ui/field_formats_mixin.js @@ -0,0 +1,5 @@ +import { FieldFormatsService } from '../core_plugins/kibana/common/field_formats/field_formats'; + +export function fieldFormatsMixin(kbnServer, server) { + server.decorate('server', 'fieldFormats', new FieldFormatsService); +} diff --git a/src/ui/index.js b/src/ui/index.js index 1a978dc86f291..aa8517c9e7d0f 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -10,6 +10,7 @@ import UiBundlerEnv from './ui_bundler_env'; import { UiI18n } from './ui_i18n'; import { uiSettingsMixin } from './ui_settings'; +import { fieldFormatsMixin } from './field_formats_mixin'; export default async (kbnServer, server, config) => { const uiExports = kbnServer.uiExports = new UiExports({ @@ -18,6 +19,8 @@ export default async (kbnServer, server, config) => { await kbnServer.mixin(uiSettingsMixin); + await kbnServer.mixin(fieldFormatsMixin); + const uiI18n = kbnServer.uiI18n = new UiI18n(config.get('i18n.defaultLocale')); uiI18n.addUiExportConsumer(uiExports); diff --git a/src/ui/public/agg_types/buckets/range.js b/src/ui/public/agg_types/buckets/range.js index 2a9ea4741947e..8dd5d64ace8db 100644 --- a/src/ui/public/agg_types/buckets/range.js +++ b/src/ui/public/agg_types/buckets/range.js @@ -1,6 +1,6 @@ import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type'; import { AggTypesBucketsCreateFilterRangeProvider } from 'ui/agg_types/buckets/create_filter/range'; -import { FieldFormat } from '../../../../core_plugins/kibana/common/field_format/field_format'; +import { FieldFormat } from '../../../../core_plugins/kibana/common/field_formats/field_format'; import { RangeKeyProvider } from './range_key'; import rangesTemplate from 'ui/agg_types/controls/ranges.html'; diff --git a/src/ui/public/field_format/register.js b/src/ui/public/field_format/register.js deleted file mode 100644 index 56e800472efd9..0000000000000 --- a/src/ui/public/field_format/register.js +++ /dev/null @@ -1,26 +0,0 @@ -import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { stringifyUrl } from '../../../core_plugins/kibana/common/field_format/types/url'; -import { stringifyBytes } from '../../../core_plugins/kibana/common/field_format/types/bytes'; -import { stringifyDate } from '../../../core_plugins/kibana/common/field_format/types/date'; -import { stringifyDuration } from '../../../core_plugins/kibana/common/field_format/types/duration'; -import { stringifyIp } from '../../../core_plugins/kibana/common/field_format/types/ip'; -import { stringifyNumber } from '../../../core_plugins/kibana/common/field_format/types/number'; -import { stringifyPercent } from '../../../core_plugins/kibana/common/field_format/types/percent'; -import { stringifyString } from '../../../core_plugins/kibana/common/field_format/types/string'; -import { stringifySource } from '../../../core_plugins/kibana/common/field_format/types/source'; -import { stringifyColor } from '../../../core_plugins/kibana/common/field_format/types/color'; -import { stringifyTruncate } from '../../../core_plugins/kibana/common/field_format/types/truncate'; -import { stringifyBoolean } from '../../../core_plugins/kibana/common/field_format/types/boolean'; - -RegistryFieldFormatsProvider.register(stringifyUrl); -RegistryFieldFormatsProvider.register(stringifyBytes); -RegistryFieldFormatsProvider.register(stringifyDate); -RegistryFieldFormatsProvider.register(stringifyDuration); -RegistryFieldFormatsProvider.register(stringifyIp); -RegistryFieldFormatsProvider.register(stringifyNumber); -RegistryFieldFormatsProvider.register(stringifyPercent); -RegistryFieldFormatsProvider.register(stringifyString); -RegistryFieldFormatsProvider.register(stringifySource); -RegistryFieldFormatsProvider.register(stringifyColor); -RegistryFieldFormatsProvider.register(stringifyTruncate); -RegistryFieldFormatsProvider.register(stringifyBoolean); diff --git a/src/ui/public/field_format_editor/editors/color/color.js b/src/ui/public/field_format_editor/editors/color/color.js index 6d08817e4c461..edccaf21cf3ef 100644 --- a/src/ui/public/field_format_editor/editors/color/color.js +++ b/src/ui/public/field_format_editor/editors/color/color.js @@ -1,6 +1,6 @@ import './color.less'; import colorTemplate from './color.html'; -import { DEFAULT_COLOR } from '../../../../../core_plugins/kibana/common/field_format/types/color_default'; +import { DEFAULT_COLOR } from '../../../../../core_plugins/kibana/common/field_formats/types/color_default'; export function colorEditor() { return { diff --git a/src/ui/public/index_patterns/_field.js b/src/ui/public/index_patterns/_field.js index 8401621161926..b0282ca87d8ce 100644 --- a/src/ui/public/index_patterns/_field.js +++ b/src/ui/public/index_patterns/_field.js @@ -1,5 +1,5 @@ import { ObjDefine } from 'ui/utils/obj_define'; -import { FieldFormat } from '../../../core_plugins/kibana/common/field_format/field_format'; +import { FieldFormat } from '../../../core_plugins/kibana/common/field_formats/field_format'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; import { getKbnFieldType } from '../../../utils'; diff --git a/src/ui/ui_exports.js b/src/ui/ui_exports.js index 5c0e6a9b2907a..3808037de9711 100644 --- a/src/ui/ui_exports.js +++ b/src/ui/ui_exports.js @@ -10,7 +10,6 @@ export default class UiExports { this.navLinks = new UiNavLinkCollection(this); this.apps = new UiAppCollection(this); this.aliases = { - fieldFormats: ['ui/field_format/register'], fieldFormatEditors: ['ui/field_format_editor/register'] }; this.urlBasePath = urlBasePath; From d27ed542dcc255b01acfe9683e97e6e07caab815 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 30 Jun 2017 11:53:57 -0600 Subject: [PATCH 03/15] export Format class from field_formats/types --- .../field_formats/types/__tests__/boolean.js | 3 +- .../field_formats/types/__tests__/bytes.js | 20 ++ .../field_formats/types/__tests__/color.js | 7 +- .../field_formats/types/__tests__/date.js | 3 +- .../field_formats/types/__tests__/duration.js | 7 +- .../field_formats/types/__tests__/ip.js | 3 +- .../field_formats/types/__tests__/number.js | 20 ++ .../field_formats/types/__tests__/percent.js | 20 ++ .../field_formats/types/__tests__/string.js | 8 +- .../field_formats/types/__tests__/truncate.js | 17 +- .../field_formats/types/__tests__/url.js | 32 ++- .../common/field_formats/types/_numeral.js | 4 +- .../common/field_formats/types/_source.html | 7 - .../common/field_formats/types/boolean.js | 48 ++--- .../common/field_formats/types/bytes.js | 10 +- .../common/field_formats/types/color.js | 91 ++++----- .../kibana/common/field_formats/types/date.js | 83 ++++---- .../common/field_formats/types/duration.js | 132 ++++++------ .../kibana/common/field_formats/types/ip.js | 23 +-- .../common/field_formats/types/number.js | 10 +- .../common/field_formats/types/percent.js | 32 ++- .../common/field_formats/types/source.js | 76 +++---- .../common/field_formats/types/string.js | 81 ++++---- .../common/field_formats/types/truncate.js | 30 ++- .../kibana/common/field_formats/types/url.js | 193 +++++++++--------- .../kibana/public/field_formats/register.js | 48 ++--- .../kibana/server/register_field_formats.js | 48 ++--- .../public/index_patterns/__tests__/index.js | 1 - 28 files changed, 519 insertions(+), 538 deletions(-) create mode 100644 src/core_plugins/kibana/common/field_formats/types/__tests__/bytes.js create mode 100644 src/core_plugins/kibana/common/field_formats/types/__tests__/number.js create mode 100644 src/core_plugins/kibana/common/field_formats/types/__tests__/percent.js delete mode 100644 src/core_plugins/kibana/common/field_formats/types/_source.html diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js index 0d8a1810160dd..1cab26a836b17 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/boolean.js @@ -1,11 +1,10 @@ import expect from 'expect.js'; -import { stringifyBoolean } from '../boolean'; +import { BoolFormat } from '../boolean'; describe('Boolean Format', function () { let boolean; beforeEach(() => { - const BoolFormat = stringifyBoolean(); boolean = new BoolFormat(); }); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/bytes.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/bytes.js new file mode 100644 index 0000000000000..d742d56c7c3f6 --- /dev/null +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/bytes.js @@ -0,0 +1,20 @@ +import expect from 'expect.js'; +import { BytesFormat } from '../bytes'; + +describe('BytesFormat', function () { + + const config = {}; + config['format:bytes:defaultPattern'] = '0,0.[000]b'; + const getConfig = (key) => config[key]; + + it('default pattern', ()=> { + const formatter = new BytesFormat({}, getConfig); + expect(formatter.convert(5150000)).to.be('4.911MB'); + }); + + it('custom pattern', ()=> { + const formatter = new BytesFormat({ pattern: '0,0b' }, getConfig); + expect(formatter.convert('5150000')).to.be('5MB'); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/color.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/color.js index 6db886fcf7bd8..139fc0f8e4089 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/color.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/color.js @@ -1,12 +1,7 @@ import expect from 'expect.js'; -import { stringifyColor } from '../color'; +import { ColorFormat } from '../color'; describe('Color Format', function () { - let ColorFormat; - - beforeEach(() => { - ColorFormat = stringifyColor(); - }); describe('field is a number', () => { it('should add colors if the value is in range', function () { diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/date.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/date.js index 1d3acf98d4c4f..cd11f12a85200 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/date.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/date.js @@ -1,6 +1,6 @@ import expect from 'expect.js'; import moment from 'moment-timezone'; -import { stringifyDate } from '../date'; +import { DateFormat } from '../date'; describe('Date Format', function () { let convert; @@ -12,7 +12,6 @@ describe('Date Format', function () { mockConfig['dateFormat:tz'] = 'Browser'; const getConfig = (key) => mockConfig[key]; - const DateFormat = stringifyDate(); const date = new DateFormat({}, getConfig); convert = date.convert.bind(date); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js index 622d4b18e9ad2..e3adb9b3f5af7 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js @@ -1,12 +1,7 @@ import expect from 'expect.js'; -import { stringifyDuration } from '../duration'; +import { DurationFormat } from '../duration'; describe('Duration Format', function () { - let DurationFormat; - - beforeEach(function () { - DurationFormat = stringifyDuration(); - }); test({ inputFormat: 'seconds', outputFormat: 'humanize' }) (-60, 'minus a minute') diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js index 0eaf0ff126c09..2c4ae3f8fdddb 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/ip.js @@ -1,10 +1,9 @@ import expect from 'expect.js'; -import { stringifyIp } from '../ip'; +import { IpFormat } from '../ip'; describe('IP Address Format', function () { let ip; beforeEach(function () { - const IpFormat = stringifyIp(); ip = new IpFormat(); }); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/number.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/number.js new file mode 100644 index 0000000000000..7d070b401be7c --- /dev/null +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/number.js @@ -0,0 +1,20 @@ +import expect from 'expect.js'; +import { NumberFormat } from '../number'; + +describe('NumberFormat', function () { + + const config = {}; + config['format:number:defaultPattern'] = '0,0.[000]'; + const getConfig = (key) => config[key]; + + it('default pattern', ()=> { + const formatter = new NumberFormat({}, getConfig); + expect(formatter.convert(12.345678)).to.be('12.346'); + }); + + it('custom pattern', ()=> { + const formatter = new NumberFormat({ pattern: '0,0' }, getConfig); + expect(formatter.convert('12.345678')).to.be('12'); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/percent.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/percent.js new file mode 100644 index 0000000000000..111bf636fc13d --- /dev/null +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/percent.js @@ -0,0 +1,20 @@ +import expect from 'expect.js'; +import { PercentFormat } from '../percent'; + +describe('PercentFormat', function () { + + const config = {}; + config['format:percent:defaultPattern'] = '0,0.[000]%'; + const getConfig = (key) => config[key]; + + it('default pattern', ()=> { + const formatter = new PercentFormat({}, getConfig); + expect(formatter.convert(0.99999)).to.be('99.999%'); + }); + + it('custom pattern', ()=> { + const formatter = new PercentFormat({ pattern: '0,0%' }, getConfig); + expect(formatter.convert('0.99999')).to.be('100%'); + }); + +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js index 694f4792fa9da..ff149e386e264 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js @@ -1,14 +1,8 @@ import expect from 'expect.js'; -import { stringifyString } from '../string'; +import { StringFormat } from '../string'; describe('String Format', function () { - let StringFormat; - - beforeEach(function () { - StringFormat = stringifyString(); - }); - it('convert a string to lower case', function () { const string = new StringFormat({ transform: 'lower' diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js index cbec58d90dc44..4c37b916698fd 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/truncate.js @@ -1,33 +1,28 @@ import expect from 'expect.js'; -import { stringifyTruncate } from '../truncate'; +import { TruncateFormat } from '../truncate'; -describe('String Truncate Format', function () { - let Truncate; - - beforeEach(function () { - Truncate = stringifyTruncate(); - }); +describe('String TruncateFormat', function () { it('truncate large string', function () { - const truncate = new Truncate({ fieldLength: 4 }); + const truncate = new TruncateFormat({ fieldLength: 4 }); expect(truncate.convert('This is some text')).to.be('This...'); }); it('does not truncate large string when field length is not a string', function () { - const truncate = new Truncate({ fieldLength: 'not number' }); + const truncate = new TruncateFormat({ fieldLength: 'not number' }); expect(truncate.convert('This is some text')).to.be('This is some text'); }); it('does not truncate large string when field length is null', function () { - const truncate = new Truncate({ fieldLength: null }); + const truncate = new TruncateFormat({ fieldLength: null }); expect(truncate.convert('This is some text')).to.be('This is some text'); }); it('does not truncate large string when field length larger than the text', function () { - const truncate = new Truncate({ fieldLength: 100000 }); + const truncate = new TruncateFormat({ fieldLength: 100000 }); expect(truncate.convert('This is some text')).to.be('This is some text'); }); diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/url.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/url.js index 7335dfdcd0489..86d07c02ef2ef 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/url.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/url.js @@ -1,23 +1,17 @@ import expect from 'expect.js'; -import { stringifyUrl } from '../url'; +import { UrlFormat } from '../url'; -describe('Url Format', function () { - - let Url; - - beforeEach(function () { - Url = stringifyUrl(); - }); +describe('UrlFormat', function () { it('ouputs a simple tab by default', function () { - const url = new Url(); + const url = new UrlFormat(); expect(url.convert('http://elastic.co', 'html')) .to.be('http://elastic.co'); }); it('outputs an if type === "img"', function () { - const url = new Url({ type: 'img' }); + const url = new UrlFormat({ type: 'img' }); expect(url.convert('http://elastic.co', 'html')) .to.be('A dynamically-specified image located at http://elastic.co'); @@ -25,38 +19,38 @@ describe('Url Format', function () { describe('url template', function () { it('accepts a template', function () { - const url = new Url({ urlTemplate: 'url: {{ value }}' }); + const url = new UrlFormat({ urlTemplate: 'url: {{ value }}' }); expect(url.convert('url', 'html')) .to.be('url: url'); }); it('only outputs the url if the contentType === "text"', function () { - const url = new Url(); + const url = new UrlFormat(); expect(url.convert('url', 'text')).to.be('url'); }); }); describe('label template', function () { it('accepts a template', function () { - const url = new Url({ labelTemplate: 'extension: {{ value }}' }); + const url = new UrlFormat({ labelTemplate: 'extension: {{ value }}' }); expect(url.convert('php', 'html')) .to.be('extension: php'); }); it('uses the label template for text formating', function () { - const url = new Url({ labelTemplate: 'external {{value }}' }); + const url = new UrlFormat({ labelTemplate: 'external {{value }}' }); expect(url.convert('url', 'text')).to.be('external url'); }); it('can use the raw value', function () { - const url = new Url({ + const url = new UrlFormat({ labelTemplate: 'external {{value}}' }); expect(url.convert('url?', 'text')).to.be('external url?'); }); it('can use the url', function () { - const url = new Url({ + const url = new UrlFormat({ urlTemplate: 'http://google.com/{{value}}', labelTemplate: 'external {{url}}' }); @@ -66,18 +60,18 @@ describe('Url Format', function () { describe('templating', function () { it('ignores unknown variables', function () { - const url = new Url({ urlTemplate: '{{ not really a var }}' }); + const url = new UrlFormat({ urlTemplate: '{{ not really a var }}' }); expect(url.convert('url', 'text')).to.be(''); }); it('does not allow executing code in variable expressions', function () { - const url = new Url({ urlTemplate: '{{ (__dirname = true) && value }}' }); + const url = new UrlFormat({ urlTemplate: '{{ (__dirname = true) && value }}' }); expect(url.convert('url', 'text')).to.be(''); }); describe('', function () { it('does not get values from the prototype chain', function () { - const url = new Url({ urlTemplate: '{{ toString }}' }); + const url = new UrlFormat({ urlTemplate: '{{ toString }}' }); expect(url.convert('url', 'text')).to.be(''); }); }); diff --git a/src/core_plugins/kibana/common/field_formats/types/_numeral.js b/src/core_plugins/kibana/common/field_formats/types/_numeral.js index fa0c1abd4a961..086daf15b0921 100644 --- a/src/core_plugins/kibana/common/field_formats/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_formats/types/_numeral.js @@ -14,7 +14,9 @@ export class Numeral extends FieldFormat { if (isNaN(val)) return ''; - return numeralInst.set(val).format(this.param('pattern')); + const formatted = numeralInst.set(val).format(this.param('pattern')); + + return formatted; } static factory(opts) { diff --git a/src/core_plugins/kibana/common/field_formats/types/_source.html b/src/core_plugins/kibana/common/field_formats/types/_source.html deleted file mode 100644 index 8cebbbe5ac3ee..0000000000000 --- a/src/core_plugins/kibana/common/field_formats/types/_source.html +++ /dev/null @@ -1,7 +0,0 @@ -
- <% defPairs.forEach(function (def) { %> -
<%- def[0] %>:
-
<%= def[1] %>
- <%= ' ' %> - <% }); %> -
diff --git a/src/core_plugins/kibana/common/field_formats/types/boolean.js b/src/core_plugins/kibana/common/field_formats/types/boolean.js index 4b9a6ffaa9e31..2a27e00326967 100644 --- a/src/core_plugins/kibana/common/field_formats/types/boolean.js +++ b/src/core_plugins/kibana/common/field_formats/types/boolean.js @@ -1,35 +1,29 @@ import { asPrettyString } from '../../utils/as_pretty_string'; import { FieldFormat } from '../field_format'; -export function stringifyBoolean() { - - class Bool extends FieldFormat { - - _convert(value) { - if (typeof value === 'string') { - value = value.trim().toLowerCase(); - } - - switch (value) { - case false: - case 0: - case 'false': - case 'no': - return 'false'; - case true: - case 1: - case 'true': - case 'yes': - return 'true'; - default: - return asPrettyString(value); - } +export class BoolFormat extends FieldFormat { + _convert(value) { + if (typeof value === 'string') { + value = value.trim().toLowerCase(); } - static id = 'boolean'; - static title = 'Boolean'; - static fieldType = ['boolean', 'number', 'string']; + switch (value) { + case false: + case 0: + case 'false': + case 'no': + return 'false'; + case true: + case 1: + case 'true': + case 'yes': + return 'true'; + default: + return asPrettyString(value); + } } - return Bool; + static id = 'boolean'; + static title = 'Boolean'; + static fieldType = ['boolean', 'number', 'string']; } diff --git a/src/core_plugins/kibana/common/field_formats/types/bytes.js b/src/core_plugins/kibana/common/field_formats/types/bytes.js index 46fbe2e8196e9..8091a5e2c643c 100644 --- a/src/core_plugins/kibana/common/field_formats/types/bytes.js +++ b/src/core_plugins/kibana/common/field_formats/types/bytes.js @@ -1,8 +1,6 @@ import { Numeral } from './_numeral'; -export function stringifyBytes() { - return Numeral.factory({ - id: 'bytes', - title: 'Bytes' - }); -} +export const BytesFormat = Numeral.factory({ + id: 'bytes', + title: 'Bytes' +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/color.js b/src/core_plugins/kibana/common/field_formats/types/color.js index d83a75f803e1a..bdfc5c0f507d0 100644 --- a/src/core_plugins/kibana/common/field_formats/types/color.js +++ b/src/core_plugins/kibana/common/field_formats/types/color.js @@ -3,58 +3,51 @@ import { asPrettyString } from '../../utils/as_pretty_string'; import { DEFAULT_COLOR } from './color_default'; import { FieldFormat } from '../field_format'; -export function stringifyColor() { - - const convertTemplate = _.template('<%- val %>'); - - class ColorFormat extends FieldFormat { - getParamDefaults() { - return { - fieldType: null, // populated by editor, see controller below - colors: [_.cloneDeep(DEFAULT_COLOR)] - }; - } +const convertTemplate = _.template('<%- val %>'); + +export class ColorFormat extends FieldFormat { + getParamDefaults() { + return { + fieldType: null, // populated by editor, see controller below + colors: [_.cloneDeep(DEFAULT_COLOR)] + }; + } - findColorRuleForVal(val) { - switch (this.param('fieldType')) { - case 'string': - return _.findLast(this.param('colors'), (colorParam) => { - return new RegExp(colorParam.regex).test(val); - }); - - case 'number': - return _.findLast(this.param('colors'), ({ range }) => { - if (!range) return; - const [start, end] = range.split(':'); - return val >= Number(start) && val <= Number(end); - }); - - default: - return null; - } + findColorRuleForVal(val) { + switch (this.param('fieldType')) { + case 'string': + return _.findLast(this.param('colors'), (colorParam) => { + return new RegExp(colorParam.regex).test(val); + }); + + case 'number': + return _.findLast(this.param('colors'), ({ range }) => { + if (!range) return; + const [start, end] = range.split(':'); + return val >= Number(start) && val <= Number(end); + }); + + default: + return null; } - - static id = 'color'; - static title = 'Color'; - static fieldType = [ - 'number', - 'string' - ]; } + static id = 'color'; + static title = 'Color'; + static fieldType = [ + 'number', + 'string' + ]; +} +ColorFormat.prototype._convert = { + html(val) { + const color = this.findColorRuleForVal(val); + if (!color) return asPrettyString(val); - ColorFormat.prototype._convert = { - html(val) { - const color = this.findColorRuleForVal(val); - if (!color) return asPrettyString(val); - - let style = ''; - if (color.text) style += `color: ${color.text};`; - if (color.background) style += `background-color: ${color.background};`; - return convertTemplate({ val, style }); - } - }; - - return ColorFormat; -} + let style = ''; + if (color.text) style += `color: ${color.text};`; + if (color.background) style += `background-color: ${color.background};`; + return convertTemplate({ val, style }); + } +}; diff --git a/src/core_plugins/kibana/common/field_formats/types/date.js b/src/core_plugins/kibana/common/field_formats/types/date.js index 80d2cbc7f9e33..455c8002b8337 100644 --- a/src/core_plugins/kibana/common/field_formats/types/date.js +++ b/src/core_plugins/kibana/common/field_formats/types/date.js @@ -2,55 +2,50 @@ import _ from 'lodash'; import moment from 'moment'; import { FieldFormat } from '../field_format'; -export function stringifyDate() { +export class DateFormat extends FieldFormat { + constructor(params, getConfig) { + super(params); - class DateFormat extends FieldFormat { - constructor(params, getConfig) { - super(params); - - this.getConfig = getConfig; - } + this.getConfig = getConfig; + } - getParamDefaults() { - return { - pattern: this.getConfig('dateFormat'), - timezone: this.getConfig('dateFormat:tz') - }; - } + getParamDefaults() { + return { + pattern: this.getConfig('dateFormat'), + timezone: this.getConfig('dateFormat:tz') + }; + } - _convert(val) { - // don't give away our ref to converter so - // we can hot-swap when config changes - const pattern = this.param('pattern'); - const timezone = this.param('timezone'); - - const timezoneChanged = this._timeZone !== timezone; - const datePatternChanged = this._memoizedPattern !== pattern; - if (timezoneChanged || datePatternChanged) { - this._timeZone = timezone; - this._memoizedPattern = pattern; - - this._memoizedConverter = _.memoize(function converter(val) { - if (val === null || val === undefined) { - return '-'; - } - - const date = moment(val); - if (date.isValid()) { - return date.format(pattern); - } else { - return val; - } - }); - } - - return this._memoizedConverter(val); + _convert(val) { + // don't give away our ref to converter so + // we can hot-swap when config changes + const pattern = this.param('pattern'); + const timezone = this.param('timezone'); + + const timezoneChanged = this._timeZone !== timezone; + const datePatternChanged = this._memoizedPattern !== pattern; + if (timezoneChanged || datePatternChanged) { + this._timeZone = timezone; + this._memoizedPattern = pattern; + + this._memoizedConverter = _.memoize(function converter(val) { + if (val === null || val === undefined) { + return '-'; + } + + const date = moment(val); + if (date.isValid()) { + return date.format(pattern); + } else { + return val; + } + }); } - static id = 'date'; - static title = 'Date'; - static fieldType = 'date'; + return this._memoizedConverter(val); } - return DateFormat; + static id = 'date'; + static title = 'Date'; + static fieldType = 'date'; } diff --git a/src/core_plugins/kibana/common/field_formats/types/duration.js b/src/core_plugins/kibana/common/field_formats/types/duration.js index 7b45ce07eaea1..834f6ed49cb11 100644 --- a/src/core_plugins/kibana/common/field_formats/types/duration.js +++ b/src/core_plugins/kibana/common/field_formats/types/duration.js @@ -1,78 +1,74 @@ import moment from 'moment'; import { FieldFormat } from '../field_format'; -export function stringifyDuration() { - const ratioToSeconds = { - picoseconds: 0.000000000001, - nanoseconds: 0.000000001, - microseconds: 0.000001 - }; - const HUMAN_FRIENDLY = 'humanize'; - const DEFAULT_OUTPUT_PRECISION = 2; - const DEFAULT_INPUT_FORMAT = { text: 'Seconds', kind: 'seconds' }; - const inputFormats = [ - { text: 'Picoseconds', kind: 'picoseconds' }, - { text: 'Nanoseconds', kind: 'nanoseconds' }, - { text: 'Microseconds', kind: 'microseconds' }, - { text: 'Milliseconds', kind: 'milliseconds' }, - DEFAULT_INPUT_FORMAT, - { text: 'Minutes', kind: 'minutes' }, - { text: 'Hours', kind: 'hours' }, - { text: 'Days', kind: 'days' }, - { text: 'Weeks', kind: 'weeks' }, - { text: 'Months', kind: 'months' }, - { text: 'Years', kind: 'years' } - ]; - const DEFAULT_OUTPUT_FORMAT = { text: 'Human Readable', method: 'humanize' }; - const outputFormats = [ - DEFAULT_OUTPUT_FORMAT, - { text: 'Milliseconds', method: 'asMilliseconds' }, - { text: 'Seconds', method: 'asSeconds' }, - { text: 'Minutes', method: 'asMinutes' }, - { text: 'Hours', method: 'asHours' }, - { text: 'Days', method: 'asDays' }, - { text: 'Weeks', method: 'asWeeks' }, - { text: 'Months', method: 'asMonths' }, - { text: 'Years', method: 'asYears' } - ]; +const ratioToSeconds = { + picoseconds: 0.000000000001, + nanoseconds: 0.000000001, + microseconds: 0.000001 +}; +const HUMAN_FRIENDLY = 'humanize'; +const DEFAULT_OUTPUT_PRECISION = 2; +const DEFAULT_INPUT_FORMAT = { text: 'Seconds', kind: 'seconds' }; +const inputFormats = [ + { text: 'Picoseconds', kind: 'picoseconds' }, + { text: 'Nanoseconds', kind: 'nanoseconds' }, + { text: 'Microseconds', kind: 'microseconds' }, + { text: 'Milliseconds', kind: 'milliseconds' }, + DEFAULT_INPUT_FORMAT, + { text: 'Minutes', kind: 'minutes' }, + { text: 'Hours', kind: 'hours' }, + { text: 'Days', kind: 'days' }, + { text: 'Weeks', kind: 'weeks' }, + { text: 'Months', kind: 'months' }, + { text: 'Years', kind: 'years' } +]; +const DEFAULT_OUTPUT_FORMAT = { text: 'Human Readable', method: 'humanize' }; +const outputFormats = [ + DEFAULT_OUTPUT_FORMAT, + { text: 'Milliseconds', method: 'asMilliseconds' }, + { text: 'Seconds', method: 'asSeconds' }, + { text: 'Minutes', method: 'asMinutes' }, + { text: 'Hours', method: 'asHours' }, + { text: 'Days', method: 'asDays' }, + { text: 'Weeks', method: 'asWeeks' }, + { text: 'Months', method: 'asMonths' }, + { text: 'Years', method: 'asYears' } +]; - class Duration extends FieldFormat { - isHuman() { - return this.param('outputFormat') === HUMAN_FRIENDLY; - } - _convert(val) { - const inputFormat = this.param('inputFormat'); - const outputFormat = this.param('outputFormat'); - const outputPrecision = this.param('outputPrecision'); - const human = this.isHuman(); - const prefix = val < 0 && human ? 'minus ' : ''; - const duration = parseInputAsDuration(val, inputFormat); - const formatted = duration[outputFormat](); - const precise = human ? formatted : formatted.toFixed(outputPrecision); - return prefix + precise; - } +export class DurationFormat extends FieldFormat { + isHuman() { + return this.param('outputFormat') === HUMAN_FRIENDLY; + } + _convert(val) { + const inputFormat = this.param('inputFormat'); + const outputFormat = this.param('outputFormat'); + const outputPrecision = this.param('outputPrecision'); + const human = this.isHuman(); + const prefix = val < 0 && human ? 'minus ' : ''; + const duration = parseInputAsDuration(val, inputFormat); + const formatted = duration[outputFormat](); + const precise = human ? formatted : formatted.toFixed(outputPrecision); + return prefix + precise; + } - static id = 'duration'; - static title = 'Duration'; - static fieldType = 'number'; + static id = 'duration'; + static title = 'Duration'; + static fieldType = 'number'; - static inputFormats = inputFormats; - static outputFormats = outputFormats; - } + static inputFormats = inputFormats; + static outputFormats = outputFormats; +} - Duration.prototype.getParamDefaults = function () { - return { - inputFormat: DEFAULT_INPUT_FORMAT.kind, - outputFormat: DEFAULT_OUTPUT_FORMAT.method, - outputPrecision: DEFAULT_OUTPUT_PRECISION - }; +DurationFormat.prototype.getParamDefaults = function () { + return { + inputFormat: DEFAULT_INPUT_FORMAT.kind, + outputFormat: DEFAULT_OUTPUT_FORMAT.method, + outputPrecision: DEFAULT_OUTPUT_PRECISION }; +}; - return Duration; - - function parseInputAsDuration(val, inputFormat) { - const ratio = ratioToSeconds[inputFormat] || 1; - const kind = inputFormat in ratioToSeconds ? 'seconds' : inputFormat; - return moment.duration(val * ratio, kind); - } +function parseInputAsDuration(val, inputFormat) { + const ratio = ratioToSeconds[inputFormat] || 1; + const kind = inputFormat in ratioToSeconds ? 'seconds' : inputFormat; + return moment.duration(val * ratio, kind); } diff --git a/src/core_plugins/kibana/common/field_formats/types/ip.js b/src/core_plugins/kibana/common/field_formats/types/ip.js index a934001762a06..ec973f2c7b459 100644 --- a/src/core_plugins/kibana/common/field_formats/types/ip.js +++ b/src/core_plugins/kibana/common/field_formats/types/ip.js @@ -1,20 +1,15 @@ import { FieldFormat } from '../field_format'; -export function stringifyIp() { +export class IpFormat extends FieldFormat { + _convert(val) { + if (val === undefined || val === null) return '-'; + if (!isFinite(val)) return val; - class IpFormat extends FieldFormat { - _convert(val) { - if (val === undefined || val === null) return '-'; - if (!isFinite(val)) return val; - - // shazzam! - return [val >>> 24, val >>> 16 & 0xFF, val >>> 8 & 0xFF, val & 0xFF].join('.'); - } - - static id = 'ip'; - static title = 'IP Address'; - static fieldType = 'ip'; + // shazzam! + return [val >>> 24, val >>> 16 & 0xFF, val >>> 8 & 0xFF, val & 0xFF].join('.'); } - return IpFormat; + static id = 'ip'; + static title = 'IP Address'; + static fieldType = 'ip'; } diff --git a/src/core_plugins/kibana/common/field_formats/types/number.js b/src/core_plugins/kibana/common/field_formats/types/number.js index b4d7a478f3466..0022c52369519 100644 --- a/src/core_plugins/kibana/common/field_formats/types/number.js +++ b/src/core_plugins/kibana/common/field_formats/types/number.js @@ -1,8 +1,6 @@ import { Numeral } from './_numeral'; -export function stringifyNumber() { - return Numeral.factory({ - id: 'number', - title: 'Number' - }); -} +export const NumberFormat = Numeral.factory({ + id: 'number', + title: 'Number' +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/percent.js b/src/core_plugins/kibana/common/field_formats/types/percent.js index d2e35c69a98db..958c55bf76071 100644 --- a/src/core_plugins/kibana/common/field_formats/types/percent.js +++ b/src/core_plugins/kibana/common/field_formats/types/percent.js @@ -1,20 +1,18 @@ import _ from 'lodash'; import { Numeral } from './_numeral'; -export function stringifyPercent() { - return Numeral.factory({ - id: 'percent', - title: 'Percentage', - getParamDefaults: (getConfig) => { - return { - pattern: getConfig('format:percent:defaultPattern'), - fractional: true - }; - }, - prototype: { - _convert: _.compose(Numeral.prototype._convert, function (val) { - return this.param('fractional') ? val : val / 100; - }) - } - }); -} +export const PercentFormat = Numeral.factory({ + id: 'percent', + title: 'Percentage', + getParamDefaults: (getConfig) => { + return { + pattern: getConfig('format:percent:defaultPattern'), + fractional: true + }; + }, + prototype: { + _convert: _.compose(Numeral.prototype._convert, function (val) { + return this.param('fractional') ? val : val / 100; + }) + } +}); diff --git a/src/core_plugins/kibana/common/field_formats/types/source.js b/src/core_plugins/kibana/common/field_formats/types/source.js index 0d07f152f17fa..98712d1be4d9d 100644 --- a/src/core_plugins/kibana/common/field_formats/types/source.js +++ b/src/core_plugins/kibana/common/field_formats/types/source.js @@ -4,42 +4,46 @@ import { toJson } from '../../utils/aggressive_parse'; import { FieldFormat } from '../field_format'; import { shortenDottedString } from '../../utils/shorten_dotted_string'; -export function stringifySource() { - const template = _.template(noWhiteSpace(require('./_source.html'))); - - class SourceFormat extends FieldFormat { - constructor(params, getConfig) { - super(params); - - this.getConfig = getConfig; - } - - static id = '_source'; - static title = '_source'; - static fieldType = '_source'; +const templateHtml = ` +
+ <% defPairs.forEach(function (def) { %> +
<%- def[0] %>:
+
<%= def[1] %>
+ <%= ' ' %> + <% }); %> +
`; +const template = _.template(noWhiteSpace(templateHtml)); + +export class SourceFormat extends FieldFormat { + constructor(params, getConfig) { + super(params); + + this.getConfig = getConfig; } - SourceFormat.prototype._convert = { - text: (value) => toJson(value), - html: function sourceToHtml(source, field, hit) { - if (!field) return this.getConverterFor('text')(source, field, hit); - - const highlights = (hit && hit.highlight) || {}; - const formatted = field.indexPattern.formatHit(hit); - const highlightPairs = []; - const sourcePairs = []; - - const isShortDots = this.getConfig('shortDots:enable'); - _.keys(formatted).forEach((key) => { - const pairs = highlights[key] ? highlightPairs : sourcePairs; - const field = isShortDots ? shortenDottedString(key) : key; - const val = formatted[key]; - pairs.push([field, val]); - }, []); - - return template({ defPairs: highlightPairs.concat(sourcePairs) }); - } - }; - - return SourceFormat; + static id = '_source'; + static title = '_source'; + static fieldType = '_source'; } + +SourceFormat.prototype._convert = { + text: (value) => toJson(value), + html: function sourceToHtml(source, field, hit) { + if (!field) return this.getConverterFor('text')(source, field, hit); + + const highlights = (hit && hit.highlight) || {}; + const formatted = field.indexPattern.formatHit(hit); + const highlightPairs = []; + const sourcePairs = []; + + const isShortDots = this.getConfig('shortDots:enable'); + _.keys(formatted).forEach((key) => { + const pairs = highlights[key] ? highlightPairs : sourcePairs; + const field = isShortDots ? shortenDottedString(key) : key; + const val = formatted[key]; + pairs.push([field, val]); + }, []); + + return template({ defPairs: highlightPairs.concat(sourcePairs) }); + } +}; diff --git a/src/core_plugins/kibana/common/field_formats/types/string.js b/src/core_plugins/kibana/common/field_formats/types/string.js index a64ff4d35b8e6..b3c24e77741e7 100644 --- a/src/core_plugins/kibana/common/field_formats/types/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/string.js @@ -2,54 +2,49 @@ import { asPrettyString } from '../../utils/as_pretty_string'; import { FieldFormat } from '../field_format'; import { shortenDottedString } from '../../utils/shorten_dotted_string'; -export function stringifyString() { - - class StringFormat extends FieldFormat { - getParamDefaults() { - return { - transform: false - }; - } +export class StringFormat extends FieldFormat { + getParamDefaults() { + return { + transform: false + }; + } - _base64Decode(val) { - try { - return window.atob(val); - } catch (e) { - return asPrettyString(val); - } + _base64Decode(val) { + try { + return window.atob(val); + } catch (e) { + return asPrettyString(val); } + } - _toTitleCase(val) { - return val.replace(/\w\S*/g, txt => { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); - } + _toTitleCase(val) { + return val.replace(/\w\S*/g, txt => { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); + } - _convert(val) { - switch (this.param('transform')) { - case 'lower': return String(val).toLowerCase(); - case 'upper': return String(val).toUpperCase(); - case 'title': return this._toTitleCase(val); - case 'short': return shortenDottedString(val); - case 'base64': return this._base64Decode(val); - default: return asPrettyString(val); - } + _convert(val) { + switch (this.param('transform')) { + case 'lower': return String(val).toLowerCase(); + case 'upper': return String(val).toUpperCase(); + case 'title': return this._toTitleCase(val); + case 'short': return shortenDottedString(val); + case 'base64': return this._base64Decode(val); + default: return asPrettyString(val); } - - static id = 'string'; - static title = 'String'; - static fieldType = [ - 'number', - 'boolean', - 'date', - 'ip', - 'attachment', - 'geo_point', - 'geo_shape', - 'string', - 'murmur3', - 'unknown', - 'conflict' - ]; } - return StringFormat; + static id = 'string'; + static title = 'String'; + static fieldType = [ + 'number', + 'boolean', + 'date', + 'ip', + 'attachment', + 'geo_point', + 'geo_shape', + 'string', + 'murmur3', + 'unknown', + 'conflict' + ]; } diff --git a/src/core_plugins/kibana/common/field_formats/types/truncate.js b/src/core_plugins/kibana/common/field_formats/types/truncate.js index c3e0780e8ed19..2bd2793b41d40 100644 --- a/src/core_plugins/kibana/common/field_formats/types/truncate.js +++ b/src/core_plugins/kibana/common/field_formats/types/truncate.js @@ -1,26 +1,22 @@ import _ from 'lodash'; import { FieldFormat } from '../field_format'; -export function stringifyTruncate() { - const omission = '...'; +const omission = '...'; - class TruncateFormat extends FieldFormat { - _convert(val) { - const length = this.param('fieldLength'); - if (length > 0) { - return _.trunc(val, { - 'length': length + omission.length, - 'omission': omission - }); - } - - return val; +export class TruncateFormat extends FieldFormat { + _convert(val) { + const length = this.param('fieldLength'); + if (length > 0) { + return _.trunc(val, { + 'length': length + omission.length, + 'omission': omission + }); } - static id = 'truncate'; - static title = 'Truncated String'; - static fieldType = ['string']; + return val; } - return TruncateFormat; + static id = 'truncate'; + static title = 'Truncated String'; + static fieldType = ['string']; } diff --git a/src/core_plugins/kibana/common/field_formats/types/url.js b/src/core_plugins/kibana/common/field_formats/types/url.js index 5ecdf97346aa8..5a49eab2f7ee2 100644 --- a/src/core_plugins/kibana/common/field_formats/types/url.js +++ b/src/core_plugins/kibana/common/field_formats/types/url.js @@ -2,116 +2,111 @@ import _ from 'lodash'; import { FieldFormat } from '../field_format'; import { getHighlightHtml } from '../../highlight/highlight_html'; -export function stringifyUrl() { +const templateMatchRE = /{{([\s\S]+?)}}/g; - const templateMatchRE = /{{([\s\S]+?)}}/g; - - class UrlFormat extends FieldFormat { - constructor(params) { - super(params); - this._compileTemplate = _.memoize(this._compileTemplate); - } +export class UrlFormat extends FieldFormat { + constructor(params) { + super(params); + this._compileTemplate = _.memoize(this._compileTemplate); + } - getParamDefaults() { - return { - type: 'a', - urlTemplate: null, - labelTemplate: null - }; - } + getParamDefaults() { + return { + type: 'a', + urlTemplate: null, + labelTemplate: null + }; + } - _formatLabel(value, url) { - const template = this.param('labelTemplate'); - if (url == null) url = this._formatUrl(value); - if (!template) return url; + _formatLabel(value, url) { + const template = this.param('labelTemplate'); + if (url == null) url = this._formatUrl(value); + if (!template) return url; - return this._compileTemplate(template)({ - value: value, - url: url - }); - } + return this._compileTemplate(template)({ + value: value, + url: url + }); + } - _formatUrl(value) { - const template = this.param('urlTemplate'); - if (!template) return value; + _formatUrl(value) { + const template = this.param('urlTemplate'); + if (!template) return value; - return this._compileTemplate(template)({ - value: encodeURIComponent(value), - rawValue: value - }); - } + return this._compileTemplate(template)({ + value: encodeURIComponent(value), + rawValue: value + }); + } - _compileTemplate(template) { - const parts = template.split(templateMatchRE).map(function (part, i) { - // trim all the odd bits, the variable names - return (i % 2) ? part.trim() : part; - }); - - return function (locals) { - // replace all the odd bits with their local var - let output = ''; - let i = -1; - while (++i < parts.length) { - if (i % 2) { - if (locals.hasOwnProperty(parts[i])) { - const local = locals[parts[i]]; - output += local == null ? '' : local; - } - } else { - output += parts[i]; + _compileTemplate(template) { + const parts = template.split(templateMatchRE).map(function (part, i) { + // trim all the odd bits, the variable names + return (i % 2) ? part.trim() : part; + }); + + return function (locals) { + // replace all the odd bits with their local var + let output = ''; + let i = -1; + while (++i < parts.length) { + if (i % 2) { + if (locals.hasOwnProperty(parts[i])) { + const local = locals[parts[i]]; + output += local == null ? '' : local; } + } else { + output += parts[i]; } + } - return output; - }; - } - - static id = 'url'; - static title = 'Url'; - static fieldType = [ - 'number', - 'boolean', - 'date', - 'ip', - 'string', - 'murmur3', - 'unknown', - 'conflict' - ]; + return output; + }; } - UrlFormat.prototype._convert = { - text: function (value) { - return this._formatLabel(value); - }, - - html: function (rawValue, field, hit) { - const url = _.escape(this._formatUrl(rawValue)); - const label = _.escape(this._formatLabel(rawValue, url)); - - switch (this.param('type')) { - case 'img': - // If the URL hasn't been formatted to become a meaningful label then the best we can do - // is tell screen readers where the image comes from. - const imageLabel = - label === url - ? `A dynamically-specified image located at ${url}` - : label; - - return `${imageLabel}`; - default: - let linkLabel; - - if (hit && hit.highlight && hit.highlight[field.name]) { - linkLabel = getHighlightHtml(label, hit.highlight[field.name]); - } else { - linkLabel = label; - } + static id = 'url'; + static title = 'Url'; + static fieldType = [ + 'number', + 'boolean', + 'date', + 'ip', + 'string', + 'murmur3', + 'unknown', + 'conflict' + ]; +} - return `${linkLabel}`; - } - } - }; +UrlFormat.prototype._convert = { + text: function (value) { + return this._formatLabel(value); + }, + + html: function (rawValue, field, hit) { + const url = _.escape(this._formatUrl(rawValue)); + const label = _.escape(this._formatLabel(rawValue, url)); + + switch (this.param('type')) { + case 'img': + // If the URL hasn't been formatted to become a meaningful label then the best we can do + // is tell screen readers where the image comes from. + const imageLabel = + label === url + ? `A dynamically-specified image located at ${url}` + : label; + + return `${imageLabel}`; + default: + let linkLabel; + + if (hit && hit.highlight && hit.highlight[field.name]) { + linkLabel = getHighlightHtml(label, hit.highlight[field.name]); + } else { + linkLabel = label; + } - return UrlFormat; -} + return `${linkLabel}`; + } + } +}; diff --git a/src/core_plugins/kibana/public/field_formats/register.js b/src/core_plugins/kibana/public/field_formats/register.js index 6a0b6b9fb1e36..74196e44fd7a2 100644 --- a/src/core_plugins/kibana/public/field_formats/register.js +++ b/src/core_plugins/kibana/public/field_formats/register.js @@ -1,26 +1,26 @@ import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { stringifyUrl } from '../../common/field_formats/types/url'; -import { stringifyBytes } from '../../common/field_formats/types/bytes'; -import { stringifyDate } from '../../common/field_formats/types/date'; -import { stringifyDuration } from '../../common/field_formats/types/duration'; -import { stringifyIp } from '../../common/field_formats/types/ip'; -import { stringifyNumber } from '../../common/field_formats/types/number'; -import { stringifyPercent } from '../../common/field_formats/types/percent'; -import { stringifyString } from '../../common/field_formats/types/string'; -import { stringifySource } from '../../common/field_formats/types/source'; -import { stringifyColor } from '../../common/field_formats/types/color'; -import { stringifyTruncate } from '../../common/field_formats/types/truncate'; -import { stringifyBoolean } from '../../common/field_formats/types/boolean'; +import { UrlFormat } from '../../common/field_formats/types/url'; +import { BytesFormat } from '../../common/field_formats/types/bytes'; +import { DateFormat } from '../../common/field_formats/types/date'; +import { DurationFormat } from '../../common/field_formats/types/duration'; +import { IpFormat } from '../../common/field_formats/types/ip'; +import { NumberFormat } from '../../common/field_formats/types/number'; +import { PercentFormat } from '../../common/field_formats/types/percent'; +import { StringFormat } from '../../common/field_formats/types/string'; +import { SourceFormat } from '../../common/field_formats/types/source'; +import { ColorFormat } from '../../common/field_formats/types/color'; +import { TruncateFormat } from '../../common/field_formats/types/truncate'; +import { BoolFormat } from '../../common/field_formats/types/boolean'; -RegistryFieldFormatsProvider.register(stringifyUrl); -RegistryFieldFormatsProvider.register(stringifyBytes); -RegistryFieldFormatsProvider.register(stringifyDate); -RegistryFieldFormatsProvider.register(stringifyDuration); -RegistryFieldFormatsProvider.register(stringifyIp); -RegistryFieldFormatsProvider.register(stringifyNumber); -RegistryFieldFormatsProvider.register(stringifyPercent); -RegistryFieldFormatsProvider.register(stringifyString); -RegistryFieldFormatsProvider.register(stringifySource); -RegistryFieldFormatsProvider.register(stringifyColor); -RegistryFieldFormatsProvider.register(stringifyTruncate); -RegistryFieldFormatsProvider.register(stringifyBoolean); +RegistryFieldFormatsProvider.register(() => UrlFormat); +RegistryFieldFormatsProvider.register(() => BytesFormat); +RegistryFieldFormatsProvider.register(() => DateFormat); +RegistryFieldFormatsProvider.register(() => DurationFormat); +RegistryFieldFormatsProvider.register(() => IpFormat); +RegistryFieldFormatsProvider.register(() => NumberFormat); +RegistryFieldFormatsProvider.register(() => PercentFormat); +RegistryFieldFormatsProvider.register(() => StringFormat); +RegistryFieldFormatsProvider.register(() => SourceFormat); +RegistryFieldFormatsProvider.register(() => ColorFormat); +RegistryFieldFormatsProvider.register(() => TruncateFormat); +RegistryFieldFormatsProvider.register(() => BoolFormat); diff --git a/src/core_plugins/kibana/server/register_field_formats.js b/src/core_plugins/kibana/server/register_field_formats.js index c326b846c19af..5ce545b3479b9 100644 --- a/src/core_plugins/kibana/server/register_field_formats.js +++ b/src/core_plugins/kibana/server/register_field_formats.js @@ -1,27 +1,27 @@ -import { stringifyUrl } from '../common/field_formats/types/url'; -import { stringifyBytes } from '../common/field_formats/types/bytes'; -import { stringifyDate } from '../common/field_formats/types/date'; -import { stringifyDuration } from '../common/field_formats/types/duration'; -import { stringifyIp } from '../common/field_formats/types/ip'; -import { stringifyNumber } from '../common/field_formats/types/number'; -import { stringifyPercent } from '../common/field_formats/types/percent'; -import { stringifyString } from '../common/field_formats/types/string'; -//import { stringifySource } from '../common/field_formats/types/source'; -import { stringifyColor } from '../common/field_formats/types/color'; -import { stringifyTruncate } from '../common/field_formats/types/truncate'; -import { stringifyBoolean } from '../common/field_formats/types/boolean'; +import { UrlFormat } from '../common/field_formats/types/url'; +import { BytesFormat } from '../common/field_formats/types/bytes'; +import { DateFormat } from '../common/field_formats/types/date'; +import { DurationFormat } from '../common/field_formats/types/duration'; +import { IpFormat } from '../common/field_formats/types/ip'; +import { NumberFormat } from '../common/field_formats/types/number'; +import { PercentFormat } from '../common/field_formats/types/percent'; +import { StringFormat } from '../common/field_formats/types/string'; +import { SourceFormat } from '../common/field_formats/types/source'; +import { ColorFormat } from '../common/field_formats/types/color'; +import { TruncateFormat } from '../common/field_formats/types/truncate'; +import { BoolFormat } from '../common/field_formats/types/boolean'; export function registerFieldFormats(server) { - server.fieldFormats.register(stringifyUrl()); - server.fieldFormats.register(stringifyBytes()); - server.fieldFormats.register(stringifyDate()); - server.fieldFormats.register(stringifyDuration()); - server.fieldFormats.register(stringifyIp()); - server.fieldFormats.register(stringifyNumber()); - server.fieldFormats.register(stringifyPercent()); - server.fieldFormats.register(stringifyString()); - //server.fieldFormats.register(stringifySource()); - server.fieldFormats.register(stringifyColor()); - server.fieldFormats.register(stringifyTruncate()); - server.fieldFormats.register(stringifyBoolean()); + server.fieldFormats.register(UrlFormat); + server.fieldFormats.register(BytesFormat); + server.fieldFormats.register(DateFormat); + server.fieldFormats.register(DurationFormat); + server.fieldFormats.register(IpFormat); + server.fieldFormats.register(NumberFormat); + server.fieldFormats.register(PercentFormat); + server.fieldFormats.register(StringFormat); + server.fieldFormats.register(SourceFormat); + server.fieldFormats.register(ColorFormat); + server.fieldFormats.register(TruncateFormat); + server.fieldFormats.register(BoolFormat); } diff --git a/src/ui/public/index_patterns/__tests__/index.js b/src/ui/public/index_patterns/__tests__/index.js index c07829d17d06c..2bc90734fd25a 100644 --- a/src/ui/public/index_patterns/__tests__/index.js +++ b/src/ui/public/index_patterns/__tests__/index.js @@ -1,5 +1,4 @@ import './_index_pattern'; import './_get_computed_fields'; -import './_field_format'; describe('Index Patterns', function () { }); From 06b88d2327992a9d9b198e0eb9f3b54ce198845e Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 30 Jun 2017 14:38:40 -0600 Subject: [PATCH 04/15] remove use of window.atob in StringFormat --- .../kibana/common/field_formats/types/__tests__/string.js | 2 -- src/core_plugins/kibana/common/field_formats/types/string.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js index ff149e386e264..4e0473add2b6d 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js @@ -18,14 +18,12 @@ describe('String Format', function () { }); // TODO fix base64 encoded to not use window.atob -/* it('decode a base64 string', function () { const string = new StringFormat({ transform: 'base64' }); expect(string.convert('Zm9vYmFy')).to.be('foobar'); }); -*/ it('convert a string to title case', function () { const string = new StringFormat({ diff --git a/src/core_plugins/kibana/common/field_formats/types/string.js b/src/core_plugins/kibana/common/field_formats/types/string.js index b3c24e77741e7..944bc32170d79 100644 --- a/src/core_plugins/kibana/common/field_formats/types/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/string.js @@ -11,7 +11,7 @@ export class StringFormat extends FieldFormat { _base64Decode(val) { try { - return window.atob(val); + return Buffer.from(val, 'base64').toString('utf8'); } catch (e) { return asPrettyString(val); } From 2156a0a95a1b38bf650f9d0d2d03c08f6a535a90 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sat, 1 Jul 2017 06:36:10 -0600 Subject: [PATCH 05/15] fix test and move server register under directory field_formats --- .../field_formats/__tests__/field_formats.js | 3 +-- src/core_plugins/kibana/index.js | 2 +- .../kibana/server/field_formats/register.js | 27 +++++++++++++++++++ .../kibana/server/register_field_formats.js | 27 ------------------- 4 files changed, 29 insertions(+), 30 deletions(-) create mode 100644 src/core_plugins/kibana/server/field_formats/register.js delete mode 100644 src/core_plugins/kibana/server/register_field_formats.js diff --git a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js index ede32b5571423..b0afa479d2db3 100644 --- a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js +++ b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js @@ -1,10 +1,9 @@ import expect from 'expect.js'; import { FieldFormatsService } from '../field_formats'; -import { stringifyNumber } from '../types/number'; +import { NumberFormat } from '../types/number'; describe('FieldFormatsService', function () { - const NumberFormat = stringifyNumber(); const config = {}; config['format:defaultTypeMap'] = { 'ip': { 'id': 'ip', 'params': {} }, diff --git a/src/core_plugins/kibana/index.js b/src/core_plugins/kibana/index.js index aa991d09e874d..d9f6205b1b901 100644 --- a/src/core_plugins/kibana/index.js +++ b/src/core_plugins/kibana/index.js @@ -10,7 +10,7 @@ import { importApi } from './server/routes/api/import'; import { exportApi } from './server/routes/api/export'; import scripts from './server/routes/api/scripts'; import { registerSuggestionsApi } from './server/routes/api/suggestions'; -import { registerFieldFormats } from './server/register_field_formats'; +import { registerFieldFormats } from './server/field_formats/register'; import * as systemApi from './server/lib/system_api'; import handleEsError from './server/lib/handle_es_error'; import mappings from './mappings.json'; diff --git a/src/core_plugins/kibana/server/field_formats/register.js b/src/core_plugins/kibana/server/field_formats/register.js new file mode 100644 index 0000000000000..e39e2322aad04 --- /dev/null +++ b/src/core_plugins/kibana/server/field_formats/register.js @@ -0,0 +1,27 @@ +import { UrlFormat } from '../../common/field_formats/types/url'; +import { BytesFormat } from '../../common/field_formats/types/bytes'; +import { DateFormat } from '../../common/field_formats/types/date'; +import { DurationFormat } from '../../common/field_formats/types/duration'; +import { IpFormat } from '../../common/field_formats/types/ip'; +import { NumberFormat } from '../../common/field_formats/types/number'; +import { PercentFormat } from '../../common/field_formats/types/percent'; +import { StringFormat } from '../../common/field_formats/types/string'; +import { SourceFormat } from '../../common/field_formats/types/source'; +import { ColorFormat } from '../../common/field_formats/types/color'; +import { TruncateFormat } from '../../common/field_formats/types/truncate'; +import { BoolFormat } from '../../common/field_formats/types/boolean'; + +export function registerFieldFormats(server) { + server.fieldFormats.register(UrlFormat); + server.fieldFormats.register(BytesFormat); + server.fieldFormats.register(DateFormat); + server.fieldFormats.register(DurationFormat); + server.fieldFormats.register(IpFormat); + server.fieldFormats.register(NumberFormat); + server.fieldFormats.register(PercentFormat); + server.fieldFormats.register(StringFormat); + server.fieldFormats.register(SourceFormat); + server.fieldFormats.register(ColorFormat); + server.fieldFormats.register(TruncateFormat); + server.fieldFormats.register(BoolFormat); +} diff --git a/src/core_plugins/kibana/server/register_field_formats.js b/src/core_plugins/kibana/server/register_field_formats.js deleted file mode 100644 index 5ce545b3479b9..0000000000000 --- a/src/core_plugins/kibana/server/register_field_formats.js +++ /dev/null @@ -1,27 +0,0 @@ -import { UrlFormat } from '../common/field_formats/types/url'; -import { BytesFormat } from '../common/field_formats/types/bytes'; -import { DateFormat } from '../common/field_formats/types/date'; -import { DurationFormat } from '../common/field_formats/types/duration'; -import { IpFormat } from '../common/field_formats/types/ip'; -import { NumberFormat } from '../common/field_formats/types/number'; -import { PercentFormat } from '../common/field_formats/types/percent'; -import { StringFormat } from '../common/field_formats/types/string'; -import { SourceFormat } from '../common/field_formats/types/source'; -import { ColorFormat } from '../common/field_formats/types/color'; -import { TruncateFormat } from '../common/field_formats/types/truncate'; -import { BoolFormat } from '../common/field_formats/types/boolean'; - -export function registerFieldFormats(server) { - server.fieldFormats.register(UrlFormat); - server.fieldFormats.register(BytesFormat); - server.fieldFormats.register(DateFormat); - server.fieldFormats.register(DurationFormat); - server.fieldFormats.register(IpFormat); - server.fieldFormats.register(NumberFormat); - server.fieldFormats.register(PercentFormat); - server.fieldFormats.register(StringFormat); - server.fieldFormats.register(SourceFormat); - server.fieldFormats.register(ColorFormat); - server.fieldFormats.register(TruncateFormat); - server.fieldFormats.register(BoolFormat); -} From 8d455ffc661c80a9ca8f9f4e45c55a9aede964a6 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sat, 1 Jul 2017 07:13:53 -0600 Subject: [PATCH 06/15] cleanup --- .../kibana/common/field_formats/types/__tests__/string.js | 1 - .../kibana/common/field_formats/types/_numeral.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js index 4e0473add2b6d..f00718d11c436 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/string.js @@ -17,7 +17,6 @@ describe('String Format', function () { expect(string.convert('Kibana')).to.be('KIBANA'); }); -// TODO fix base64 encoded to not use window.atob it('decode a base64 string', function () { const string = new StringFormat({ transform: 'base64' diff --git a/src/core_plugins/kibana/common/field_formats/types/_numeral.js b/src/core_plugins/kibana/common/field_formats/types/_numeral.js index 086daf15b0921..fa0c1abd4a961 100644 --- a/src/core_plugins/kibana/common/field_formats/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_formats/types/_numeral.js @@ -14,9 +14,7 @@ export class Numeral extends FieldFormat { if (isNaN(val)) return ''; - const formatted = numeralInst.set(val).format(this.param('pattern')); - - return formatted; + return numeralInst.set(val).format(this.param('pattern')); } static factory(opts) { From 8f046c824ecf6ef57e458f964b79c0bf392e7314 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 5 Jul 2017 12:24:50 -0600 Subject: [PATCH 07/15] expose uiSettingDefaults on server so fieldFormats knows how to parse uiSettings --- src/ui/field_formats_mixin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/field_formats_mixin.js b/src/ui/field_formats_mixin.js index cea4c28fe8f5e..ff7d177a14954 100644 --- a/src/ui/field_formats_mixin.js +++ b/src/ui/field_formats_mixin.js @@ -1,5 +1,7 @@ import { FieldFormatsService } from '../core_plugins/kibana/common/field_formats/field_formats'; +import { getUiSettingDefaults } from '../core_plugins/kibana/ui_setting_defaults'; export function fieldFormatsMixin(kbnServer, server) { + server.decorate('server', 'uiSettingDefaults', getUiSettingDefaults()); server.decorate('server', 'fieldFormats', new FieldFormatsService); } From e655ab3a825aff74f1b9bbfdec14f7b379d7bbe8 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 5 Jul 2017 15:50:42 -0600 Subject: [PATCH 08/15] remove uiSettingDefaults decorator and clean up tests --- .../kibana/common/field_formats/__tests__/field_formats.js | 6 +----- src/ui/field_formats_mixin.js | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js index b0afa479d2db3..15a46a27a91a6 100644 --- a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js +++ b/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js @@ -6,11 +6,7 @@ describe('FieldFormatsService', function () { const config = {}; config['format:defaultTypeMap'] = { - 'ip': { 'id': 'ip', 'params': {} }, - 'date': { 'id': 'date', 'params': {} }, 'number': { 'id': 'number', 'params': {} }, - 'boolean': { 'id': 'boolean', 'params': {} }, - '_source': { 'id': '_source', 'params': {} }, '_default_': { 'id': 'string', 'params': {} } }; config['format:number:defaultPattern'] = '0,0.[000]'; @@ -18,7 +14,7 @@ describe('FieldFormatsService', function () { let fieldFormats; beforeEach(function () { - fieldFormats = new FieldFormatsService; + fieldFormats = new FieldFormatsService(); }); it('registered FieldFormats are accessible via getType method', function () { diff --git a/src/ui/field_formats_mixin.js b/src/ui/field_formats_mixin.js index ff7d177a14954..1e77414126a0c 100644 --- a/src/ui/field_formats_mixin.js +++ b/src/ui/field_formats_mixin.js @@ -1,7 +1,5 @@ import { FieldFormatsService } from '../core_plugins/kibana/common/field_formats/field_formats'; -import { getUiSettingDefaults } from '../core_plugins/kibana/ui_setting_defaults'; export function fieldFormatsMixin(kbnServer, server) { - server.decorate('server', 'uiSettingDefaults', getUiSettingDefaults()); - server.decorate('server', 'fieldFormats', new FieldFormatsService); + server.decorate('server', 'fieldFormats', new FieldFormatsService()); } From d5d93c801770d6fb48f0fd7f89026c9e3c5a8b8d Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 19:57:35 -0600 Subject: [PATCH 09/15] move field_formats_service out of kibana plugin --- .../field_formats/__tests__/field_formats_service.js} | 4 ++-- .../field_formats/field_formats_service.js} | 0 src/ui/field_formats_mixin.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/{core_plugins/kibana/common/field_formats/__tests__/field_formats.js => ui/field_formats/__tests__/field_formats_service.js} (85%) rename src/{core_plugins/kibana/common/field_formats/field_formats.js => ui/field_formats/field_formats_service.js} (100%) diff --git a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js b/src/ui/field_formats/__tests__/field_formats_service.js similarity index 85% rename from src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js rename to src/ui/field_formats/__tests__/field_formats_service.js index 15a46a27a91a6..c456fadda5a1a 100644 --- a/src/core_plugins/kibana/common/field_formats/__tests__/field_formats.js +++ b/src/ui/field_formats/__tests__/field_formats_service.js @@ -1,6 +1,6 @@ import expect from 'expect.js'; -import { FieldFormatsService } from '../field_formats'; -import { NumberFormat } from '../types/number'; +import { FieldFormatsService } from '../field_formats_service'; +import { NumberFormat } from '../../../core_plugins/kibana/common/field_formats/types/number'; describe('FieldFormatsService', function () { diff --git a/src/core_plugins/kibana/common/field_formats/field_formats.js b/src/ui/field_formats/field_formats_service.js similarity index 100% rename from src/core_plugins/kibana/common/field_formats/field_formats.js rename to src/ui/field_formats/field_formats_service.js diff --git a/src/ui/field_formats_mixin.js b/src/ui/field_formats_mixin.js index 1e77414126a0c..088047dcf77da 100644 --- a/src/ui/field_formats_mixin.js +++ b/src/ui/field_formats_mixin.js @@ -1,4 +1,4 @@ -import { FieldFormatsService } from '../core_plugins/kibana/common/field_formats/field_formats'; +import { FieldFormatsService } from './field_formats/field_formats_service'; export function fieldFormatsMixin(kbnServer, server) { server.decorate('server', 'fieldFormats', new FieldFormatsService()); From ca79831b994098d54cf766e36ff8b5a49e3135f7 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 20:08:49 -0600 Subject: [PATCH 10/15] make duration test more unstandable --- .../field_formats/types/__tests__/duration.js | 126 ++++++++++++++---- 1 file changed, 101 insertions(+), 25 deletions(-) diff --git a/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js b/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js index e3adb9b3f5af7..138336ea1219b 100644 --- a/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js +++ b/src/core_plugins/kibana/common/field_formats/types/__tests__/duration.js @@ -3,39 +3,115 @@ import { DurationFormat } from '../duration'; describe('Duration Format', function () { - test({ inputFormat: 'seconds', outputFormat: 'humanize' }) - (-60, 'minus a minute') - (60, 'a minute') - (125, '2 minutes'); + test({ + inputFormat: 'seconds', + outputFormat: 'humanize', + fixtures: [ + { + input: -60, + output: 'minus a minute' + }, + { + input: 60, + output: 'a minute' + }, + { + input: 125, + output: '2 minutes' + } + ] + }); - test({ inputFormat: 'minutes', outputFormat: 'humanize' }) - (-60, 'minus an hour') - (60, 'an hour') - (125, '2 hours'); + test({ + inputFormat: 'minutes', + outputFormat: 'humanize', + fixtures: [ + { + input: -60, + output: 'minus an hour' + }, + { + input: 60, + output: 'an hour' + }, + { + input: 125, + output: '2 hours' + } + ] + }); - test({ inputFormat: 'minutes', outputFormat: 'asHours' }) // outputPrecision defaults to: 2 - (-60, '-1.00') - (60, '1.00') - (125, '2.08'); + test({ + inputFormat: 'minutes', + outputFormat: 'asHours', + fixtures: [ + { + input: -60, + output: '-1.00' + }, + { + input: 60, + output: '1.00' + }, + { + input: 125, + output: '2.08' + } + ] + }); - test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 0 }) - (-60, '-60') - (60, '60') - (125, '125'); + test({ + inputFormat: 'seconds', + outputFormat: 'asSeconds', + outputPrecision: 0, + fixtures: [ + { + input: -60, + output: '-60' + }, + { + input: 60, + output: '60' + }, + { + input: 125, + output: '125' + } + ] + }); - test({ inputFormat: 'seconds', outputFormat: 'asSeconds', outputPrecision: 2 }) - (-60, '-60.00') - (-32.333, '-32.33') - (60, '60.00') - (125, '125.00'); + test({ + inputFormat: 'seconds', + outputFormat: 'asSeconds', + outputPrecision: 2, + fixtures: [ + { + input: -60, + output: '-60.00' + }, + { + input: -32.333, + output: '-32.33' + }, + { + input: 60, + output: '60.00' + }, + { + input: 125, + output: '125.00' + } + ] + }); - function test({ inputFormat, outputFormat, outputPrecision }) { - return function testFixture(input, output) { + function test({ inputFormat, outputFormat, outputPrecision, fixtures }) { + fixtures.forEach((fixture) => { + const input = fixture.input; + const output = fixture.output; it(`should format ${input} ${inputFormat} through ${outputFormat}${outputPrecision ? `, ${outputPrecision} decimals` : ''}`, () => { const duration = new DurationFormat({ inputFormat, outputFormat, outputPrecision }); expect(duration.convert(input)).to.eql(output); }); - return testFixture; - }; + }); } }); From 9de5325512cb079d3378c1ebfcd48ea5a72d3ef9 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 20:11:16 -0600 Subject: [PATCH 11/15] prefix internal member with underscore --- src/ui/field_formats/field_formats_service.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/field_formats/field_formats_service.js b/src/ui/field_formats/field_formats_service.js index 9040f90dab49f..3b707e4e92c67 100644 --- a/src/ui/field_formats/field_formats_service.js +++ b/src/ui/field_formats/field_formats_service.js @@ -1,6 +1,6 @@ export class FieldFormatsService { constructor() { - this.fieldFormats = new Map(); + this._fieldFormats = new Map(); } /** @@ -25,7 +25,7 @@ export class FieldFormatsService { */ getDefaultInstance(fieldType, getConfig) { const conf = this.getDefaultConfig(fieldType, getConfig); - const FieldFormat = this.fieldFormats.get(conf.id); + const FieldFormat = this._fieldFormats.get(conf.id); return new FieldFormat(conf.params, getConfig); } @@ -36,10 +36,10 @@ export class FieldFormatsService { * @return {FieldFormat} */ getType(fieldFormatId) { - return this.fieldFormats.get(fieldFormatId); + return this._fieldFormats.get(fieldFormatId); } register(FieldFormat) { - this.fieldFormats.set(FieldFormat.id, FieldFormat); + this._fieldFormats.set(FieldFormat.id, FieldFormat); } } From 6d51b7bbe96b90def3aef731ad8f51dd3a33cad2 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 21:36:27 -0600 Subject: [PATCH 12/15] pass getConfig in constructor instead of methods --- .../kibana/server/field_formats/register.js | 24 ++++++++--------- .../__tests__/field_formats_service.js | 7 +++-- src/ui/field_formats/field_formats_service.js | 27 +++++++++---------- src/ui/field_formats_mixin.js | 25 ++++++++++++++++- 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/src/core_plugins/kibana/server/field_formats/register.js b/src/core_plugins/kibana/server/field_formats/register.js index e39e2322aad04..2298dd312b11f 100644 --- a/src/core_plugins/kibana/server/field_formats/register.js +++ b/src/core_plugins/kibana/server/field_formats/register.js @@ -12,16 +12,16 @@ import { TruncateFormat } from '../../common/field_formats/types/truncate'; import { BoolFormat } from '../../common/field_formats/types/boolean'; export function registerFieldFormats(server) { - server.fieldFormats.register(UrlFormat); - server.fieldFormats.register(BytesFormat); - server.fieldFormats.register(DateFormat); - server.fieldFormats.register(DurationFormat); - server.fieldFormats.register(IpFormat); - server.fieldFormats.register(NumberFormat); - server.fieldFormats.register(PercentFormat); - server.fieldFormats.register(StringFormat); - server.fieldFormats.register(SourceFormat); - server.fieldFormats.register(ColorFormat); - server.fieldFormats.register(TruncateFormat); - server.fieldFormats.register(BoolFormat); + server.registerFieldFormatClass(UrlFormat); + server.registerFieldFormatClass(BytesFormat); + server.registerFieldFormatClass(DateFormat); + server.registerFieldFormatClass(DurationFormat); + server.registerFieldFormatClass(IpFormat); + server.registerFieldFormatClass(NumberFormat); + server.registerFieldFormatClass(PercentFormat); + server.registerFieldFormatClass(StringFormat); + server.registerFieldFormatClass(SourceFormat); + server.registerFieldFormatClass(ColorFormat); + server.registerFieldFormatClass(TruncateFormat); + server.registerFieldFormatClass(BoolFormat); } diff --git a/src/ui/field_formats/__tests__/field_formats_service.js b/src/ui/field_formats/__tests__/field_formats_service.js index c456fadda5a1a..3f5f4a69dabd5 100644 --- a/src/ui/field_formats/__tests__/field_formats_service.js +++ b/src/ui/field_formats/__tests__/field_formats_service.js @@ -11,20 +11,19 @@ describe('FieldFormatsService', function () { }; config['format:number:defaultPattern'] = '0,0.[000]'; const getConfig = (key) => config[key]; + const fieldFormatClasses = [NumberFormat]; let fieldFormats; beforeEach(function () { - fieldFormats = new FieldFormatsService(); + fieldFormats = new FieldFormatsService(fieldFormatClasses, getConfig); }); - it('registered FieldFormats are accessible via getType method', function () { - fieldFormats.register(NumberFormat); + it('FieldFormats are accessible via getType method', function () { const Type = fieldFormats.getType('number'); expect(Type.id).to.be('number'); }); it('getDefaultInstance returns default FieldFormat instance for fieldType', function () { - fieldFormats.register(NumberFormat); const instance = fieldFormats.getDefaultInstance('number', getConfig); expect(instance.type.id).to.be('number'); expect(instance.convert('0.33333')).to.be('0.333'); diff --git a/src/ui/field_formats/field_formats_service.js b/src/ui/field_formats/field_formats_service.js index 3b707e4e92c67..7eb48d8c7ddf7 100644 --- a/src/ui/field_formats/field_formats_service.js +++ b/src/ui/field_formats/field_formats_service.js @@ -1,6 +1,9 @@ +import _ from 'lodash'; + export class FieldFormatsService { - constructor() { - this._fieldFormats = new Map(); + constructor(fieldFormatClasses, getConfig) { + this._fieldFormats = _.indexBy(fieldFormatClasses, 'id'); + this.getConfig = getConfig; } /** @@ -8,11 +11,10 @@ export class FieldFormatsService { * using the format:defaultTypeMap config map * * @param {String} fieldType - the field type - * @param {Func} getConfig * @return {String} */ - getDefaultConfig(fieldType, getConfig) { - const defaultMap = getConfig('format:defaultTypeMap'); + getDefaultConfig(fieldType) { + const defaultMap = this.getConfig('format:defaultTypeMap'); return defaultMap[fieldType] || defaultMap._default_; } @@ -20,13 +22,12 @@ export class FieldFormatsService { * Get the default fieldFormat instance for a field type. * * @param {String} fieldType - * @param {Func} getConfig * @return {FieldFormat} */ - getDefaultInstance(fieldType, getConfig) { - const conf = this.getDefaultConfig(fieldType, getConfig); - const FieldFormat = this._fieldFormats.get(conf.id); - return new FieldFormat(conf.params, getConfig); + getDefaultInstance(fieldType) { + const conf = this.getDefaultConfig(fieldType); + const FieldFormat = this._fieldFormats[conf.id]; + return new FieldFormat(conf.params, this.getConfig); } /** @@ -36,10 +37,6 @@ export class FieldFormatsService { * @return {FieldFormat} */ getType(fieldFormatId) { - return this._fieldFormats.get(fieldFormatId); - } - - register(FieldFormat) { - this._fieldFormats.set(FieldFormat.id, FieldFormat); + return this._fieldFormats[fieldFormatId]; } } diff --git a/src/ui/field_formats_mixin.js b/src/ui/field_formats_mixin.js index 088047dcf77da..4f151a537bb38 100644 --- a/src/ui/field_formats_mixin.js +++ b/src/ui/field_formats_mixin.js @@ -1,5 +1,28 @@ +import _ from 'lodash'; import { FieldFormatsService } from './field_formats/field_formats_service'; export function fieldFormatsMixin(kbnServer, server) { - server.decorate('server', 'fieldFormats', new FieldFormatsService()); + const fieldFormatClasses = []; + + // for use in the context of a request, the default context + server.decorate('request', 'getFieldFormatService', async function () { + return await server.fieldFormatServiceFactory(this.getUiSettingsService()); + }); + + // for use outside of the request context, for special cases + server.decorate('server', 'fieldFormatServiceFactory', async function (uiSettings) { + const uiConfigs = await uiSettings.getAll(); + const uiSettingDefaults = await uiSettings.getDefaults(); + Object.keys(uiSettingDefaults).forEach((key) => { + if (_.has(uiConfigs, key) && uiSettingDefaults[key].type === 'json') { + uiConfigs[key] = JSON.parse(uiConfigs[key]); + } + }); + const getConfig = (key) => uiConfigs[key]; + return new FieldFormatsService(fieldFormatClasses, getConfig); + }); + + server.decorate('server', 'registerFieldFormatClass', (FieldFormat) => { + fieldFormatClasses.push(FieldFormat); + }); } From 929429d8ce4e3523e9daffdc4ab6a3ba53ee39b4 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 21:39:39 -0600 Subject: [PATCH 13/15] move getParamsDefaults for DurationFormat --- .../kibana/common/field_formats/types/duration.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/core_plugins/kibana/common/field_formats/types/duration.js b/src/core_plugins/kibana/common/field_formats/types/duration.js index 834f6ed49cb11..58b8559835be7 100644 --- a/src/core_plugins/kibana/common/field_formats/types/duration.js +++ b/src/core_plugins/kibana/common/field_formats/types/duration.js @@ -39,6 +39,13 @@ export class DurationFormat extends FieldFormat { isHuman() { return this.param('outputFormat') === HUMAN_FRIENDLY; } + getParamDefaults() { + return { + inputFormat: DEFAULT_INPUT_FORMAT.kind, + outputFormat: DEFAULT_OUTPUT_FORMAT.method, + outputPrecision: DEFAULT_OUTPUT_PRECISION + }; + } _convert(val) { const inputFormat = this.param('inputFormat'); const outputFormat = this.param('outputFormat'); @@ -59,14 +66,6 @@ export class DurationFormat extends FieldFormat { static outputFormats = outputFormats; } -DurationFormat.prototype.getParamDefaults = function () { - return { - inputFormat: DEFAULT_INPUT_FORMAT.kind, - outputFormat: DEFAULT_OUTPUT_FORMAT.method, - outputPrecision: DEFAULT_OUTPUT_PRECISION - }; -}; - function parseInputAsDuration(val, inputFormat) { const ratio = ratioToSeconds[inputFormat] || 1; const kind = inputFormat in ratioToSeconds ? 'seconds' : inputFormat; From 729a2b5e90cf8795d0658ada224606cfab4972d9 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 6 Jul 2017 22:08:46 -0600 Subject: [PATCH 14/15] add getInstance method to field_formats_server --- src/ui/field_formats/field_formats_service.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ui/field_formats/field_formats_service.js b/src/ui/field_formats/field_formats_service.js index 7eb48d8c7ddf7..db5f415921262 100644 --- a/src/ui/field_formats/field_formats_service.js +++ b/src/ui/field_formats/field_formats_service.js @@ -30,6 +30,17 @@ export class FieldFormatsService { return new FieldFormat(conf.params, this.getConfig); } + /** + * Get the fieldFormat instance for a field format configuration. + * + * @param {Object} conf:id, conf:params + * @return {FieldFormat} + */ + getInstance(conf) { + const FieldFormat = this._fieldFormats[conf.id]; + return new FieldFormat(conf.params, this.getConfig); + } + /** * Get a FieldFormat type (class) by it's id. * From 399006c9bd03166c0d94b7d41ec6cda6ad89c703 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 7 Jul 2017 10:53:55 -0600 Subject: [PATCH 15/15] move FieldFormat class outside of kibana plugin --- .../kibana/common/field_formats/types/_numeral.js | 2 +- src/core_plugins/kibana/common/field_formats/types/boolean.js | 2 +- src/core_plugins/kibana/common/field_formats/types/color.js | 2 +- src/core_plugins/kibana/common/field_formats/types/date.js | 2 +- .../kibana/common/field_formats/types/duration.js | 2 +- src/core_plugins/kibana/common/field_formats/types/ip.js | 2 +- src/core_plugins/kibana/common/field_formats/types/source.js | 2 +- src/core_plugins/kibana/common/field_formats/types/string.js | 2 +- .../kibana/common/field_formats/types/truncate.js | 2 +- src/core_plugins/kibana/common/field_formats/types/url.js | 2 +- .../kibana/public/field_formats/__tests__/_conformance.js | 2 +- .../common => ui}/field_formats/__tests__/field_format.js | 2 +- .../kibana/common => ui}/field_formats/content_types.js | 4 ++-- .../kibana/common => ui}/field_formats/field_format.js | 0 src/ui/public/agg_types/buckets/range.js | 2 +- src/ui/public/index_patterns/_field.js | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) rename src/{core_plugins/kibana/common => ui}/field_formats/__tests__/field_format.js (98%) rename src/{core_plugins/kibana/common => ui}/field_formats/content_types.js (89%) rename src/{core_plugins/kibana/common => ui}/field_formats/field_format.js (100%) diff --git a/src/core_plugins/kibana/common/field_formats/types/_numeral.js b/src/core_plugins/kibana/common/field_formats/types/_numeral.js index fa0c1abd4a961..e0665eb45f7e6 100644 --- a/src/core_plugins/kibana/common/field_formats/types/_numeral.js +++ b/src/core_plugins/kibana/common/field_formats/types/_numeral.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import numeral from '@spalger/numeral'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; const numeralInst = numeral(); diff --git a/src/core_plugins/kibana/common/field_formats/types/boolean.js b/src/core_plugins/kibana/common/field_formats/types/boolean.js index 2a27e00326967..238ab44f27bf2 100644 --- a/src/core_plugins/kibana/common/field_formats/types/boolean.js +++ b/src/core_plugins/kibana/common/field_formats/types/boolean.js @@ -1,5 +1,5 @@ import { asPrettyString } from '../../utils/as_pretty_string'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; export class BoolFormat extends FieldFormat { _convert(value) { diff --git a/src/core_plugins/kibana/common/field_formats/types/color.js b/src/core_plugins/kibana/common/field_formats/types/color.js index bdfc5c0f507d0..a4308b8f107b5 100644 --- a/src/core_plugins/kibana/common/field_formats/types/color.js +++ b/src/core_plugins/kibana/common/field_formats/types/color.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { asPrettyString } from '../../utils/as_pretty_string'; import { DEFAULT_COLOR } from './color_default'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; const convertTemplate = _.template('<%- val %>'); diff --git a/src/core_plugins/kibana/common/field_formats/types/date.js b/src/core_plugins/kibana/common/field_formats/types/date.js index 455c8002b8337..a0d7653ed313b 100644 --- a/src/core_plugins/kibana/common/field_formats/types/date.js +++ b/src/core_plugins/kibana/common/field_formats/types/date.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import moment from 'moment'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; export class DateFormat extends FieldFormat { constructor(params, getConfig) { diff --git a/src/core_plugins/kibana/common/field_formats/types/duration.js b/src/core_plugins/kibana/common/field_formats/types/duration.js index 58b8559835be7..01aeae08dcda9 100644 --- a/src/core_plugins/kibana/common/field_formats/types/duration.js +++ b/src/core_plugins/kibana/common/field_formats/types/duration.js @@ -1,5 +1,5 @@ import moment from 'moment'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; const ratioToSeconds = { picoseconds: 0.000000000001, diff --git a/src/core_plugins/kibana/common/field_formats/types/ip.js b/src/core_plugins/kibana/common/field_formats/types/ip.js index ec973f2c7b459..bf02d883aa62f 100644 --- a/src/core_plugins/kibana/common/field_formats/types/ip.js +++ b/src/core_plugins/kibana/common/field_formats/types/ip.js @@ -1,4 +1,4 @@ -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; export class IpFormat extends FieldFormat { _convert(val) { diff --git a/src/core_plugins/kibana/common/field_formats/types/source.js b/src/core_plugins/kibana/common/field_formats/types/source.js index 98712d1be4d9d..f686a357427af 100644 --- a/src/core_plugins/kibana/common/field_formats/types/source.js +++ b/src/core_plugins/kibana/common/field_formats/types/source.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { noWhiteSpace } from '../../utils/no_white_space'; import { toJson } from '../../utils/aggressive_parse'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; import { shortenDottedString } from '../../utils/shorten_dotted_string'; const templateHtml = ` diff --git a/src/core_plugins/kibana/common/field_formats/types/string.js b/src/core_plugins/kibana/common/field_formats/types/string.js index 944bc32170d79..6df77b74420a5 100644 --- a/src/core_plugins/kibana/common/field_formats/types/string.js +++ b/src/core_plugins/kibana/common/field_formats/types/string.js @@ -1,5 +1,5 @@ import { asPrettyString } from '../../utils/as_pretty_string'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; import { shortenDottedString } from '../../utils/shorten_dotted_string'; export class StringFormat extends FieldFormat { diff --git a/src/core_plugins/kibana/common/field_formats/types/truncate.js b/src/core_plugins/kibana/common/field_formats/types/truncate.js index 2bd2793b41d40..3432dee63e216 100644 --- a/src/core_plugins/kibana/common/field_formats/types/truncate.js +++ b/src/core_plugins/kibana/common/field_formats/types/truncate.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; const omission = '...'; diff --git a/src/core_plugins/kibana/common/field_formats/types/url.js b/src/core_plugins/kibana/common/field_formats/types/url.js index 5a49eab2f7ee2..07ffd1ed76259 100644 --- a/src/core_plugins/kibana/common/field_formats/types/url.js +++ b/src/core_plugins/kibana/common/field_formats/types/url.js @@ -1,5 +1,5 @@ import _ from 'lodash'; -import { FieldFormat } from '../field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; import { getHighlightHtml } from '../../highlight/highlight_html'; const templateMatchRE = /{{([\s\S]+?)}}/g; diff --git a/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js b/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js index 2488edf2e105d..3e5e2657f4df4 100644 --- a/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js +++ b/src/core_plugins/kibana/public/field_formats/__tests__/_conformance.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import expect from 'expect.js'; import ngMock from 'ng_mock'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; -import { FieldFormat } from '../../../common/field_formats/field_format'; +import { FieldFormat } from '../../../../../ui/field_formats/field_format'; let fieldFormats; let config; diff --git a/src/core_plugins/kibana/common/field_formats/__tests__/field_format.js b/src/ui/field_formats/__tests__/field_format.js similarity index 98% rename from src/core_plugins/kibana/common/field_formats/__tests__/field_format.js rename to src/ui/field_formats/__tests__/field_format.js index c25a55f95f278..b4ccf83012dc1 100644 --- a/src/core_plugins/kibana/common/field_formats/__tests__/field_format.js +++ b/src/ui/field_formats/__tests__/field_format.js @@ -1,6 +1,6 @@ import _ from 'lodash'; import expect from 'expect.js'; -import { asPrettyString } from '../../utils/as_pretty_string'; +import { asPrettyString } from '../../../core_plugins/kibana/common/utils/as_pretty_string'; import { FieldFormat } from '../field_format'; describe('FieldFormat class', function () { diff --git a/src/core_plugins/kibana/common/field_formats/content_types.js b/src/ui/field_formats/content_types.js similarity index 89% rename from src/core_plugins/kibana/common/field_formats/content_types.js rename to src/ui/field_formats/content_types.js index 78f2e3d1aec6d..8371d7fa9dd3c 100644 --- a/src/core_plugins/kibana/common/field_formats/content_types.js +++ b/src/ui/field_formats/content_types.js @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { asPrettyString } from '../utils/as_pretty_string'; -import { getHighlightHtml } from '../highlight/highlight_html'; +import { asPrettyString } from '../../core_plugins/kibana/common/utils/as_pretty_string'; +import { getHighlightHtml } from '../../core_plugins/kibana/common/highlight/highlight_html'; const types = { html: function (format, convert) { diff --git a/src/core_plugins/kibana/common/field_formats/field_format.js b/src/ui/field_formats/field_format.js similarity index 100% rename from src/core_plugins/kibana/common/field_formats/field_format.js rename to src/ui/field_formats/field_format.js diff --git a/src/ui/public/agg_types/buckets/range.js b/src/ui/public/agg_types/buckets/range.js index 8dd5d64ace8db..dbbc6d96ce0ff 100644 --- a/src/ui/public/agg_types/buckets/range.js +++ b/src/ui/public/agg_types/buckets/range.js @@ -1,6 +1,6 @@ import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type'; import { AggTypesBucketsCreateFilterRangeProvider } from 'ui/agg_types/buckets/create_filter/range'; -import { FieldFormat } from '../../../../core_plugins/kibana/common/field_formats/field_format'; +import { FieldFormat } from '../../../field_formats/field_format'; import { RangeKeyProvider } from './range_key'; import rangesTemplate from 'ui/agg_types/controls/ranges.html'; diff --git a/src/ui/public/index_patterns/_field.js b/src/ui/public/index_patterns/_field.js index b0282ca87d8ce..58a6849d8f814 100644 --- a/src/ui/public/index_patterns/_field.js +++ b/src/ui/public/index_patterns/_field.js @@ -1,5 +1,5 @@ import { ObjDefine } from 'ui/utils/obj_define'; -import { FieldFormat } from '../../../core_plugins/kibana/common/field_formats/field_format'; +import { FieldFormat } from '../../field_formats/field_format'; import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats'; import { getKbnFieldType } from '../../../utils';