From 97a6217a0908bf1db1c7a22f26f588d2474b2191 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Mon, 15 Jul 2024 17:01:36 -0300 Subject: [PATCH] refactor: Removes dead code of Word Cloud plugin --- .../WordCloud.stories.tsx | 4 - .../src/chart/Encoder.ts | 18 ---- .../plugin-chart-word-cloud/src/index.ts | 1 - .../src/legacyPlugin/index.ts | 43 ---------- .../src/legacyPlugin/transformProps.ts | 85 ------------------- .../src/legacyPlugin/types.ts | 29 ------- .../test/{plugin => }/buildQuery.test.ts | 4 +- .../test/index.test.ts | 29 ------- .../test/legacyPlugin/transformProps.test.ts | 75 ---------------- 9 files changed, 2 insertions(+), 286 deletions(-) delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/src/chart/Encoder.ts delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/index.ts delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/transformProps.ts delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/types.ts rename superset-frontend/plugins/plugin-chart-word-cloud/test/{plugin => }/buildQuery.test.ts (92%) delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/test/index.test.ts delete mode 100644 superset-frontend/plugins/plugin-chart-word-cloud/test/legacyPlugin/transformProps.test.ts diff --git a/superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/plugin-chart-word-cloud/WordCloud.stories.tsx b/superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/plugin-chart-word-cloud/WordCloud.stories.tsx index 82f6ffedda4e7..9ea6ed42a8f46 100644 --- a/superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/plugin-chart-word-cloud/WordCloud.stories.tsx +++ b/superset-frontend/packages/superset-ui-demo/storybook/stories/plugins/plugin-chart-word-cloud/WordCloud.stories.tsx @@ -20,16 +20,12 @@ import { SuperChart, getChartTransformPropsRegistry } from '@superset-ui/core'; import { WordCloudChartPlugin, - LegacyWordCloudChartPlugin, WordCloudTransformProps, } from '@superset-ui/plugin-chart-word-cloud'; import { withResizableChartDemo } from '../../../shared/components/ResizableChartDemo'; import data from './data'; new WordCloudChartPlugin().configure({ key: 'word-cloud2' }).register(); -new LegacyWordCloudChartPlugin() - .configure({ key: 'legacy-word-cloud2' }) - .register(); // Enable the new WordCloud Props to show case its full features // if the control panel is updated to be able to pass formData in the new format. diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/chart/Encoder.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/chart/Encoder.ts deleted file mode 100644 index 042f3ce1f3966..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/chart/Encoder.ts +++ /dev/null @@ -1,18 +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. - */ diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/index.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/index.ts index 76168eaba77b2..50ab5676e4d20 100644 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/index.ts +++ b/superset-frontend/plugins/plugin-chart-word-cloud/src/index.ts @@ -19,6 +19,5 @@ export { default as WordCloudChartPlugin } from './plugin'; export { default as WordCloudTransformProps } from './plugin/transformProps'; -export { default as LegacyWordCloudChartPlugin } from './legacyPlugin'; export * from './types'; export { default as configureEncodable } from './configureEncodable'; diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/index.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/index.ts deleted file mode 100644 index 527dcba50a867..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/index.ts +++ /dev/null @@ -1,43 +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 { t, ChartMetadata, ChartPlugin } from '@superset-ui/core'; -import transformProps from './transformProps'; -import buildQuery from '../plugin/buildQuery'; -import thumbnail from '../images/thumbnail.png'; -import { LegacyWordCloudFormData } from './types'; - -const metadata = new ChartMetadata({ - credits: ['https://github.com/jasondavies/d3-cloud'], - description: '', - name: t('Word Cloud'), - thumbnail, - useLegacyApi: true, -}); - -export default class LegacyWordCloudChartPlugin extends ChartPlugin { - constructor() { - super({ - buildQuery, - loadChart: () => import('../chart/WordCloud'), - metadata, - transformProps, - }); - } -} diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/transformProps.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/transformProps.ts deleted file mode 100644 index 5685edd92129e..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/transformProps.ts +++ /dev/null @@ -1,85 +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 { ChartProps, getColumnLabel } from '@superset-ui/core'; -import { WordCloudProps, WordCloudEncoding } from '../chart/WordCloud'; -import { LegacyWordCloudFormData } from './types'; - -function getMetricLabel( - metric: LegacyWordCloudFormData['metric'], -): string | undefined { - if (typeof metric === 'string' || typeof metric === 'undefined') { - return metric; - } - if (Array.isArray(metric)) { - return metric.length > 0 ? getMetricLabel(metric[0]) : undefined; - } - - return metric.label; -} - -export default function transformProps(chartProps: ChartProps): WordCloudProps { - const { width, height, formData, queriesData } = chartProps; - const { - colorScheme, - metric, - rotation, - series, - sizeFrom = 0, - sizeTo, - sliceId, - } = formData as LegacyWordCloudFormData; - - const metricLabel = getMetricLabel(metric); - const seriesLabel = getColumnLabel(series); - - const encoding: Partial = { - color: { - field: seriesLabel, - scale: { - scheme: colorScheme, - }, - type: 'nominal', - }, - fontSize: - typeof metricLabel === 'undefined' - ? undefined - : { - field: metricLabel, - scale: { - range: [sizeFrom, sizeTo], - zero: true, - }, - type: 'quantitative', - }, - text: { - field: seriesLabel, - }, - }; - - return { - data: queriesData[0].data, - encoding, - height, - rotation, - width, - sliceId, - colorScheme, - }; -} diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/types.ts b/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/types.ts deleted file mode 100644 index 2cdc348126c3f..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/src/legacyPlugin/types.ts +++ /dev/null @@ -1,29 +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 { QueryFormColumn, QueryFormData } from '@superset-ui/core'; -import { RotationType } from '../chart/WordCloud'; - -export type LegacyWordCloudFormData = QueryFormData & { - colorScheme: string; - rotation?: RotationType; - series: QueryFormColumn; - sizeFrom?: number; - sizeTo: number; -}; diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/test/plugin/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-word-cloud/test/buildQuery.test.ts similarity index 92% rename from superset-frontend/plugins/plugin-chart-word-cloud/test/plugin/buildQuery.test.ts rename to superset-frontend/plugins/plugin-chart-word-cloud/test/buildQuery.test.ts index bd75f9a5e9354..6c236742697c4 100644 --- a/superset-frontend/plugins/plugin-chart-word-cloud/test/plugin/buildQuery.test.ts +++ b/superset-frontend/plugins/plugin-chart-word-cloud/test/buildQuery.test.ts @@ -17,8 +17,8 @@ * under the License. */ -import { WordCloudFormData } from '../../src'; -import buildQuery from '../../src/plugin/buildQuery'; +import { WordCloudFormData } from '../src'; +import buildQuery from '../src/plugin/buildQuery'; describe('WordCloud buildQuery', () => { const formData: WordCloudFormData = { diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/test/index.test.ts b/superset-frontend/plugins/plugin-chart-word-cloud/test/index.test.ts deleted file mode 100644 index bec7a1171d2e1..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/test/index.test.ts +++ /dev/null @@ -1,29 +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 { WordCloudChartPlugin, LegacyWordCloudChartPlugin } from '../src'; - -describe('plugin-chart-word-cloud', () => { - it('exports WordCloudChartPlugin', () => { - expect(WordCloudChartPlugin).toBeDefined(); - }); - it('exports LegacyWordCloudChartPlugin', () => { - expect(LegacyWordCloudChartPlugin).toBeDefined(); - }); -}); diff --git a/superset-frontend/plugins/plugin-chart-word-cloud/test/legacyPlugin/transformProps.test.ts b/superset-frontend/plugins/plugin-chart-word-cloud/test/legacyPlugin/transformProps.test.ts deleted file mode 100644 index a61e7408de750..0000000000000 --- a/superset-frontend/plugins/plugin-chart-word-cloud/test/legacyPlugin/transformProps.test.ts +++ /dev/null @@ -1,75 +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 { ChartProps, supersetTheme } from '@superset-ui/core'; -import transformProps from '../../src/legacyPlugin/transformProps'; - -describe('WordCloud transformProps', () => { - const formData = { - colorScheme: 'bnbColors', - datasource: '3__table', - granularity_sqla: 'ds', - metric: 'sum__num', - rotation: 'square', - series: 'name', - sizeFrom: 10, - sizeTo: 70, - }; - const chartProps = new ChartProps({ - formData, - width: 800, - height: 600, - queriesData: [ - { - data: [{ name: 'Hulk', sum__num: 1 }], - }, - ], - theme: supersetTheme, - }); - - it('should transform chart props for word cloud viz', () => { - expect(transformProps(chartProps)).toEqual({ - width: 800, - height: 600, - encoding: { - color: { - field: 'name', - scale: { - scheme: 'bnbColors', - }, - type: 'nominal', - }, - fontSize: { - field: 'sum__num', - scale: { - range: [10, 70], - zero: true, - }, - type: 'quantitative', - }, - text: { - field: 'name', - }, - }, - rotation: 'square', - colorScheme: 'bnbColors', - data: [{ name: 'Hulk', sum__num: 1 }], - }); - }); -});