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

feat(ui): Hide Reader and Writer options in toolbox if subworkflow #693

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

popy01012
Copy link

@popy01012 popy01012 commented Dec 12, 2024

Overview

I made if the current tab is subworkflow, reader and writer node in the toolbox are not visible.

What I've done

  • Get current tab name
  • If current tab in not main, make reader and writer node in the toolbox are not visible.

What I haven't done

How I tested

Manually

Screenshot

image
image

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features
    • Enhanced Toolbox component to display tools based on the current workflow context.
    • Introduced a new hook to access the current workflow ID.
  • Bug Fixes
    • Adjusted available tools based on workflow ID, ensuring the correct tools are shown for different workflows.

@popy01012 popy01012 requested a review from KaWaite as a code owner December 12, 2024 09:29
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes introduce a new import of useCurrentWorkflowId in the Toolbox component, enabling the retrieval of the current workflow context. A new state variable workflowId is created to manage this context. The logic for determining available tools is modified: when workflowId is equal to DEFAULT_ENTRY_GRAPH_ID, all tools are accessible; otherwise, only the "reader" and "writer" tools are available. This adjustment alters the control flow for tool availability while maintaining the overall structure and functionality of the component.

Changes

File Change Summary
ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx Added import for useCurrentWorkflowId, created workflowId state, and modified availableTools logic based on workflowId.
ui/src/stores/index.ts Introduced new atom currentWorkflowId and hook useCurrentWorkflowId for managing workflow context.

Possibly related PRs

Suggested reviewers

  • KaWaite

🐰 In the toolbox, where tools align,
A workflow's magic, oh so fine!
With "main" all tools, a feast to see,
But if not "main," just two for thee.
Hops of joy in code we find,
Celebrating changes, oh so kind! 🎉


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. (Experiment)
  • @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 Dec 12, 2024

Deploy Preview for reearth-flow ready!

Name Link
🔨 Latest commit 4ff20ab
🔍 Latest deploy log https://app.netlify.com/sites/reearth-flow/deploys/675ab4e21aeaa700081c03b6
😎 Deploy Preview https://deploy-preview-693--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
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

🧹 Outside diff range and nitpick comments (2)
ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (2)

40-41: Add error handling for workflow context

While the hook usage is correct, consider adding error handling for cases where the workflow context might be undefined.

-  const [workflowId] = useCurrentWorkflowId();
+  const [workflowId = "main"] = useCurrentWorkflowId();

75-78: Extract magic string and improve filtering logic

The implementation correctly hides reader and writer nodes in subworkflows, but could be more maintainable.

Consider these improvements:

+ const MAIN_WORKFLOW_ID = "main";
+ const EXCLUDED_SUBWORKFLOW_TOOLS: NodeType[] = ["reader", "writer"];

  const availableTools =
-   workflowId === "main"
+   workflowId === MAIN_WORKFLOW_ID
      ? allTools
-     : allTools.filter((tool) => tool.id !== "reader" && tool.id !== "writer");
+     : allTools.filter((tool) => !EXCLUDED_SUBWORKFLOW_TOOLS.includes(tool.id));

This makes the code more maintainable and easier to update if the list of excluded tools changes in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2fa9aeb and 82d92cc.

📒 Files selected for processing (1)
  • ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (3 hunks)
🔇 Additional comments (2)
ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (2)

17-17: LGTM: Clean import of workflow context hook

The addition of useCurrentWorkflowId hook follows React best practices for managing workflow context.


75-78: Verify impact on existing workflow functionality

While the implementation correctly achieves the PR objective, let's verify the integration points.

✅ Verification successful

No impact on existing functionality detected

The implementation is isolated to the Toolbox component and the condition is specific to subworkflow behavior. The search results show:

  • The Toolbox component is only imported for UI purposes in WorkspaceSettings and WorkspaceLeftPanel
  • No other components rely on the workflowId === "main" logic
  • The change doesn't affect any existing tests as there are no direct Toolbox component tests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components that might be affected by this change
rg -l "useCurrentWorkflowId|workflowId.*main" --type tsx

# Look for any tests that might need updating
fd -e test.tsx -e spec.tsx

Length of output: 115


Script:

#!/bin/bash
# Search for other components that might be affected by this change, using TypeScript extensions
rg -l "useCurrentWorkflowId|workflowId.*main" -g "*.ts" -g "*.tsx"

# Look for any tests that might need updating
fd . -e .test.tsx -e .test.ts -e .spec.tsx -e .spec.ts

# Search for toolbox-related tests and components
rg -l "Toolbox" -g "*.test.tsx" -g "*.test.ts" -g "*.spec.tsx" -g "*.spec.ts"

