Skip to content

Commit 8264352

Browse files
authored
[Discover] Fix broken setting of bucketInterval (#62939)
* Fix broken setting of bucketInterval, remove $watch * Fix and adapt functional tests
1 parent bf63b56 commit 8264352

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
140140
position="'top'"
141141
></icon-tip>
142142
<span
143+
data-test-subj="discoverIntervalSelectScaledToDesc"
143144
i18n-id="kbn.discover.scaledToDescription"
144145
i18n-default-message="Scaled to {bucketIntervalDescription}"
145146
i18n-values="{

src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,6 @@ function discoverController(
675675
}
676676
});
677677

678-
$scope.$watch('vis.aggs', function() {
679-
// no timefield, no vis, nothing to update
680-
if (!getTimeField() || !$scope.vis) return;
681-
682-
const buckets = $scope.vis.data.aggs.byTypeName('buckets');
683-
684-
if (buckets && buckets.length === 1) {
685-
$scope.bucketInterval = buckets[0].buckets.getInterval();
686-
}
687-
});
688-
689678
$scope.$watchMulti(
690679
['rows', 'fetchStatus'],
691680
(function updateResultState() {
@@ -891,6 +880,9 @@ function discoverController(
891880
tabifiedData,
892881
getDimensions($scope.vis.data.aggs.aggs, $scope.timeRange)
893882
);
883+
if ($scope.vis.data.aggs.aggs[1]) {
884+
$scope.bucketInterval = $scope.vis.data.aggs.aggs[1].buckets.getInterval();
885+
}
894886
}
895887

896888
$scope.hits = resp.hits.total;

test/functional/apps/discover/_discover_histogram.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,34 @@ export default function({ getService, getPageObjects }) {
6666
});
6767

6868
it('should visualize monthly data with different day intervals', async () => {
69-
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
70-
const fromTime = '2017-11-01 00:00:00.000';
71-
const toTime = '2018-03-21 00:00:00.000';
69+
const fromTime = 'Nov 01, 2017 @ 00:00:00.000';
70+
const toTime = 'Mar 21, 2018 @ 00:00:00.000';
7271
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
7372
await PageObjects.discover.setChartInterval('Monthly');
7473
await PageObjects.header.waitUntilLoadingHasFinished();
7574
const chartCanvasExist = await elasticChart.canvasExists();
7675
expect(chartCanvasExist).to.be(true);
7776
});
7877
it('should visualize weekly data with within DST changes', async () => {
79-
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
80-
const fromTime = '2018-03-01 00:00:00.000';
81-
const toTime = '2018-05-01 00:00:00.000';
78+
const fromTime = 'Mar 01, 2018 @ 00:00:00.000';
79+
const toTime = 'May 01, 2018 @ 00:00:00.000';
8280
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
8381
await PageObjects.discover.setChartInterval('Weekly');
8482
await PageObjects.header.waitUntilLoadingHasFinished();
8583
const chartCanvasExist = await elasticChart.canvasExists();
8684
expect(chartCanvasExist).to.be(true);
8785
});
88-
it('should visualize monthly data with different years Scaled to 30d', async () => {
89-
//Nov 1, 2017 @ 01:00:00.000 - Mar 21, 2018 @ 02:00:00.000
90-
const fromTime = '2010-01-01 00:00:00.000';
91-
const toTime = '2018-03-21 00:00:00.000';
86+
it('should visualize monthly data with different years Scaled to 30 days', async () => {
87+
const fromTime = 'Jan 01, 2010 @ 00:00:00.000';
88+
const toTime = 'Mar 21, 2019 @ 00:00:00.000';
89+
9290
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
9391
await PageObjects.discover.setChartInterval('Daily');
9492
await PageObjects.header.waitUntilLoadingHasFinished();
9593
const chartCanvasExist = await elasticChart.canvasExists();
9694
expect(chartCanvasExist).to.be(true);
95+
const chartIntervalScaledDesc = await PageObjects.discover.getChartIntervalScaledToDesc();
96+
expect(chartIntervalScaledDesc).to.be('Scaled to 30 days');
9797
});
9898
});
9999
}

test/functional/page_objects/discover_page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ export function DiscoverPageProvider({ getService, getPageObjects }: FtrProvider
162162
return selectedOption.getVisibleText();
163163
}
164164

165+
public async getChartIntervalScaledToDesc() {
166+
await header.waitUntilLoadingHasFinished();
167+
return await testSubjects.getVisibleText('discoverIntervalSelectScaledToDesc');
168+
}
169+
165170
public async setChartInterval(interval: string) {
166171
const optionElement = await find.byCssSelector(`option[label="${interval}"]`, 5000);
167172
await optionElement.click();

0 commit comments

Comments
 (0)