Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/plugins/kibana/public/visualize/editor/agg.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<!-- down button -->
<button
aria-lebl="Decrease Priority"
aria-label="Decrease Priority"
ng-if="stats.count > 1"
ng-class="{ disabled: $last }"
ng-click="moveDown(agg)"
Expand All @@ -65,7 +65,9 @@
class="btn btn-xs btn-danger">
<i aria-hidden="true" class="fa fa-times"></i>
</button>

</div>

</div>

<vis-editor-agg-params
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/Vis/AggConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ define(function (require) {
};

AggConfig.prototype.makeLabel = function () {
if (this.params.customLabel) {
return this.params.customLabel;
}

if (!this.type) return '';
var pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
return pre += this.type.makeLabel(this);
Expand Down
30 changes: 30 additions & 0 deletions src/ui/public/Vis/__tests__/_AggConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,36 @@ describe('AggConfig', function () {
});
});

describe('#makeLabel', function () {
it('uses the custom label if it is defined', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.params.customLabel = 'Custom label';
var label = aggConfig.makeLabel();
expect(label).to.be(aggConfig.params.customLabel);
});
it('default label should be "Count"', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
var label = aggConfig.makeLabel();
expect(label).to.be('Count');
});
it('default label should be "Percentage of Count" when Vis is in percentage mode', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.vis.params.mode = 'percentage';
var label = aggConfig.makeLabel();
expect(label).to.be('Percentage of Count');
});
it('empty label if the Vis type is not defined', function () {
var vis = new Vis(indexPattern, {});
var aggConfig = vis.aggs[0];
aggConfig.type = undefined;
var label = aggConfig.makeLabel();
expect(label).to.be('');
});
});

describe('#fieldFormatter', function () {
it('returns the fields format unless the agg type has a custom getFormat handler', function () {
var vis = new Vis(indexPattern, {
Expand Down
9 changes: 9 additions & 0 deletions src/ui/public/agg_types/AggType.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ define(function (require) {
type: 'json',
advanced: true
});
// always append custom label

if (config.customLabels !== false) {
this.params.push({
name: 'customLabel',
type: 'string',
write: _.noop
});
}

this.params = new AggParams(this.params);
}
Expand Down
13 changes: 12 additions & 1 deletion src/ui/public/agg_types/__tests__/AggType.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ describe('AggType Class', function () {
});

expect(aggType.params).to.be.an(AggParams);
expect(aggType.params.length).to.be(2);
expect(aggType.params[0].name).to.be('json');
expect(aggType.params[1].name).to.be('customLabel');
});

it('can disable customLabel', function () {
var aggType = new AggType({
name: 'smart agg',
customLabels: false
});

expect(aggType.params.length).to.be(1);
expect(aggType.params[0].name).to.be('json');
});
Expand All @@ -137,7 +148,7 @@ describe('AggType Class', function () {
{name: 'one'},
{name: 'two'}
];
var paramLength = params.length + 1; // json is always appended
var paramLength = params.length + 2; // json and custom label are always appended

var aggType = new AggType({
name: 'bucketeer',
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/agg_types/buckets/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(function (require) {
name: 'filters',
title: 'Filters',
createFilter: createFilter,
customLabels: false,
params: [
{
name: 'filters',
Expand Down