react-grid-layout icon indicating copy to clipboard operation
react-grid-layout copied to clipboard

fix GridItem calcXY error calculation

Open xiaobao66 opened this issue 7 years ago • 13 comments

Fixed: #918

Issue: GridItem calcXY calculation is wrong.

Solution: Change the calculation of the left and top value. The new calculation is left = colWidth * x + margin * x + containerPadding

xiaobao66 avatar Mar 03 '19 10:03 xiaobao66

Indeed #918 is a real bug. If we can get codesandbox working on PRs it would be great to try this out, otherwise we can pull & compare.

STRML avatar Oct 09 '19 14:10 STRML

@xiaobao66 could you please add a test that fails on master?

STRML avatar Oct 09 '19 14:10 STRML

Verified this fixes the issue locally with the example grid and:

          containerPadding={[0, 0]}
          margin={[100, 10]}

However we need a regression test.

STRML avatar Oct 09 '19 14:10 STRML

@STRML Sorry, I don't know how to write a regression test for this fix. Do you mean add a example in the test directory?

xiaobao66 avatar Oct 09 '19 15:10 xiaobao66

Yes, something in test/spec that fails under the old code but succeeds under the new.

STRML avatar Oct 09 '19 15:10 STRML

Yes, something in test/spec that fails under the old code but succeeds under the new.

Sorry, I don't know what fails under the old code. I didn't change test/spec and my pr has passed the test.

xiaobao66 avatar Oct 09 '19 15:10 xiaobao66

The intention here is to write a new test that ensures that your fix doesn't get removed in the future and to ensure that the new behavior we've just identified as "good" stays good.

STRML avatar Oct 09 '19 16:10 STRML

@STRML I find test/spec only test function, but GridItem.jsx is a react component. This is my first time to commit pr, so I don't know how to add a test for react component. Could you give an example?

xiaobao66 avatar Oct 10 '19 02:10 xiaobao66

Yeah, we do it in https://github.com/mzabriskie/react-draggable/blob/master/specs/draggable.spec.jsx using react-dom/test-utils & react-test-renderer. Enzyme is also an option.

STRML avatar Oct 10 '19 13:10 STRML

Ok, I will look at it first and then spend time adding the test

xiaobao66 avatar Oct 10 '19 16:10 xiaobao66

@STRML I have added a test case for the fix.But it shows Run actions/labeler@v2 failed,

##[error]HttpError: Resource not accessible by integration ##[error]Resource not accessible by integration ##[error]Node run failed with exit code 1

what does it mean?

xiaobao66 avatar Oct 16 '19 17:10 xiaobao66

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this PR will be closed in 7 days

github-actions[bot] avatar Nov 15 '19 18:11 github-actions[bot]