Skip to content

Commit

Permalink
Merge pull request #2033 from lukasolson/shortened-fields
Browse files Browse the repository at this point in the history
Shorten field names according to shortDots setting
  • Loading branch information
w33ble committed Nov 25, 2014
2 parents 9cec879 + 1d6edee commit e244fd9
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/kibana/components/agg_response/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ define(function (require) {
var groupMap = chartData.splits || (chartData.splits = {});

result.buckets.forEach(function (bucket) {
var bucketId = bucket.key + (col.field ? ': ' + col.field.name : '');
var bucketId = bucket.key + (col.field ? ': ' + col.field.displayName : '');
var group = groupMap[bucketId];

if (!group) {
Expand Down Expand Up @@ -167,7 +167,7 @@ define(function (require) {
}

if (config.field) {
config.label = config.field.name;
config.label = config.field.displayName;
return;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ define(function (require) {
// record the the depth
var depth = item.depth - 1;

// Using the aggConfig determin what the field name is. If the aggConfig
// 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
var col = item.aggConfig;
var field = (col && col.params && col.params.field && col.params.field.name)
var field = (col && col.params && col.params.field && col.params.field.displayName)
|| (col && col.label)
|| ('level ' + item.depth);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define(function (require) {
var agg = firstAgg._next;
var split = buildSplit(agg, metric, bucket[agg.id]);
// Since splits display labels we need to set it.
split.label = bucket.key + ': ' + firstAgg.params.field.name;
split.label = bucket.key + ': ' + firstAgg.params.field.displayName;
split.tooltipFormatter = tooltipFormatter(raw.columns);
return split;
});
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
title: 'Histogram',
ordered: {},
makeLabel: function (aggConfig) {
return aggConfig.params.field.name;
return aggConfig.params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
name: 'range',
title: 'Range',
makeLabel: function (aggConfig) {
return aggConfig.params.field.name + ' ranges';
return aggConfig.params.field.displayName + ' ranges';
},
params: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(function (require) {
name: 'significant_terms',
title: 'Significant Terms',
makeLabel: function (aggConfig) {
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.name;
return 'Top ' + aggConfig.params.size + ' unusual terms in ' + aggConfig.params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define(function (require) {
title: 'Terms',
makeLabel: function (aggConfig) {
var params = aggConfig.params;
return params.order.display + ' ' + params.size + ' ' + params.field.name;
return params.order.display + ' ' + params.size + ' ' + params.field.displayName;
},
params: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/controls/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
required
ng-model="params.field"
ng-options="
field as field.name group by field.type for field in aggConfig.vis.indexPattern.fields.raw
field as field.displayName group by field.type for field in aggConfig.vis.indexPattern.fields.raw
| fieldType: aggParam.filterFieldTypes
| filter: { indexed: true }
| orderBy: ['type', 'name']
Expand Down
10 changes: 5 additions & 5 deletions src/kibana/components/agg_types/metric_aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(function (require) {
name: 'avg',
title: 'Average',
makeLabel: function (aggConfig) {
return 'Average ' + aggConfig.params.field.name;
return 'Average ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -28,7 +28,7 @@ define(function (require) {
name: 'sum',
title: 'Sum',
makeLabel: function (aggConfig) {
return 'Sum of ' + aggConfig.params.field.name;
return 'Sum of ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -41,7 +41,7 @@ define(function (require) {
name: 'min',
title: 'Min',
makeLabel: function (aggConfig) {
return 'Min ' + aggConfig.params.field.name;
return 'Min ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -54,7 +54,7 @@ define(function (require) {
name: 'max',
title: 'Max',
makeLabel: function (aggConfig) {
return 'Max ' + aggConfig.params.field.name;
return 'Max ' + aggConfig.params.field.displayName;
},
params: [
{
Expand All @@ -67,7 +67,7 @@ define(function (require) {
name: 'cardinality',
title: 'Unique count',
makeLabel: function (aggConfig) {
return 'Unique count of ' + aggConfig.params.field.name;
return 'Unique count of ' + aggConfig.params.field.displayName;
},
params: [
{
Expand Down
20 changes: 14 additions & 6 deletions src/kibana/components/index_patterns/_index_pattern.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function (require) {
return function IndexPatternFactory(Private, timefilter, configFile, Notifier) {
return function IndexPatternFactory(Private, timefilter, configFile, Notifier, shortDotsFilter) {
var _ = require('lodash');
var angular = require('angular');
var errors = require('errors');
Expand Down Expand Up @@ -95,11 +95,19 @@ define(function (require) {
field.count = field.count || 0;

// non-enumerable type so that it does not get included in the JSON
Object.defineProperty(field, 'format', {
enumerable: false,
get: function () {
var formatName = self.customFormats && self.customFormats[field.name];
return formatName ? fieldFormats.byName[formatName] : fieldFormats.defaultByType[field.type];
Object.defineProperties(field, {
format: {
enumerable: false,
get: function () {
var formatName = self.customFormats && self.customFormats[field.name];
return formatName ? fieldFormats.byName[formatName] : fieldFormats.defaultByType[field.type];
}
},
displayName: {
enumerable: false,
get: function () {
return shortDotsFilter(field.name);
}
}
});

Expand Down
1 change: 1 addition & 0 deletions src/kibana/components/index_patterns/index_patterns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define(function (require) {
var module = require('modules').get('kibana/index_patterns');
require('filters/short_dots');

module.service('indexPatterns', function (configFile, es, Notifier, Private, Promise) {
var self = this;
Expand Down
1 change: 1 addition & 0 deletions src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ define(function (require) {
_.defaults(field, currentState[field.name]);
// clone the field and add it's display prop
var clone = _.assign({}, field, {
displayName: field.displayName, // this is a getter, so we need to copy it over manually
format: field.format, // this is a getter, so we need to copy it over manually
display: columnObjects[field.name] || false,
rowCount: $scope.rows ? $scope.rows.fieldCounts[field.name] : 0
Expand Down
2 changes: 2 additions & 0 deletions src/kibana/plugins/discover/directives/table_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ define(function (require) {
var _ = require('lodash');
var module = require('modules').get('app/discover');

require('filters/short_dots');

module.directive('kbnTableHeader', function () {
var headerHtml = require('text!plugins/discover/partials/table_header.html');
return {
Expand Down
6 changes: 4 additions & 2 deletions src/kibana/plugins/discover/directives/table_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define(function (require) {

require('components/highlight/highlight');
require('filters/trust_as_html');
require('filters/short_dots');

// guestimate at the minimum number of chars wide cells in the table should be
var MIN_LINE_LENGTH = 20;
Expand All @@ -19,7 +20,7 @@ define(function (require) {
* <tr ng-repeat="row in rows" kbn-table-row="row"></tr>
* ```
*/
module.directive('kbnTableRow', function ($compile, config, highlightFilter) {
module.directive('kbnTableRow', function ($compile, config, highlightFilter, shortDotsFilter) {
var openRowHtml = require('text!plugins/discover/partials/table_row/open.html');
var detailsHtml = require('text!plugins/discover/partials/table_row/details.html');
var cellTemplate = _.template(require('text!plugins/discover/partials/table_row/cell.html'));
Expand Down Expand Up @@ -134,7 +135,8 @@ define(function (require) {
source: _.mapValues(row._formatted, function (val, field) {
return _displayField(row, field, false);
}),
highlight: row.highlight
highlight: row.highlight,
shortDotsFilter: shortDotsFilter
});
} else {
formatted = _displayField(row, column, true);
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/plugins/discover/partials/table_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</th>
<th ng-repeat="name in columns">
<span ng-click="sort(name)" class="table-header-name">
{{name}} <i ng-class="headerClass(name)"></i>
{{name | shortDots}} <i ng-class="headerClass(name)"></i>
</span>
<span class="table-header-move">
<i ng-click="moveLeft(name)" class="fa fa-angle-double-left" ng-show="!$first"></i>
Expand Down
4 changes: 2 additions & 2 deletions src/kibana/plugins/discover/partials/table_row/_source.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<dl class="source truncate-by-height">
<% _.each(highlight, function (value, field) { /* show fields that match the query first */ %>
<dt><%= field %>:</dt>
<dt><%= shortDotsFilter(field) %>:</dt>
<dd><%= source[field] %></dd>
<%= ' ' %>
<% }); %>
<% _.each(source, function (value, field) { %>
<% if (_.has(highlight, field)) return; %>
<dt><%= field %>:</dt>
<dt><%= shortDotsFilter(field) %>:</dt>
<dd><%= value %></dd>
<%= ' ' %>
<% }); %>
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/plugins/settings/sections/indices/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1>
<tr class="field-settings"
ng-repeat="field in page">
<td>
<span bo-text="field.name"></span>
<span bo-text="field.displayName"></span>
&nbsp;
<span
bo-if="indexPattern.timeFieldName === field.name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define(function (require) {
break;
}

label = (col.aggConfig && col.aggConfig.makeLabel()) || (col.field && col.field.name) || label;
label = (col.aggConfig && col.aggConfig.makeLabel()) || (col.field && col.field.displayName) || label;
if (col.field) val = col.field.format.convert(val);

return {
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/plugins/vis_types/vislib/converters/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ define(function (require) {
var col = columns[i];

// field/agg details
var group = (col.field && col.field.name) || col.label || ('level ' + datum.depth);
var group = (col.field && col.field.displayName) || col.label || ('level ' + datum.depth);

// field value that defines the bucket
var bucket = parent.name;
Expand Down
28 changes: 14 additions & 14 deletions test/unit/fixtures/stubbed_logstash_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ define(function (require) {
var fieldFormats = Private(require('components/index_patterns/_field_formats'));

return new StubIndexPattern('logstash-*', 'time', [
{ name: 'bytes', type: 'number', indexed: true, analyzed: true, count: 10 },
{ name: 'ssl', type: 'boolean', indexed: true, analyzed: true, count: 20 },
{ name: '@timestamp', type: 'date', indexed: true, analyzed: true, count: 30 },
{ name: 'phpmemory', type: 'number', indexed: true, analyzed: true, count: 0 },
{ name: 'ip', type: 'ip', indexed: true, analyzed: true, count: 0 },
{ name: 'request_body', type: 'attachment', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'point', type: 'geo_point', indexed: true, analyzed: true, count: 0 },
{ name: 'area', type: 'geo_shape', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'machine.os', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'geo.src', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: '_type', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false, count: 0 }
{ name: 'bytes', displayName: 'bytes', type: 'number', indexed: true, analyzed: true, count: 10 },
{ name: 'ssl', displayName: 'ssl', type: 'boolean', indexed: true, analyzed: true, count: 20 },
{ name: '@timestamp', displayName: '@timestamp', type: 'date', indexed: true, analyzed: true, count: 30 },
{ name: 'phpmemory', displayName: 'phpmemory', type: 'number', indexed: true, analyzed: true, count: 0 },
{ name: 'ip', displayName: 'ip', type: 'ip', indexed: true, analyzed: true, count: 0 },
{ name: 'request_body', displayName: 'request_body', type: 'attachment', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', displayName: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'point', displayName: 'point', type: 'geo_point', indexed: true, analyzed: true, count: 0 },
{ name: 'area', displayName: 'area', type: 'geo_shape', indexed: true, analyzed: true, count: 0 },
{ name: 'extension', displayName: 'extension', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'machine.os', displayName: 'machine.os', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'geo.src', displayName: 'geo.src', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: '_type', displayName: '_type', type: 'string', indexed: true, analyzed: true, count: 0 },
{ name: 'custom_user_field', displayName: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false, count: 0 }
]);
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define(function (require) {
depth: 3,
value: 6,
field: { format: { convert: convert } },
aggConfig: { params: { field: { name: 'field3' } } },
aggConfig: { params: { field: { displayName: 'field3' } } },
parent: {
name: 'bucket2',
depth: 2,
Expand Down

0 comments on commit e244fd9

Please sign in to comment.