Skip to content

Conversation

@amhsirak
Copy link
Member

@amhsirak amhsirak commented Mar 18, 2025

No description provided.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request introduces a new targetUrl parameter into the workflow update process across multiple components. The server endpoint now validates and processes this parameter by updating workflow steps, and the API function has been modified to accept an optional targetUrl. Additionally, the robot editing modal on the frontend now features a dedicated text field and handler for dynamically setting this URL, ensuring that any "goto" actions are properly updated before saving.

Changes

File(s) Change Summary
server/src/routes/storage.ts Updated the PUT /recordings/:id endpoint by adding targetUrl to the request body, enhancing validation to require one of name, limit, or targetUrl, and modifying workflow steps to replace existing URLs (including goto actions) with targetUrl when provided.
src/api/storage.ts Modified the updateRecording function signature to include an optional targetUrl in the data parameter, expanding the accepted properties without altering the core logic.
src/components/robot/RobotEdit.tsx Removed the unused useNavigate import; added a new handleTargetUrlChange function to update the robot's target URL; updated the save function to send the targetUrl with the API call; introduced a new TextField in the modal for user input of the target URL.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Modal as RobotEditModal
    participant API
    participant Server

    User->>Modal: Enter target URL in TextField
    Modal->>Modal: handleTargetUrlChange() updates robot state
    User->>Modal: Click Save
    Modal->>API: Call updateRecording({ targetUrl, ... })
    API->>Server: PUT /recordings/:id with targetUrl
    Server->>Server: Validate input & update workflow steps (replace URLs)
    Server-->>API: Return updated recording
    API-->>Modal: Send response back to UI
Loading

Possibly related PRs

  • getmaxun/maxun#309: Aligns with the addition of the targetUrl parameter in both the API and workflow update logic.
  • getmaxun/maxun#385: Involves similar updates to function signatures where the targetUrl is incorporated.
  • getmaxun/maxun#435: Focuses on modifying workflow actions to integrate the new targetUrl, closely relating to these changes.

Suggested labels

Type: Feature

Poem

In a field of code, I softly bound,
A new target URL hopped around.
With each step updated on the fly,
Workflows now reach for the sky.
A rabbit’s cheer, so playful and bright,
Leaping through changes with pure delight! 🐰💻

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@amhsirak amhsirak added the Type: Feature New features label Mar 18, 2025
Copy link

@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 (6)
server/src/routes/storage.ts (3)

265-266: Update error message to match parameter name.

There's a discrepancy between the error message which refers to "target_url" and the actual parameter name "targetUrl".

-  return res.status(400).json({ error: 'Either "name", "limit" or "target_url" must be provided.' });
+  return res.status(400).json({ error: 'Either "name", "limit" or "targetUrl" must be provided.' });

281-297: Consider adding URL validation.

The code updates the workflow with the provided target URL without any validation. Consider adding basic URL validation to prevent potential issues.

if (targetUrl) {
+  // Basic URL validation
+  try {
+    new URL(targetUrl);
+  } catch (error) {
+    return res.status(400).json({ error: 'Invalid URL format.' });
+  }

  const updatedWorkflow = robot.recording.workflow.map((step) => {
    if (step.where?.url && step.where.url !== "about:blank") {
      step.where.url = targetUrl;
    }

    step.what.forEach((action) => {
      if (action.action === "goto" && action.args?.length) {
        action.args[0] = targetUrl; 
      }
    });

    return step;
  });

281-297: Consider refactoring duplicated URL update logic.

The URL update logic is duplicated in the duplicate endpoint (lines 399-411). Consider extracting this logic into a reusable helper function.

// Suggested helper function to place at the module level
function updateWorkflowUrls(workflow: any[], targetUrl: string): any[] {
  return workflow.map((step) => {
    if (step.where?.url && step.where.url !== "about:blank") {
      step.where.url = targetUrl;
    }

    step.what.forEach((action) => {
      if (action.action === "goto" && action.args?.length) {
        action.args[0] = targetUrl; 
      }
    });

    return step;
  });
}

Then use it in both places:

// In the PUT endpoint
const updatedWorkflow = updateWorkflowUrls(robot.recording.workflow, targetUrl);
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });

