-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove private module dependencies from field formatters (#12239)
* remove Private module loader from FieldFormat * remove dependency on bound_to_config_obj * update field_formats registry getDefaultInstanc and getInstance to pass getConfig to FieldFormat constructors * make previous changes work * remove paramDefaults state from FieldFormat class, instead use getter * remove use of shortDotsFilter in source field formatter * fix broken tests * remove angular dependency from field formatters * fix _conformance test * getConfig service and replace with inline function * remove unneeded ngMock from __tests__/_field_format.js * use JSON.stringify in content_types instead of aggressive_parse.tojson because function is only converting an array of strings to into a string * pass getParamDefaults to _numeral in opts argument * update field format editors to handle moving paramDefaults from class to instance via getter * remove unneeded reference to self * change to arrow functions * change content_type export from object to only the setup function * remove unneeded function block around simple arrow function
- Loading branch information
Showing
26 changed files
with
291 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 46 additions & 55 deletions
101
src/ui/public/index_patterns/_field_format/content_types.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,64 @@ | ||
import _ from 'lodash'; | ||
import angular from 'angular'; | ||
import { getHighlightHtml } from 'ui/highlight'; | ||
|
||
export function IndexPatternsFieldFormatContentTypesProvider() { | ||
|
||
const types = { | ||
html: function (format, convert) { | ||
function recurse(value, field, hit) { | ||
if (value == null) { | ||
return _.asPrettyString(value); | ||
} | ||
|
||
if (!value || typeof value.map !== 'function') { | ||
return convert.call(format, value, field, hit); | ||
} | ||
|
||
const subVals = value.map(function (v) { | ||
return recurse(v, field, hit); | ||
}); | ||
const useMultiLine = subVals.some(function (sub) { | ||
return sub.indexOf('\n') > -1; | ||
}); | ||
|
||
return subVals.join(',' + (useMultiLine ? '\n' : ' ')); | ||
const types = { | ||
html: function (format, convert) { | ||
function recurse(value, field, hit) { | ||
if (value == null) { | ||
return _.asPrettyString(value); | ||
} | ||
|
||
return function (...args) { | ||
return `<span ng-non-bindable>${recurse(...args)}</span>`; | ||
}; | ||
}, | ||
if (!value || typeof value.map !== 'function') { | ||
return convert.call(format, value, field, hit); | ||
} | ||
|
||
text: function (format, convert) { | ||
return function recurse(value) { | ||
if (!value || typeof value.map !== 'function') { | ||
return convert.call(format, value); | ||
} | ||
const subVals = value.map(v => { | ||
return recurse(v, field, hit); | ||
}); | ||
const useMultiLine = subVals.some(sub => { | ||
return sub.indexOf('\n') > -1; | ||
}); | ||
|
||
// format a list of values. In text contexts we just use JSON encoding | ||
return angular.toJson(value.map(recurse), true); | ||
}; | ||
return subVals.join(',' + (useMultiLine ? '\n' : ' ')); | ||
} | ||
}; | ||
|
||
function fallbackText(value) { | ||
return _.asPrettyString(value); | ||
} | ||
return function (...args) { | ||
return `<span ng-non-bindable>${recurse(...args)}</span>`; | ||
}; | ||
}, | ||
|
||
function fallbackHtml(value, field, hit) { | ||
const formatted = _.escape(this.convert(value, 'text')); | ||
text: function (format, convert) { | ||
return function recurse(value) { | ||
if (!value || typeof value.map !== 'function') { | ||
return convert.call(format, value); | ||
} | ||
|
||
if (!hit || !hit.highlight || !hit.highlight[field.name]) { | ||
return formatted; | ||
} else { | ||
return getHighlightHtml(formatted, hit.highlight[field.name]); | ||
} | ||
// format a list of values. In text contexts we just use JSON encoding | ||
return JSON.stringify(value.map(recurse)); | ||
}; | ||
} | ||
}; | ||
|
||
function setup(format) { | ||
const src = format._convert || {}; | ||
const converters = format._convert = {}; | ||
function fallbackText(value) { | ||
return _.asPrettyString(value); | ||
} | ||
|
||
converters.text = types.text(format, src.text || fallbackText); | ||
converters.html = types.html(format, src.html || fallbackHtml); | ||
function fallbackHtml(value, field, hit) { | ||
const formatted = _.escape(this.convert(value, 'text')); | ||
|
||
return format._convert; | ||
if (!hit || !hit.highlight || !hit.highlight[field.name]) { | ||
return formatted; | ||
} else { | ||
return getHighlightHtml(formatted, hit.highlight[field.name]); | ||
} | ||
} | ||
|
||
export function contentTypesSetup(format) { | ||
const src = format._convert || {}; | ||
const converters = format._convert = {}; | ||
|
||
converters.text = types.text(format, src.text || fallbackText); | ||
converters.html = types.html(format, src.html || fallbackHtml); | ||
|
||
return { | ||
types: types, | ||
setup: setup | ||
}; | ||
return format._convert; | ||
} |
Oops, something went wrong.