Skip to content

refactor(plugins): chart-registry delegation shim + derive ChartType - #426

Closed
alfredo1996 wants to merge 1 commit into
release/1.1from
refactor/plugin-registry-shim
Closed

refactor(plugins): chart-registry delegation shim + derive ChartType#426
alfredo1996 wants to merge 1 commit into
release/1.1from
refactor/plugin-registry-shim

Conversation

@alfredo1996

@alfredo1996 alfredo1996 commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Summary

Phases 2+3 of the plugin system refactor. Makes chart-registry.ts a thin delegation layer over pluginRegistry and derives ChartType from a single source of truth.

Closes #417, Closes #419

Changes

Phase 2: Plugin delegation shim

  • chart-registry.ts — replaced static chartRegistry object with a Proxy that delegates to pluginRegistry.get(type) via adaptPlugin() converter
  • All helper functions (getChartConfig, chartSupportsClickAction, getStylingTargets, etc.) now delegate to plugin registry
  • No consumer changes needed — all existing imports work unchanged
  • 6 new delegation tests

Phase 3: Derived ChartType

  • app/src/plugins/chart-types.ts — single CHART_TYPES const array, ChartType derived via (typeof CHART_TYPES)[number]
  • chart-registry.ts re-exports ChartType from chart-types.ts (no more manual union)
  • Startup validation warns if any CHART_TYPES entry lacks a registered plugin
  • 5 new chart-types tests (bidirectional sync verification)

Stats

  • 5 files changed, +499 / -215 lines
  • 11 new tests (6 delegation + 5 chart-types)
  • 335 existing tests pass unchanged

Test plan

  • 335 existing chart-registry + mapping tests pass
  • 11 new delegation + chart-types tests pass
  • TypeScript compilation clean
  • E2E: all chart types render correctly
  • CI green

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Tests

    • Added comprehensive test suites for chart registry delegation and chart types validation
  • Refactor

    • Refactored chart registry to use a plugin-based architecture for improved organization
    • Introduced a canonical list of supported chart types with startup validation
    • Maintained backward compatibility with existing chart APIs

@alfredo1996 alfredo1996 added pkg:app Next.js application package area:charts Chart rendering refactor Code refactoring labels Apr 7, 2026
Phase 2: chart-registry.ts is now a thin shim that registers
lightweight plugin entries with pluginRegistry and delegates all
lookups via a Proxy. The static chartRegistry object, getChartConfig,
and all helper functions continue to work unchanged for consumers.

Phase 3: ChartType union is now derived from a single CHART_TYPES
constant in plugins/chart-types.ts. Startup validation in
plugins/index.ts warns if any declared type lacks a registered plugin.

All 1971+ existing tests pass unchanged. New tests verify delegation
behavior and CHART_TYPES/plugin registry alignment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alfredo1996
alfredo1996 force-pushed the refactor/plugin-registry-shim branch from 23d0d08 to af58dc9 Compare April 7, 2026 01:20
@sonarqubecloud

sonarqubecloud Bot commented Apr 7, 2026

Copy link
Copy Markdown

@alfredo1996

Copy link
Copy Markdown
Owner Author

Superseded by #428 (integration branch)

@alfredo1996 alfredo1996 closed this Apr 7, 2026
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84eb1269-1d8a-4f78-83fe-19b74f6ea3d8

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca3ebc and af58dc9.

📒 Files selected for processing (5)
  • app/src/lib/__tests__/chart-registry-delegation.test.ts
  • app/src/lib/chart-registry.ts
  • app/src/plugins/__tests__/chart-types.test.ts
  • app/src/plugins/chart-types.ts
  • app/src/plugins/index.ts

Walkthrough

This PR converts the chart registry from a static hardcoded object to a plugin-backed Proxy system. A new canonical CHART_TYPES constant drives the ChartType union, replacing manual maintenance. The registry delegates to pluginRegistry at access time, adapting plugin entries to legacy ChartConfig shape while preserving all existing public APIs.

Changes

Cohort / File(s) Summary
Chart Types Definition
app/src/plugins/chart-types.ts
New module exporting canonical CHART_TYPES array and ChartType union type derived from array elements via typeof indexing.
Registry Delegation
app/src/lib/chart-registry.ts
Replaced static registry object with Proxy that delegates to pluginRegistry and adapts ChartPlugin entries to ChartConfig at runtime. Rewired all legacy functions (getChartConfig, chartSupportsClickAction, chartSupportsStyling, etc.) to query plugin capabilities and compatibility lists instead of in-module data.
Plugin Index Updates
app/src/plugins/index.ts
Added startup-time validation warning for unregistered chart types in CHART_TYPES, and re-exported CHART_TYPES/ChartType from chart-types module.
Delegation Test
app/src/lib/__tests__/chart-registry-delegation.test.ts
New Vitest suite validating getChartConfig and chartRegistry Proxy behavior, including config shape, registry contents, property access, and capability flag correctness across chart types.
Chart Types Test
app/src/plugins/__tests__/chart-types.test.ts
New Vitest suite verifying CHART_TYPES uniqueness and bidirectional sync with pluginRegistry.getTypes(), plus compile-time TypeScript compatibility check.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant getChartConfig
    participant Proxy as chartRegistry<br/>(Proxy)
    participant pluginRegistry
    participant adaptPlugin
    participant componentLoader

    Client->>getChartConfig: getChartConfig("bar")
    getChartConfig->>Proxy: pluginRegistry.get("bar")
    Proxy->>pluginRegistry: get("bar")
    pluginRegistry-->>Proxy: ChartPlugin

    Proxy->>adaptPlugin: adaptPlugin(plugin)
    adaptPlugin->>componentLoader: Load component via<br/>componentLoader map
    componentLoader-->>adaptPlugin: Lazy module
    adaptPlugin-->>Proxy: ChartConfig with<br/>lazy component
    Proxy-->>getChartConfig: ChartConfig
    getChartConfig-->>Client: ChartConfig object
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/plugin-registry-shim

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.

@alfredo1996
alfredo1996 deleted the refactor/plugin-registry-shim branch April 7, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:charts Chart rendering pkg:app Next.js application package refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants