diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts index 898c80802cac..d92283d7ccad 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/index.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { t, ChartMetadata, Behavior } from '@superset-ui/core'; +import { t, Behavior } from '@superset-ui/core'; import controlPanel from './controlPanel'; import transformProps from './transformProps'; import buildQuery from './buildQuery'; @@ -26,7 +26,7 @@ import thumbnail from './images/thumbnail.png'; import { BigNumberTotalChartProps, BigNumberTotalFormData } from '../types'; import { EchartsChartPlugin } from '../../types'; -const metadata = new ChartMetadata({ +const metadata = { category: t('KPI'), description: t( 'Showcases a single metric front-and-center. Big number is best used to call attention to a KPI or the one thing you want your audience to focus on.', @@ -47,7 +47,7 @@ const metadata = new ChartMetadata({ ], thumbnail, behaviors: [Behavior.DRILL_TO_DETAIL], -}); +}; export default class BigNumberTotalChartPlugin extends EchartsChartPlugin< BigNumberTotalFormData, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberWithTrendline/index.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberWithTrendline/index.ts index d094105376f6..80a21ad2290b 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberWithTrendline/index.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberWithTrendline/index.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { t, ChartMetadata, Behavior } from '@superset-ui/core'; +import { t, Behavior } from '@superset-ui/core'; import controlPanel from './controlPanel'; import transformProps from './transformProps'; import buildQuery from './buildQuery'; @@ -28,7 +28,7 @@ import { } from '../types'; import { EchartsChartPlugin } from '../../types'; -const metadata = new ChartMetadata({ +const metadata = { category: t('KPI'), description: t( 'Showcases a single number accompanied by a simple line chart, to call attention to an important metric along with its change over time or other dimension.', @@ -46,7 +46,7 @@ const metadata = new ChartMetadata({ ], thumbnail, behaviors: [Behavior.DRILL_TO_DETAIL], -}); +}; export default class BigNumberWithTrendlineChartPlugin extends EchartsChartPlugin< BigNumberWithTrendlineFormData, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts index 62b12316fa7e..32438f79dd52 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/types.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/types.ts @@ -176,15 +176,14 @@ export class EchartsChartPlugin< P extends ChartProps = ChartProps, > extends ChartPlugin { constructor(props: any) { - const { metadata } = props; - const mergedProps = { - ...props, + const { metadata, ...restProps } = props; + super({ + ...restProps, metadata: new ChartMetadata({ parseMethod: 'json', ...metadata, }), - }; - super(mergedProps); + }); } } diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/index.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/index.test.ts deleted file mode 100644 index 2a26ea50a232..000000000000 --- a/superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/index.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** -+ * 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 { EchartsTimeseriesChartPlugin } from '@superset-ui/plugin-chart-echarts'; - -describe('@superset-ui/plugin-chart-echarts', () => { - it('exists', () => { - const chart = new EchartsTimeseriesChartPlugin().configure({ - key: 'echarts_timeseries', - }); - expect(chart.metadata.parseMethod).toEqual('json'); - }); -}); diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/index.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/index.test.ts index 4ffd1cf473f2..f9b69393aef9 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/test/index.test.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/test/index.test.ts @@ -23,15 +23,107 @@ import { EchartsGraphChartPlugin, EchartsFunnelChartPlugin, EchartsTreemapChartPlugin, + EchartsAreaChartPlugin, + EchartsTimeseriesBarChartPlugin, + EchartsTimeseriesLineChartPlugin, + EchartsTimeseriesScatterChartPlugin, + EchartsTimeseriesSmoothLineChartPlugin, + EchartsTimeseriesStepChartPlugin, + EchartsMixedTimeseriesChartPlugin, + EchartsGaugeChartPlugin, + EchartsRadarChartPlugin, + EchartsTreeChartPlugin, + BigNumberChartPlugin, + BigNumberTotalChartPlugin, + EchartsSunburstChartPlugin, } from '../src'; -describe('@superset-ui/plugin-chart-echarts', () => { - it('exists', () => { - expect(EchartsBoxPlotChartPlugin).toBeDefined(); - expect(EchartsPieChartPlugin).toBeDefined(); - expect(EchartsTimeseriesChartPlugin).toBeDefined(); - expect(EchartsGraphChartPlugin).toBeDefined(); - expect(EchartsFunnelChartPlugin).toBeDefined(); - expect(EchartsTreemapChartPlugin).toBeDefined(); +import { EchartsChartPlugin } from '../src/types'; + +test('@superset-ui/plugin-chart-echarts exists', () => { + expect(EchartsBoxPlotChartPlugin).toBeDefined(); + expect(EchartsPieChartPlugin).toBeDefined(); + expect(EchartsTimeseriesChartPlugin).toBeDefined(); + expect(EchartsGraphChartPlugin).toBeDefined(); + expect(EchartsFunnelChartPlugin).toBeDefined(); + expect(EchartsTreemapChartPlugin).toBeDefined(); + expect(EchartsAreaChartPlugin).toBeDefined(); + expect(EchartsTimeseriesBarChartPlugin).toBeDefined(); + expect(EchartsTimeseriesLineChartPlugin).toBeDefined(); + expect(EchartsTimeseriesScatterChartPlugin).toBeDefined(); + expect(EchartsTimeseriesSmoothLineChartPlugin).toBeDefined(); + expect(EchartsTimeseriesStepChartPlugin).toBeDefined(); + expect(EchartsMixedTimeseriesChartPlugin).toBeDefined(); + expect(EchartsGaugeChartPlugin).toBeDefined(); + expect(EchartsRadarChartPlugin).toBeDefined(); + expect(EchartsTreeChartPlugin).toBeDefined(); + expect(BigNumberChartPlugin).toBeDefined(); + expect(BigNumberTotalChartPlugin).toBeDefined(); + expect(EchartsSunburstChartPlugin).toBeDefined(); +}); + +test('@superset-ui/plugin-chart-echarts-parsemethod-validation', () => { + const plugins: EchartsChartPlugin[] = [ + new EchartsBoxPlotChartPlugin().configure({ + key: 'box_plot', + }), + new EchartsPieChartPlugin().configure({ + key: 'pie', + }), + new EchartsTimeseriesChartPlugin().configure({ + key: 'echarts_timeseries', + }), + new EchartsGraphChartPlugin().configure({ + key: 'graph_chart', + }), + new EchartsFunnelChartPlugin().configure({ + key: 'funnel', + }), + new EchartsTreemapChartPlugin().configure({ + key: 'treemap_v2', + }), + new EchartsAreaChartPlugin().configure({ + key: 'echarts_area', + }), + new EchartsTimeseriesBarChartPlugin().configure({ + key: 'echarts_timeseries_bar', + }), + new EchartsTimeseriesLineChartPlugin().configure({ + key: 'echarts_timeseries_line', + }), + new EchartsTimeseriesScatterChartPlugin().configure({ + key: 'echarts_timeseries_scatter', + }), + new EchartsTimeseriesSmoothLineChartPlugin().configure({ + key: 'echarts_timeseries_smooth', + }), + new EchartsTimeseriesStepChartPlugin().configure({ + key: 'echarts_timeseries_step', + }), + new EchartsMixedTimeseriesChartPlugin().configure({ + key: 'mixed_timeseries', + }), + new EchartsGaugeChartPlugin().configure({ + key: 'gauge_chart', + }), + new EchartsRadarChartPlugin().configure({ + key: 'radar', + }), + new EchartsTreeChartPlugin().configure({ + key: 'tree', + }), + new BigNumberChartPlugin().configure({ + key: 'big_number', + }), + new BigNumberTotalChartPlugin().configure({ + key: 'big_number_total', + }), + new EchartsSunburstChartPlugin().configure({ + key: 'sunburst', + }), + ]; + + plugins.forEach(plugin => { + expect(plugin.metadata.parseMethod).toEqual('json'); }); });