Skip to content

feat: enhance ChartExample type with Controls#7239

Merged
ckifer merged 1 commit into
mainfrom
example-controls
Apr 13, 2026
Merged

feat: enhance ChartExample type with Controls#7239
ckifer merged 1 commit into
mainfrom
example-controls

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator

I added support for controls to all website examples, not just the ones in the guide. Also refactored the ExamplesView a little bit while here.

AI description below

This pull request refactors and enhances the handling of example components in the documentation site. The changes improve type safety, enable more flexible controls for chart examples, and simplify the logic for looking up and rendering examples. Notably, it updates the ChartExample type to support associated controls, streamlines the example lookup process, and improves error handling for missing examples.

Type and API improvements:

  • Enhanced the ChartExample type to accept a generic ControlsType, support an optional Controls component for interactive knobs/controls, and use a more specific ToolType for the defaultTool property. [1] [2]

Example lookup and rendering simplification:

  • Refactored the example lookup logic in ExamplesView.tsx to flatten all examples into a single array, simplifying and improving the performance of the lookup process.
  • Updated the rendering logic in ExamplesView.tsx to use the new flattened example lookup, display a NotFoundView if an example is missing, and pass the new Controls and defaultTool props to CodeEditorWithPreview. [1] [2]

Component integration:

  • Updated ApiExamples and ExamplesViewImpl to pass the new Controls prop from the ChartExample type to the CodeEditorWithPreview component, enabling interactive controls in examples. [1] [2]

Testing and documentation:

  • Added a clarifying comment in the example components test to emphasize that example names must be unique for URL-based lookup.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added interactive controls support to example components for enhanced demonstrations.
    • Improved handling of missing or invalid example pages.
  • Refactor

    • Restructured example component system for better flexibility and maintainability.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The PR enhances the example components system by making ChartExample a generic type to support parameterized control types, adding an optional Controls component field to configure example behavior, and standardizing defaultTool as a ToolType. Integration points are updated to pass these new properties through the component rendering pipeline.

Changes

Cohort / File(s) Summary
Type Definition
www/src/docs/exampleComponents/types.ts
Introduced ToolType import, made ChartExample generic with ControlsType parameter, updated Component field to accept props via ComponentType<ControlsType>, and added optional Controls field for control components.
Example Views & API Integration
www/src/views/APIViewNew.tsx, www/src/views/ExamplesView.tsx
Updated CodeEditorWithPreview invocations to pass Controls and defaultTool props; refactored ExamplesView to use flattened example lookup and updated prop names from ExampleComponent to Component.
Test Documentation
www/test/docs/exampleComponents/exampleComponents.spec.tsx
Added explanatory comment clarifying that unique example names are required for URL identification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers motivation, changes made, and includes implementation details, but lacks explicit sections matching the template (Related Issue, Testing, Type of changes, Checklist). Add Related Issue link, describe testing approach, and mark applicable checkboxes (New feature, documentation/tests updated) from the template.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: enhancing the ChartExample type with Controls support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch example-controls

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@www/src/views/ExamplesView.tsx`:
- Around line 9-15: The lookup in parseExampleComponent uses the record key
(entries()[0]) instead of the documented example identity (the
ChartExample.name), which can mis-resolve URLs; update parseExampleComponent to
compare params.name to the ChartExample.name (the second element of each tuple)
rather than the record key: use allExamplesFlattened and parseExampleComponent
to destructure each tuple to (key, example) and match example.name (or
example?.name) against exampleName, returning the example object when it
matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3cfd348a-abbf-4236-93b8-78af63de1b71

📥 Commits

Reviewing files that changed from the base of the PR and between c619621 and f098555.

📒 Files selected for processing (4)
  • www/src/docs/exampleComponents/types.ts
  • www/src/views/APIViewNew.tsx
  • www/src/views/ExamplesView.tsx
  • www/test/docs/exampleComponents/exampleComponents.spec.tsx

Comment on lines +9 to 15
const allExamplesFlattened: ReadonlyArray<[string, ChartExample]> = Object.values(allExamples)
.map(e => e.examples)
.flatMap(Object.entries);

if (res && res.length) {
const example = allExamples[res[0]].examples[compName];
return {
cateName: res[0],
exampleName: example.name,
ExampleComponent: example.Component,
sourceCode: example.sourceCode,
description: example.description,
};
}
return null;
const parseExampleComponent = (exampleName: string): ChartExample | undefined => {
return allExamplesFlattened.find(examples => examples[0] === exampleName)?.[1];
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Lookup key changed from example name to record key (can break URL resolution).

The parser now matches params.name against Object.entries(...)[0] (record key). But URL identity is documented as example name, so valid example URLs can resolve to NotFoundView when key and example.name diverge.

🔧 Proposed fix
-const allExamplesFlattened: ReadonlyArray<[string, ChartExample]> = Object.values(allExamples)
-  .map(e => e.examples)
-  .flatMap(Object.entries);
+const allExamplesFlattened: ReadonlyArray<ChartExample> = Object.values(allExamples)
+  .flatMap(e => Object.values(e.examples));

 const parseExampleComponent = (exampleName: string): ChartExample | undefined => {
-  return allExamplesFlattened.find(examples => examples[0] === exampleName)?.[1];
+  return allExamplesFlattened.find(example => example.name === exampleName);
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const allExamplesFlattened: ReadonlyArray<[string, ChartExample]> = Object.values(allExamples)
.map(e => e.examples)
.flatMap(Object.entries);
if (res && res.length) {
const example = allExamples[res[0]].examples[compName];
return {
cateName: res[0],
exampleName: example.name,
ExampleComponent: example.Component,
sourceCode: example.sourceCode,
description: example.description,
};
}
return null;
const parseExampleComponent = (exampleName: string): ChartExample | undefined => {
return allExamplesFlattened.find(examples => examples[0] === exampleName)?.[1];
};
const allExamplesFlattened: ReadonlyArray<ChartExample> = Object.values(allExamples)
.flatMap(e => Object.values(e.examples));
const parseExampleComponent = (exampleName: string): ChartExample | undefined => {
return allExamplesFlattened.find(example => example.name === exampleName);
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@www/src/views/ExamplesView.tsx` around lines 9 - 15, The lookup in
parseExampleComponent uses the record key (entries()[0]) instead of the
documented example identity (the ChartExample.name), which can mis-resolve URLs;
update parseExampleComponent to compare params.name to the ChartExample.name
(the second element of each tuple) rather than the record key: use
allExamplesFlattened and parseExampleComponent to destructure each tuple to
(key, example) and match example.name (or example?.name) against exampleName,
returning the example object when it matches.

@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.07%. Comparing base (c619621) to head (f098555).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
www/src/views/ExamplesView.tsx 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7239      +/-   ##
==========================================
- Coverage   89.07%   89.07%   -0.01%     
==========================================
  Files         539      539              
  Lines       41014    41009       -5     
  Branches     5555     5555              
==========================================
- Hits        36532    36527       -5     
  Misses       4474     4474              
  Partials        8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@ckifer
ckifer merged commit bb99006 into main Apr 13, 2026
58 of 59 checks passed
@ckifer
ckifer deleted the example-controls branch April 13, 2026 16:14
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.

2 participants