diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js index ade71b4a5c228..1903a12e5bdaa 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/boolean.js @@ -17,7 +17,7 @@ * under the License. */ -import { asPrettyString } from '../../utils/as_pretty_string'; +import { asPrettyString } from '../../../../../../plugins/data/common/utils/as_pretty_string'; export function createBoolFormat(FieldFormat) { return class BoolFormat extends FieldFormat { diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/color.js b/src/legacy/core_plugins/kibana/common/field_formats/types/color.js index be7c92bc80ade..be66ef448dbfb 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/color.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/color.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import { asPrettyString } from '../../utils/as_pretty_string'; +import { asPrettyString } from '../../../../../../plugins/data/common/utils/as_pretty_string'; import { DEFAULT_COLOR } from './color_default'; const convertTemplate = _.template('<%- val %>'); diff --git a/src/legacy/core_plugins/kibana/common/field_formats/types/string.js b/src/legacy/core_plugins/kibana/common/field_formats/types/string.js index 9440f740c7659..c6fc1436e57b3 100644 --- a/src/legacy/core_plugins/kibana/common/field_formats/types/string.js +++ b/src/legacy/core_plugins/kibana/common/field_formats/types/string.js @@ -17,7 +17,7 @@ * under the License. */ -import { asPrettyString } from '../../utils/as_pretty_string'; +import { asPrettyString } from '../../../../../../plugins/data/common/utils/as_pretty_string'; import { shortenDottedString } from '../../utils/shorten_dotted_string'; const TRANSFORM_OPTIONS = [ diff --git a/src/legacy/ui/field_formats/content_types/html_content_type.ts b/src/legacy/ui/field_formats/content_types/html_content_type.ts index 3253ea5f60126..d5e042f3191d0 100644 --- a/src/legacy/ui/field_formats/content_types/html_content_type.ts +++ b/src/legacy/ui/field_formats/content_types/html_content_type.ts @@ -18,10 +18,8 @@ */ import { escape, isFunction } from 'lodash'; import { FieldFormatConvert, IFieldFormat, HtmlConventTypeConvert } from '../types'; - -// @ts-ignore -import { asPrettyString } from '../../../core_plugins/kibana/common/utils/as_pretty_string'; import { getHighlightHtml } from '../../../../plugins/data/common/highlight/highlight_html'; +import { asPrettyString } from '../../../../plugins/data/common/utils/as_pretty_string'; const CONTEXT_TYPE = 'html'; diff --git a/src/legacy/ui/field_formats/content_types/text_content_type.ts b/src/legacy/ui/field_formats/content_types/text_content_type.ts index 0a6983f8f1a87..a0f720d51be19 100644 --- a/src/legacy/ui/field_formats/content_types/text_content_type.ts +++ b/src/legacy/ui/field_formats/content_types/text_content_type.ts @@ -19,9 +19,7 @@ import { isFunction } from 'lodash'; import { IFieldFormat, FieldFormatConvert, TextContextTypeConvert } from '../types'; - -// @ts-ignore -import { asPrettyString } from '../../../core_plugins/kibana/common/utils/as_pretty_string'; +import { asPrettyString } from '../../../../plugins/data/common/utils/as_pretty_string'; const CONTEXT_TYPE = 'text'; diff --git a/src/legacy/ui/field_formats/field_format.test.ts b/src/legacy/ui/field_formats/field_format.test.ts index 05912d5b5f4a8..9952870a8b680 100644 --- a/src/legacy/ui/field_formats/field_format.test.ts +++ b/src/legacy/ui/field_formats/field_format.test.ts @@ -20,9 +20,7 @@ import { constant, trimRight, trimLeft, get } from 'lodash'; import { FieldFormat } from './field_format'; import { FieldFormatConvert } from './types'; - -// @ts-ignore -import { asPrettyString } from '../../core_plugins/kibana/common/utils/as_pretty_string'; +import { asPrettyString } from '../../../plugins/data/common/utils/as_pretty_string'; const getTestFormat = ( _convert: FieldFormatConvert = { diff --git a/src/legacy/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js b/src/plugins/data/common/utils/as_pretty_string.test.ts similarity index 57% rename from src/legacy/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js rename to src/plugins/data/common/utils/as_pretty_string.test.ts index 723b3ccf0c596..fe9f62a2c681d 100644 --- a/src/legacy/core_plugins/kibana/common/utils/__tests__/as_pretty_string.js +++ b/src/plugins/data/common/utils/as_pretty_string.test.ts @@ -17,28 +17,25 @@ * under the License. */ -import expect from '@kbn/expect'; -import { asPrettyString } from '../as_pretty_string'; +import { asPrettyString } from './as_pretty_string'; describe('asPrettyString', () => { - - it('Converts null and undefined values into a string signifying no value', () => { - expect(asPrettyString(null)).to.equal(' - '); - expect(asPrettyString(undefined)).to.equal(' - '); + test('Converts null and undefined values into a string signifying no value', () => { + expect(asPrettyString(null)).toBe(' - '); + expect(asPrettyString(undefined)).toBe(' - '); }); - it('Does not mutate string values', () => { + test('Does not mutate string values', () => { const s = 'I am a string!@'; - expect(asPrettyString(s)).to.equal(s); + expect(asPrettyString(s)).toBe(s); }); - it('Converts objects values into presentable strings', () => { - expect(asPrettyString({ key: 'value' })).to.equal('{\n "key": "value"\n}'); + test('Converts objects values into presentable strings', () => { + expect(asPrettyString({ key: 'value' })).toBe('{\n "key": "value"\n}'); }); - it('Converts other non-string values into strings', () => { - expect(asPrettyString(true)).to.equal('true'); - expect(asPrettyString(123)).to.equal('123'); + test('Converts other non-string values into strings', () => { + expect(asPrettyString(true)).toBe('true'); + expect(asPrettyString(123)).toBe('123'); }); - }); diff --git a/src/legacy/core_plugins/kibana/common/utils/as_pretty_string.js b/src/plugins/data/common/utils/as_pretty_string.ts similarity index 80% rename from src/legacy/core_plugins/kibana/common/utils/as_pretty_string.js rename to src/plugins/data/common/utils/as_pretty_string.ts index e2aac9f6edceb..0bd3080377165 100644 --- a/src/legacy/core_plugins/kibana/common/utils/as_pretty_string.js +++ b/src/plugins/data/common/utils/as_pretty_string.ts @@ -19,14 +19,15 @@ /** * Convert a value to a presentable string - * @param {any} val - the value to transform - * @return {string} */ -export function asPrettyString(val) { +export function asPrettyString(val: any): string { if (val === null || val === undefined) return ' - '; switch (typeof val) { - case 'string': return val; - case 'object': return JSON.stringify(val, null, ' '); - default: return '' + val; + case 'string': + return val; + case 'object': + return JSON.stringify(val, null, ' '); + default: + return '' + val; } }