Skip to content

fix: ensure that Grid columns are configured before setting a footer toolbar #130

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

Merged
merged 1 commit into from
Jun 11, 2025

Conversation

javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Jun 11, 2025

Add a explicit check to ensure the grid has columns before the toolbar is initialized.

Close #129

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when adding a footer toolbar to a grid without configured columns, now displaying a clear exception if attempted.
  • Documentation

    • Enhanced method documentation to clarify usage requirements and exceptions for adding a toolbar footer to a grid.
  • Tests

    • Added and updated tests to verify correct exception handling and footer toolbar functionality in various scenarios.

@javier-godoy javier-godoy requested review from mlopezFC and paodb June 11, 2025 14:42
Copy link

coderabbitai bot commented Jun 11, 2025

Walkthrough

The changes introduce a precondition check in FooterToolbarGridHelper.setFooterToolbar to throw an IllegalStateException if the grid has no columns configured. Javadoc documentation is added to GridHelper.addToolbarFooter to clarify this requirement. Corresponding unit tests are updated and expanded to verify this behavior.

Changes

Files/Groups Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/FooterToolbarGridHelper.java Added precondition: throws IllegalStateException if grid columns are not configured in setFooterToolbar.
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java Added Javadoc to addToolbarFooter documenting the new precondition and exception.
src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java Refactored tests; added test for exception when toolbar is added before columns are configured.

Assessment against linked issues

Objective Addressed Explanation
Prevent IndexOutOfBoundsException by ensuring grid columns are configured before adding toolbar (#129)
Throw a clear exception (IllegalStateException) if toolbar is set before columns are configured (#129)
Add or update tests to verify exception is thrown in this scenario (#129)
Add documentation clarifying the requirement for columns before adding toolbar (#129)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Copy link

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: 1

🧹 Nitpick comments (2)
src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java (2)

31-37: Test asserts nothing beyond “no exception”

addToolbarFooter() currently passes if no exception is thrown. To verify the feature, consider asserting that the toolbar was actually placed:

var footerRows = grid.getFooterRows();
assertEquals(1, footerRows.size());
assertTrue(footerRows.get(0).getCells().stream()
        .anyMatch(c -> toolbarFooter.equals(c.getComponent().orElse(null))));

This makes the test robust against regressions where the call silently becomes a no-op.


39-44: Prefer assertThrows over expected attribute

Using assertThrows (JUnit 4.13+) gives more control and allows you to assert the exception message too:

assertThrows(IllegalStateException.class,
    () -> GridHelper.addToolbarFooter(grid, toolbarFooter));

It also isolates the failing statement, preventing false positives if another line unexpectedly throws.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea5ddb5 and da3f8e0.

📒 Files selected for processing (3)
  • src/main/java/com/flowingcode/vaadin/addons/gridhelpers/FooterToolbarGridHelper.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java (2 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java (2 hunks)
🔇 Additional comments (1)
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java (1)

351-360: Clear, helpful Javadoc – thanks for adding it

The new comment precisely describes the pre-condition and the resulting exception, making the API contract explicit and discoverable via IDEs/Javadoc.
No further action needed.

Copy link
Member

@paodb paodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved this, but then I realized there's a Sonar issue that might need to be addressed first.

@javier-godoy
Copy link
Member Author

I approved this, but then I realized there's a Sonar issue that might need to be addressed first.

re sonar, it was already there (5bd2788), I just refactored it. Any comments about that test are independent from this issue (Sonar is right, though, and FooterToolbarIT already covers it).

re code rabbit, it was reported under #131 since it's not related to this PR

@javier-godoy javier-godoy requested a review from paodb June 11, 2025 17:01
@paodb paodb merged commit 3d73abc into master Jun 11, 2025
4 of 5 checks passed
@paodb paodb deleted the fix-footer-toolbar-no-columns branch June 11, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IndexOutOfBoundsException when using createFor(grid) before grid added to UI
2 participants