Skip to content
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

fix: apply excel format for blank cells #160

Merged
merged 2 commits into from
Nov 11, 2024
Merged

fix: apply excel format for blank cells #160

merged 2 commits into from
Nov 11, 2024

Conversation

mlopezFC
Copy link
Member

@mlopezFC mlopezFC commented Nov 11, 2024

Fixes #159

Summary by CodeRabbit

  • New Features
    • Enhanced Excel export functionality with improved cell formatting capabilities for blank, numeric, and date values.
    • Conditional formatting applied based on specified Excel format strings, ensuring better data presentation in generated Excel files.

@mlopezFC mlopezFC requested a review from paodb November 11, 2024 16:05
Copy link

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes made in the pull request focus on enhancing the ExcelStreamResourceWriter class, particularly the buildCell method. Modifications include the addition of Excel formatting capabilities for cells with null values, allowing them to receive formatting based on a specified excelFormat. The method now also applies formatting for numeric and date values, defaulting to specific formats when none are provided. Overall, these updates improve the handling of cell formatting in exported Excel files.

Changes

File Path Change Summary
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java Enhanced buildCell method to apply Excel formatting for null, numeric, and date values.

Assessment against linked issues

Objective Addressed Explanation
Cell styles should apply on null cell values (#159)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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: 0

🧹 Outside diff range and nitpick comments (1)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (1)

344-346: LGTM: Null cell formatting implementation

The implementation correctly addresses the issue by applying Excel formats to null cells, maintaining consistent styling across the exported file.

Consider breaking down the buildCell method

The method is handling multiple responsibilities (value extraction, type checking, formatting). Consider splitting it into smaller, focused methods for better maintainability.

Example refactor:

- private void buildCell(Object value, Cell cell, Column<T> column, T item) {
+ private void buildCell(Object value, Cell cell, Column<T> column, T item) {
+   CellFormatting formatting = prepareCellFormatting(column, item);
+   applyCellValue(value, cell, formatting);
+ }
+
+ private CellFormatting prepareCellFormatting(Column<T> column, T item) {
+   ValueProvider<T,String> provider = (ValueProvider<T, String>) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA_PROVIDER);
+   Map<String, CellStyle> cellStyles = getCellStyles(column);
+   String excelFormat = getExcelFormat(column, item, provider);
+   return new CellFormatting(provider, cellStyles, excelFormat);
+ }
+
+ private void applyCellValue(Object value, Cell cell, CellFormatting formatting) {
+   if (value == null) {
+     applyNullCellFormatting(cell, formatting);
+   } else if (value instanceof Number) {
+     applyNumberFormatting(cell, (Number)value, formatting);
+   } // ... etc
+ }

Also applies to: 349-351

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 310afd3 and 98491e1.

📒 Files selected for processing (1)
  • src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (2 hunks)
🔇 Additional comments (3)
src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java (3)

370-379: LGTM: Clean format resolution implementation

The method cleanly handles format resolution with clear precedence rules and good separation of concerns.


Line range hint 344-389: Verify test coverage for null cell formatting

The changes look good, but ensure there are unit tests covering:

  1. Null cells with different format providers
  2. Null cells with static formats
  3. Null cells without any format

Let's check the test coverage:

✅ Verification successful

Let me search for test files specifically related to Excel export and null values:


Let me check the content of some demo files that might contain test scenarios:


Let me check for integration or unit tests specifically:


Let me check the demo files for test data setup that might include null values:


Based on the review of the code and test files, I can now generate the final response:

Null cell formatting is adequately tested through demo scenarios

The codebase includes comprehensive test coverage for null cell formatting through demo scenarios:

  • GridExporterCustomTemplateDemo and GridExporterMultipleHeaderRowsDemo explicitly test null values by randomly setting lastName to null: (Math.random() > 0.3 ? faker.name().lastName() : null)
  • Person class constructor supports null dates: favDate and worstDate can be null
  • The implementation correctly handles various null scenarios with appropriate formatting:
    • Blank cells for null values
    • Default formats for non-null values
    • Custom formats through format providers
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Look for relevant test files
fd -e java -e groovy test

# Search for null value test cases
rg -A 5 "null.*cell|cell.*null" 

Length of output: 9803


Script:

#!/bin/bash
# Search for test files containing Excel or export related tests
rg -l "Excel|export" src/test

# Search for test cases specifically handling null values in Excel export
rg -B 5 -A 5 "null.*value|value.*null" src/test

Length of output: 1906


Script:

#!/bin/bash
# Check demo files for test scenarios involving null values
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterDemo.java
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/GridExporterCustomColumnsDemo.java

# Look for test data setup that might include null values
rg -A 10 "createPerson|setupGrid" src/test/java/com/flowingcode/vaadin/addons/gridexporter/

Length of output: 8725


Script:

#!/bin/bash
# Check integration tests
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/it/ViewIT.java

# Check concurrent export tests which might include null value scenarios
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/ConcurrentExportTests.java

# Look for test setup methods in all test files
rg -B 2 -A 10 "@Test|@Before" src/test/java/com/flowingcode/vaadin/addons/gridexporter/test/

Length of output: 31700


Script:

#!/bin/bash
# Look for test data setup in demo files
cat src/test/java/com/flowingcode/vaadin/addons/gridexporter/Person.java

# Search for grid setup and data population in demo files
rg -A 10 "grid.setItems|new Person" src/test/java/com/flowingcode/vaadin/addons/gridexporter/

Length of output: 22804


381-389: Consider thread safety implications

The shared cellStyles map is modified without synchronization. While the Grid component typically operates in a single-threaded context, it's worth documenting this assumption or adding synchronization if concurrent access is possible.

Let's check for potential concurrent access patterns:

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.

LGTM

@paodb paodb merged commit 8f5767b into master Nov 11, 2024
4 checks passed
@paodb paodb deleted the issue-159 branch November 11, 2024 17:08
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.

Cell styles not applying on null cell values.
2 participants