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

Backport fix #4035 on 2019.02.xx #4120

Merged
merged 1 commit into from
Aug 30, 2019
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
5 changes: 4 additions & 1 deletion web/client/components/widgets/view/WidgetsView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const DefaultWidget = withGroupColor(require('../widget/DefaultWidget'));
const getWidgetGroups = (groups = [], w) => groups.filter(g => find(g.widgets, id => id === w.id));
require('react-grid-layout-resize-prevent-collision/css/styles.css');

const WIDGET_MOBILE_RIGHT_SPACE = 34;
const getResponsiveWidgetWidth = width => width < 480 ? width - WIDGET_MOBILE_RIGHT_SPACE : width;

module.exports = pure(({
id,
style,
Expand Down Expand Up @@ -56,7 +59,7 @@ module.exports = pure(({
key={id || "widgets-view"}
useDefaultWidthProvider={useDefaultWidthProvider}
measureBeforeMount={measureBeforeMount}
width={!useDefaultWidthProvider ? width : undefined}
width={!useDefaultWidthProvider ? getResponsiveWidgetWidth(width) : undefined}
isResizable={canEdit}
isDraggable={canEdit}
draggableHandle={".draggableHandle"}
Expand Down
19 changes: 19 additions & 0 deletions web/client/components/widgets/view/__tests__/WidgetsView-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
const React = require('react');
const ReactDOM = require('react-dom');
const expect = require('expect');
const { Responsive } = require('react-grid-layout-resize-prevent-collision');
const WidgetsView = require('../WidgetsView');
const ReactTestUtils = require('react-dom/test-utils');

const dummyWidget = {
title: "TEST",
id: "TEST",
Expand Down Expand Up @@ -48,6 +50,23 @@ describe('WidgetsView component', () => {
const el = container.querySelector('.mapstore-widget-card');
expect(el).toExist();
});
it('Test WidgetsView with width=460', () => {
const WIDGET_MOBILE_RIGHT_SPACE = 34;
const width = 460;
const cmp = ReactDOM.render(<WidgetsView widgets={[dummyWidget]} useDefaultWidthProvider={false} width={width}/>, document.getElementById("container"));
expect(cmp).toExist();
const innerLayout = ReactTestUtils.findRenderedComponentWithType(cmp, Responsive);
expect(innerLayout).toExist();
expect(innerLayout.props.width).toEqual(width - WIDGET_MOBILE_RIGHT_SPACE);
});
it('Test WidgetsView with width=640', () => {
const width = 640;
const cmp = ReactDOM.render(<WidgetsView widgets={[dummyWidget]} useDefaultWidthProvider={false} width={width}/>, document.getElementById("container"));
expect(cmp).toExist();
const innerLayout = ReactTestUtils.findRenderedComponentWithType(cmp, Responsive);
expect(innerLayout).toExist();
expect(innerLayout.props.width).toEqual(width);
});
it('handler editWidget', () => {
const actions = {
editWidget: () => {}
Expand Down