From 525d2d9dbb7ae77c81687cd3f624fd86083082c4 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Wed, 17 Feb 2021 12:35:55 +0200 Subject: [PATCH] [Vislib] Use timestamp on brush event instead of iso dates (#91483) * [Vislib] Use timestamp on brush event instead of iso dates * Fix functional test and update documentation * Update documentation Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- docs/user/dashboard/url-drilldown.asciidoc | 2 +- src/plugins/vis_type_vislib/public/vislib/lib/handler.js | 9 ++++++++- .../dashboard/drilldowns/dashboard_to_url_drilldown.ts | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/user/dashboard/url-drilldown.asciidoc b/docs/user/dashboard/url-drilldown.asciidoc index df9fa2dca81fd..0a0aa3e1b2af4 100644 --- a/docs/user/dashboard/url-drilldown.asciidoc +++ b/docs/user/dashboard/url-drilldown.asciidoc @@ -250,7 +250,7 @@ Note: | *Range selection* | event.from + event.to -| `from` and `to` values of selected range. Depending on your data, could be either a date or number. + +| `from` and `to` values of the selected range as numbers. + Tip: Consider using <> helper for date formatting. | diff --git a/src/plugins/vis_type_vislib/public/vislib/lib/handler.js b/src/plugins/vis_type_vislib/public/vislib/lib/handler.js index 6ffe2fb410db8..83569dc96e375 100644 --- a/src/plugins/vis_type_vislib/public/vislib/lib/handler.js +++ b/src/plugins/vis_type_vislib/public/vislib/lib/handler.js @@ -9,6 +9,7 @@ import d3 from 'd3'; import _ from 'lodash'; import MarkdownIt from 'markdown-it'; +import moment from 'moment'; import { NoResults } from '../errors'; import { Layout } from './layout/layout'; @@ -25,6 +26,10 @@ const markdownIt = new MarkdownIt({ linkify: true, }); +const convertToTimestamp = (date) => { + return parseInt(moment(date).format('x')); +}; + /** * Handles building all the components of the visualization * @@ -79,11 +84,13 @@ export class Handler { case 'brush': const xRaw = _.get(eventPayload.data, 'series[0].values[0].xRaw'); if (!xRaw) return; // not sure if this is possible? + const [start, end] = eventPayload.range; + const range = [convertToTimestamp(start), convertToTimestamp(end)]; return self.vis.emit(eventType, { name: 'brush', data: { table: xRaw.table, - range: eventPayload.range, + range, column: xRaw.column, }, }); diff --git a/x-pack/test/functional/apps/dashboard/drilldowns/dashboard_to_url_drilldown.ts b/x-pack/test/functional/apps/dashboard/drilldowns/dashboard_to_url_drilldown.ts index 3c48e8fe15738..67b51dfd2dece 100644 --- a/x-pack/test/functional/apps/dashboard/drilldowns/dashboard_to_url_drilldown.ts +++ b/x-pack/test/functional/apps/dashboard/drilldowns/dashboard_to_url_drilldown.ts @@ -37,7 +37,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await dashboardDrilldownPanelActions.clickCreateDrilldown(); await dashboardDrilldownsManage.expectsCreateDrilldownFlyoutOpen(); - const urlTemplate = `{{kibanaUrl}}/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'{{event.from}}',to:'{{event.to}}'))&_a=(columns:!(_source),filters:{{rison context.panel.filters}},index:'{{context.panel.indexPatternId}}',interval:auto,query:(language:{{context.panel.query.language}},query:'{{context.panel.query.query}}'),sort:!())`; + const urlTemplate = `{{kibanaUrl}}/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'{{date event.from}}',to:'{{date event.to}}'))&_a=(columns:!(_source),filters:{{rison context.panel.filters}},index:'{{context.panel.indexPatternId}}',interval:auto,query:(language:{{context.panel.query.language}},query:'{{context.panel.query.query}}'),sort:!())`; await dashboardDrilldownsManage.fillInDashboardToURLDrilldownWizard({ drilldownName: DRILLDOWN_TO_DISCOVER_URL, @@ -66,10 +66,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await dashboardDrilldownPanelActions.clickActionByText(DRILLDOWN_TO_DISCOVER_URL); await PageObjects.discover.waitForDiscoverAppOnScreen(); - // check that new time range duration was applied const newTimeRangeDurationHours = await PageObjects.timePicker.getTimeDurationInHours(); expect(newTimeRangeDurationHours).to.be.lessThan(originalTimeRangeDurationHours); + // check that hours duration is more than 1 hour (meaning that the default time range of last 15 minutes has not been applied) + expect(newTimeRangeDurationHours).to.be.greaterThan(1); }); });