Skip to content

Feat: single-pod cut-n-paste support #165

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

Merged
merged 2 commits into from
Dec 24, 2022

Conversation

li-xin-yi
Copy link
Collaborator

@li-xin-yi li-xin-yi commented Dec 23, 2022

Don't merge now, this is just a demo to align the idea of cut-n-paste functionality and tests. The code is too dirty now, clean-up is required after we agree on the idea.

Update: clean-up & ready for review.

How to use:

  1. Click on the cut button of a pod, then the pod become half-transparent immediately.
  2. This half-transparent pod will follow your mouse like pasting behavior.
  3. Choose a destination location, click on it, the new pasted pod is located here and become solid.
  4. If you don't want to proceed anymore, press Esc, the half-transparent pod disappears and the origin pod shows up again.

Note:

  1. Like copying, the data will be written in your clipboard, you can still paste it into any repos even if your cutting procedure ends, until you copy new contents.
  2. During the whole cut-n-paste procedure, that is, before canceled by Esc or confirmed by clicking, collaborators won't observe any clues. They can't see the half-transparent pods, the origin pod remains on their side.

Any test and suggestion are welcome.

@li-xin-yi li-xin-yi marked this pull request as draft December 23, 2022 18:51
@lihebi lihebi linked an issue Dec 23, 2022 that may be closed by this pull request
@lihebi
Copy link
Collaborator

lihebi commented Dec 23, 2022

Thanks, Xinyi! Yes, this is what we want.

@forrestbao FYI, this would complete #99 and deprecate #143

Later, we'll have another PR to support copy/cut for a scope (recursively for all descendants).

@li-xin-yi
Copy link
Collaborator Author

li-xin-yi commented Dec 23, 2022

Update:

Check if there is an in-progress pasting before exiting. If there is, do what Esc does.

@li-xin-yi li-xin-yi changed the title [WIP] Single-pod cut-n-paste demo Feat: single-pod cut-n-paste support Dec 23, 2022
@li-xin-yi li-xin-yi marked this pull request as ready for review December 23, 2022 23:02
Copy link
Collaborator

@lihebi lihebi left a comment

Choose a reason for hiding this comment

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

Thank you!

@lihebi lihebi merged commit fa4016e into codepod-io:main Dec 24, 2022
@@ -1344,12 +1394,16 @@ export function Canvas() {
checkNodesEndLocation(event, [currentNode], "ROOT");
//clear the pasting state
setPasting(null);
// delete the original (hidden) node
if (cutting) {
reactFlowInstance.deleteElements({ nodes: [{ id: cutting }] });
Copy link
Collaborator

Choose a reason for hiding this comment

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

When cutting, once the user left-click to drop the node, it will trigger:

  1. add the new node (the addPod(apolloClient, ...) above)
  2. delete the original hidden node.

I'm having some trouble with 2. This line seems to trigger deletePod(null, ...) in nodes.tsx, so there won't be a remote deletePod graphql query. But I do see a deletePod query. Can you point out where does that deletePod query come from?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. It should come from onNodesDelete.

Copy link
Collaborator Author

@li-xin-yi li-xin-yi Jan 1, 2023

Choose a reason for hiding this comment

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

Yes, it triggers onNodeChanges's delete type when deleteElements is called, which deletes the corresponding in nodesMap, any deletion in nodesMap invokes a deletePod(null, ...) call.

I generalized the logic in #184. This PR is almost done, except I need a better implementation to create a scope as well as its children in DB at once. You can try that PR to see if it is the expected behavior of scope cut-copy-paste.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see, thanks. Yeah, that PR is a great reference on this. I'll take a close look.

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.

Cannot move pod out of a scope
2 participants