diff --git a/src/core_plugins/kibana/public/dashboard/grid/dashboard_grid.test.js b/src/core_plugins/kibana/public/dashboard/grid/dashboard_grid.test.js index 7ad93bd5829544..88a3276f1be369 100644 --- a/src/core_plugins/kibana/public/dashboard/grid/dashboard_grid.test.js +++ b/src/core_plugins/kibana/public/dashboard/grid/dashboard_grid.test.js @@ -6,6 +6,8 @@ import { PanelUtils } from '../panel/panel_utils'; import { DashboardGrid } from './dashboard_grid'; import { DashboardPanel } from '../panel/dashboard_panel'; +jest.mock('ui/chrome', () => ({ getKibanaVersion: () => '6.0.0' }), { virtual: true }); + const getContainerApi = () => { return { addFilter: () => {}, diff --git a/src/core_plugins/kibana/public/dashboard/panel/panel_state.js b/src/core_plugins/kibana/public/dashboard/panel/panel_state.js index 64f4ddcf20c8d3..c5d0238d5a70fa 100644 --- a/src/core_plugins/kibana/public/dashboard/panel/panel_state.js +++ b/src/core_plugins/kibana/public/dashboard/panel/panel_state.js @@ -2,6 +2,7 @@ export const DEFAULT_PANEL_WIDTH = 6; export const DEFAULT_PANEL_HEIGHT = 3; import { DASHBOARD_GRID_COLUMN_COUNT } from '../dashboard_constants'; +import chrome from 'ui/chrome'; /** * Represents a panel on a grid. Keeps track of position in the grid and what visualization it @@ -96,6 +97,7 @@ export function createPanelState(id, type, panelIndex, currentPanels) { y, i: panelIndex.toString() }, + version: chrome.getKibanaVersion(), panelIndex: panelIndex, type: type, id: id diff --git a/src/core_plugins/kibana/public/dashboard/panel/panel_utils.js b/src/core_plugins/kibana/public/dashboard/panel/panel_utils.js index d27a5a98e5803b..b04607e89cb38a 100644 --- a/src/core_plugins/kibana/public/dashboard/panel/panel_utils.js +++ b/src/core_plugins/kibana/public/dashboard/panel/panel_utils.js @@ -1,4 +1,5 @@ import { DEFAULT_PANEL_WIDTH, DEFAULT_PANEL_HEIGHT } from 'plugins/kibana/dashboard/panel/panel_state'; +import chrome from 'ui/chrome'; import _ from 'lodash'; @@ -31,7 +32,7 @@ export class PanelUtils { w: panel.size_x || DEFAULT_PANEL_WIDTH, h: panel.size_y || DEFAULT_PANEL_HEIGHT, i: panel.panelIndex.toString(), - version: 6, + version: chrome.getKibanaVersion(), }; delete panel.size_x; delete panel.size_y; @@ -39,32 +40,6 @@ export class PanelUtils { delete panel.col; } - /** - * Ensures that the panel object has the latest size/pos info. - * @param {PanelState} panel - * @param {Element} panelElement - jQuery element representing the element in the UI - */ - static refreshSizeAndPosition(panel, panelElement) { - const data = panelElement.coords().grid; - panel.size_x = data.size_x; - panel.size_y = data.size_y; - panel.col = data.col; - panel.row = data.row; - } - - /** - * Ensures that the grid element matches the latest size/pos info in the panel element. - * @param {PanelState} panel - * @param {Element} panelElement - jQuery element representing the element in the UI - */ - static refreshElementSizeAndPosition(panel, panelElement) { - const data = panelElement.coords().grid; - data.size_x = panel.size_x; - data.size_y = panel.size_y; - data.col = panel.col; - data.row = panel.row; - } - /** * Returns the panel with the given panelIndex from the panels array (*NOT* the panel at the given index). * @param panelIndex {number} - Note this is *NOT* the index of the panel in the panels array. diff --git a/src/ui/public/chrome/api/apps.js b/src/ui/public/chrome/api/apps.js index 42c532b2d4e91b..96c45fbfd33d65 100644 --- a/src/ui/public/chrome/api/apps.js +++ b/src/ui/public/chrome/api/apps.js @@ -38,6 +38,11 @@ export default function (chrome, internals) { return internals.showAppsLink == null ? internals.nav.length > 1 : internals.showAppsLink; }; + + chrome.getKibanaVersion = function () { + return internals.version; + }; + chrome.getApp = function () { return clone(internals.app); }; diff --git a/test/functional/apps/dashboard/_dashboard.js b/test/functional/apps/dashboard/_dashboard.js index b7b4c51550407d..29f7863f534dac 100644 --- a/test/functional/apps/dashboard/_dashboard.js +++ b/test/functional/apps/dashboard/_dashboard.js @@ -140,7 +140,11 @@ export default function ({ getService, getPageObjects }) { if (newPanelDimensions.length < 0) { throw new Error('No panel dimensions...'); } - expect(newPanelDimensions[0].width).to.equal(currentPanelDimensions[0].width * 2); + // Some margin of error is allowed, I've noticed it being off by one pixel. Probably something to do with + // an odd width and dividing by two. Note that if we add margins, we'll have to adjust this as well. + const marginOfError = 5; + expect(newPanelDimensions[0].width).to.be.lessThan(currentPanelDimensions[0].width * 2 + marginOfError); + expect(newPanelDimensions[0].width).to.be.greaterThan(currentPanelDimensions[0].width * 2 - marginOfError); }); }); });