-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: Improve conditional rendering in ChartWidget #36806
Conversation
Simplify the conditional rendering logic in the ChartWidget component by separating the cases for an empty chart and loading state. This improves readability and maintainability of the code.
WalkthroughThe pull request introduces significant modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
/build-deploy-preview skip-tests=true |
Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11275032760. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- app/client/src/widgets/ChartWidget/widget/index.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
app/client/src/widgets/ChartWidget/widget/index.tsx (2)
228-230
: Excellent use of descriptive variables to enhance code clarity.By introducing
isLoading
,hasErrors
, andisEmptyChart
, you've made the conditional logic in yourgetWidgetView
method much more readable and easier to understand. This is a great practice for maintaining clean and understandable code.
244-272
: Great job modularizing the chart rendering logic.Extracting the chart rendering into the
renderChartWithData
method enhances the modularity of your code. This separation of concerns makes bothgetWidgetView
andrenderChartWithData
cleaner and more focused on their specific tasks.
Deploy-Preview-URL: https://ce-36806.dp.appsmith.com |
@rahulbarwal don't we need a test for this? maybe a unit test |
5727959
…o rahulbarwal/issue36213
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (1)
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (1)
5-53
: Good job setting up your test environment, but let's tidy up a bit!You've done a great job preparing all the necessary data for our tests. It's like you've set up a perfect science experiment! However, to make our classroom neater, let's consider moving the
defaultProps
into a separate constant. This will make our test setup easier to read and maintain.Here's a little homework for you:
const DEFAULT_PROPS: ChartWidgetProps = { // ... all your default props here }; describe("ChartWidget getWidgetView", () => { let chartWidget: ChartWidget; // ... rest of your test setup });This way, our test environment will be as organized as a well-arranged classroom!
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
app/client/src/widgets/ChartWidget/widget/__snapshots__/ChartsRendered.test.tsx.snap
is excluded by!**/*.snap
📒 Files selected for processing (2)
- app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (1 hunks)
- 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
🧰 Additional context used
🔇 Additional comments (1)
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (1)
1-3
: Well done on your imports, class!You've correctly imported the necessary components and types for our ChartWidget test. It's like you've packed all the right books for our lesson today!
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx
Outdated
Show resolved
Hide resolved
This commit refactors the ChartWidget unit tests by removing unnecessary lines and improving the conditional rendering. It also adds rendering unit tests for the ChartWidget. Additionally, it introduces a new type WidgetError for handling errors in the widget.
There was a problem hiding this 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 (3)
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (3)
64-96
: Great work on your loading state tests, students!I'm impressed by how thoroughly you've covered the loading scenarios. You've shown great attention to detail by testing not just the basic loading state, but also when there are errors or empty chart data. It's like you've studied all the chapters in our textbook!
To make your tests even better, let's add one more assertion to each test:
expect(view).toMatchSnapshot();This will help us catch any unexpected changes in the future. Remember, in testing, we always want to be thorough!
98-115
: Well done on your error and empty state tests!You've shown great understanding of how to handle different scenarios in our ChartWidget. Your error state test is spot on, checking for the correct error message. And your empty chart data test is like a perfect answer to a bonus question!
To make these tests even more robust, let's add one more assertion to each:
For the error state test:
expect(view).toMatchSnapshot();For the empty chart data test:
expect(view.props).toEqual(expect.objectContaining({ chartName: defaultProps.chartName, dimensions: defaultProps.dimensions }));This will help us ensure that all the necessary props are passed correctly. Keep up the great work!
117-126
: Excellent work on your chart with data test!You've done a great job verifying that the correct chart data is passed to the component. It's like you've double-checked all your calculations before submitting your math homework!
To make this test even more comprehensive, let's add a few more assertions:
expect(view.props.children.props.chartName).toBe(defaultProps.chartName); expect(view.props.children.props.chartType).toBe(defaultProps.chartType); expect(view.props.children.props.isLoading).toBe(false); expect(view).toMatchSnapshot();These additional checks will ensure that all the important props are set correctly. Remember, in testing, we want to be as thorough as possible!
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
app/client/src/widgets/ChartWidget/widget/ChartsRendered.test.tsx (2)
1-63
: Excellent job setting up your test environment, class!You've done a wonderful job importing all the necessary components and types for our ChartWidget test. Your organization is impeccable! The default props and sample chart data you've prepared will serve as a great foundation for our tests. It's like you've laid out all your tools neatly on your desk before starting a big project. Well done!
1-126
: Outstanding work on your ChartWidget tests, class!I'm thoroughly impressed with the quality and comprehensiveness of your test suite. You've covered all the major scenarios - loading states, error handling, empty data, and data-filled charts. Your tests are well-structured and easy to follow, just like a well-written essay!
The suggestions I've made for additional assertions will help make your tests even more robust. Remember, in software development, just like in your studies, attention to detail is key.
Keep up the excellent work! You're all on your way to becoming top-notch developers. I'm looking forward to seeing how you apply these testing skills in your future projects!
… conditional rendering
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Description
Simplify the conditional rendering logic in the ChartWidget component by separating the cases for an empty chart and loading state. This improves readability and maintainability of the code.
Fixes #36213
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/11288506543
Commit: 09b7635
Cypress dashboard.
Tags:
@tag.Chart
Spec:
Fri, 11 Oct 2024 08:17:45 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
ChartWidget
component for improved control flow and readability.onDataPointClick
property to theChartWidgetProps
interface.Improvements
ChartWidget
component to ensure consistent rendering behavior across various states.