Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix refreshed dashboard losing time range #20858

Merged
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
19 changes: 10 additions & 9 deletions src/ui/public/timepicker/kbn_global_timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ uiModules
.directive('kbnGlobalTimepicker', (globalState, config) => {
const getConfig = (...args) => config.get(...args);

const updateGlobalStateWithTime = ($scope) => {
globalState.refreshInterval = timefilter.getRefreshInterval();
globalState.time = timefilter.getTime();
globalState.save();
setTimefilterValues($scope);
};

const listenForUpdates = ($scope) => {
$scope.$listenAndDigestAsync(timefilter, 'refreshIntervalUpdate', () => {
globalState.refreshInterval = timefilter.getRefreshInterval();
globalState.time = timefilter.getTime();
globalState.save();
setTimefilterValues($scope);
updateGlobalStateWithTime($scope);
});
$scope.$listenAndDigestAsync(timefilter, 'timeUpdate', () => {
globalState.refreshInterval = timefilter.getRefreshInterval();
globalState.time = timefilter.getTime();
globalState.save();
setTimefilterValues($scope);
updateGlobalStateWithTime($scope);
});
$scope.$listenAndDigestAsync(timefilter, 'enabledUpdated', () => {
setTimefilterValues($scope);
Expand Down Expand Up @@ -69,8 +70,8 @@ uiModules
require: '^kbnTopNav',
link: ($scope, element, attributes, kbnTopNav) => {
listenForUpdates($scope);
updateGlobalStateWithTime($scope);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what fixed the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, global state wasn't initialized the first time on page load which only created a problem for dashboards stored with time. As soon as any interaction happened with the time picker, it'd update global state. Everything appeared to work correctly in the UI because that was set up correctly, it was just the URL that didn't match it.


setTimefilterValues($scope);
$scope.toggleRefresh = () => {
timefilter.toggleRefresh();
};
Expand Down
149 changes: 85 additions & 64 deletions test/functional/apps/dashboard/_embeddable_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,108 +29,129 @@ import expect from 'expect.js';

export default function ({ getService, getPageObjects }) {
const find = getService('find');
const remote = getService('remote');
const dashboardExpect = getService('dashboardExpect');
const dashboardAddPanel = getService('dashboardAddPanel');
const PageObjects = getPageObjects(['common', 'dashboard', 'header', 'visualize', 'discover']);

const expectAllDataRenders = async () => {
await dashboardExpect.pieSliceCount(16);
await dashboardExpect.seriesElementCount(19);
await dashboardExpect.dataTableRowCount(5);
await dashboardExpect.savedSearchRowCount(50);
await dashboardExpect.goalAndGuageLabelsExist(['63%', '56%', '11.915 GB']);
await dashboardExpect.inputControlItemCount(5);
await dashboardExpect.metricValuesExist(['7,544']);
await dashboardExpect.markdownWithValuesExists(['I\'m a markdown!']);
await dashboardExpect.lineChartPointsCount(5);
await dashboardExpect.tagCloudWithValuesFound(['CN', 'IN', 'US', 'BR', 'ID']);
await dashboardExpect.timelionLegendCount(0);
const tsvbGuageExists = await find.existsByCssSelector('.thorHalfGauge');
expect(tsvbGuageExists).to.be(true);
await dashboardExpect.tsvbMetricValuesExist(['210,007,889,606']);
await dashboardExpect.tsvbMarkdownWithValuesExists(['Hi Avg last bytes: 6286.674715909091']);
await dashboardExpect.tsvbTableCellCount(20);
await dashboardExpect.tsvbTimeSeriesLegendCount(1);
await dashboardExpect.tsvbTopNValuesExist(['5,734.79', '6,286.67']);
await dashboardExpect.vegaTextsExist(['5,000']);
};

const expectNoDataRenders = async () => {
await dashboardExpect.pieSliceCount(0);
await dashboardExpect.seriesElementCount(0);
await dashboardExpect.dataTableRowCount(0);
await dashboardExpect.savedSearchRowCount(0);
await dashboardExpect.inputControlItemCount(5);
await dashboardExpect.metricValuesExist(['0']);
await dashboardExpect.markdownWithValuesExists(['I\'m a markdown!']);

// Three instead of 0 because there is a visualization based off a non time based index that
// should still show data.
await dashboardExpect.lineChartPointsCount(3);

await dashboardExpect.timelionLegendCount(0);
const tsvbGuageExists = await find.existsByCssSelector('.thorHalfGauge');
expect(tsvbGuageExists).to.be(true);
await dashboardExpect.tsvbMetricValuesExist(['0']);
await dashboardExpect.tsvbMarkdownWithValuesExists(['Hi Avg last bytes: 0']);
await dashboardExpect.tsvbTableCellCount(0);
await dashboardExpect.tsvbTimeSeriesLegendCount(1);
await dashboardExpect.tsvbTopNValuesExist(['0']);
await dashboardExpect.vegaTextsDoNotExist(['5,000']);
};

describe('dashboard embeddable rendering', function describeIndexTests() {
before(async () => {
await PageObjects.dashboard.clickNewDashboard();

const fromTime = '2018-01-01 00:00:00.000';
const toTime = '2018-04-13 00:00:00.000';
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
});

after(async () => {
// Get rid of the timestamp added in this test, as well any global or app state.
const currentUrl = await remote.getCurrentUrl();
const newUrl = currentUrl.replace(/\?.*$/, '');
await remote.get(newUrl, false);
});

it('adding visualizations', async () => {
await dashboardAddPanel.addEveryVisualization('"Rendering Test"');

// This one is rendered via svg which lets us do better testing of what is being rendered.
await dashboardAddPanel.addVisualization('Filter Bytes Test: vega');

await PageObjects.header.waitUntilLoadingHasFinished();
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(26);
expect(panelCount).to.be(27);
});

it('adding saved searches', async () => {
await dashboardAddPanel.addEverySavedSearch('"Rendering Test"');
await dashboardAddPanel.closeAddPanel();
await PageObjects.header.waitUntilLoadingHasFinished();
const panelCount = await PageObjects.dashboard.getPanelCount();
expect(panelCount).to.be(27);

// Not necessary but helpful for local debugging.
await PageObjects.dashboard.saveDashboard('embeddable rendering test');
});

it('pie charts rendered', async () => {
await dashboardExpect.pieSliceCount(16);
});

it('area, bar and heatmap charts rendered', async () => {
await dashboardExpect.seriesElementCount(19);
});

it('data tables render', async () => {
await dashboardExpect.dataTableRowCount(5);
});

it('saved searches render', async () => {
await dashboardExpect.savedSearchRowCount(50);
});
expect(panelCount).to.be(28);

it('goal and gauge render', async () => {
await dashboardExpect.goalAndGuageLabelsExist(['63%', '56%', '11.915 GB']);
await PageObjects.dashboard.saveDashboard('embeddable rendering test', { storeTimeWithDashboard: true });
});

it('input controls render', async () => {
await dashboardExpect.inputControlItemCount(5);
it('initial render test', async () => {
await expectAllDataRenders();
});

it('metric vis renders', async () => {
await dashboardExpect.metricValuesExist(['7,544']);
});

it('markdown renders', async () => {
await dashboardExpect.markdownWithValuesExists(['I\'m a markdown!']);
});

it('line charts render', async () => {
await dashboardExpect.lineChartPointsCount(5);
});

it('tag cloud renders', async () => {
await dashboardExpect.tagCloudWithValuesFound(['CN', 'IN', 'US', 'BR', 'ID']);
});

it('timelion chart renders', async () => {
await dashboardExpect.timelionLegendCount(0);
});
it('data rendered correctly when dashboard is opened from listing page', async () => {
// Change the time to make sure that it's updated when re-opened from the listing page.
const fromTime = '2018-05-10 00:00:00.000';
const toTime = '2018-05-11 00:00:00.000';
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.dashboard.loadSavedDashboard('embeddable rendering test');

it('tsvb gauge renders', async () => {
const tsvbGuageExists = await find.existsByCssSelector('.thorHalfGauge');
expect(tsvbGuageExists).to.be(true);
await expectAllDataRenders();
});

it('tsvb metric chart renders', async () => {
await dashboardExpect.tsvbMetricValuesExist(['210,007,889,606']);
});
it('data rendered correctly when dashboard is hard refreshed', async () => {
const currentUrl = await remote.getCurrentUrl();
await remote.get(currentUrl, true);

it('tsvb markdown renders', async () => {
await dashboardExpect.tsvbMarkdownWithValuesExists(['Hi Avg last bytes: 6286.674715909091']);
await expectAllDataRenders();
});

it('tsvb table chart renders', async () => {
await dashboardExpect.tsvbTableCellCount(20);
});
it('panels are updated when time changes outside of data', async () => {
const fromTime = '2018-05-11 00:00:00.000';
const toTime = '2018-05-12 00:00:00.000';
await PageObjects.header.setAbsoluteRange(fromTime, toTime);

it('tsvb time series renders', async () => {
await dashboardExpect.tsvbTimeSeriesLegendCount(1);
await expectNoDataRenders();
});

it('tsvb top n chart renders', async () => {
await dashboardExpect.tsvbTopNValuesExist(['5,734.79', '6,286.67']);
});
it('panels are updated when time changes inside of data', async () => {
const fromTime = '2018-01-01 00:00:00.000';
const toTime = '2018-04-13 00:00:00.000';
await PageObjects.header.setAbsoluteRange(fromTime, toTime);

it('vega chart renders', async () => {
const tsvb = await find.existsByCssSelector('.vega-view-container');
expect(tsvb).to.be(true);
await expectAllDataRenders();
});
});
}
2 changes: 1 addition & 1 deletion test/functional/apps/home/_home.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function ({ getService, getPageObjects }) {
it('clicking on console on homepage should take you to console app', async ()=> {
await PageObjects.home.clickSynopsis('console');
const url = await remote.getCurrentUrl();
expect(url.includes('/app/kibana#/dev_tools/console?_g=()')).to.be(true);
expect(url.includes('/app/kibana#/dev_tools/console')).to.be(true);
});

});
Expand Down
Loading