Skip to content

Commit 9b52ba4

Browse files
Tag Cloud should deal with empty responses correctly
tag cloud did not work with empty responses correctly. One of the side-effects is that the back button did not work properly. For example, pressing the back button would not empty out the screen and show stale clouds. This also caused a type-error. Empty configurations meant that we could not access any aggregation-configs to produce a label.
1 parent d635c11 commit 9b52ba4

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

src/core_plugins/tagcloud/public/tag_cloud.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,23 @@ class TagCloud extends EventEmitter {
129129

130130
const job = this._queue.pop();
131131
this._inFlight = true;
132-
this._onLayoutEnd(job);
133132

133+
if (job.words.length) {
134+
this._onLayoutEnd(job);
135+
} else {
136+
this._emptyCloud(job);
137+
}
138+
139+
}
140+
141+
_emptyCloud(job) {
142+
this._svgGroup.selectAll('text').remove();
143+
this._cloudWidth = 0;
144+
this._cloudHeight = 0;
145+
this._allInViewBox = true;
146+
this._inFlight = false;
147+
this._currentJob = job;
148+
this._processQueue();
134149
}
135150

136151
_onLayoutEnd(job) {

src/core_plugins/tagcloud/public/tag_cloud_controller.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@ module.controller('KbnTagCloudController', function ($scope, $element, Private,
2121
clickHandler({point: {aggConfigResult: aggConfigResult}});
2222
});
2323
tagCloud.on('renderComplete', () => {
24+
25+
const truncatedMessage = containerNode.querySelector('.tagcloud-truncated-message');
26+
const incompleteMessage = containerNode.querySelector('.tagcloud-incomplete-message');
27+
28+
if (!$scope.vis.aggs[0] || !$scope.vis.aggs[1]) {
29+
incompleteMessage.style.display = 'none';
30+
truncatedMessage.style.display = 'none';
31+
return;
32+
}
33+
2434
const bucketName = containerNode.querySelector('.tagcloud-custom-label');
2535
bucketName.innerHTML = `${$scope.vis.aggs[0].makeLabel()} - ${$scope.vis.aggs[1].makeLabel()}`;
2636

27-
const truncatedMessage = containerNode.querySelector('.tagcloud-truncated-message');
37+
2838
truncatedMessage.style.display = truncated ? 'block' : 'none';
2939

30-
const incompleteMessage = containerNode.querySelector('.tagcloud-incomplete-message');
40+
3141
const status = tagCloud.getStatus();
3242

3343
if (TagCloud.STATUS.COMPLETE === status) {
@@ -36,17 +46,20 @@ module.controller('KbnTagCloudController', function ($scope, $element, Private,
3646
incompleteMessage.style.display = 'block';
3747
}
3848

49+
3950
$element.trigger('renderComplete');
4051
});
4152

4253
$scope.$watch('esResponse', async function (response) {
4354

4455
if (!response) {
56+
tagCloud.setData([]);
4557
return;
4658
}
4759

4860
const tagsAggId = _.first(_.pluck($scope.vis.aggs.bySchemaName.segment, 'id'));
4961
if (!tagsAggId || !response.aggregations) {
62+
tagCloud.setData([]);
5063
return;
5164
}
5265

0 commit comments

Comments
 (0)