Skip to content

Restore drag and drop between two trees #420

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

thomasstjerne
Copy link
Contributor

@thomasstjerne thomasstjerne commented Feb 10, 2021

When dragging from another tree, this.dragNode is null  and convertNodePropsToEventData(this.dragNode) will fail.
@vercel
Copy link

vercel bot commented Feb 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/tree/3FQKrkja9nLcroD7hxfDxpgeHEZn
✅ Preview: https://tree-git-fork-thomasstjerne-master-react-component.vercel.app

@codecov
Copy link

codecov bot commented Feb 10, 2021

Codecov Report

❌ Patch coverage is 88.88889% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.78%. Comparing base (ba4aa47) to head (9c54df2).
⚠️ Report is 173 commits behind head on master.

Files with missing lines Patch % Lines
src/Tree.tsx 88.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #420      +/-   ##
==========================================
- Coverage   99.67%   98.78%   -0.90%     
==========================================
  Files          11       11              
  Lines        1226     1231       +5     
  Branches      355      359       +4     
==========================================
- Hits         1222     1216       -6     
- Misses          4       15      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thomasstjerne
Copy link
Contributor Author

@07akioni
Copy link
Contributor

07akioni commented Feb 11, 2021

image

Need to clear drag status of a tree when drop on another tree. In the picture, the drag status is not cleaned up.

Co-authored-by: 07akioni <07akioni2@gmail.com>
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 12, 2021

This pull request introduces 2 alerts when merging 1aa00e4 into 39a01f0 - view on LGTM.com

new alerts:

  • 2 for Useless conditional

@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 12, 2021

This pull request introduces 2 alerts when merging d9d399b into 39a01f0 - view on LGTM.com

new alerts:

  • 2 for Useless conditional

@afc163
Copy link
Member

afc163 commented Feb 12, 2021

图片

@thomasstjerne
Copy link
Contributor Author

@07akioni
Copy link
Contributor

07akioni commented Feb 12, 2021

Appreciate for your works.


On the first drag the drop indicator isn't shown on the right tree.

Screen.Recording.2021-02-13.at.1.45.19.AM.mov

@thomasstjerne
Copy link
Contributor Author

@07akioni could you take a look again please?

@afc163
Copy link
Member

afc163 commented Mar 8, 2021

图片

@thomasstjerne
Copy link
Contributor Author

@afc163 this was fixed in 9984b1e

@thomasstjerne thomasstjerne requested a review from 07akioni March 9, 2021 08:52
@jmatelowski
Copy link

I tested it on the fork repo and it works very well :) @thomasstjerne can you rebase this branch? There are several conflicts to be resolved with the current master branch.

Bug (corner case) reported here: #420 (comment) (Issue 2) still exists.

@07akioni
Copy link
Contributor

I tested it on the fork repo and it works very well :) @thomasstjerne can you rebase this branch? There are several conflicts to be resolved with the current master branch.

Bug (corner case) reported here: #420 (comment) (Issue 2) still exists.

I think Issue 2 in comment 420 is fixed

@07akioni
Copy link
Contributor

I think currently the main problem is that if it's neccessary to expose clearDragState to the user, since the timing to call it is not implicit. It's better to let it works internally.

@thomasstjerne
Copy link
Contributor Author

I was not able to keep the coverage % up, sorry.
But I think the main code conflicts are solved

Comment on lines +441 to +443
if (props.dragging === true) {
newState.dragging = props.dragging;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's possible to use a global variable to save the dragging state rather than let user passing it in?

Copy link
Contributor

@07akioni 07akioni Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let someTreeDragging = false

{
  onDragOver () {
    if (someTreeDragging && !this.state.dragging) { this.setState(dragging) }
  },
  onDragStart() {
    someTreeDragging = true
    this.setState({ dragging: true })
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be fine as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du you want a fixed "magic" variable name, or should we pass the variable name in props as a string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le to use a global variable to save the dragging state r

Is there a need for magic name? I think we can hold it in a varaible in the package.

@afc163
Copy link
Member

afc163 commented Dec 23, 2021

图片

@jmatelowski
Copy link

Too low test coverage is the only reason why it is still not merged? 😞

@thomasstjerne
Copy link
Contributor Author

I am afraid the code on master changed too much since March 8th 2021 when this pull request was active. I am not able to find time for another round of rewriting, sorry.

@yarlajs
Copy link

yarlajs commented Oct 8, 2023

可以这样解决

const treeInstance = React.useRef<Tree>();
React.useLayoutEffect(() => {
    if (treeInstance.current) {
        const onNodeDragEnter = treeInstance.current.onNodeDragEnter;
        const onNodeDragOver = treeInstance.current.onNodeDragOver;
        if (typeof onNodeDragEnter === "function") {
            treeInstance.current.onNodeDragEnter = function (...argv: any[]) {
                if (treeInstance.current.dragNode) {
                    return onNodeDragEnter.call(this, ...argv);
                }
            }
        }
        if (typeof onNodeDragOver === "function") {
            treeInstance.current.onNodeDragOver = function (...argv: any[]) {
                if (treeInstance.current.dragNode) {
                    return onNodeDragOver.call(this, ...argv);
                }
            }
        }
    }
}, []);
return <Tree ref={treeInstance} />;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants