From 1143e17742d1fa4c4cbae2c86e4998f4cc7e9f88 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Fri, 26 Aug 2022 08:22:57 -0300 Subject: [PATCH] fix: Typing of labelMap (#21181) * fix: Typing of labelMap * Adjusts val types --- .../superset-ui-core/src/query/types/Query.ts | 4 +-- .../src/query/types/QueryResponse.ts | 2 +- .../src/BoxPlot/transformProps.ts | 28 ++++++++----------- .../src/Funnel/transformProps.ts | 26 ++++++++--------- .../src/Gauge/transformProps.ts | 5 ++-- .../src/MixedTimeseries/types.ts | 3 +- .../src/Pie/transformProps.ts | 28 ++++++++----------- .../src/Radar/transformProps.ts | 5 ++-- .../src/Treemap/transformProps.ts | 3 +- .../plugins/plugin-chart-echarts/src/types.ts | 3 +- .../src/utils/eventHandlers.ts | 4 +-- 11 files changed, 47 insertions(+), 64 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts index 94c48d432..6c86b397f 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/Query.ts @@ -40,13 +40,13 @@ export type BaseQueryObjectFilterClause = { export type BinaryQueryObjectFilterClause = BaseQueryObjectFilterClause & { op: BinaryOperator; - val: string | number | boolean | null | Date; + val: string | number | boolean; formattedVal?: string; }; export type SetQueryObjectFilterClause = BaseQueryObjectFilterClause & { op: SetOperator; - val: (string | number | boolean | null | Date)[]; + val: (string | number | boolean)[]; formattedVal?: string[]; }; diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/QueryResponse.ts b/superset-frontend/packages/superset-ui-core/src/query/types/QueryResponse.ts index 0ae58202c..e4869805f 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/QueryResponse.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/QueryResponse.ts @@ -83,7 +83,7 @@ export interface ChartDataResponseResult { export interface TimeseriesChartDataResponseResult extends ChartDataResponseResult { data: TimeseriesDataRecord[]; - label_map: Record; + label_map: Record; } /** diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts index d83811eac..e41f82f96 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts @@ -18,7 +18,6 @@ */ import { CategoricalColorNamespace, - DataRecordValue, getColumnLabel, getMetricLabel, getNumberFormatter, @@ -156,21 +155,18 @@ export default function transformProps( ) .flat(2); - const labelMap = data.reduce( - (acc: Record, datum) => { - const label = extractGroupbyLabel({ - datum, - groupby: groupbyLabels, - coltypeMapping, - timeFormatter: getTimeFormatter(dateFormat), - }); - return { - ...acc, - [label]: groupbyLabels.map(col => datum[col]), - }; - }, - {}, - ); + const labelMap = data.reduce((acc: Record, datum) => { + const label = extractGroupbyLabel({ + datum, + groupby: groupbyLabels, + coltypeMapping, + timeFormatter: getTimeFormatter(dateFormat), + }); + return { + ...acc, + [label]: groupbyLabels.map(col => datum[col] as string), + }; + }, {}); const selectedValues = (filterState.selectedValues || []).reduce( (acc: Record, selectedValue: string) => { 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 e5ba6d0ad..ebb1d4f40 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Funnel/transformProps.ts @@ -18,7 +18,6 @@ */ import { CategoricalColorNamespace, - DataRecordValue, DataRecord, getMetricLabel, getNumberFormatter, @@ -121,20 +120,17 @@ export default function transformProps( const keys = data.map(datum => extractGroupbyLabel({ datum, groupby: groupbyLabels, coltypeMapping: {} }), ); - const labelMap = data.reduce( - (acc: Record, datum) => { - const label = extractGroupbyLabel({ - datum, - groupby: groupbyLabels, - coltypeMapping: {}, - }); - return { - ...acc, - [label]: groupbyLabels.map(col => datum[col]), - }; - }, - {}, - ); + const labelMap = data.reduce((acc: Record, datum) => { + const label = extractGroupbyLabel({ + datum, + groupby: groupbyLabels, + coltypeMapping: {}, + }); + return { + ...acc, + [label]: groupbyLabels.map(col => datum[col] as string), + }; + }, {}); const { setDataMask = () => {}, onContextMenu } = hooks; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/transformProps.ts index edd31d9d0..9bc733ebb 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Gauge/transformProps.ts @@ -23,7 +23,6 @@ import { DataRecord, getNumberFormatter, getMetricLabel, - DataRecordValue, getColumnLabel, } from '@superset-ui/core'; import { EChartsCoreOption, GaugeSeriesOption } from 'echarts'; @@ -132,7 +131,7 @@ export default function transformProps( FONT_SIZE_MULTIPLIERS.titleOffsetFromTitle * fontSize; const detailOffsetFromTitle = FONT_SIZE_MULTIPLIERS.detailOffsetFromTitle * fontSize; - const columnsLabelMap = new Map(); + const columnsLabelMap = new Map(); const transformedData: GaugeDataItemOption[] = data.map( (data_point, index) => { @@ -141,7 +140,7 @@ export default function transformProps( .join(', '); columnsLabelMap.set( name, - groupbyLabels.map(col => data_point[col]), + groupbyLabels.map(col => data_point[col] as string), ); let item: GaugeDataItemOption = { value: data_point[getMetricLabel(metric as QueryFormMetric)] as number, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts index 478e2c265..9a751d5d6 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/types.ts @@ -19,7 +19,6 @@ import { AnnotationLayer, TimeGranularity, - DataRecordValue, QueryFormData, ChartProps, ChartDataResponseResult, @@ -142,7 +141,7 @@ export type EchartsMixedTimeseriesChartTransformedProps = EChartTransformedProps & { emitFilterB: boolean; groupbyB: QueryFormColumn[]; - labelMapB: Record; + labelMapB: Record; seriesBreakdown: number; xValueFormatter: TimeFormatter | StringConstructor; }; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts index a7b5036fd..dc1adb11b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts @@ -18,7 +18,6 @@ */ import { CategoricalColorNamespace, - DataRecordValue, getColumnLabel, getMetricLabel, getNumberFormatter, @@ -185,21 +184,18 @@ export default function transformProps( timeFormatter: getTimeFormatter(dateFormat), }), ); - const labelMap = data.reduce( - (acc: Record, datum) => { - const label = extractGroupbyLabel({ - datum, - groupby: groupbyLabels, - coltypeMapping, - timeFormatter: getTimeFormatter(dateFormat), - }); - return { - ...acc, - [label]: groupbyLabels.map(col => datum[col]), - }; - }, - {}, - ); + const labelMap = data.reduce((acc: Record, datum) => { + const label = extractGroupbyLabel({ + datum, + groupby: groupbyLabels, + coltypeMapping, + timeFormatter: getTimeFormatter(dateFormat), + }); + return { + ...acc, + [label]: groupbyLabels.map(col => datum[col] as string), + }; + }, {}); const { setDataMask = () => {}, onContextMenu } = hooks; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts index 137324d2e..77f5f9dc3 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Radar/transformProps.ts @@ -18,7 +18,6 @@ */ import { CategoricalColorNamespace, - DataRecordValue, ensureIsInt, getColumnLabel, getMetricLabel, @@ -120,7 +119,7 @@ export default function transformProps( const groupbyLabels = groupby.map(getColumnLabel); const metricLabelAndMaxValueMap = new Map(); - const columnsLabelMap = new Map(); + const columnsLabelMap = new Map(); const transformedData: RadarSeriesDataItemOption[] = []; data.forEach(datum => { const joinedName = extractGroupbyLabel({ @@ -132,7 +131,7 @@ export default function transformProps( // map(joined_name: [columnLabel_1, columnLabel_2, ...]) columnsLabelMap.set( joinedName, - groupbyLabels.map(col => datum[col]), + groupbyLabels.map(col => datum[col] as string), ); // put max value of series into metricLabelAndMaxValueMap diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/transformProps.ts index e0a6f63ea..80bcabdd4 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Treemap/transformProps.ts @@ -19,7 +19,6 @@ import { CategoricalColorNamespace, DataRecord, - DataRecordValue, getColumnLabel, getMetricLabel, getNumberFormatter, @@ -150,7 +149,7 @@ export default function transformProps( labelType, }); - const columnsLabelMap = new Map(); + const columnsLabelMap = new Map(); const transformer = ( data: DataRecord[], diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts index 693a889ac..36f2b297f 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts @@ -17,7 +17,6 @@ * under the License. */ import { - DataRecordValue, HandlerFunction, QueryFormColumn, QueryObjectFilterClause, @@ -112,7 +111,7 @@ export interface EChartTransformedProps { emitFilter: boolean; setDataMask: SetDataMaskHook; setControlValue?: HandlerFunction; - labelMap: Record; + labelMap: Record; groupby: QueryFormColumn[]; selectedValues: Record; legendData?: OptionName[]; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts b/superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts index e40e77b4b..bcbacf03b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { DataRecordValue, QueryObjectFilterClause } from '@superset-ui/core'; +import { QueryObjectFilterClause } from '@superset-ui/core'; import { EChartTransformedProps, EventHandlers } from '../types'; export type Event = { @@ -42,7 +42,7 @@ export const contextMenuEventHandler = ( groupby: EChartTransformedProps['groupby'], onContextMenu: EChartTransformedProps['onContextMenu'], - labelMap: Record, + labelMap: Record, ) => (e: Event) => { if (onContextMenu) {