mirror of
https://github.com/apache/superset.git
synced 2026-05-12 11:25:56 +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>
99 lines
3.1 KiB
TypeScript
99 lines
3.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, QueryFormData } from '@superset-ui/core';
|
|
|
|
import transformProps from '../../src/plugin/transformProps';
|
|
import { MetricsLayoutEnum } from '../../src/types';
|
|
|
|
describe('PivotTableChart transformProps', () => {
|
|
const setDataMask = jest.fn();
|
|
const formData = {
|
|
groupbyRows: ['row1', 'row2'],
|
|
groupbyColumns: ['col1', 'col2'],
|
|
metrics: ['metric1', 'metric2'],
|
|
tableRenderer: 'Table With Subtotal',
|
|
colOrder: 'key_a_to_z',
|
|
rowOrder: 'key_a_to_z',
|
|
aggregateFunction: 'Sum',
|
|
transposePivot: true,
|
|
combineMetric: true,
|
|
rowSubtotalPosition: true,
|
|
colSubtotalPosition: true,
|
|
colTotals: true,
|
|
rowTotals: true,
|
|
valueFormat: 'SMART_NUMBER',
|
|
metricsLayout: MetricsLayoutEnum.COLUMNS,
|
|
viz_type: '',
|
|
datasource: '',
|
|
conditionalFormatting: [],
|
|
dateFormat: '',
|
|
legacy_order_by: 'count',
|
|
order_desc: true,
|
|
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
|
};
|
|
const chartProps = new ChartProps<QueryFormData>({
|
|
formData,
|
|
width: 800,
|
|
height: 600,
|
|
queriesData: [
|
|
{
|
|
data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }],
|
|
colnames: ['name', 'sum__num', '__timestamp'],
|
|
coltypes: [1, 0, 2],
|
|
},
|
|
],
|
|
hooks: { setDataMask },
|
|
filterState: { selectedFilters: {} },
|
|
datasource: { verboseMap: {}, columnFormats: {} },
|
|
});
|
|
|
|
it('should transform chart props for viz', () => {
|
|
expect(transformProps(chartProps)).toEqual({
|
|
width: 800,
|
|
height: 600,
|
|
groupbyRows: ['row1', 'row2'],
|
|
groupbyColumns: ['col1', 'col2'],
|
|
metrics: ['metric1', 'metric2'],
|
|
tableRenderer: 'Table With Subtotal',
|
|
colOrder: 'key_a_to_z',
|
|
rowOrder: 'key_a_to_z',
|
|
aggregateFunction: 'Sum',
|
|
transposePivot: true,
|
|
combineMetric: true,
|
|
rowSubtotalPosition: true,
|
|
colSubtotalPosition: true,
|
|
colTotals: true,
|
|
rowTotals: true,
|
|
valueFormat: 'SMART_NUMBER',
|
|
data: [{ name: 'Hulk', sum__num: 1, __timestamp: 599616000000 }],
|
|
setDataMask,
|
|
selectedFilters: {},
|
|
verboseMap: {},
|
|
metricsLayout: MetricsLayoutEnum.COLUMNS,
|
|
metricColorFormatters: [],
|
|
dateFormatters: {},
|
|
emitCrossFilters: false,
|
|
columnFormats: {},
|
|
currencyFormats: {},
|
|
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
|
});
|
|
});
|
|
});
|