mirror of
https://github.com/apache/superset.git
synced 2026-06-12 19:19:20 +00:00
- Create modern Pie chart control panel using React/AntD components - Add ModernControlPanelRenderer bridge for backward compatibility - Create ReactControlWrappers for control components - Update ControlPanelsContainer to support both legacy and modern formats - Add comprehensive migration documentation and plan This establishes the foundation for migrating from controlSetRows to modern React-based control panels while maintaining full backward compatibility. The Pie chart serves as the proof of concept for the phased migration approach. Note: This is a work-in-progress implementation that demonstrates the migration approach. TypeScript errors and linting issues will be resolved as the migration progresses. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
5.1 KiB
5.1 KiB
Control Panel Modernization Guide
Current State
Apache Superset's control panels currently use a legacy controlSetRows structure that relies on nested arrays to define layout. This approach has several limitations:
- Rigid Layout: The nested array structure makes it difficult to create responsive or complex layouts
- Poor Type Safety: Arrays of arrays don't provide good TypeScript support
- Mixed Paradigms: String references, configuration objects, and React components are mixed together
- Limited Reusability: Layout logic is embedded in the structure rather than using composable components
Migration Strategy
Phase 1: Component Modernization ✅ COMPLETED
- Replaced string-based control references with React components
- Updated individual control components to use Ant Design
- Modernized the
ControlRowcomponent to use Ant Design's Grid
Phase 2: Layout Utilities ✅ COMPLETED
- Created
ControlPanelLayout.tsxwith reusable layout components - Implemented
ControlSection,SingleControlRow,TwoColumnRow,ThreeColumnRow - Updated control group components to use Ant Design Row/Col
Phase 3: React-Based Control Panels 🚧 IN PROGRESS
- Create
ReactControlPanelcomponent for rendering modern panels - Support both legacy and modern formats during transition
- Provide migration helpers and examples
Phase 4: Gradual Migration 📋 TODO
- Migrate chart control panels one by one
- Start with simpler charts (Pie, Bar) before complex ones
- Maintain backward compatibility throughout
Modern Control Panel Structure
Legacy Structure (controlSetRows)
const config: ControlPanelConfig = {
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [
[GroupByControl()],
[MetricControl()],
[AdhocFiltersControl()],
[RowLimitControl()],
],
},
],
};
Modern Structure (React Components)
const modernConfig: ReactControlPanelConfig = {
sections: [
{
key: 'query',
label: t('Query'),
expanded: true,
render: ({ values, onChange }) => (
<>
<SingleControlRow>
<GroupByControl value={values.groupby} onChange={onChange} />
</SingleControlRow>
<SingleControlRow>
<MetricControl value={values.metrics} onChange={onChange} />
</SingleControlRow>
<TwoColumnRow
left={<AdhocFiltersControl value={values.adhoc_filters} onChange={onChange} />}
right={<RowLimitControl value={values.row_limit} onChange={onChange} />}
/>
</>
),
},
],
};
Benefits of Modernization
- Better Type Safety: Full TypeScript support with proper interfaces
- Flexible Layouts: Use Ant Design's Grid system for responsive layouts
- Cleaner Code: React components instead of nested arrays
- Improved DX: Better IDE support and autocomplete
- Easier Testing: Component-based architecture is easier to test
- Consistent Styling: Leverage Ant Design's theme system
Migration Example
To migrate a control panel:
-
Create a modern version alongside the existing one:
// controlPanelModern.tsx export const modernConfig: ReactControlPanelConfig = { sections: [/* ... */] }; -
Use the compatibility wrapper for backward compatibility:
export default createReactControlPanel(modernConfig); -
Update the chart plugin to use the new control panel:
import controlPanel from './controlPanelModern';
Layout Components Available
ControlSection: Collapsible section containerSingleControlRow: Full-width single controlTwoColumnRow: Two controls side by side (50/50)ThreeColumnRow: Three controls in a row (33/33/33)RowandColfrom Ant Design for custom layouts
Files Created
-
packages/superset-ui-chart-controls/src/shared-controls/components/ControlPanelLayout.tsx- Layout utility components
-
packages/superset-ui-chart-controls/src/shared-controls/components/ModernControlPanelExample.tsx- Example of modern control panel structure
-
plugins/plugin-chart-echarts/src/Pie/controlPanelModern.tsx- Modern version of Pie chart control panel
Next Steps
- Complete the ReactControlPanel integration with ControlPanelsContainer
- Create migration tooling to help convert existing panels
- Document best practices for control panel design
- Update chart plugin template to use modern structure
- Gradually migrate all 90+ control panels in the codebase
Technical Debt Addressed
- Eliminates nested array layout structure
- Removes string-based control references
- Reduces coupling between layout and configuration
- Improves maintainability and testability
- Enables better code splitting and lazy loading
Backward Compatibility
The migration maintains full backward compatibility:
- Existing control panels continue to work
- Both formats can coexist during migration
- No breaking changes to the public API
- Charts can be migrated incrementally