mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* de-angularize indexPatterns Field and FieldList * do not remove shortDots angular filter * remove ui/chrome mock in _index_pattern test
This commit is contained in:
parent
38c44389cf
commit
5fae20eec0
9 changed files with 95 additions and 137 deletions
|
@ -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: {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
}));
|
||||
|
|
|
@ -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;
|
||||
|
||||
// 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);
|
||||
|
||||
if (spec.name === '_source') {
|
||||
spec.type = '_source';
|
||||
}
|
||||
|
||||
// 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 + '"'
|
||||
);
|
||||
}
|
||||
|
||||
if (!type) type = getKbnFieldType('unknown');
|
||||
|
||||
let format = spec.format;
|
||||
if (!format || !(format instanceof FieldFormat)) {
|
||||
format = indexPattern.fieldFormatMap[spec.name] || fieldFormats.getDefaultInstance(spec.type);
|
||||
}
|
||||
|
||||
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();
|
||||
if (spec.name === '_source') {
|
||||
spec.type = '_source';
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
},
|
||||
});
|
||||
// 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.`
|
||||
});
|
||||
}
|
||||
|
||||
Field.prototype.routes = {
|
||||
edit: '/management/kibana/indices/{{indexPattern.id}}/field/{{name}}'
|
||||
};
|
||||
if (!type) type = getKbnFieldType('unknown');
|
||||
|
||||
return Field;
|
||||
let format = spec.format;
|
||||
if (!format || !(format instanceof FieldFormat)) {
|
||||
format = indexPattern.fieldFormatMap[spec.name] || fieldFormats.getDefaultInstance(spec.type);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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}}'
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<dl class="source truncate-by-height">
|
||||
<% _.each(highlight, function (value, field) { /* show fields that match the query first */ %>
|
||||
<dt><%- shortDotsFilter(field) %>:</dt>
|
||||
<dd><%= source[field] %></dd>
|
||||
<%= ' ' %>
|
||||
<% }); %>
|
||||
<% _.each(source, function (value, field) { %>
|
||||
<% if (_.has(highlight, field)) return; %>
|
||||
<dt><%- shortDotsFilter(field) %>:</dt>
|
||||
<dd><%= value %></dd>
|
||||
<%= ' ' %>
|
||||
<% }); %>
|
||||
</dl>
|
|
@ -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';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue