-
Notifications
You must be signed in to change notification settings - Fork 827
Update/charts 52 barchart revision #44515
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
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
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.
Pull Request Overview
This pull request implements a composition API for the BarChart component, allowing for cleaner syntax when adding legends using child components (e.g., <BarChart.Legend />
). The changes maintain backward compatibility while providing a more modern and flexible approach to chart configuration.
- Introduces a composition API that enables
<BarChart.Legend />
syntax instead of prop-based legend configuration - Adds chart ID context providers for automatic data sharing between parent charts and child components
- Maintains full backward compatibility with existing prop-based legend APIs
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
create-chart-composition.ts | Utility function for attaching subcomponents to create composition API |
chart-id-context.tsx | Context provider for sharing chart IDs between parent and child components |
chart-legend.tsx | New ChartLegend component that works with composition API |
bar-chart.tsx | Updated to support composition API with ChartLegend as a subcomponent |
*.test.tsx | Test coverage for composition API functionality |
legend.stories.tsx | Updated Storybook examples showcasing both composition and legacy APIs |
Comments suppressed due to low confidence (1)
projects/js-packages/charts/src/components/bar-chart/test/bar-chart.test.tsx:462
- The test expectation has changed from '1/1/2024' to 'Custom: 01/01/2024', but this change is not explained in the PR description and appears unrelated to the composition API implementation. This could indicate an unintended side effect or should be documented as a separate change.
expect( screen.getByTestId( 'chart-tooltip-0' ) ).toHaveTextContent( 'Custom: 01/01/2024' );
@@ -30,7 +37,7 @@ const validateData = ( data: SeriesData[] ) => { | |||
|
|||
const hasInvalidData = data.some( series => | |||
series.data.some( | |||
point => | |||
( point: DataPointDate ) => |
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.
[nitpick] The explicit type annotation for the point
parameter is redundant since TypeScript can infer this from the series.data.some()
context. This change appears unrelated to the composition API feature being added.
( point: DataPointDate ) => | |
( point ) => |
Copilot uses AI. Check for mistakes.
const contextChartId = useChartIdFromContext(); | ||
|
||
// Use provided chartId, fall back to context chartId | ||
const effectiveChartId = props.chartId || contextChartId; |
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.
The fallback logic uses ||
which will use contextChartId even if props.chartId is an empty string. Consider using nullish coalescing (??
) if you want to distinguish between explicitly passed empty strings and undefined values.
const effectiveChartId = props.chartId || contextChartId; | |
const effectiveChartId = props.chartId ?? contextChartId; |
Copilot uses AI. Check for mistakes.
Code Coverage SummaryCoverage changed in 3 files.
3 files are newly checked for coverage.
|
Closing this up in favour of the progress happening in #44691 |
Fixes #
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: