Skip to content

Fix #426 Add loading states #427

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

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

Fix #426 Add loading states #427

wants to merge 3 commits into from

Conversation

Anchel123
Copy link
Contributor

@Anchel123 Anchel123 commented Mar 26, 2025

PR Type

Enhancement, Bug fix


Description

  • Added loading indicators for graph fetching and options loading.

    • Introduced isFetchingGraph state for graph loading.
    • Updated CodeGraph to display a spinner during graph fetching.
    • Enhanced Combobox to show a loading state when fetching options.
  • Improved Combobox behavior:

    • Disabled selection when no options are available and not fetching.
    • Added a spinner and message for fetching options.
  • Fixed minor issues and improved user experience:

    • Removed unnecessary debugger statement in GraphView.
    • Enhanced error handling for API fetch failures.

Changes walkthrough 📝

Relevant files
Enhancement
code-graph.tsx
Added loading state and spinner for graph fetching             

app/components/code-graph.tsx

  • Added isFetchingGraph state to manage graph loading.
  • Displayed a spinner when fetching the graph.
  • Updated UI to handle empty graph state more gracefully.
  • +16/-7   
    combobox.tsx
    Enhanced combobox with loading state and error handling   

    app/components/combobox.tsx

  • Added isFetchingOptions state for options loading.
  • Disabled combobox when no options are available.
  • Displayed spinner and messages during options fetching.
  • Improved API fetch error handling.
  • +44/-23 
    page.tsx
    Added graph loading state and improved error handling       

    app/page.tsx

  • Added isFetchingGraph state to manage graph loading.
  • Enhanced error handling for graph fetching API calls.
  • Updated CodeGraph component to use the new loading state.
  • +25/-18 
    Bug fix
    graphView.tsx
    Minor cleanup and zoom behavior improvement                           

    app/components/graphView.tsx

  • Removed unnecessary debugger statement.
  • Improved zoom behavior by resetting zoomed nodes.
  • +0/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • - Introduced `isFetchingGraph` state to manage loading state in the graph component.
    - Updated `CodeGraph` to display a loading spinner while fetching the graph.
    - Enhanced `Combobox` to show a loading state when fetching options.
    - Updated the Combobox component to disable the select input when there are no options and not fetching options, improving user experience.
    Copy link

    vercel bot commented Mar 26, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    code-graph ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 3, 2025 9:59am

    Copy link
    Contributor

    coderabbitai bot commented Mar 26, 2025

    Important

    Review skipped

    Auto reviews are disabled on base/target branches other than the default branch.

    Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


    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 plan to trigger planning for file edits and PR creation.
    • @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.

    @Anchel123 Anchel123 requested a review from barakb March 26, 2025 12:48
    @Anchel123 Anchel123 linked an issue Mar 26, 2025 that may be closed by this pull request
    Copy link
    Contributor

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Prop Inconsistency

    The component signature has changed with options/setOptions being moved from props to internal state, but the component is still being called with these props in page.tsx.

    const [options, setOptions] = useState<string[]>([]);
    
    Error Handling

    The error handling in fetchOptions doesn't properly handle network errors (like connection failures) which could cause the loading state to remain indefinitely.

    try {
        const result = await fetch(`/api/repo`, {
            method: 'GET',
        })
    
        if (!result.ok) {
            toast({
                variant: "destructive",
                title: "Uh oh! Something went wrong.",
                description: await result.text(),
            })
            return 
        }
    
        const json = await result.json()
        setOptions(json.result)
    } finally {
        setIsFetchingOptions(false)
    }
    

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 26, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix parameter mismatch

    The function parameters don't match the Props interface. The options and
    setOptions parameters are missing in the function signature but are used later
    in the component. This mismatch could cause runtime errors.

    app/components/code-graph.tsx [48-58]

     export function CodeGraph({
         graph,
         data,
         setData,
         onFetchGraph,
         isFetchingGraph,
         onFetchNode,
    +    options,
    +    setOptions,
         isShowPath,
         setPath,
         chartRef,
         selectedValue,
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: The function signature is missing the options and setOptions parameters that are defined in the Props interface and used in the component. This mismatch would cause runtime errors when the component tries to access these undefined props.

    High
    Remove duplicate state definition

    This component is redefining options and setOptions as local state, but these
    are also passed as props. This creates a conflict where the local state shadows
    the props, making the component ignore the props values and potentially causing
    inconsistent behavior.

    app/components/code-graph.tsx [85]

    -const [options, setOptions] = useState<string[]>([]);
    +// Remove this line as options and setOptions should be used from props
    +// const [options, setOptions] = useState<string[]>([]);
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The component defines local state for options and setOptions while also receiving them as props, creating a conflict where the local state shadows the props. This would cause the component to ignore the props values, breaking expected behavior.

    Medium
    Fix invalid select value

    The value prop is using string literals like "Fetching options..." and "No
    options found" which might not exist in the options array. This can cause React
    Select to have an invalid state where the selected value doesn't match any
    available option, potentially causing rendering issues or unexpected behavior.

    app/components/combobox.tsx [63]

    -<Select open={open} onOpenChange={setOpen} disabled={options.length === 0 && !isFetchingOptions} value={isFetchingOptions ? "Fetching options..." : options.length !== 0 ? selectedValue : "No options found"} onValueChange={onSelectedValue}>
    +<Select 
    +  open={open} 
    +  onOpenChange={setOpen} 
    +  disabled={options.length === 0 && !isFetchingOptions} 
    +  value={options.includes(selectedValue) ? selectedValue : ""} 
    +  onValueChange={onSelectedValue}
    +>
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    __

    Why: The current implementation uses string literals as values that don't exist in the options array, which can cause React Select to have an invalid state. The improved code ensures the value is always valid by checking if the selectedValue exists in options.

    Low
    • Update

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Add loading states
    2 participants