# Search for workflow-related hooks and utilities
rg -l "useCurrentWorkflow" -g "*.ts" -g "*.tsx"

Length of output: 1062


Script:

#!/bin/bash
# Let's check the Toolbox component's test coverage and related workflow tests
rg -g "*.test.{ts,tsx}" -g "*.spec.{ts,tsx}" -C 5 "Toolbox|workflowId.*main"

# Check for any workflow-related components that might interact with the Toolbox
rg -g "*.{ts,tsx}" -C 3 "import.*Toolbox|from.*Toolbox"

# Look for any workflow ID related logic in the codebase
rg -g "*.{ts,tsx}" -C 3 "workflowId === 'main'"

Length of output: 1543

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

🧹 Outside diff range and nitpick comments (2)
ui/src/stores/index.ts (2)

5-5: Consider using a more specific type for workflow ID

While the current type string | undefined works, consider using a union type to explicitly define allowed values since it appears the workflow ID can only be "main" or undefined based on the PR context.

-const currentWorkflowId = atom<string | undefined>("main");
+type WorkflowId = "main" | undefined;
+const currentWorkflowId = atom<WorkflowId>("main");

5-6: Add documentation for the workflow ID atom

Please add JSDoc comments to document:

  • The purpose of this atom
  • The significance of the "main" value
  • How it affects the toolbox visibility
+/**
+ * Atom to track the current workflow context.
+ * - "main": Indicates the main workflow where all tools are visible
+ * - undefined: Indicates a subworkflow where reader/writer tools are hidden
+ */
const currentWorkflowId = atom<string | undefined>("main");
export const useCurrentWorkflowId = () => useAtom(currentWorkflowId);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82d92cc and bf6d1de.

📒 Files selected for processing (1)
  • ui/src/stores/index.ts (1 hunks)

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

🧹 Outside diff range and nitpick comments (1)
ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (1)

76-80: Consider improving filtering logic readability and performance

While the logic is correct, consider these improvements for better maintainability:

-  const availableTools =
-    workflowId === DEFAULT_ENTRY_GRAPH_ID
-      ? allTools
-      : allTools.filter((tool) => tool.id !== "reader" && tool.id !== "writer");
+  // Hide reader and writer nodes in subworkflows
+  const isMainWorkflow = workflowId === DEFAULT_ENTRY_GRAPH_ID;
+  const restrictedToolTypes = new Set(["reader", "writer"]);
+  const availableTools = isMainWorkflow
+    ? allTools
+    : allTools.filter((tool) => !restrictedToolTypes.has(tool.id));

This refactor:

  1. Adds a descriptive comment explaining the business logic
  2. Introduces a clearer variable name isMainWorkflow
  3. Uses Set for potentially better performance with larger tool sets
  4. Improves readability of the filtering condition
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bf6d1de and 4ff20ab.

📒 Files selected for processing (1)
  • ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (3 hunks)
🔇 Additional comments (4)
ui/src/features/Editor/components/OverlayUI/components/Toolbox/index.tsx (4)

17-18: LGTM: Clean import additions

The new imports are well-organized and necessary for the workflow context functionality.


Line range hint 43-75: LGTM: Clear separation of tool definitions

The renaming from availableTools to allTools improves code clarity by clearly separating the complete set of tools from the filtered subset.


41-41: Verify hook behavior in edge cases

The hook usage looks correct, but let's ensure it handles all scenarios properly:

  1. Initial render with undefined workflowId
  2. Transitions between main workflow and subworkflows
✅ Verification successful

Hook implementation and usage verified as correct

The hook is properly implemented and safely handles all scenarios:

  • Initialized with a default value of "main" in the atom
  • Used consistently across components for workflow management
  • Properly handles transitions between workflows as evidenced by the WorkflowTabs component implementation
  • Safely destructured with only the state value where the setter isn't needed
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for hook usage and initialization to verify proper handling
ast-grep --pattern 'const currentWorkflowId = atom<$_>($_)'
ast-grep --pattern 'export const useCurrentWorkflowId = $_'

Length of output: 303


Script:

#!/bin/bash
# Let's check for all usages of useCurrentWorkflowId to understand the patterns
rg "useCurrentWorkflowId" -A 2

# Also check for any transitions or updates to currentWorkflowId
rg "currentWorkflowId" -A 2

Length of output: 5932


76-80: Verify UI behavior matches provided screenshots

The implementation logic looks correct, but please ensure:

  1. The toolbox UI updates immediately when switching between main workflow and subworkflows
  2. The transition is smooth without visual glitches
  3. The layout adjusts properly when tools are hidden

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