mirror of
https://github.com/apache/superset.git
synced 2026-05-12 03:15:55 +00:00
This comprehensive architectural transformation removes all static theme imports (supersetTheme, themeObject) across the entire codebase, replacing them with proper dynamic theme access patterns that support real-time theme switching. ## What Changed **Static Exports Eliminated:** - Removed `supersetTheme` and `themeObject` exports from core theme module - Eliminated static theme dependencies across 47 files - Updated ESLint rules to reflect removed exports **Dynamic Theme Architecture:** - Functional components: Use `useTheme()` hook for reactive theme access - Class components: Use `withTheme()` HOC for theme injection - Transform functions: Access `theme` from chartProps parameter - Test infrastructure: Use `Theme.fromConfig()` for isolated testing - Singleton pattern: `DEFAULT_THEME` for efficient fallbacks **Test Architecture Cleanup:** - Removed unnecessary theme setup from 30+ test files - Eliminated legacy `dynamicTheme` cruft from logic tests - Simplified theme assertions to focus on behavior vs implementation details - Maintained theme testing only where legitimately needed **Core Infrastructure:** - ThemeController uses dynamic theme creation instead of static imports - ChartProps uses singleton DEFAULT_THEME for efficient fallbacks - Theme providers only at app root and isolated contexts (tests, storybook) ## Why This Was Needed The previous architecture had static theme imports that: - Always returned light theme values regardless of current theme mode - Broke dark mode compatibility in visualizations (fixed in previous commit) - Created performance overhead with redundant theme instance creation - Prevented real-time theme switching across components - Led to inconsistent theme access patterns ## Benefits - ✅ Perfect dark mode support - no static dependencies to break theming - ✅ True dynamic theming - all components react to theme changes - ✅ Clean architecture - minimal providers, consistent patterns - ✅ Better performance - singleton pattern eliminates waste - ✅ Future-proof - ready for theme customization and user preferences - ✅ Developer experience - clear patterns for every context This transformation enables the next generation of Superset theming with complete dynamic theme support and perfect dark mode compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
147 lines
4.1 KiB
TypeScript
147 lines
4.1 KiB
TypeScript
/**
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
* or more contributor license agreements. See the NOTICE file
|
|
* distributed with this work for additional information
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
* to you under the Apache License, Version 2.0 (the
|
|
* "License"); you may not use this file except in compliance
|
|
* with the License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
* KIND, either express or implied. See the License for the
|
|
* specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
import { ChartProps, getChartTransformPropsRegistry } from '@superset-ui/core';
|
|
|
|
import { LayerConf, MapViewConfigs, ZoomConfigs } from '../../src/types';
|
|
import transformProps from '../../src/plugin/transformProps';
|
|
import {
|
|
groupedTimeseriesChartData,
|
|
groupedTimeseriesLabelMap,
|
|
} from '../testData';
|
|
|
|
describe('CartodiagramPlugin transformProps', () => {
|
|
const chartSize: ZoomConfigs = {
|
|
type: 'FIXED',
|
|
configs: {
|
|
height: 10,
|
|
width: 10,
|
|
zoom: 1,
|
|
},
|
|
values: {
|
|
1: {
|
|
height: 10,
|
|
width: 10,
|
|
},
|
|
},
|
|
};
|
|
const layerConfigs: LayerConf[] = [
|
|
{
|
|
type: 'XYZ',
|
|
title: 'foo',
|
|
url: 'example.com',
|
|
},
|
|
];
|
|
const mapView: MapViewConfigs = {
|
|
mode: 'FIT_DATA',
|
|
zoom: 1,
|
|
latitude: 0,
|
|
longitude: 0,
|
|
fixedZoom: 1,
|
|
fixedLatitude: 0,
|
|
fixedLongitude: 0,
|
|
};
|
|
|
|
// only minimal subset of actual params
|
|
const selectedChartParams = {
|
|
groupby: ['bar'],
|
|
x_axis: 'mydate',
|
|
};
|
|
|
|
const selectedChart = {
|
|
id: 1,
|
|
viz_type: 'pie',
|
|
slice_name: 'foo',
|
|
params: JSON.stringify(selectedChartParams),
|
|
};
|
|
|
|
const formData = {
|
|
viz_type: 'cartodiagram',
|
|
geomColumn: 'geom',
|
|
selectedChart: JSON.stringify(selectedChart),
|
|
chartSize,
|
|
layerConfigs,
|
|
mapView,
|
|
chartBackgroundColor: '#000000',
|
|
chartBackgroundBorderRadius: 5,
|
|
};
|
|
|
|
const chartProps = new ChartProps({
|
|
formData,
|
|
width: 800,
|
|
height: 600,
|
|
queriesData: [
|
|
{
|
|
data: groupedTimeseriesChartData,
|
|
label_map: groupedTimeseriesLabelMap,
|
|
},
|
|
],
|
|
});
|
|
|
|
let chartTransformPropsPieMock: jest.MockedFunction<any>;
|
|
let chartTransformPropsTimeseriesMock: jest.MockedFunction<any>;
|
|
beforeEach(() => {
|
|
chartTransformPropsPieMock = jest.fn();
|
|
chartTransformPropsTimeseriesMock = jest.fn();
|
|
const registry = getChartTransformPropsRegistry();
|
|
registry.registerValue('pie', chartTransformPropsPieMock);
|
|
registry.registerValue(
|
|
'echarts_timeseries',
|
|
chartTransformPropsTimeseriesMock,
|
|
);
|
|
});
|
|
|
|
afterEach(() => {
|
|
// remove registered transformProps
|
|
const registry = getChartTransformPropsRegistry();
|
|
registry.clear();
|
|
});
|
|
|
|
it('should call the transform props function of the referenced chart', () => {
|
|
transformProps(chartProps);
|
|
expect(chartTransformPropsPieMock).toHaveBeenCalled();
|
|
expect(chartTransformPropsTimeseriesMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should transform chart props for viz', () => {
|
|
const transformedProps = transformProps(chartProps);
|
|
expect(transformedProps).toEqual(
|
|
expect.objectContaining({
|
|
width: chartProps.width,
|
|
height: chartProps.height,
|
|
geomColumn: formData.geomColumn,
|
|
selectedChart: expect.objectContaining({
|
|
viz_type: selectedChart.viz_type,
|
|
params: selectedChartParams,
|
|
}),
|
|
// The actual test for the created chartConfigs
|
|
// will be done in transformPropsUtil.test.ts
|
|
chartConfigs: expect.objectContaining({
|
|
type: 'FeatureCollection',
|
|
}),
|
|
chartVizType: selectedChart.viz_type,
|
|
chartSize,
|
|
layerConfigs,
|
|
mapView,
|
|
chartBackgroundColor: formData.chartBackgroundColor,
|
|
chartBackgroundBorderRadius: formData.chartBackgroundBorderRadius,
|
|
}),
|
|
);
|
|
});
|
|
});
|