Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove dead code from the Word Cloud plugin #29594

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,12 @@
* under the License.
*/

import { SuperChart, getChartTransformPropsRegistry } from '@superset-ui/core';
import {
WordCloudChartPlugin,
LegacyWordCloudChartPlugin,
WordCloudTransformProps,
} from '@superset-ui/plugin-chart-word-cloud';
import { SuperChart } from '@superset-ui/core';
import { WordCloudChartPlugin } 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.
getChartTransformPropsRegistry().registerValue(
'word-cloud2',
WordCloudTransformProps,
);

export default {
title: 'Chart Plugins/plugin-chart-word-cloud',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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';

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
import transformProps from '../legacyPlugin/transformProps';
import transformProps from './transformProps';
import buildQuery from './buildQuery';
import { WordCloudFormData } from '../types';
import thumbnail from '../images/thumbnail.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,61 @@
* under the License.
*/

import { ChartProps } from '@superset-ui/core';
import { WordCloudProps } from '../chart/WordCloud';
import { ChartProps, getColumnLabel } from '@superset-ui/core';
import { WordCloudProps, WordCloudEncoding } from '../chart/WordCloud';
import { WordCloudFormData } from '../types';

function getMetricLabel(
metric: WordCloudFormData['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 { encoding, rotation, sliceId, colorScheme } =
formData as WordCloudFormData;
const {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index file of the plugin was referencing the legacy transformProps function. I just copied the code from there here and deleted that file.

colorScheme,
metric,
rotation,
series,
sizeFrom = 0,
sizeTo,
sliceId,
} = formData as WordCloudFormData;

const metricLabel = getMetricLabel(metric);
const seriesLabel = getColumnLabel(series);

const encoding: Partial<WordCloudEncoding> = {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

This file was deleted.

Loading
Loading