refactor(explore): colocate visualization rules with chart configs and simplify registry#11589
Conversation
Each config file now self-registers with visualizationRegistry via registerVisualization() at module level. Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
…tions Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Failed to generate code suggestions for PR |
+ remove out-dated unit tests Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Failed to generate code suggestions for PR |
heatmap can no longer auto-selected, for the given data, stacked bar will have higher priority Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Failed to generate code suggestions for PR |
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Failed to generate code suggestions for PR |
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
PR Reviewer Guide 🔍(Review updated until commit d7f01b0)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d7f01b0 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 43aae6cSuggestions up to commit 9b6e244
Suggestions up to commit c4e399f
Suggestions up to commit bda9319
|
+ address review feedback Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
- Fix findRulesByColumns using ||= so any matching mapping keeps the flag true, not just the last one - Fix getAxesMappingByRule to only return complete mappings and try subsequent mappings when a mapping fails - Update embeddable test mock to use new VisRule shape (priority, mappings, render) instead of old VisualizationRule shape - Remove unused imports (visualizationRegistry in state_timeline_config, ReactNode in use_visualization_types) - Remove stale getVisualizationConfig mock and availableMappings setups from axes_selector tests - Fix VisRule.render return type from any to React.ReactNode - Rename getVisualizationConfigSpy to getVisualizationSpy Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Persistent review updated to latest commit bda9319 |
❌ Empty Changelog SectionThe Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section. |
|
Persistent review updated to latest commit c4e399f |
|
Persistent review updated to latest commit 43aae6c |
Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
|
Persistent review updated to latest commit 9b6e244 |
|
Persistent review updated to latest commit d7f01b0 |
|
|
||
| for (const [type, config] of this.visualizations) { | ||
| if (chartType && chartType !== type) { | ||
| continue; |
There was a problem hiding this comment.
Nit: Since we will skip the not matched visualizations here. What about just call this.visualizations.get(chartType) here?
There was a problem hiding this comment.
right, that's a good call, I will tweak in next PR
| visualizations.push(input); | ||
| } | ||
| for (const visConfig of visualizations) { | ||
| if (!this.visualizations.has(visConfig.type)) { |
There was a problem hiding this comment.
Nit: Do we need to throw error when vis type already exists?
There was a problem hiding this comment.
Also thought about this, will come back to when necessary
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11589 +/- ##
===========================================
- Coverage 61.58% 0 -61.59%
===========================================
Files 4995 0 -4995
Lines 137542 0 -137542
Branches 23901 0 -23901
===========================================
- Hits 84707 0 -84707
+ Misses 46692 0 -46692
+ Partials 6143 0 -6143
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…d simplify registry (opensearch-project#11589) * refactor: centralize chart metadata and self-register all visualizations Each config file now self-registers with visualizationRegistry via registerVisualization() at module level. Signed-off-by: Yulong Ruan <ruanyl@amazon.com> * refactor: Remove unused column params from visualization create* functions Signed-off-by: Yulong Ruan <ruanyl@amazon.com> * refactor(explore): colocate visualization rules with chart configs and remove centralized rule repository Move visualization matching rules (VisRule) from the centralized rule_repository into each chart type's config file (e.g. line_vis_config, bar_vis_config), giving each visualization ownership of its own rules and render function via a new getRules() method on VisualizationType. - Delete rule_repository.ts and its tests (~1,450 lines removed) - Add VisRule interface with priority, mappings, and render function - Convert *_vis_config.ts files to .tsx to colocate rule render logic - Simplify VisualizationRegistry to derive available chart types and matching from registered visualizations instead of separate rule lists - Replace availableMappings with AxisTypeMapping-based rule matching using exact/compatible column-count comparison - Add updateAxesMappingByChartType for chart type switching - Simplify VisualizationRegistryService API: replace registerRule/ registerRules/getRules with registerVisualization/getVisualization - Update chart_type_selector, visualization_render, embeddable, and related components to use the new registry API Signed-off-by: Yulong Ruan <ruanyl@amazon.com> * fix: address code review issues in visualization registry refactor - Fix findRulesByColumns using ||= so any matching mapping keeps the flag true, not just the last one - Fix getAxesMappingByRule to only return complete mappings and try subsequent mappings when a mapping fails - Update embeddable test mock to use new VisRule shape (priority, mappings, render) instead of old VisualizationRule shape - Remove unused imports (visualizationRegistry in state_timeline_config, ReactNode in use_visualization_types) - Remove stale getVisualizationConfig mock and availableMappings setups from axes_selector tests - Fix VisRule.render return type from any to React.ReactNode - Rename getVisualizationConfigSpy to getVisualizationSpy Signed-off-by: Yulong Ruan <ruanyl@amazon.com> * Changeset file for PR opensearch-project#11589 created/updated * fix unit tests Signed-off-by: Yulong Ruan <ruanyl@amazon.com> --------- Signed-off-by: Yulong Ruan <ruanyl@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Description
Refactors the Explore plugin's visualization system to give each chart type ownership of its own matching rules and render logic, replacing the centralized rule_repository with colocated VisRule definitions inside each chart config file.
Motivation
The previous architecture maintained a large centralized rule_repository.ts (~1,000 lines) that mapped column types to chart types and defined rendering logic separately from the chart configurations. This created tight coupling, made it hard to reason about individual chart types, and required updating multiple files when adding or modifying a visualization.
Key changes
New VisRule interface — each chart config now defines its own rules with priority, mappings (axis-role-to-field-type), and a render function:
VisualizationRegistry simplified — instead of maintaining separate rule lists, the registry derives available chart types and performs rule matching directly from registered
Issues Resolved
Screenshot
Testing the changes
Changelog
Check List
yarn test:jestyarn test:jest_integration