Skip to content

Update/charts 49 chart context foundation #44189

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

Draft
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

annacmc
Copy link
Contributor

@annacmc annacmc commented Jul 4, 2025

Fixes #

Proposed changes:

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Go to '..'

@annacmc annacmc requested a review from Copilot July 4, 2025 02:04
Copy link
Contributor

github-actions bot commented Jul 4, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the update/charts-49-chart-context-foundation branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/charts-49-chart-context-foundation

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Jul 4, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 4, 2025
Copilot

This comment was marked as outdated.

Copy link

jp-launch-control bot commented Jul 4, 2025

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

@annacmc annacmc requested a review from Copilot July 4, 2025 04:18
@annacmc annacmc self-assigned this Jul 4, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 PR lays the groundwork for a new ChartContext system, enabling charts to register themselves and share metadata across components.

  • Introduce an optional chartId prop and auto-generated fallback
  • Add ChartProvider, useChartContext, useChartId, and useChartRegistration utilities
  • Integrate context registration into existing chart components (Pie, Semi-Pie, Line, Bar)

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/js-packages/charts/src/types.ts Added optional chartId to base chart props
projects/js-packages/charts/src/providers/chart-context/utils.ts Implemented useChartId and useChartRegistration hooks
projects/js-packages/charts/src/providers/chart-context/types.ts Defined types for chart registration entries
projects/js-packages/charts/src/providers/chart-context/chart-context.tsx Created ChartProvider and useChartContext
projects/js-packages/charts/src/providers/chart-context/chart-context.test.tsx Added tests for context hooks
projects/js-packages/charts/src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx Wrapped component in ChartProvider and register via context
projects/js-packages/charts/src/components/pie-chart/pie-chart.tsx Wrapped component in ChartProvider and register via context
projects/js-packages/charts/src/components/line-chart/line-chart.tsx Wrapped component in ChartProvider and register via context; updated ID handling
projects/js-packages/charts/src/components/bar-chart/bar-chart.tsx Wrapped component in ChartProvider and register via context; updated ID handling
projects/js-packages/charts/changelog/update-charts-49-chart-context-foundation Added changelog entry for chart context foundation
Comments suppressed due to low confidence (1)

projects/js-packages/charts/src/components/pie-chart/pie-chart.tsx:123

  • Add a test case for the PieChart component to verify that it correctly registers itself with the context when rendered, and unregisters on unmount.
	useChartRegistration( chartId, legendItems, providerTheme, 'pie', {

@annacmc annacmc force-pushed the update/charts-49-chart-context-foundation branch 2 times, most recently from 76beea3 to 29635bb Compare July 7, 2025 01:07
@annacmc annacmc mentioned this pull request Jul 9, 2025
3 tasks
annacmc and others added 15 commits July 9, 2025 16:33
Define ChartRegistration interface for chart data storage and
ChartContextValue interface for context API operations.
Sets up foundation for chart registry system.
Create ChartProvider component with Map-based registry for chart data.
Add useChartContext hook with error boundary for outside usage.
Implement registerChart, unregisterChart, and getChartData methods.
Add useChartId hook for ID generation and resolution.
Add useChartRegistration hook for chart lifecycle management.
Support auto-generated IDs via React.useId() for unique identification.
Export ChartProvider and useChartContext from chart-context module.
Export utility hooks useChartId and useChartRegistration.
Export TypeScript types for external usage.
Add chartId prop for user-provided chart identifiers.
Update JSDoc documentation for the new property.
Maintains full backward compatibility with existing usage.
Wrap BarChart with ChartProvider for context registration.
Register chart data with legend items, theme, and metadata on mount.
Use memoized legend items for performance optimization.
Maintain separate internal ID for pattern generation.
Wrap LineChart with ChartProvider for context registration.
Register chart data including glyph options and gradient settings.
Use memoized legend items with proper dependencies.
Maintain separate internal ID for gradient generation.
Wrap PieChart with ChartProvider for context registration.
Register chart data with metadata including thickness and gap options.
Use memoized legend items for performance optimization.
Support chart-specific configuration options in metadata.
Wrap PieSemiCircleChart with ChartProvider for context registration.
Register chart data with semi-circle specific metadata options.
Use memoized legend items with accessor dependencies.
Support clockwise and thickness configuration in metadata.
Test provider functionality and error boundaries.
Test chart registration and unregistration lifecycle.
Test multiple chart independence and ID generation.
Verify function reference stability and collision handling.
- Use provider theme instead of XY theme for registration
- Fix TypeScript types in chart context tests
- Fix ESLint import order and formatting issues

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add metadata memoization in useChartRegistration to prevent unnecessary re-renders
- Add displayName to LineChart and BarChart for better debugging in React DevTools
- Maintain all necessary React hook imports (useContext, useEffect are used)

🤖 Generated with [Claude Code](https://claude.ai/code)
- Add isDataValid parameter to useChartRegistration hook
- Only register charts with valid data to prevent invalid context entries
- Maintain React hooks rules by calling all hooks in same order every render
- Apply to all chart components: BarChart, LineChart, PieChart, PieSemiCircleChart

🤖 Generated with [Claude Code](https://claude.ai/code)
…context.tsx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@annacmc annacmc force-pushed the update/charts-49-chart-context-foundation branch from 16aefa0 to d79adff Compare July 9, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Charts RNA [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant