diff --git a/public/app/features/dashboard/containers/DashboardPage.test.tsx b/public/app/features/dashboard/containers/DashboardPage.test.tsx index 042b759f401..0d81fc1b3f7 100644 --- a/public/app/features/dashboard/containers/DashboardPage.test.tsx +++ b/public/app/features/dashboard/containers/DashboardPage.test.tsx @@ -12,6 +12,7 @@ import { notifyApp } from 'app/core/actions'; import { selectors } from '@grafana/e2e-selectors'; import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps'; import { createTheme } from '@grafana/data'; +import { AutoSizerProps } from 'react-virtualized-auto-sizer'; jest.mock('app/features/dashboard/components/DashboardSettings/GeneralSettings', () => { class GeneralSettings extends React.Component<{}, {}> { @@ -37,6 +38,12 @@ jest.mock('app/core/core', () => ({ }, })); +jest.mock('react-virtualized-auto-sizer', () => { + // The size of the children need to be small enough to be outside the view. + // So it does not trigger the query to be run by the PanelQueryRunner. + return ({ children }: AutoSizerProps) => children({ height: 1, width: 1 }); +}); + interface ScenarioContext { dashboard?: DashboardModel | null; container?: HTMLElement; diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index bcac051f5bc..acae4b650f2 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -214,49 +214,57 @@ export class DashboardGrid extends PureComponent { render() { const { dashboard } = this.props; - - const autoSizerStyle: CSSProperties = { - width: '100%', - height: '100%', - }; - return ( - - {({ width }) => { - if (width === 0) { - return null; - } + /** + * We have a parent with "flex: 1 1 0" we need to reset it to "flex: 1 1 auto" to have the AutoSizer + * properly working. For more information go here: + * https://github.com/bvaughn/react-virtualized/blob/master/docs/usingAutoSizer.md#can-i-use-autosizer-within-a-flex-container + */ +
+ + {({ width }) => { + if (width === 0) { + return null; + } - const draggable = width <= 769 ? false : dashboard.meta.canEdit; + const draggable = width <= 769 ? false : dashboard.meta.canEdit; - /* + /* Disable draggable if mobile device, solving an issue with unintentionally moving panels. https://github.com/grafana/grafana/issues/18497 theme.breakpoints.md = 769 */ - return ( - - {this.renderPanels(width)} - - ); - }} - + return ( + /** + * The children is using a width of 100% so we need to guarantee that it is wrapped + * in an element that has the calculated size given by the AutoSizer. The AutoSizer + * has a width of 0 and will let its content overflow its div. + */ +
+ + {this.renderPanels(width)} + +
+ ); + }} + +
); } } diff --git a/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap b/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap index bff9bbbda0c..34968349e38 100644 --- a/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap +++ b/public/app/features/dashboard/dashgrid/__snapshots__/DashboardGrid.test.tsx.snap @@ -1,17 +1,20 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DashboardGrid Can render dashboard grid Should render 1`] = ` - - - + + + + `;