Merge pull request #8729 from elastic/jasper/backport/8717/5.x

[backport] PR #8717 to 5.x
This commit is contained in:
Spencer 2016-10-19 11:54:19 -07:00 committed by GitHub
commit b4521f5e15
29 changed files with 55 additions and 51 deletions

View file

@ -14,12 +14,12 @@ describe('collectBranch()', function () {
depth: 3,
size: 6,
field: { format: { convert: convert } },
aggConfig: { params: { field: { displayName: 'field3' } }, fieldFormatter: _.constant(String) },
aggConfig: { getFieldDisplayName: _.constant('field3'), fieldFormatter: _.constant(String) },
parent: {
name: 'bucket2',
depth: 2,
size: 12,
aggConfig: { label: 'field2', fieldFormatter: _.constant(String) },
aggConfig: { fieldFormatter: _.constant(String), getFieldDisplayName: _.constant('field2') },
parent: {
name: 'bucket1',
depth: 1,

View file

@ -8,14 +8,14 @@ define(function () {
// Using the aggConfig determine what the field name is. If the aggConfig
// doesn't exist (which means it's an _all agg) then use the level for
// the field name
let col = item.aggConfig;
let field = (col && col.params && col.params.field && col.params.field.displayName)
|| (col && col.label)
const { aggConfig } = item;
let field = (aggConfig && aggConfig.getFieldDisplayName())
|| (aggConfig && aggConfig.label)
|| ('level ' + item.depth);
// Add the row to the tooltipScope.rows
memo.unshift({
aggConfig: col,
aggConfig,
depth: depth,
field: field,
bucket: item.name,

View file

@ -73,7 +73,7 @@ export default function buildHierarchicalDataProvider(Private, Notifier) {
// Since splits display labels we need to set it.
split.label = firstAgg.fieldFormatter()(agg.getKey(bucket));
let displayName = firstAgg.fieldDisplayName();
let displayName = firstAgg.getFieldDisplayName();
if (!_.isEmpty(displayName)) split.label += ': ' + displayName;
split.tooltipFormatter = tooltipFormatter(raw.columns);

View file

@ -54,12 +54,12 @@ describe('Table class', function () {
});
describe('#field', function () {
it('calls the columns aggConfig#field() method', function () {
it('calls the columns aggConfig#getField() method', function () {
let table = new Table();
let football = {};
let column = {
aggConfig: {
field: _.constant(football)
getField: _.constant(football)
}
};

View file

@ -26,7 +26,7 @@ export default function TableProvider() {
};
Table.prototype.field = function (col) {
return this.aggConfig(col).field();
return this.aggConfig(col).getField();
};
Table.prototype.fieldFormatter = function (col) {

View file

@ -13,7 +13,7 @@ export default function TableGroupProvider() {
}
TableGroup.prototype.field = function () {
if (this.aggConfig) return this.aggConfig.field();
if (this.aggConfig) return this.aggConfig.getField();
};
TableGroup.prototype.fieldFormatter = function () {

View file

@ -83,7 +83,7 @@ uiModules
$scope.rows = table.rows;
$scope.formattedColumns = table.columns.map(function (col, i) {
let agg = $scope.table.aggConfig(col);
let field = agg.field();
let field = agg.getField();
let formattedColumn = {
title: col.title,
filterable: field && field.filterable && agg.schema.group === 'buckets'

View file

@ -142,7 +142,7 @@ export default function AggTypeFactory(Private) {
* @return {FieldFromat}
*/
AggType.prototype.getFormat = function (agg) {
let field = agg.field();
let field = agg.getField();
return field ? field.format : fieldFormats.getDefaultInstance('string');
};

View file

@ -41,7 +41,7 @@ export default function DateHistogramAggType(timefilter, config, Private) {
makeLabel: function (agg) {
const output = this.params.write(agg);
const params = output.params;
const field = params.field || _.get(agg, 'params.field.displayName', '');
const field = agg.getFieldDisplayName();
return field + ' per ' + (output.metricScaleText || output.bucketInterval.description);
},
createFilter: createFilter,

View file

@ -24,7 +24,7 @@ export default function DateRangeAggDefinition(Private, config) {
return fieldFormats.getDefaultInstance('string');
},
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName + ' date ranges';
return aggConfig.getFieldDisplayName() + ' date ranges';
},
params: [{
name: 'field',

View file

@ -16,7 +16,7 @@ export default function HistogramAggDefinition(Private) {
title: 'Histogram',
ordered: {},
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName;
return aggConfig.getFieldDisplayName();
},
createFilter: createFilter,
params: [

View file

@ -14,7 +14,7 @@ export default function RangeAggDefinition(Private) {
title: 'IPv4 Range',
createFilter: createFilter,
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName + ' IP ranges';
return aggConfig.getFieldDisplayName() + ' IP ranges';
},
params: [
{

View file

@ -18,7 +18,7 @@ export default function RangeAggDefinition(Private) {
title: 'Range',
createFilter: createFilter,
makeLabel: function (aggConfig) {
return aggConfig.params.field.displayName + ' ranges';
return aggConfig.getFieldDisplayName() + ' ranges';
},
getKey: function (bucket, key, agg) {
let keys = keyCaches.get(agg);

View file

@ -10,7 +10,7 @@ export default function SignificantTermsAggDefinition(Private) {
name: 'significant_terms',
title: 'Significant Terms',
makeLabel: function (aggConfig) {
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.displayName;
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.getFieldDisplayName();
},
createFilter: createFilter,
params: [

View file

@ -37,7 +37,7 @@ export default function TermsAggDefinition(Private) {
title: 'Terms',
makeLabel: function (agg) {
let params = agg.params;
return params.field.displayName + ': ' + params.order.display;
return agg.getFieldDisplayName() + ': ' + params.order.display;
},
createFilter: createFilter,
params: [
@ -143,7 +143,7 @@ export default function TermsAggDefinition(Private) {
// thus causing issues with filtering. This probably causes other issues since float might not
// be able to contain the number on the elasticsearch side
if (output.params.script) {
output.params.valueType = agg.field().type === 'number' ? 'float' : agg.field().type;
output.params.valueType = agg.getField().type === 'number' ? 'float' : agg.getField().type;
}
if (!orderAgg) {

View file

@ -7,7 +7,7 @@ export default function AggTypeMetricAvgProvider(Private) {
name: 'avg',
title: 'Average',
makeLabel: function (aggConfig) {
return 'Average ' + aggConfig.params.field.displayName;
return 'Average ' + aggConfig.getFieldDisplayName();
},
params: [
{

View file

@ -9,7 +9,7 @@ export default function AggTypeMetricCardinalityProvider(Private) {
name: 'cardinality',
title: 'Unique Count',
makeLabel: function (aggConfig) {
return 'Unique count of ' + aggConfig.params.field.displayName;
return 'Unique count of ' + aggConfig.getFieldDisplayName();
},
getFormat: function () {
return fieldFormats.getDefaultInstance('number');

View file

@ -7,7 +7,7 @@ export default function AggTypeMetricMaxProvider(Private) {
name: 'max',
title: 'Max',
makeLabel: function (aggConfig) {
return 'Max ' + aggConfig.params.field.displayName;
return 'Max ' + aggConfig.getFieldDisplayName();
},
params: [
{

View file

@ -12,7 +12,7 @@ export default function AggTypeMetricMedianProvider(Private) {
dslName: 'percentiles',
title: 'Median',
makeLabel: function (aggConfig) {
return 'Median ' + aggConfig.params.field.displayName;
return 'Median ' + aggConfig.getFieldDisplayName();
},
params: [
{

View file

@ -42,7 +42,7 @@ export default function MetricAggTypeProvider(Private) {
* @return {FieldFromat}
*/
MetricAggType.prototype.getFormat = function (agg) {
let field = agg.field();
let field = agg.getField();
return field ? field.format : fieldFormats.getDefaultInstance('number');
};

View file

@ -7,7 +7,7 @@ export default function AggTypeMetricMinProvider(Private) {
name: 'min',
title: 'Min',
makeLabel: function (aggConfig) {
return 'Min ' + aggConfig.params.field.displayName;
return 'Min ' + aggConfig.getFieldDisplayName();
},
params: [
{

View file

@ -15,9 +15,9 @@ export default function AggTypeMetricPercentileRanksProvider(Private) {
let valueProps = {
makeLabel: function () {
let field = this.field();
let field = this.getField();
let format = (field && field.format) || fieldFormats.getDefaultInstance('number');
const label = this.params.customLabel || this.fieldDisplayName();
const label = this.params.customLabel || this.getFieldDisplayName();
return 'Percentile rank ' + format.convert(this.key, 'text') + ' of "' + label + '"';
}
@ -27,7 +27,7 @@ export default function AggTypeMetricPercentileRanksProvider(Private) {
name: 'percentile_ranks',
title: 'Percentile Ranks',
makeLabel: function (agg) {
return 'Percentile ranks of ' + agg.fieldDisplayName();
return 'Percentile ranks of ' + agg.getFieldDisplayName();
},
params: [
{

View file

@ -16,7 +16,7 @@ export default function AggTypeMetricPercentilesProvider(Private) {
let valueProps = {
makeLabel: function () {
const label = this.params.customLabel || this.fieldDisplayName();
const label = this.params.customLabel || this.getFieldDisplayName();
return ordinalSuffix(this.key) + ' percentile of ' + label;
}
};
@ -25,7 +25,7 @@ export default function AggTypeMetricPercentilesProvider(Private) {
name: 'percentiles',
title: 'Percentiles',
makeLabel: function (agg) {
return 'Percentiles of ' + agg.fieldDisplayName();
return 'Percentiles of ' + agg.getFieldDisplayName();
},
params: [
{

View file

@ -11,7 +11,7 @@ export default function AggTypeMetricStandardDeviationProvider(Private) {
return details.valProp;
},
makeLabel: function () {
const fieldDisplayName = this.fieldDisplayName();
const fieldDisplayName = this.getFieldDisplayName();
const details = this.keyedDetails(this.params.customLabel, fieldDisplayName);
return _.get(details, [this.key, 'title']);
},
@ -35,7 +35,7 @@ export default function AggTypeMetricStandardDeviationProvider(Private) {
dslName: 'extended_stats',
title: 'Standard Deviation',
makeLabel: function (agg) {
return 'Standard Deviation of ' + agg.fieldDisplayName();
return 'Standard Deviation of ' + agg.getFieldDisplayName();
},
params: [
{

View file

@ -7,7 +7,7 @@ export default function AggTypeMetricSumProvider(Private) {
name: 'sum',
title: 'Sum',
makeLabel: function (aggConfig) {
return 'Sum of ' + aggConfig.params.field.displayName;
return 'Sum of ' + aggConfig.getFieldDisplayName();
},
params: [
{

View file

@ -53,7 +53,11 @@ export default function FieldAggParamFactory(Private) {
* @return {undefined}
*/
FieldAggParam.prototype.write = function (aggConfig, output) {
let field = aggConfig.params.field;
let field = aggConfig.getField();
if (!field) {
throw new Error(`"${aggConfig.makeLabel()}" requires a field`);
}
if (field.scripted) {
output.params.script = {

View file

@ -32,7 +32,7 @@ module.directive('kbnRows', function ($compile, $rootScope, getAppState, Private
};
if (contents instanceof AggConfigResult) {
if (contents.type === 'bucket' && contents.aggConfig.field() && contents.aggConfig.field().filterable) {
if (contents.type === 'bucket' && contents.aggConfig.getField() && contents.aggConfig.getField().filterable) {
$cell = createAggConfigResultCell(contents);
}
contents = contents.toString('html');

View file

@ -425,7 +425,7 @@ describe('AggConfig', function () {
}
]
});
expect(vis.aggs[0].fieldFormatter()).to.be(vis.aggs[0].field().format.getConverterFor());
expect(vis.aggs[0].fieldFormatter()).to.be(vis.aggs[0].getField().format.getConverterFor());
vis = new Vis(indexPattern, {
type: 'metric',

View file

@ -169,8 +169,8 @@ export default function AggConfigFactory(Private, fieldTypeFilter) {
throw new TypeError('The "' + this.type.title + '" aggregation does not support filtering.');
}
let field = this.field();
let label = this.fieldDisplayName();
let field = this.getField();
let label = this.getFieldDisplayName();
if (field && !field.filterable) {
let message = 'The "' + label + '" field can not be used for filtering.';
if (field.scripted) {
@ -267,6 +267,15 @@ export default function AggConfigFactory(Private, fieldTypeFilter) {
return this.type.getKey(bucket, key, this);
};
AggConfig.prototype.getFieldDisplayName = function () {
let field = this.getField();
return field ? (field.displayName || this.fieldName()) : '';
};
AggConfig.prototype.getField = function () {
return this.params.field;
};
AggConfig.prototype.makeLabel = function () {
if (this.params.customLabel) {
return this.params.customLabel;
@ -277,10 +286,6 @@ export default function AggConfigFactory(Private, fieldTypeFilter) {
return pre += this.type.makeLabel(this);
};
AggConfig.prototype.field = function () {
return this.params.field;
};
AggConfig.prototype.fieldFormatter = function (contentType, defaultFormat) {
let format = this.type && this.type.getFormat(this);
if (format) return format.getConverterFor(contentType);
@ -288,7 +293,7 @@ export default function AggConfigFactory(Private, fieldTypeFilter) {
};
AggConfig.prototype.fieldOwnFormatter = function (contentType, defaultFormat) {
let field = this.field();
let field = this.getField();
let format = field && field.format;
if (!format) format = defaultFormat;
if (!format) format = fieldFormats.getDefaultInstance('string');
@ -296,15 +301,10 @@ export default function AggConfigFactory(Private, fieldTypeFilter) {
};
AggConfig.prototype.fieldName = function () {
let field = this.field();
let field = this.getField();
return field ? field.name : '';
};
AggConfig.prototype.fieldDisplayName = function () {
let field = this.field();
return field ? (field.displayName || this.fieldName()) : '';
};
AggConfig.prototype.fieldIsTimeField = function () {
let timeFieldName = this.vis.indexPattern.timeFieldName;
return timeFieldName && this.fieldName() === timeFieldName;