// In the duplicate endpoint
const workflow = updateWorkflowUrls(originalRobot.recording.workflow, targetUrl);
src/components/robot/RobotEdit.tsx (3)

308-324: Implement consistent URL handling logic.

The handleTargetUrlChange function only updates the URL in the last workflow pair, while the server updates all applicable URLs in the workflow. Consider making the client-side behavior match the server-side implementation for consistency.

const handleTargetUrlChange = (newUrl: string) => {
    setRobot((prev) => {
        if (!prev) return prev;

        const updatedWorkflow = [...prev.recording.workflow];
-       const lastPairIndex = updatedWorkflow.length - 1;
-
-       if (lastPairIndex >= 0) {
-           const gotoAction = updatedWorkflow[lastPairIndex]?.what?.find(action => action.action === "goto");
-           if (gotoAction && gotoAction.args && gotoAction.args.length > 0) {
-               gotoAction.args[0] = newUrl;
-           }
-       }
+       
+       // Update all URLs in the workflow, matching server-side behavior
+       updatedWorkflow.forEach((step) => {
+           if (step.where?.url && step.where.url !== "about:blank") {
+               step.where.url = newUrl;
+           }
+           
+           step.what.forEach((action) => {
+               if (action.action === "goto" && action.args?.length) {
+                   action.args[0] = newUrl;
+               }
+           });
+       });

        return { ...prev, recording: { ...prev.recording, workflow: updatedWorkflow } };
    });
};
🧰 Tools
🪛 Biome (1.9.4)

[error] 317-317: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


317-318: Use optional chaining consistently.

The code can be simplified by using optional chaining consistently.

-            const gotoAction = updatedWorkflow[lastPairIndex]?.what?.find(action => action.action === "goto");
-            if (gotoAction && gotoAction.args && gotoAction.args.length > 0) {
+            const gotoAction = updatedWorkflow[lastPairIndex]?.what?.find(action => action.action === "goto");
+            if (gotoAction?.args?.length > 0) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 317-317: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


410-418: Consider DRY principle for target URL extraction.

The URL extraction logic is duplicated across the component. Consider extracting it into a helper function or memoizing the result.

// Add this helper function to the component
const getTargetUrl = (workflow: WhereWhatPair[] = []) => {
  const lastPair = workflow[workflow.length - 1];
  return lastPair?.what?.find(action => action.action === "goto")?.args?.[0] || '';
};

// Then use it in both places:
// 1. For the TextField value
const targetUrl = getTargetUrl(robot?.recording?.workflow);

// 2. In the handleSave function
const payload = {
  name: robot.recording_meta.name,
  limit: robot.recording.workflow[0]?.what[0]?.args?.[0]?.limit,
  credentials: credentialsForPayload,
  targetUrl: getTargetUrl(robot.recording.workflow),
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39022a5 and bdbbc02.

📒 Files selected for processing (3)
  • server/src/routes/storage.ts (2 hunks)
  • src/api/storage.ts (1 hunks)
  • src/components/robot/RobotEdit.tsx (8 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/robot/RobotEdit.tsx

[error] 317-317: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
server/src/routes/storage.ts (2)

262-262: Good addition of the new targetUrl parameter.

The code now properly includes the target URL in the request body destructuring.


296-298: Good use of model update patterns.

The code correctly uses set and changed methods to update the model, which ensures proper change tracking.

src/api/storage.ts (1)

31-31: Function signature correctly updated to include targetUrl.

The updateRecording function now properly accepts the new optional targetUrl parameter, aligning with the server-side implementation.

src/components/robot/RobotEdit.tsx (2)

437-438: Good use of optional chaining in URL extraction.

The code effectively uses optional chaining to safely extract the target URL from potentially undefined nested properties.


462-469: Good UI implementation for target URL editing.

The new text field for editing the target URL is properly integrated with the component state and handlers.

@amhsirak amhsirak merged commit 2f3a769 into develop Mar 19, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants