This is an automated email from the ASF dual-hosted git repository. rusackas pushed a commit to branch refactor/type-consolidation in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4e0bcd8a84c45afda93f4fb22cd63bee4a7cfe8b Author: Evan Rusackas <[email protected]> AuthorDate: Fri Feb 6 14:05:49 2026 -0800 refactor(types): consolidate shared table types and fix Funnel enum typo ### Type Consolidation - Move shared table types to @superset-ui/chart-controls: - BasicColorFormatterType - SortByItem - SearchOption - ServerPaginationData - TableColumnConfig - DataColumnMeta - CustomFormatter - Update plugin-chart-table and plugin-chart-ag-grid-table to import from chart-controls and re-export for backwards compatibility ### Funnel Label Type Fix - Rename EchartsFunnelLabelTypeType to EchartsFunnelLabelType (fix typo) - Update all references in types.ts, transformProps.ts, and controlPanel.tsx Co-Authored-By: Claude Opus 4.5 <[email protected]> --- .../superset-ui-chart-controls/src/types.ts | 75 ++++++++++++++++++ .../plugin-chart-ag-grid-table/src/types.ts | 83 +++++--------------- .../src/Funnel/controlPanel.tsx | 28 +++---- .../src/Funnel/transformProps.ts | 18 ++--- .../plugin-chart-echarts/src/Funnel/types.ts | 10 +-- .../plugins/plugin-chart-table/src/types.ts | 88 +++++----------------- 6 files changed, 141 insertions(+), 161 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts index ffb32bf9d28..1bc9fc90fb9 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts @@ -22,16 +22,21 @@ import { ReactElement, ReactNode, ReactText, ComponentType } from 'react'; import type { AdhocColumn, Column, + CurrencyFormatter, Currency, DatasourceType, + DataRecordValue, JsonObject, JsonValue, Metric, + NumberFormatter, QueryFormColumn, QueryFormData, QueryFormMetric, QueryResponse, + TimeFormatter, } from '@superset-ui/core'; +import { GenericDataType } from '@apache-superset/core/api/core'; import { sharedControls, sharedControlComponents } from './shared-controls'; export type { Metric } from '@superset-ui/core'; @@ -608,3 +613,73 @@ export type ControlFormItemSpec<T extends ControlType = ControlType> = { defaultValue?: Currency; } : {}); + +/** ---------------------------------------------- + * Shared Table Chart Types + * Used by plugin-chart-table and plugin-chart-ag-grid-table + * --------------------------------------------- */ + +export type CustomFormatter = (value: DataRecordValue) => string; + +export type BasicColorFormatterType = { + backgroundColor: string; + arrowColor: string; + mainArrow: string; +}; + +export type SortByItem = { + id: string; + key: string; + desc?: boolean; +}; + +export type SearchOption = { + value: string; + label: string; +}; + +export interface ServerPaginationData { + pageSize?: number; + currentPage?: number; + sortBy?: SortByItem[]; + searchText?: string; + searchColumn?: string; +} + +export type TableColumnConfig = { + d3NumberFormat?: string; + d3SmallNumberFormat?: string; + d3TimeFormat?: string; + columnWidth?: number; + horizontalAlign?: 'left' | 'right' | 'center'; + showCellBars?: boolean; + alignPositiveNegative?: boolean; + colorPositiveNegative?: boolean; + truncateLongCells?: boolean; + currencyFormat?: Currency; + visible?: boolean; + customColumnName?: string; + displayTypeIcon?: boolean; +}; + +export interface DataColumnMeta { + // `key` is what is called `label` in the input props + key: string; + // `label` is verbose column name used for rendering + label: string; + // `originalLabel` preserves the original label when time comparison transforms the labels + originalLabel?: string; + dataType: GenericDataType; + formatter?: + | TimeFormatter + | NumberFormatter + | CustomFormatter + | CurrencyFormatter; + isMetric?: boolean; + isPercentMetric?: boolean; + isNumeric?: boolean; + config?: TableColumnConfig; + isChildColumn?: boolean; + description?: string; + currencyCodeColumn?: string; +} diff --git a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/types.ts b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/types.ts index d1a4cc143a1..c615621fd60 100644 --- a/superset-frontend/plugins/plugin-chart-ag-grid-table/src/types.ts +++ b/superset-frontend/plugins/plugin-chart-ag-grid-table/src/types.ts @@ -16,7 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -import { ColorFormatters } from '@superset-ui/chart-controls'; +import { + ColorFormatters, + BasicColorFormatterType, + CustomFormatter, + DataColumnMeta, + ServerPaginationData, + SortByItem, + SearchOption, + TableColumnConfig, +} from '@superset-ui/chart-controls'; import { NumberFormatter, TimeFormatter, @@ -24,7 +33,6 @@ import { QueryFormMetric, ChartProps, DataRecord, - DataRecordValue, DataRecordFilters, QueryMode, ChartDataResponseResult, @@ -36,7 +44,6 @@ import { Metric, AgGridChartState, } from '@superset-ui/core'; -import { GenericDataType } from '@apache-superset/core/api/core'; import { ColDef, Column, @@ -44,44 +51,17 @@ import { CustomCellRendererProps, } from '@superset-ui/core/components/ThemedAgGridReact'; -export type CustomFormatter = (value: DataRecordValue) => string; - -export type TableColumnConfig = { - d3NumberFormat?: string; - d3SmallNumberFormat?: string; - d3TimeFormat?: string; - columnWidth?: number; - horizontalAlign?: 'left' | 'right' | 'center'; - showCellBars?: boolean; - alignPositiveNegative?: boolean; - colorPositiveNegative?: boolean; - truncateLongCells?: boolean; - currencyFormat?: Currency; - visible?: boolean; - customColumnName?: string; - displayTypeIcon?: boolean; +// Re-export shared types for backwards compatibility +export type { + BasicColorFormatterType, + CustomFormatter, + DataColumnMeta, + ServerPaginationData, + SortByItem, + SearchOption, + TableColumnConfig, }; -export interface DataColumnMeta { - // `key` is what is called `label` in the input props - key: string; - // `label` is verbose column name used for rendering - label: string; - // `originalLabel` preserves the original label when time comparison transforms the labels - originalLabel?: string; - dataType: GenericDataType; - formatter?: - | TimeFormatter - | NumberFormatter - | CustomFormatter - | CurrencyFormatter; - isMetric?: boolean; - isPercentMetric?: boolean; - isNumeric?: boolean; - config?: TableColumnConfig; - isChildColumn?: boolean; -} - export interface TableChartData { records: DataRecord[]; columns: string[]; @@ -116,31 +96,6 @@ export interface TableChartProps extends ChartProps { queriesData: ChartDataResponseResult[]; } -export type BasicColorFormatterType = { - backgroundColor: string; - arrowColor: string; - mainArrow: string; -}; - -export type SortByItem = { - id: string; - key: string; - desc?: boolean; -}; - -export type SearchOption = { - value: string; - label: string; -}; - -export interface ServerPaginationData { - pageSize?: number; - currentPage?: number; - sortBy?: SortByItem[]; - searchText?: string; - searchColumn?: string; -} - export interface AgGridTableChartTransformedProps< D extends DataRecord = DataRecord, > { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx index 09adc2dbe6b..4d706d4bb42 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/controlPanel.tsx @@ -28,7 +28,7 @@ import { } from '@superset-ui/chart-controls'; import { DEFAULT_FORM_DATA, - EchartsFunnelLabelTypeType, + EchartsFunnelLabelType, PercentCalcType, } from './types'; import { legendSection } from '../controls'; @@ -107,20 +107,20 @@ const config: ControlPanelConfig = { default: labelType, renderTrigger: true, choices: [ - [EchartsFunnelLabelTypeType.Key, t('Category Name')], - [EchartsFunnelLabelTypeType.Value, t('Value')], - [EchartsFunnelLabelTypeType.Percent, t('Percentage')], - [EchartsFunnelLabelTypeType.KeyValue, t('Category and Value')], + [EchartsFunnelLabelType.Key, t('Category Name')], + [EchartsFunnelLabelType.Value, t('Value')], + [EchartsFunnelLabelType.Percent, t('Percentage')], + [EchartsFunnelLabelType.KeyValue, t('Category and Value')], [ - EchartsFunnelLabelTypeType.KeyPercent, + EchartsFunnelLabelType.KeyPercent, t('Category and Percentage'), ], [ - EchartsFunnelLabelTypeType.KeyValuePercent, + EchartsFunnelLabelType.KeyValuePercent, t('Category, Value and Percentage'), ], [ - EchartsFunnelLabelTypeType.ValuePercent, + EchartsFunnelLabelType.ValuePercent, t('Value and Percentage'), ], ], @@ -137,16 +137,16 @@ const config: ControlPanelConfig = { default: defaultTooltipLabel, renderTrigger: true, choices: [ - [EchartsFunnelLabelTypeType.Key, t('Category Name')], - [EchartsFunnelLabelTypeType.Value, t('Value')], - [EchartsFunnelLabelTypeType.Percent, t('Percentage')], - [EchartsFunnelLabelTypeType.KeyValue, t('Category and Value')], + [EchartsFunnelLabelType.Key, t('Category Name')], + [EchartsFunnelLabelType.Value, t('Value')], + [EchartsFunnelLabelType.Percent, t('Percentage')], + [EchartsFunnelLabelType.KeyValue, t('Category and Value')], [ - EchartsFunnelLabelTypeType.KeyPercent, + EchartsFunnelLabelType.KeyPercent, t('Category and Percentage'), ], [ - EchartsFunnelLabelTypeType.KeyValuePercent, + EchartsFunnelLabelType.KeyValuePercent, t('Category, Value and Percentage'), ], ], diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts index 05b5683e628..58c0a697402 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts @@ -35,7 +35,7 @@ import { DEFAULT_FORM_DATA as DEFAULT_FUNNEL_FORM_DATA, EchartsFunnelChartProps, EchartsFunnelFormData, - EchartsFunnelLabelTypeType, + EchartsFunnelLabelType, FunnelChartTransformedProps, PercentCalcType, } from './types'; @@ -215,19 +215,19 @@ export default function transformProps( percentCalculationType, }); switch (labelType) { - case EchartsFunnelLabelTypeType.Key: + case EchartsFunnelLabelType.Key: return name; - case EchartsFunnelLabelTypeType.Value: + case EchartsFunnelLabelType.Value: return formattedValue; - case EchartsFunnelLabelTypeType.Percent: + case EchartsFunnelLabelType.Percent: return formattedPercent; - case EchartsFunnelLabelTypeType.KeyValue: + case EchartsFunnelLabelType.KeyValue: return `${name}: ${formattedValue}`; - case EchartsFunnelLabelTypeType.KeyValuePercent: + case EchartsFunnelLabelType.KeyValuePercent: return `${name}: ${formattedValue} (${formattedPercent})`; - case EchartsFunnelLabelTypeType.KeyPercent: + case EchartsFunnelLabelType.KeyPercent: return `${name}: ${formattedPercent}`; - case EchartsFunnelLabelTypeType.ValuePercent: + case EchartsFunnelLabelType.ValuePercent: return `${formattedValue} (${formattedPercent})`; default: return name; @@ -283,7 +283,7 @@ export default function transformProps( percentCalculationType, }); const row = []; - const enumName = EchartsFunnelLabelTypeType[tooltipLabelType]; + const enumName = EchartsFunnelLabelType[tooltipLabelType]; const title = enumName.includes('Key') ? name : undefined; if (enumName.includes('Value') || enumName.includes('Percent')) { row.push(metricLabel); diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts index 5c1183d1fc5..171c049e58e 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/types.ts @@ -33,8 +33,8 @@ export type EchartsFunnelFormData = QueryFormData & colorScheme?: string; groupby: QueryFormData[]; labelLine: boolean; - labelType: EchartsFunnelLabelTypeType; - tooltipLabelType: EchartsFunnelLabelTypeType; + labelType: EchartsFunnelLabelType; + tooltipLabelType: EchartsFunnelLabelType; metric?: string; showLabels: boolean; showTooltipLabels: boolean; @@ -45,7 +45,7 @@ export type EchartsFunnelFormData = QueryFormData & percentCalculationType: PercentCalcType; }; -export enum EchartsFunnelLabelTypeType { +export enum EchartsFunnelLabelType { Key, Value, Percent, @@ -64,8 +64,8 @@ export const DEFAULT_FORM_DATA: EchartsFunnelFormData = { ...DEFAULT_LEGEND_FORM_DATA, groupby: [], labelLine: false, - labelType: EchartsFunnelLabelTypeType.Key, - defaultTooltipLabel: EchartsFunnelLabelTypeType.KeyValuePercent, + labelType: EchartsFunnelLabelType.Key, + defaultTooltipLabel: EchartsFunnelLabelType.KeyValuePercent, legendOrientation: LegendOrientation.Top, legendType: LegendType.Scroll, numberFormat: 'SMART_NUMBER', diff --git a/superset-frontend/plugins/plugin-chart-table/src/types.ts b/superset-frontend/plugins/plugin-chart-table/src/types.ts index 85a27777f49..d8cfad96a45 100644 --- a/superset-frontend/plugins/plugin-chart-table/src/types.ts +++ b/superset-frontend/plugins/plugin-chart-table/src/types.ts @@ -17,65 +17,40 @@ * under the License. */ import { - NumberFormatter, - TimeFormatter, TimeGranularity, QueryFormMetric, ChartProps, DataRecord, - DataRecordValue, DataRecordFilters, QueryMode, ChartDataResponseResult, QueryFormData, SetDataMaskHook, ContextMenuFilters, - CurrencyFormatter, Currency, } from '@superset-ui/core'; -import { GenericDataType } from '@apache-superset/core/api/core'; -import { ColorFormatters } from '@superset-ui/chart-controls'; - -export type CustomFormatter = (value: DataRecordValue) => string; +import { + ColorFormatters, + BasicColorFormatterType, + CustomFormatter, + DataColumnMeta, + ServerPaginationData, + SortByItem, + SearchOption, + TableColumnConfig, +} from '@superset-ui/chart-controls'; -export type TableColumnConfig = { - d3NumberFormat?: string; - d3SmallNumberFormat?: string; - d3TimeFormat?: string; - columnWidth?: number; - horizontalAlign?: 'left' | 'right' | 'center'; - showCellBars?: boolean; - alignPositiveNegative?: boolean; - colorPositiveNegative?: boolean; - truncateLongCells?: boolean; - currencyFormat?: Currency; - visible?: boolean; - customColumnName?: string; - displayTypeIcon?: boolean; +// Re-export shared types for backwards compatibility +export type { + BasicColorFormatterType, + CustomFormatter, + DataColumnMeta, + ServerPaginationData, + SortByItem, + SearchOption, + TableColumnConfig, }; -export interface DataColumnMeta { - // `key` is what is called `label` in the input props - key: string; - // `label` is verbose column name used for rendering - label: string; - // `originalLabel` preserves the original label when time comparison transforms the labels - originalLabel?: string; - dataType: GenericDataType; - formatter?: - | TimeFormatter - | NumberFormatter - | CustomFormatter - | CurrencyFormatter; - isMetric?: boolean; - isPercentMetric?: boolean; - isNumeric?: boolean; - config?: TableColumnConfig; - isChildColumn?: boolean; - description?: string; - currencyCodeColumn?: string; -} - export interface TableChartData { records: DataRecord[]; columns: string[]; @@ -110,31 +85,6 @@ export interface TableChartProps extends ChartProps { queriesData: ChartDataResponseResult[]; } -export type BasicColorFormatterType = { - backgroundColor: string; - arrowColor: string; - mainArrow: string; -}; - -export type SortByItem = { - id: string; - key: string; - desc?: boolean; -}; - -export type SearchOption = { - value: string; - label: string; -}; - -export interface ServerPaginationData { - pageSize?: number; - currentPage?: number; - sortBy?: SortByItem[]; - searchText?: string; - searchColumn?: string; -} - export interface TableChartTransformedProps<D extends DataRecord = DataRecord> { timeGrain?: TimeGranularity; height: number;
