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

fix(ui): SubWork Flow Multi Select Deletion #743

Merged
merged 11 commits into from
Jan 9, 2025

Conversation

billcookie
Copy link
Contributor

@billcookie billcookie commented Jan 7, 2025

Overview

Originally subwork flows could only be deleted one by one and multi selecting subwork flows for deletion would not work (error: “Exceeds maximum length”)

What I've done

  • Essentially it seemed originally we could not handle multiple deletions and that when we deleted multiple subwork flows the index would "shift" and not properly realign. This should now be fixed.

What I haven't done

How I tested

Manually

Screenshot

Which point I want you to review particularly

  • Refactors and possible Improvements

Memo

Summary by CodeRabbit

  • Bug Fixes
    • Improved workflow removal process to handle node and workflow deletion more efficiently.
    • Enhanced logic to prevent index shifting issues during workflow removal.
    • Streamlined the removal logic for better clarity and performance.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request modifies the handleWorkflowsRemove function in the useYWorkflow.ts file, enhancing the logic for removing workflows. A new variable localWorkflows is introduced to create a copy of rawWorkflows, which is used for the removal process, ensuring that the original rawWorkflows remains intact. The nested function removeNodes is updated to work with localWorkflows. After processing node removals, workflow IDs are filtered from both setWorkflows and setOpenWorkflowIds to accurately reflect the state.

Changes

File Change Summary
ui/src/lib/yjs/useYWorkflow.ts Enhanced workflow removal logic by:
  • Introducing localWorkflows to copy rawWorkflows
  • Updating removeNodes to use localWorkflows
  • Filtering workflow IDs from setWorkflows and setOpenWorkflowIds post-removal |

Suggested reviewers

  • KaWaite

Possibly related PRs

Poem

🐰 In the code, workflows twirl and sway,
With careful hops, we clear the way.
IDs collected, nodes set free,
A tidy space for all to see.
Refactoring brings a joyful cheer,
Simplified paths, we hold so dear! ✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daf7631 and d421a45.

📒 Files selected for processing (1)
  • ui/src/lib/yjs/useYWorkflow.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ui/src/lib/yjs/useYWorkflow.ts

Finishing Touches

  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for reearth-flow ready!

Name Link
🔨 Latest commit e90df18
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/677cbddcac6e370008e4455b
😎 Deploy Preview https://deploy-preview-743--reearth-flow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 7, 2025

Deploy Preview for reearth-flow ready!

Name Link
🔨 Latest commit d421a45
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/677f12983a11b00008ff6958
😎 Deploy Preview https://deploy-preview-743--reearth-flow.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@billcookie billcookie marked this pull request as ready for review January 7, 2025 23:52
@billcookie billcookie requested a review from KaWaite as a code owner January 7, 2025 23:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
ui/src/lib/yjs/useYWorkflow.ts (2)

165-173: Consider wrapping Yjs operations in a transaction.

While the descending order approach correctly handles index shifting, consider wrapping the Yjs operations in a transaction for better performance and atomicity.

+        // Wrap deletions in a transaction for better performance and atomicity
+        yWorkflows.doc?.transact(() => {
           indexesToRemove.forEach((index) => {
             yWorkflows.delete(index);
           });
+        });

Also, consider enhancing the comment to better explain the reasoning:

-        // Indexes in descending order to avoid index shifting problems
+        // Sort indexes in descending order (highest to lowest) to ensure that
+        // deleting an item doesn't affect the indexes of subsequent deletions

175-183: Consider batching state updates.

The state updates could be combined using a single React state update for better performance. Also, there's an indentation inconsistency in the setOpenWorkflowIds call.

-        setWorkflows((currentWorkflows) => {
-          const remainingWorkflows = currentWorkflows.filter(
-            (w) => !workflowIds.includes(w.id),
-          );
-          return remainingWorkflows;
-        });
-
-        setOpenWorkflowIds((ids) =>
-          ids.filter((id) => !workflowIds.includes(id)),
-        );
+        const updateStates = () => {
+          setWorkflows((currentWorkflows) => 
+            currentWorkflows.filter((w) => !workflowIds.includes(w.id))
+          );
+          setOpenWorkflowIds((ids) => 
+            ids.filter((id) => !workflowIds.includes(id))
+          );
+        };
+        updateStates();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cfb882 and 5f71e49.

📒 Files selected for processing (1)
  • ui/src/lib/yjs/useYWorkflow.ts (1 hunks)
🔇 Additional comments (2)
ui/src/lib/yjs/useYWorkflow.ts (2)

150-183: Overall implementation looks good! 👍

The changes successfully fix the multi-select deletion issue by:

  1. Correctly handling index shifting during multiple deletions
  2. Maintaining consistency between Yjs and React states
  3. Properly handling nested subworkflows

The suggested improvements above are minor and can be addressed in follow-up PRs.


150-163: 🛠️ Refactor suggestion

Add validation and error handling for workflow IDs.

The current implementation assumes every nodeId (except DEFAULT_ENTRY_GRAPH_ID) is a valid workflow ID. Consider adding validation to ensure the workflow exists before adding it to workflowIds.

 nodeIds.forEach((nid) => {
   if (nid === DEFAULT_ENTRY_GRAPH_ID) return;
-  workflowIds.push(nid);
   const workflow = rawWorkflows.find((w) => w.id === nid);
+  if (!workflow) {
+    console.warn(`Workflow with ID ${nid} not found`);
+    return;
+  }
+  workflowIds.push(nid);
   const nodes = workflow?.nodes;

Also, consider adding a depth limit to prevent potential infinite recursion in case of circular references between subworkflows.

Comment on lines 155 to 156
// Loop over workflow and remove any subworkflow nodes
if (nodes && Array.isArray(nodes)) {
Copy link
Member

Choose a reason for hiding this comment

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

This change iterates on one level deep, and then stops. This is why removeNodes was using itself, to be able to reach ALL subworkflows, no matter how deep.
If you can console.log rawWorkflows and test to make sure when deleting subworkflows that contain subworkflows, that all appropriate workflows are removed on subworkflow node deletion 🙏🏻

@@ -173,6 +174,7 @@ export default ({
setOpenWorkflowIds((ids) =>
ids.filter((id) => !workflowIds.includes(id)),
);
console.log("workflowIds", rawWorkflows);
Copy link
Member

Choose a reason for hiding this comment

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

Delete please

@billcookie billcookie merged commit c711859 into main Jan 9, 2025
16 checks passed
@billcookie billcookie deleted the ui/multi-delete-sub-work-flow-bug branch January 9, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants