Skip to content

fix: preserve joined headers #178

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 10 commits into from
Jun 9, 2025
Merged

fix: preserve joined headers #178

merged 10 commits into from
Jun 9, 2025

Conversation

javier-godoy
Copy link
Member

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

Close #176

d8c12e2 - refactor: remove unused import

  • What: Removed import statements for classes or modules that were no longer being used in a particular file.
  • Why: To keep the codebase clean, reduce clutter, and potentially improve compilation times slightly. Unused imports can also mislead developers into thinking a dependency exists where it doesn't.
  • Atomic Value: This is a small, safe change that improves code hygiene. It's easily reviewable and revertible, adding value by making the code cleaner and dependencies clearer.

3a7adfe - refactor: duplicate method

  • What: An existing method was duplicated as an initial step before a more significant refactoring.
  • Why: Often a preparatory step for larger refactorings, like splitting behaviors controlled by a flag.
  • Atomic Value: Enabling step for clearer subsequent refactorings. Isolates behaviors for safer modification.

907759a - refactor: remove flag argument

  • What: Removed a flag argument from a method, after duplicating the method to handle different flag conditions separately.
  • Why: Flag arguments obscure method responsibilities and complicate testing. Removing them leads to clearer, single-responsibility methods.
  • Atomic Value: Significantly improves method design, clarity, and testability. High-value refactoring.

5c42daf - refactor: remove dead code

  • What: Deleted code that was no longer reachable or executed.
  • Why: Dead code makes the codebase larger and more complex than necessary, increasing maintenance overhead and the risk of confusion. Removing it simplifies the code.
  • Atomic Value: Improves maintainability and readability by reducing the amount of code to understand and manage. It's a clear win, easily reviewable by confirming the code is indeed unused, and safely revertible if an error in judgment was made.

106e3c9 - refactor: remove unused parameter

  • What: Removed a parameter from a method signature because it was no longer being used within the method's body. The call sites for this method also have been updated.
  • Why: Simplifies the method's interface, making it easier to call and understand. It also removes unnecessary data coupling.
  • Atomic Value: Improves the method's API and reduces complexity. This change is valuable for maintainability. Review involves checking the method body and all call sites. Reverting would mean adding the parameter back.

4de4652 - refactor: remove dead code

  • What: Similar to the previous "remove dead code" commit, this involves identifying and deleting another section of unused code.
  • Why: To further simplify the codebase, reduce maintenance burden, and improve clarity.
  • Atomic Value: Same justification as the previous dead code removal – improves maintainability and readability. Each instance of dead code removal provides incremental value.

a23167f - refactor: rename variables

  • What: Changed the names of variables to be more descriptive.
  • Why: Clear and descriptive variable names are crucial for code readability and understanding. This makes it easier for developers to grasp the purpose of the variable and the logic of the code.
  • Atomic Value: Enhances code clarity and maintainability. Renaming variables is usually a localized change, making it easy to review for correctness (ensuring all instances are renamed) and revert if needed. The value is in long-term understandability.

b007e95 - refactor: move lambda to private method

  • What: An inline lambda expression was extracted and moved into its own private helper method.
  • Why: Improves readability by naming complex lambdas. Simplifies the original method.
  • Atomic Value: Enhances code organization and readability. Localized change, easy to review.

Summary by CodeRabbit

  • Refactor

    • Improved extraction and handling of header and footer cell text in exported grids for more accurate export of merged and custom header/footer cells.
  • Tests

    • Updated the demo to showcase grids with multiple and merged header rows, enhancing examples of complex header structures.

@javier-godoy javier-godoy requested review from mlopezFC and paodb June 3, 2025 19:58
Copy link

coderabbitai bot commented Jun 3, 2025

"""

Walkthrough

The changes refactor header and footer cell text extraction in the Vaadin Grid exporter. A generic method is replaced with dedicated methods for headers and footers, introducing improved logic for handling merged cells, caching, and error handling. The test demo is updated to use explicit column variables and a new joined header row.

Changes

File(s) Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java Refactored header/footer cell text extraction: removed generic method, added specialized header/footer methods, improved merged cell handling, caching, and error handling.
src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java Refactored test grid setup: assigned columns to variables, added a joined header row, adjusted header cell references.

Assessment against linked issues

Objective Addressed Explanation
Correct handling of joined columns in grid export to prevent duplicated header rows (#176)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • mlopezFC
    """

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 331f121 and c12aad0.

📒 Files selected for processing (1)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java
✨ 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

@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 (2)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (2)

176-176: Minor formatting inconsistency.

Missing space around the equality operator.

-    return footer==null?"":footer;
+    return footer == null ? "" : footer;

155-177: Footer extraction method is well-structured with minor formatting issue.

The footer text extraction logic is sound and follows a similar pattern to the header extraction. However, there's a minor formatting issue on line 176.

Apply this diff to improve code formatting:

-    return footer==null?"":footer;
+    return footer == null ? "" : footer;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 032461e and 331f121.

📒 Files selected for processing (2)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (3 hunks)
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (2 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java
  • src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java
🔇 Additional comments (27)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/BaseStreamResourceWriter.java (15)

27-27: Import addition looks good.

The import for HeaderRow.HeaderCell is necessary for the new header cell handling logic.


107-107: Method call updated to use specialized header rendering.

The call to renderHeaderCellTextContent replaces the previous generic approach, providing better control over header text extraction.


118-118: Method call updated to use specialized footer rendering.

The call to renderFooterCellTextContent provides dedicated logic for footer text extraction.


124-133: Helper method provides safe text extraction.

The obtainCellFunction method safely extracts text from header cells, first trying getText() and falling back to getTextRecursively() from the component if available.


135-153: Excellent logic for handling merged header cells.

The key improvement is in lines 141-142 where the method checks if the current column is the first column OR if the header cell for the previous column differs from the current header cell. This prevents duplicate text extraction from merged cells, which directly addresses the PR objective to "preserve joined headers."

The error handling with try-catch is also appropriate for robustness.


155-177: Footer rendering method provides dedicated logic.

The method handles footer text extraction with proper fallback from footer text to footer component text, maintaining consistency with the header approach.


27-27: Import addition looks good.

The new import for HeaderRow.HeaderCell is necessary for the enhanced header cell handling logic.


107-107: Method call updates align with the refactoring.

The calls to the new specialized methods renderHeaderCellTextContent and renderFooterCellTextContent properly replace the previous generic approach.

Also applies to: 118-118


124-133: Helper method provides clean text extraction logic.

The obtainCellFunction method properly handles both text-based and component-based header cells with appropriate fallback logic.


135-153: Excellent implementation of joined header preservation logic.

The core fix for preserving joined headers is well-implemented. The logic at lines 141-142 correctly prevents duplicate text extraction for merged header cells by checking if the current header cell differs from the previous column's header cell. This ensures that joined headers are only processed once and their text is preserved correctly.

The error handling with descriptive exception messages is also a good practice.


27-27: LGTM: Import addition supports new functionality.

The new import for HeaderRow.HeaderCell is necessary for the enhanced header cell handling logic.


107-107: LGTM: Refactoring to specialized methods improves maintainability.

The replacement of generic method calls with dedicated renderHeaderCellTextContent and renderFooterCellTextContent methods provides better separation of concerns and allows for specialized handling of merged cells.

Also applies to: 118-118


124-133: LGTM: Helper method with good error handling.

The obtainCellFunction method provides a clean abstraction for extracting text from header cells with appropriate fallback logic (text → component text recursively).


135-153: Excellent logic for handling merged headers.

The key improvement is the merged cell detection logic:

if (columnIndex == 0
    || headerRow.getCell(grid.getColumns().get(columnIndex - 1)) != headerCell) {

This correctly prevents duplicate text extraction from merged/joined header cells by only processing when the current cell differs from the previous column's cell. This directly addresses the PR objective of preserving joined headers.


155-177: LGTM: Consistent footer handling with proper error management.

The footer text extraction method maintains consistency with the header approach and includes appropriate error handling. The logic correctly handles both text and component-based footers.

src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterMultipleHeaderRowsDemo.java (12)

60-65: Good refactoring to use explicit column variables.

Assigning columns to named variables (firstNameColumn, lastNameColumn, bigColumn) improves code readability and enables the subsequent joined header functionality.


82-82: Simplified method call is cleaner.

Removing the explicit this qualifier improves code conciseness without affecting functionality.


84-86: Perfect demonstration of joined headers functionality.

The addition of a joined header row that merges columns under grouped labels ("Full name" and "Big column and budget") provides an excellent test case for the new header cell handling logic in BaseStreamResourceWriter.java.


91-91: Correct index adjustment for the new header structure.

Changing from get(0) to get(1) correctly accounts for the prepended joined header row. Since prependHeaderRow() adds the joined header at index 0, the original headers are now at index 1.


60-65: Good refactoring to named column variables.

Converting anonymous column additions to named variables improves code readability and enables referencing these columns later for creating joined headers.


82-82: Minor code cleanup looks good.

Removing the explicit this qualifier simplifies the code without changing functionality.


84-86: Excellent test scenario for joined headers.

The addition of a joined header row that merges columns provides a perfect test case for validating the joined header preservation functionality implemented in the main code. This directly tests the scenario that issue #176 was addressing.


91-91: Correct adjustment for the new header row structure.

Changing from get(0) to get(1) is necessary because the new joined header row was prepended, making the original header row shift to index 1. This ensures the test continues to reference the correct header row for adding extra headers.


60-65: Good refactoring: Explicit column variables improve testability.

Storing column references in named variables (firstNameColumn, lastNameColumn, bigColumn) makes the code more readable and enables the subsequent joined header operations.


82-82: Minor improvement: Simplified method call.

Removing the explicit this qualifier is a minor style improvement that maintains readability.


84-86: Perfect test scenario for joined headers.

The addition of a joined header row that merges columns provides an excellent test case for validating the fix in BaseStreamResourceWriter.java. This directly supports the PR objective of preserving joined headers.


91-91: Correct index adjustment for prepended header row.

The change from get(0) to get(1) is necessary because the new joined header row was prepended, shifting the original header row to index 1. This ensures the loop correctly references the column-specific headers rather than the joined headers.

Copy link

sonarqubecloud bot commented Jun 3, 2025

@paodb paodb merged commit e81fff7 into master Jun 9, 2025
4 checks passed
@paodb paodb deleted the fix-176 branch June 9, 2025 18:33
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.

Exporting a grid with joined columns in excel format
2 participants