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): initializing a new main workflow before sync #1014

Merged
merged 3 commits into from
Mar 11, 2025

Conversation

KaWaite
Copy link
Member

@KaWaite KaWaite commented Mar 11, 2025

Overview

What I've done

What I haven't done

How I tested

Screenshot

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Enhanced node double-click interactions to trigger actions more intuitively.
    • Introduced a revamped context menu for nodes with options for opening sub-canvas views, accessing settings, and deleting nodes.
  • Refactor

    • Updated node action parameters to use simpler identifiers, improving responsiveness.
    • Streamlined workflow management through a unified document model, enhancing the collaborative editing experience.

Copy link
Contributor

coderabbitai bot commented Mar 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request updates the event handling for node double-click interactions across several components. The callback signature has been modified from accepting a full node object to receiving a node identifier and an optional subworkflow identifier. In addition, the Yjs integration is refactored by replacing the workflows state (yWorkflows) with a document model (yDoc), and the corresponding props and hook parameters have been updated. Several node type components have also been refactored to use a new ContextMenu system, with added callbacks for node deletion and secondary actions, while the legacy NodeContextMenu component is removed.

Changes

File(s) Change Summary
ui/src/features/Canvas/{hooks.ts, index.tsx} Updated onNodeDoubleClick callback signature to `(e: MouseEvent
ui/src/features/Editor/{components/LeftPanel/index.tsx, editorContext.tsx, hooks.ts, index.tsx} Modified double-click and secondary action handlers: changed parameter from Node to nodeId (with optional subworkflowId); replaced yWorkflows with yDoc in hooks and props.
ui/src/features/SharedCanvas/{hooks.ts, index.tsx} Replaced yWorkflows with yDoc and updated node event handlers to use identifiers for double-click events.
ui/src/lib/reactFlow/{nodeTypes/[BatchNode, GeneralNode, NoteNode, NodeContextMenu.tsx], useNodes.ts} Introduced a new ContextMenu system with callbacks for node deletion and secondary actions; removed the legacy NodeContextMenu component; updated useNodes to add the optional onNodeDoubleClick callback with the new signature.
ui/src/lib/yjs/useYjsSetup.ts & ui/src/routes/{shared.$sharedToken.lazy.tsx, workspaces.$workspaceId_.projects_.$projectId.lazy.tsx} Revised Yjs setup by eliminating the yWorkflows state and using yDoc instead; updated destructuring and conditional checks in route components to align with the new data structure.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant N as Node Component
    participant H as useNodes Hook
    participant C as onNodeDoubleClick Callback

    U->>N: Double-click on node
    N->>H: Call handleNodeDoubleClick(e, nodeId, subworkflowId)
    H->>C: Invoke onNodeDoubleClick(e, nodeId, subworkflowId)
Loading

Possibly related PRs

  • feat(worker): add metadata types and logging setup and update asset download logic #599: The changes in the main PR are related to the modifications of the onNodeDoubleClick callback function and its parameters, which are also updated in the retrieved PR's context, indicating a shared focus on handling node interactions.
  • feat(ui): Batch Node Customization #695: The changes in the main PR, which involve adding and modifying the onNodeDoubleClick callback in the Props type and related functions, are related to the changes in the retrieved PR that also involve node handling and customization, specifically in the BatchNode component.
  • feat(ui): improve node functionality + perf improves + bug fixes #282: The changes in the main PR, which introduce a new onNodeDoubleClick callback and modify related functionality in the Canvas component, are directly related to the changes in the retrieved PR that also involve updates to node handling and functionality in the Canvas component.

Poem

I'm a rabbit in the code garden, hopping with glee,
Chewing on new callbacks as fresh as can be.
With node IDs dancing and yDoc in my paw,
Context menus bloom without a flaw.
I nuzzle through changes with a playful spark,
Celebrating each update from dawn until dark.
🐇💻 Happy hops in every line!


📜 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 01b8fcb and 514cbe8.

⛔ Files ignored due to path filters (1)
  • engine/Cargo.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (5)
  • server/api/internal/infrastructure/gcpbatch/batch.go (1 hunks)
  • engine/Cargo.toml (1 hunks)
  • engine/plateau-gis-quality-checker/src-tauri/Cargo.toml (1 hunks)
  • engine/runtime/action-log/src/action.rs (1 hunks)
  • engine/runtime/runtime/src/feature_store.rs (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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 Mar 11, 2025

Deploy Preview for reearth-flow canceled.

Name Link
🔨 Latest commit 514cbe8
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/67cfe0d67e371c0008d5750e

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 (4)
ui/src/lib/reactFlow/nodeTypes/GeneralNode/index.tsx (1)

123-129: Consider removing commented code

There's a commented-out section for a "Subworkflow from Selection" menu item. If this feature is planned for future implementation, consider adding a TODO comment explaining the plan. Otherwise, it might be cleaner to remove this commented code.

-        {/* <ContextMenuItem
-      className="justify-between gap-4 text-xs"
-      disabled={!selected}>
-      {t("Subworkflow from Selection")}
-      <Graph weight="light" />
-    </ContextMenuItem> */}
+        {/* TODO: Implement "Subworkflow from Selection" feature in future release */}
ui/src/lib/reactFlow/nodeTypes/BatchNode/index.tsx (1)

117-122: Consider removing commented code.

The commented menu item for "Subworkflow from Selection" could be removed if it's not planned for the near future, or a TODO comment could be added to explain its purpose.

-  {/* <ContextMenuItem
-      className="justify-between gap-4 text-xs"
-      disabled={!selected}>
-      {t("Subworkflow from Selection")}
-      <Graph weight="light" />
-    </ContextMenuItem> */}
ui/src/lib/reactFlow/nodeTypes/NoteNode/index.tsx (2)

96-104: Redundant element check.

There's a redundant element check in the ref callback. The inner "if (element)" check is unnecessary as it's already within an outer element check.

ref={(element) => {
  if (element) {
-    if (element)
      element.style.setProperty(
        "color",
        data.params?.textColor || "",
        "important",
      );
  }
}}

134-139: Consider removing commented code.

The commented menu item for "Subworkflow from Selection" could be removed if it's not planned for the near future.

-  {/* <ContextMenuItem
-      className="justify-between gap-4 text-xs"
-      disabled={!selected}>
-      {t("Subworkflow from Selection")}
-      <Graph weight="light" />
-    </ContextMenuItem> */}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 67daa8b and 01b8fcb.

📒 Files selected for processing (16)
  • ui/src/features/Canvas/hooks.ts (5 hunks)
  • ui/src/features/Canvas/index.tsx (4 hunks)
  • ui/src/features/Editor/components/LeftPanel/index.tsx (2 hunks)
  • ui/src/features/Editor/editorContext.tsx (1 hunks)
  • ui/src/features/Editor/hooks.ts (3 hunks)
  • ui/src/features/Editor/index.tsx (3 hunks)
  • ui/src/features/SharedCanvas/hooks.ts (3 hunks)
  • ui/src/features/SharedCanvas/index.tsx (2 hunks)
  • ui/src/lib/reactFlow/nodeTypes/BatchNode/index.tsx (2 hunks)
  • ui/src/lib/reactFlow/nodeTypes/GeneralNode/index.tsx (3 hunks)
  • ui/src/lib/reactFlow/nodeTypes/NodeContextMenu.tsx (0 hunks)
  • ui/src/lib/reactFlow/nodeTypes/NoteNode/index.tsx (2 hunks)
  • ui/src/lib/reactFlow/useNodes.ts (3 hunks)
  • ui/src/lib/yjs/useYjsSetup.ts (2 hunks)
  • ui/src/routes/shared.$sharedToken.lazy.tsx (1 hunks)
  • ui/src/routes/workspaces.$workspaceId_.projects_.$projectId.lazy.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • ui/src/lib/reactFlow/nodeTypes/NodeContextMenu.tsx
🔇 Additional comments (47)
ui/src/features/SharedCanvas/index.tsx (1)

1-1: Clean refactoring to use Doc instead of YArray

The changes appropriately refactor the component to use the full Yjs Doc object rather than just the yWorkflows array. This approach gives the component direct access to the entire document structure, which is more flexible and aligns with the PR's goal of improving workflow initialization before sync.

Also applies to: 13-13, 19-19, 40-40

ui/src/features/Canvas/hooks.ts (2)

7-7: Improved node double-click event handler signature

The updated signature for onNodeDoubleClick now takes specific parameters (nodeId and optional subworkflowId) instead of likely passing the entire node object. This is a more precise approach that provides better type safety and clearer API contracts.

Also applies to: 18-22


51-51: Consistent implementation of the updated node double-click handler

The handler is now properly integrated throughout the component: it's destructured from props, extracted from the useNodes hook, and included in the returned object. This ensures the event propagates correctly through the component hierarchy.

Also applies to: 62-62, 69-69, 86-86

ui/src/features/Editor/index.tsx (2)

2-2: Consistent refactoring to use Doc instead of YArray

The changes in the Editor component follow the same pattern as in SharedCanvas, replacing yWorkflows with yDoc. This consistent approach across components simplifies the data flow and ensures the entire document is available where needed.

Also applies to: 17-17, 23-23, 66-66


70-72: Using handleNodeDoubleClick as onSecondaryNodeAction in editor context

The node double-click handler is now being used as the secondary action handler in the editor context. This aligns well with the signature updates in other files and maintains a consistent pattern for node interactions throughout the application.

ui/src/routes/shared.$sharedToken.lazy.tsx (2)

56-60: Improved destructuring from useYjsSetup

The refactoring from using a nested state object to directly destructuring the needed values (yDoc, isSynced, undoTrackerActionWrapper) creates a cleaner and more maintainable structure. This reduces indirection and makes the component's dependencies more explicit.


61-71: Enhanced dependency checking before rendering

The conditional rendering now properly checks for all required dependencies (yDoc, isSynced, undoTrackerActionWrapper) before rendering the SharedCanvas component. This ensures that all necessary data is available, preventing potential rendering issues or errors.

ui/src/features/Canvas/index.tsx (3)

40-44: Updated callback signature for better data flow

The onNodeDoubleClick prop type has been updated to pass node identifiers rather than the full node object. This is a good practice as it reduces data coupling and makes the component interfaces more explicit about what data they actually need.


72-72: Improved event handling through hooks abstraction

The addition of handleNodeDoubleClick and its inclusion in the props passed to useHooks creates a cleaner separation of concerns. Event handling logic now resides in a dedicated hook, which follows React best practices.

Also applies to: 82-82


132-132: Consistent callback implementation

The onNodeDoubleClick handler is now consistently implemented through handleNodeDoubleClick from the hook rather than directly using the prop. This ensures that all node double-click events are processed through the same code path.

ui/src/lib/reactFlow/useNodes.ts (3)

26-30: Well-defined prop type for node double-click event

The onNodeDoubleClick prop type is clearly defined with appropriate optional parameters, which improves type safety and code readability.


264-269: Efficient event handler implementation

The handleNodeDoubleClick function correctly extracts only the necessary data (nodeId and subworkflowId) from the node object. This approach is more efficient than passing the entire node object and follows the principle of minimizing data transfer between components.


277-277: Complete hook API exposure

Properly exposing the handleNodeDoubleClick function in the returned object ensures that consuming components can access this functionality.

ui/src/lib/yjs/useYjsSetup.ts (3)

71-71: Simplified Yjs document handling

The refactoring to use yDoc directly instead of maintaining yWorkflows in state reduces code complexity and potential state synchronization issues. This is a good architectural improvement.

Also applies to: 90-91


74-76: On-demand workflows derivation

Deriving yWorkflows from yDoc within the effect is more efficient as it ensures that workflows are only accessed when needed, rather than being stored separately in state.


87-87: Optimized effect dependencies

The dependency array now correctly includes only yDoc, reflecting that the effect no longer depends on other variables, which reduces unnecessary re-executions.

ui/src/features/Editor/components/LeftPanel/index.tsx (3)

33-37: Consistent prop typing across components

The updated onNodeDoubleClick function signature aligns with the changes in other components, ensuring a consistent API throughout the application.


74-74: Updated callback implementation

The call to onNodeDoubleClick now correctly passes the node ID and subworkflow ID instead of the entire node object, adhering to the new signature.


30-31: Explicitly defined callback props

The onOpen and onNodesAdd props are now explicitly defined in the Props type and properly destructured from the props. This improves code clarity and maintainability.

Also applies to: 46-47

ui/src/features/Editor/editorContext.tsx (2)

9-9: Import statement correctly updated to remove unused Node import

The import statement has been properly updated to remove the Node import that's no longer needed after the parameter type change in onSecondaryNodeAction.


13-17: Clean function signature improvement

The signature change from accepting a full Node object to just using a nodeId string with an optional subworkflowId improves the API design by:

  1. Reducing data passing between components
  2. Decoupling components from the full Node structure
  3. Making the interface more focused on what's actually needed

The addition of the subworkflowId parameter also provides better support for nested workflow functionality.

ui/src/routes/workspaces.$workspaceId_.projects_.$projectId.lazy.tsx (3)

71-77: State management refactoring using yDoc directly

The destructuring from useYjsSetup has been updated to extract yDoc, isSynced, undoManager, and undoTrackerActionWrapper directly, replacing the previous approach of extracting state. This change appears to be part of a broader refactoring to simplify how Yjs data is accessed throughout the application.


79-79: Updated conditional rendering with additional checks

The conditional rendering now includes checks for yDoc and undoTrackerActionWrapper in addition to isSynced. This properly ensures all required dependencies are available before rendering the Editor component.


82-86: Props updated to match new state management approach

The Editor component now receives yDoc and undoTrackerActionWrapper directly as props, rather than accessed through the state object. This is consistent with the changes in the hook destructuring and provides a more direct data flow.

ui/src/features/SharedCanvas/hooks.ts (4)

4-4: Import for Doc from yjs correctly added

The import for Doc from yjs is properly added to support the parameter type change.


18-18: Parameter type updated from yWorkflows to yDoc

The parameter has been changed from yWorkflows to yDoc of type Doc, aligning with the application-wide changes to how Yjs data is accessed.

Also applies to: 22-22


26-27: Local derivation of yWorkflows from yDoc

The hook now locally derives yWorkflows from yDoc using getArray<YWorkflow>("workflows"). This ensures consistent access to the workflow data across components and follows the pattern established in other parts of the application.


94-104: Node double-click handler updated to use IDs instead of Node objects

The handleNodeDoubleClick function now accepts nodeId and an optional subworkflowId instead of a full Node object. The internal logic has been properly adjusted to use these new parameters:

  1. It checks for subworkflowId directly and calls handleWorkflowOpen if it exists
  2. Otherwise, it fits the view using nodeId instead of node.id
  3. The call to handleNodeLocking has been updated to use nodeId

This change aligns with the broader refactoring effort to use identifiers rather than objects for node interactions.

ui/src/lib/reactFlow/nodeTypes/GeneralNode/index.tsx (3)

1-9: Imports updated for new context menu implementation

The import statements have been expanded to include additional icons and components from the @flow/components library. The NodeContextMenu has been replaced with a more structured ContextMenu implementation, and necessary hooks have been added for editor context and translations.

Also applies to: 13-22


40-52: Added callbacks for node operations using editor context

Two callback functions have been properly implemented:

  1. handleNodeDelete: Uses onNodesChange to remove the node
  2. handleSecondaryNodeAction: Uses onSecondaryNodeAction to trigger actions based on node type

Both functions are correctly wrapped with useCallback for performance optimization and properly utilize the node ID and subworkflow ID as per the updated API design.


66-138: Enhanced UI with structured context menu

The rendering logic has been upgraded to replace the previous menu system with a comprehensive context menu implementation that includes:

  1. A context menu trigger wrapping the main node display
  2. Conditional menu items based on node type (subworkflow vs other nodes)
  3. Appropriate icons and translations for menu options
  4. A separator and delete option
  5. Disabled preview option for action nodes

This enhances usability while maintaining the existing node display functionality.

ui/src/lib/reactFlow/nodeTypes/BatchNode/index.tsx (6)

1-7: LGTM: Clean imports for icons.

The icon imports from @phosphor-icons/react are well organized and match the context menu requirements.


11-20: Well-structured component imports.

Good organization of the new ContextMenu components and necessary hooks. The isActionNodeType import will be helpful for conditional rendering.


27-34: LGTM: Well-implemented node deletion callback.

The handleNodeDelete callback is correctly memoized with useCallback and has the appropriate dependencies.


35-39: LGTM: Secondary action handler looks good.

The handleSecondaryNodeAction is properly implemented with null checks and appropriate dependencies.


66-93: LGTM: Context menu trigger implementation.

The ContextMenuTrigger wraps the node content well, maintaining the existing styling while adding context menu functionality.


94-131: Clean implementation of the context menu.

The context menu implementation handles different node types appropriately, with conditional rendering based on node type and features.

ui/src/features/Editor/hooks.ts (4)

31-36: LGTM: API updated from yWorkflows to yDoc.

Good refactoring to use the Doc object directly, which provides more flexibility.


39-51: Good initialization of main workflow when empty.

The implementation correctly initializes a new main workflow if none exists, ensuring the application always has a valid starting point.


146-168: Well-structured parameter change for node double-click handler.

The handler has been refactored to take a nodeId and subworkflowId instead of the entire node object, which is more efficient and clearer.


170-174: LGTM: Updated callback signature for consistency.

The handleNodeDoubleClick callback signature has been updated to match the ref function, maintaining consistency.

ui/src/lib/reactFlow/nodeTypes/NoteNode/index.tsx (6)

1-14: LGTM: Clean imports for icons and context menu components.

Added necessary imports to support the new context menu functionality.


22-25: Updated component signature to include id and type.

Correctly updated the component signature to include the id and type props needed for the context menu functionality.


27-34: LGTM: Well-implemented node deletion callback.

The handleNodeDelete callback is properly implemented with useCallback for memoization.


31-34: LGTM: Secondary action handler looks good.

The handleSecondaryNodeAction is properly implemented with null checks and appropriate dependencies.


64-109: LGTM: Context menu trigger with proper styling.

The implementation of the context menu trigger maintains the existing styling while adding the new menu functionality.


111-147: LGTM: Well-structured context menu content.

The context menu content is well-organized with appropriate items based on node type.

@KaWaite KaWaite merged commit 289d50c into main Mar 11, 2025
21 checks passed
@KaWaite KaWaite deleted the ui/fix-when-to-initialize-ydoc branch March 11, 2025 07:08
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.

1 participant