diff --git a/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js b/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js index 5734ddfe0148c..c16a78de82f21 100644 --- a/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js +++ b/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js @@ -26,14 +26,12 @@ import _ from 'lodash'; import $ from 'jquery'; import rison from 'rison-node'; import { fieldCalculator } from './lib/field_calculator'; -import { IndexPatternsFieldListProvider } from 'ui/index_patterns/_field_list'; +import { FieldList } from 'ui/index_patterns/_field_list'; import { uiModules } from 'ui/modules'; import fieldChooserTemplate from './field_chooser.html'; const app = uiModules.get('apps/discover'); -app.directive('discFieldChooser', function ($location, globalState, config, $route, Private) { - const FieldList = Private(IndexPatternsFieldListProvider); - +app.directive('discFieldChooser', function ($location, globalState, config, $route) { return { restrict: 'E', scope: { diff --git a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/create_edit_field/create_edit_field.js b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/create_edit_field/create_edit_field.js index 89582ddd84e3f..f6bfce959e87c 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/create_edit_field/create_edit_field.js +++ b/src/core_plugins/kibana/public/management/sections/indices/edit_index_pattern/create_edit_field/create_edit_field.js @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPatternsFieldProvider } from 'ui/index_patterns/_field'; +import { Field } from 'ui/index_patterns/_field'; import { RegistryFieldFormatEditorsProvider } from 'ui/registry/field_format_editors'; import { KbnUrlProvider } from 'ui/url'; import uiRoutes from 'ui/routes'; @@ -90,7 +90,6 @@ uiRoutes }, controllerAs: 'fieldSettings', controller: function FieldEditorPageController($scope, $route, $timeout, $http, Private, docTitle, config) { - const Field = Private(IndexPatternsFieldProvider); const getConfig = (...args) => config.get(...args); const fieldFormatEditors = Private(RegistryFieldFormatEditorsProvider); const kbnUrl = Private(KbnUrlProvider); diff --git a/src/test_utils/public/stub_index_pattern.js b/src/test_utils/public/stub_index_pattern.js index 7b1115076abf3..ef4caf60bde46 100644 --- a/src/test_utils/public/stub_index_pattern.js +++ b/src/test_utils/public/stub_index_pattern.js @@ -25,12 +25,11 @@ import { formatHit } from 'ui/index_patterns/_format_hit'; import { getComputedFields } from 'ui/index_patterns/_get_computed_fields'; import { fieldFormats } from 'ui/registry/field_formats'; import { IndexPatternsFlattenHitProvider } from 'ui/index_patterns/_flatten_hit'; -import { IndexPatternsFieldListProvider } from 'ui/index_patterns/_field_list'; +import { FieldList } from 'ui/index_patterns/_field_list'; export default function (Private) { const flattenHit = Private(IndexPatternsFlattenHitProvider); - const FieldList = Private(IndexPatternsFieldListProvider); const IndexPattern = Private(IndexPatternProvider); function StubIndexPattern(pattern, timeField, fields) { diff --git a/src/ui/public/index_patterns/__tests__/_index_pattern.test.js b/src/ui/public/index_patterns/__tests__/_index_pattern.test.js index 1dc27f1bf58e7..c005408f28832 100644 --- a/src/ui/public/index_patterns/__tests__/_index_pattern.test.js +++ b/src/ui/public/index_patterns/__tests__/_index_pattern.test.js @@ -63,18 +63,6 @@ jest.mock('../_intervals', () => ({ IndexPatternsIntervalsProvider: jest.fn(), })); -jest.mock('../_field_list', () => ({ - IndexPatternsFieldListProvider: jest.fn().mockImplementation((pattern) => { - return { - byName: { - id: { value: pattern.id }, - title: { value: pattern.title }, - }, - every: jest.fn(), - }; - }) -})); - jest.mock('../_flatten_hit', () => ({ IndexPatternsFlattenHitProvider: jest.fn(), })); diff --git a/src/ui/public/index_patterns/_field.js b/src/ui/public/index_patterns/_field.js index b4fc93817a885..762ebfe1d7087 100644 --- a/src/ui/public/index_patterns/_field.js +++ b/src/ui/public/index_patterns/_field.js @@ -21,102 +21,97 @@ import { ObjDefine } from '../utils/obj_define'; import { FieldFormat } from '../../field_formats/field_format'; import { fieldFormats } from '../registry/field_formats'; import { getKbnFieldType } from '../../../utils'; +import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string'; +import { toastNotifications } from 'ui/notify'; +import chrome from 'ui/chrome'; -export function IndexPatternsFieldProvider(Private, shortDotsFilter, $rootScope, Notifier) { - const notify = new Notifier({ location: 'IndexPattern Field' }); +export function Field(indexPattern, spec) { + // unwrap old instances of Field + if (spec instanceof Field) spec = spec.$$spec; + // construct this object using ObjDefine class, which + // extends the Field.prototype but gets it's properties + // defined using the logic below + const obj = new ObjDefine(spec, Field.prototype); - function Field(indexPattern, spec) { - // unwrap old instances of Field - if (spec instanceof Field) spec = spec.$$spec; + if (spec.name === '_source') { + spec.type = '_source'; + } - // construct this object using ObjDefine class, which - // extends the Field.prototype but gets it's properties - // defined using the logic below - const obj = new ObjDefine(spec, Field.prototype); + // find the type for this field, fallback to unknown type + let type = getKbnFieldType(spec.type); + if (spec.type && !type) { + toastNotifications.addDanger({ + title: `Unknown field type ${spec.type}`, + text: `Field ${spec.name} in indexPattern ${indexPattern.title} is using an unknown field type.` + }); + } - if (spec.name === '_source') { - spec.type = '_source'; - } + if (!type) type = getKbnFieldType('unknown'); - // find the type for this field, fallback to unknown type - let type = getKbnFieldType(spec.type); - if (spec.type && !type) { - notify.error( - 'Unknown field type "' + spec.type + '"' + - ' for field "' + spec.name + '"' + - ' in indexPattern "' + indexPattern.title + '"' - ); - } + let format = spec.format; + if (!format || !(format instanceof FieldFormat)) { + format = indexPattern.fieldFormatMap[spec.name] || fieldFormats.getDefaultInstance(spec.type); + } - if (!type) type = getKbnFieldType('unknown'); + const indexed = !!spec.indexed; + const scripted = !!spec.scripted; + const searchable = !!spec.searchable || scripted; + const aggregatable = !!spec.aggregatable || scripted; + const readFromDocValues = !!spec.readFromDocValues && !scripted; + const sortable = spec.name === '_score' || ((indexed || aggregatable) && type.sortable); + const filterable = spec.name === '_id' || scripted || ((indexed || searchable) && type.filterable); + const visualizable = aggregatable; + + obj.fact('name'); + obj.fact('type'); + obj.writ('count', spec.count || 0); + + // scripted objs + obj.fact('scripted', scripted); + obj.writ('script', scripted ? spec.script : null); + obj.writ('lang', scripted ? (spec.lang || 'painless') : null); + + // stats + obj.fact('searchable', searchable); + obj.fact('aggregatable', aggregatable); + obj.fact('readFromDocValues', readFromDocValues); + + // usage flags, read-only and won't be saved + obj.comp('format', format); + obj.comp('sortable', sortable); + obj.comp('filterable', filterable); + obj.comp('visualizable', visualizable); + + // computed values + obj.comp('indexPattern', indexPattern); + obj.comp('displayName', chrome.getUiSettingsClient().get('shortDots:enable') ? shortenDottedString(spec.name) : spec.name); + obj.comp('$$spec', spec); + + // conflict info + obj.writ('conflictDescriptions'); + + return obj.create(); +} - let format = spec.format; - if (!format || !(format instanceof FieldFormat)) { - format = indexPattern.fieldFormatMap[spec.name] || fieldFormats.getDefaultInstance(spec.type); +Object.defineProperties(Field.prototype, { + indexed: { + get() { + throw new Error('field.indexed has been removed, see https://github.com/elastic/kibana/pull/11969'); } + }, + analyzed: { + get() { + throw new Error('field.analyzed has been removed, see https://github.com/elastic/kibana/pull/11969'); + } + }, + doc_values: { + get() { + throw new Error('field.doc_values has been removed, see https://github.com/elastic/kibana/pull/11969'); + } + }, +}); - const indexed = !!spec.indexed; - const scripted = !!spec.scripted; - const searchable = !!spec.searchable || scripted; - const aggregatable = !!spec.aggregatable || scripted; - const readFromDocValues = !!spec.readFromDocValues && !scripted; - const sortable = spec.name === '_score' || ((indexed || aggregatable) && type.sortable); - const filterable = spec.name === '_id' || scripted || ((indexed || searchable) && type.filterable); - const visualizable = aggregatable; - - obj.fact('name'); - obj.fact('type'); - obj.writ('count', spec.count || 0); - - // scripted objs - obj.fact('scripted', scripted); - obj.writ('script', scripted ? spec.script : null); - obj.writ('lang', scripted ? (spec.lang || 'painless') : null); - - // stats - obj.fact('searchable', searchable); - obj.fact('aggregatable', aggregatable); - obj.fact('readFromDocValues', readFromDocValues); - - // usage flags, read-only and won't be saved - obj.comp('format', format); - obj.comp('sortable', sortable); - obj.comp('filterable', filterable); - obj.comp('visualizable', visualizable); - - // computed values - obj.comp('indexPattern', indexPattern); - obj.comp('displayName', shortDotsFilter(spec.name)); - obj.comp('$$spec', spec); - - // conflict info - obj.writ('conflictDescriptions'); - - return obj.create(); - } - - Object.defineProperties(Field.prototype, { - indexed: { - get() { - throw new Error('field.indexed has been removed, see https://github.com/elastic/kibana/pull/11969'); - } - }, - analyzed: { - get() { - throw new Error('field.analyzed has been removed, see https://github.com/elastic/kibana/pull/11969'); - } - }, - doc_values: { - get() { - throw new Error('field.doc_values has been removed, see https://github.com/elastic/kibana/pull/11969'); - } - }, - }); - - Field.prototype.routes = { - edit: '/management/kibana/indices/{{indexPattern.id}}/field/{{name}}' - }; - - return Field; -} +Field.prototype.routes = { + edit: '/management/kibana/indices/{{indexPattern.id}}/field/{{name}}' +}; diff --git a/src/ui/public/index_patterns/_field_list.js b/src/ui/public/index_patterns/_field_list.js index 90152df587fc6..8963b92d9a008 100644 --- a/src/ui/public/index_patterns/_field_list.js +++ b/src/ui/public/index_patterns/_field_list.js @@ -18,15 +18,11 @@ */ import { IndexedArray } from '../indexed_array'; -import { IndexPatternsFieldProvider } from './_field'; -import { createLegacyClass } from '../utils/legacy_class'; +import { Field } from './_field'; -export function IndexPatternsFieldListProvider(Private) { - const Field = Private(IndexPatternsFieldProvider); - - createLegacyClass(FieldList).inherits(IndexedArray); - function FieldList(indexPattern, specs) { - FieldList.Super.call(this, { +export class FieldList extends IndexedArray { + constructor(indexPattern, specs) { + super({ index: ['name'], group: ['type'], initialSet: specs.map(function (field) { @@ -34,6 +30,4 @@ export function IndexPatternsFieldListProvider(Private) { }) }); } - - return FieldList; } diff --git a/src/ui/public/index_patterns/_index_pattern.js b/src/ui/public/index_patterns/_index_pattern.js index 879b3b2838322..8010d38d146d9 100644 --- a/src/ui/public/index_patterns/_index_pattern.js +++ b/src/ui/public/index_patterns/_index_pattern.js @@ -28,7 +28,7 @@ import { getComputedFields } from './_get_computed_fields'; import { formatHit } from './_format_hit'; import { IndexPatternsGetProvider } from './_get'; import { IndexPatternsIntervalsProvider } from './_intervals'; -import { IndexPatternsFieldListProvider } from './_field_list'; +import { FieldList } from './_field_list'; import { IndexPatternsFlattenHitProvider } from './_flatten_hit'; import { IndexPatternsPatternCacheProvider } from './_pattern_cache'; import { FieldsFetcherProvider } from './fields_fetcher_provider'; @@ -53,7 +53,6 @@ export function IndexPatternProvider(Private, config, Promise, confirmModalPromi const fieldsFetcher = Private(FieldsFetcherProvider); const intervals = Private(IndexPatternsIntervalsProvider); const mappingSetup = Private(UtilsMappingSetupProvider); - const FieldList = Private(IndexPatternsFieldListProvider); const flattenHit = Private(IndexPatternsFlattenHitProvider); const patternCache = Private(IndexPatternsPatternCacheProvider); const isUserAwareOfUnsupportedTimePattern = Private(IsUserAwareOfUnsupportedTimePatternProvider); diff --git a/src/ui/public/index_patterns/_object.tmpl.html b/src/ui/public/index_patterns/_object.tmpl.html deleted file mode 100644 index 86bfe8ca40865..0000000000000 --- a/src/ui/public/index_patterns/_object.tmpl.html +++ /dev/null @@ -1,13 +0,0 @@ -
- <% _.each(highlight, function (value, field) { /* show fields that match the query first */ %> -
<%- shortDotsFilter(field) %>:
-
<%= source[field] %>
- <%= ' ' %> - <% }); %> - <% _.each(source, function (value, field) { %> - <% if (_.has(highlight, field)) return; %> -
<%- shortDotsFilter(field) %>:
-
<%= value %>
- <%= ' ' %> - <% }); %> -
diff --git a/src/ui/public/index_patterns/index_patterns.js b/src/ui/public/index_patterns/index_patterns.js index 4db349929df36..6766f63df8d33 100644 --- a/src/ui/public/index_patterns/index_patterns.js +++ b/src/ui/public/index_patterns/index_patterns.js @@ -17,7 +17,6 @@ * under the License. */ -import '../filters/short_dots'; import { IndexPatternMissingIndices } from '../errors'; import { IndexPatternProvider } from './_index_pattern'; import { IndexPatternsPatternCacheProvider } from './_pattern_cache';