unstract icon indicating copy to clipboard operation
unstract copied to clipboard

UN-1720 [FIX] Refactor to resolve SonarQube duplicate return issue

Open athul-rs opened this issue 5 months ago • 3 comments

Summary

  • Fixed SonarQube code smell in FileUpload.jsx where beforeUpload function had multiple identical return false statements
  • Consolidated logic to use a single return statement with proper conditional handling
  • Added explanatory comment for why the function always returns false (to prevent automatic upload in Ant Design)

Changes

  • Refactored beforeUpload function in /frontend/src/components/agency/file-upload/FileUpload.jsx
  • Used if-else structure instead of multiple returns
  • No functional changes - behavior remains the same

Test Plan

  • [ ] File upload still works as expected
  • [ ] Files are added to list when under the limit
  • [ ] Error message appears when max files exceeded
  • [ ] Manual upload on submit still functions correctly

🤖 Generated with Claude Code

athul-rs avatar Aug 22 '25 09:08 athul-rs

Summary by CodeRabbit

  • New Features
    • Added a configurable limit on files per workflow execution (default: 2), with clear client-side messages if the limit is exceeded or no files are selected.
    • Enabled multiple file selection with UI enforcement of the maximum.
  • Bug Fixes
    • Strengthened validation by requiring a workflow ID for execution, preventing invalid submissions.
  • Chores
    • Introduced a new environment variable to control the maximum files per workflow execution and updated the sample configuration.

Walkthrough

Introduces a new max-files-per-execution setting exposed via env and used in backend validation. Updates serializer to require workflow_id and enforce file count limit from settings. Adds frontend constants and client-side checks mirroring the limit, updates the file upload component, and modifies the continueWfExecution call to include a third parameter.

Changes

Cohort / File(s) Summary
Backend config
backend/backend/settings/base.py, backend/sample.env
Adds WORKFLOW_PAGE_MAX_FILES (default 2) in settings and sample.env with descriptive comments.
Backend workflow serializer
backend/workflow_manager/workflow_v2/serializers.py
Imports settings; makes ExecuteWorkflowSerializer.workflow_id required; replaces validation to enforce max uploaded files from request.FILES against settings.WORKFLOW_PAGE_MAX_FILES; raises ValidationError on exceed with code "max_file_limit_exceeded".
Frontend upload component
frontend/src/components/agency/file-upload/FileUpload.jsx
Adds client-side max-file checks using constants; shows error messages; sets Upload maxCount and multiple; adjusts continueWfExecution call to include a third argument; prevents auto-upload.
Frontend constants
frontend/src/components/agency/file-upload/WfConstants.js
New module exporting WORKFLOW_PAGE_MAX_FILES=2 and WORKFLOW_VALIDATION_MESSAGES (MAX_FILES_EXCEEDED, NO_FILES_SELECTED, WORKFLOW_ID_REQUIRED).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as FileUpload.jsx
  participant Const as WfConstants.js
  participant API as Backend API
  participant Ser as ExecuteWorkflowSerializer

  User->>UI: Select files
  UI->>Const: Read WORKFLOW_PAGE_MAX_FILES
  alt Files exceed limit
    UI-->>User: Show MAX_FILES_EXCEEDED
  else Within limit
    User->>UI: Click Submit
    alt No files
      UI-->>User: Show NO_FILES_SELECTED
    else OK
      UI->>API: continueWfExecution(wfId, files, params)
      API->>Ser: Validate request (files, workflow_id)
      alt Exceeds server limit
        Ser-->>API: ValidationError (max_file_limit_exceeded)
        API-->>UI: 400 with error
        UI-->>User: Show error
      else Valid
        Ser-->>API: OK
        API-->>UI: 200 success
        UI-->>User: Close modal / proceed
      end
    end
  end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch UN-1720-Introducing-workflow-page-limit

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

coderabbitai[bot] avatar Aug 22 '25 09:08 coderabbitai[bot]

filepath function $$\textcolor{#23d18b}{\tt{passed}}$$ SUBTOTAL
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_logs}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_cleanup\_skip}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_client\_init}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_exists}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_container\_run\_config\_without\_mount}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_run\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_get\_image\_for\_sidecar}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{runner/src/unstract/runner/clients/test\_docker.py}}$$ $$\textcolor{#23d18b}{\tt{test\_sidecar\_container}}$$ $$\textcolor{#23d18b}{\tt{1}}$$ $$\textcolor{#23d18b}{\tt{1}}$$
$$\textcolor{#23d18b}{\tt{TOTAL}}$$ $$\textcolor{#23d18b}{\tt{11}}$$ $$\textcolor{#23d18b}{\tt{11}}$$

github-actions[bot] avatar Aug 22 '25 10:08 github-actions[bot]