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: Refactor handling of empty chart data in ChartWidget #37009

Merged
merged 3 commits into from
Oct 23, 2024

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Oct 22, 2024

Description

  • This pull request handles empty chart dAata more efficiently.
  • lso updates tests to ensure this is not overlooked again.

These changes ensure that the ChartWidget can handle scenarios where the chart data is null or undefined, and that the tests accurately reflect this behavior.

Fixes #37008
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Chart"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11473049534
Commit: 08602d3
Cypress dashboard.
Tags: @tag.Chart
Spec:


Wed, 23 Oct 2024 04:52:48 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • Improved data handling in the ChartWidget to prevent runtime errors when chart data is undefined.
  • Tests

    • Added a new test case to verify the behavior of the emptyChartData function when series data is null or undefined, enhancing test coverage.
  • Documentation

    • Updated interface to include an optional property for handling data point clicks in the ChartWidget.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request enhance the emptyChartData function within the ChartWidget component by improving the conditional checks for chart data. A new test case is added to verify that the function correctly identifies when series data is null or undefined. This ensures that potential runtime errors are avoided and expands the test coverage for various scenarios of empty chart data.

Changes

File Path Change Summary
app/client/src/widgets/ChartWidget/widget/index.test.ts Added a test case in emptyChartData to check for null and undefined series data.
app/client/src/widgets/ChartWidget/widget/index.tsx Enhanced emptyChartData to check if chartData[seriesID].data is defined before checking its length. Updated ChartWidgetProps to include an optional onDataPointClick property.

Assessment against linked issues

Objective Addressed Explanation
Improve error handling in emptyChartData to prevent TypeError (37008)

Possibly related PRs

  • fix: Improve conditional rendering in ChartWidget #36806: This PR directly modifies the ChartWidget component, specifically enhancing the conditional rendering logic, which is closely related to the changes made in the main PR that also focuses on the emptyChartData function within the ChartWidget.

Suggested labels

Critical, High, Production

Suggested reviewers

  • ApekshaBhosale
  • jacquesikot

In the world of charts, where data may stray,
A fix has emerged to brighten the day.
With checks now in place, no errors will roam,
The ChartWidget's safe, it feels like home!
So here's to the code, robust and bright,
A toast to the devs who code through the night! 🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fa0a700 and 08602d3.

📒 Files selected for processing (1)
  • app/client/src/widgets/ChartWidget/widget/index.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/ChartWidget/widget/index.tsx

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.

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.

@github-actions github-actions bot added Chart Widget Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Oct 22, 2024
@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Oct 22, 2024
@github-actions github-actions bot added the Bug Something isn't working label Oct 22, 2024
Copy link
Contributor

@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 (2)
app/client/src/widgets/ChartWidget/widget/index.test.ts (1)

75-82: LGTM. Consider adding an assertion for mixed data types.

The new test case effectively covers scenarios where series data is null or undefined. Good job on improving the test coverage.

Consider adding an assertion for a mixed scenario where one series has valid data and another has null/undefined data. This would ensure the function behaves correctly in all possible combinations.

app/client/src/widgets/ChartWidget/widget/index.tsx (1)

54-57: Approved: Robust check for empty chart data.

The additional check for props.chartData[seriesID].data existence before accessing its length effectively addresses the TypeError issue. This change aligns well with the PR objectives.

Consider using optional chaining for a more concise expression:

if (props.chartData[seriesID].data?.length > 0) {
  return false;
}

This achieves the same result with a slightly more compact syntax.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a8da0e1 and fa0a700.

📒 Files selected for processing (2)
  • app/client/src/widgets/ChartWidget/widget/index.test.ts (1 hunks)
  • app/client/src/widgets/ChartWidget/widget/index.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
app/client/src/widgets/ChartWidget/widget/index.tsx (1)

Line range hint 1-380: Verify impact on chart rendering scenarios.

The changes to emptyChartData function improve empty data handling without affecting other parts of the component. This aligns well with the PR objectives.

To ensure comprehensive coverage, please verify the following scenarios:

  1. Chart rendering with valid data
  2. Chart rendering with empty data
  3. Chart rendering with partially empty data (some series empty, others not)
✅ Verification successful

Changes to emptyChartData verified successfully.

All relevant tests are present, and usage of ChartWidget is properly covered.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test files related to ChartWidget
echo "Searching for ChartWidget test files..."
fd -e test.tsx -e test.ts ChartWidget

# Search for ChartWidget usage in the codebase
echo "Searching for ChartWidget usage..."
rg "ChartWidget" -t tsx -t ts

Length of output: 409


Script:

#!/bin/bash
# Search for test files related to ChartWidget
echo "Searching for ChartWidget test files..."
fd --extension test.tsx --extension test.ts --type f ChartWidget

# Search for ChartWidget usage in the codebase with corrected file type patterns
echo "Searching for ChartWidget usage..."
rg "ChartWidget" -g "*.tsx" -g "*.ts"

Length of output: 12984

jsartisan
jsartisan previously approved these changes Oct 22, 2024
Copy link
Contributor

@jsartisan jsartisan left a comment

Choose a reason for hiding this comment

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

LGMT, left 2 tiny comments...

@@ -72,6 +72,15 @@ describe("emptyChartData", () => {
expect(emptyChartData(props)).toEqual(true);
});

it("returns true if each series is null or undefined", () => {
const props = JSON.parse(JSON.stringify(basicEChartProps));
Copy link
Contributor

@jsartisan jsartisan Oct 22, 2024

Choose a reason for hiding this comment

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

I know you are just following what the previous developer did in this test, but why are we doing stringify and parse the JS object? 🤔 Just curious about it...What's the point?

Copy link
Contributor Author

@rahulbarwal rahulbarwal Oct 23, 2024

Choose a reason for hiding this comment

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

Basically creating a (deep)clone of the object. We change some nested properties of this object in the test.

app/client/src/widgets/ChartWidget/widget/index.tsx Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Chart Widget ok-to-test Required label for CI Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: ChartWidget sentry issue. TypeError: Cannot convert undefined or null to object
2 participants