From fea7c589f5b745858f2f78cc592dc07edec233a3 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Fri, 22 Mar 2019 11:40:23 -0700 Subject: [PATCH] chore(chart): remove faux @superset-ui/core TS declaration (#121) * chore(chart): remove faux @superset-ui/core TS declaration * test(chart): test all ChartPlugin.register() branches * refactor(chart): support loaders that return esmodules * refactor(chart): rename ChartMetaDataConfig => ChartMetadataConfig * test(chart): fix loader test + branch coverage * test(chart): hit all branches in sanitizeLoader * refactor(chart): use ChartMetadata in registry --- .../src/clients/ChartClient.ts | 10 +-- .../src/components/SuperChart.tsx | 36 +++++------ .../src/models/ChartMetadata.ts | 22 ++++--- .../src/models/ChartPlugin.ts | 61 ++++++++++++------- .../ChartBuildQueryRegistrySingleton.ts | 6 +- .../ChartComponentRegistrySingleton.ts | 3 +- .../ChartMetadataRegistrySingleton.ts | 3 +- .../ChartTransformPropsRegistrySingleton.ts | 3 +- .../superset-ui-chart/src/types/Query.ts | 18 +++--- .../test/clients/ChartClient.test.ts | 23 +++++-- .../test/components/SuperChart.test.tsx | 6 +- ...artPlugin.test.ts => ChartPlugin.test.tsx} | 30 +++++---- .../superset-ui-chart/types/external.d.ts | 1 - .../superset-ui-core/src/models/Registry.ts | 2 +- .../ChartDataProviderStories.tsx | 3 +- 15 files changed, 133 insertions(+), 94 deletions(-) rename superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/{ChartPlugin.test.ts => ChartPlugin.test.tsx} (90%) delete mode 100644 superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/types/external.d.ts diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/clients/ChartClient.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/clients/ChartClient.ts index 6297a057ee16f..2968aa2a8c10e 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/clients/ChartClient.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/clients/ChartClient.ts @@ -74,12 +74,14 @@ export default class ChartClient { : Promise.reject(new Error('At least one of sliceId or formData must be specified')); } - loadQueryData(formData: ChartFormData, options?: Partial): Promise { + async loadQueryData(formData: ChartFormData, options?: Partial): Promise { const { viz_type: visType } = formData; + const metaDataRegistry = getChartMetadataRegistry(); + const buildQueryRegistry = getChartBuildQueryRegistry(); - if (getChartMetadataRegistry().has(visType)) { - const { useLegacyApi } = getChartMetadataRegistry().get(visType); - const buildQuery = useLegacyApi ? () => formData : getChartBuildQueryRegistry().get(visType); + if (metaDataRegistry.has(visType)) { + const { useLegacyApi } = metaDataRegistry.get(visType)!; + const buildQuery = (await buildQueryRegistry.get(visType)) || (() => formData); return this.client .post({ diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/SuperChart.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/SuperChart.tsx index a0fe7674ce9b5..46eadd4a6a6f6 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/SuperChart.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/SuperChart.tsx @@ -4,6 +4,8 @@ import getChartComponentRegistry from '../registries/ChartComponentRegistrySingl import getChartTransformPropsRegistry from '../registries/ChartTransformPropsRegistrySingleton'; import ChartProps from '../models/ChartProps'; import createLoadableRenderer, { LoadableRenderer } from './createLoadableRenderer'; +import { ChartType } from '../models/ChartPlugin'; +import { PreTransformProps, TransformProps, PostTransformProps } from '../types/Query'; const IDENTITY = (x: any) => x; @@ -21,26 +23,21 @@ const defaultProps = { }; /* eslint-enable sort-keys */ -type TransformFunction = (x: Input) => Output; type HandlerFunction = (...args: any[]) => void; interface LoadingProps { error: any; } -interface PlainProps { - [key: string]: any; -} - interface LoadedModules { - Chart: React.Component | { default: React.Component }; - transformProps: TransformFunction | { default: TransformFunction }; + Chart: ChartType; + transformProps: TransformProps; } interface RenderProps { chartProps: ChartProps; - preTransformProps?: TransformFunction; - postTransformProps?: TransformFunction; + preTransformProps?: PreTransformProps; + postTransformProps?: PostTransformProps; } const BLANK_CHART_PROPS = new ChartProps(); @@ -50,17 +47,13 @@ export interface SuperChartProps { className?: string; chartProps?: ChartProps | null; chartType: string; - preTransformProps?: TransformFunction; - overrideTransformProps?: TransformFunction; - postTransformProps?: TransformFunction; + preTransformProps?: PreTransformProps; + overrideTransformProps?: TransformProps; + postTransformProps?: PostTransformProps; onRenderSuccess?: HandlerFunction; onRenderFailure?: HandlerFunction; } -function getModule(value: any): T { - return (value.default ? value.default : value) as T; -} - export default class SuperChart extends React.PureComponent { static defaultProps = defaultProps; @@ -125,19 +118,18 @@ export default class SuperChart extends React.PureComponent processChartProps: (input: { chartProps: ChartProps; - preTransformProps?: TransformFunction; - transformProps?: TransformFunction; - postTransformProps?: TransformFunction; + preTransformProps?: PreTransformProps; + transformProps?: TransformProps; + postTransformProps?: PostTransformProps; }) => any; createLoadableRenderer: (input: { chartType: string; - overrideTransformProps?: TransformFunction; + overrideTransformProps?: TransformProps; }) => LoadableRenderer | (() => null); renderChart(loaded: LoadedModules, props: RenderProps) { - const Chart = getModule(loaded.Chart); - const transformProps = getModule(loaded.transformProps); + const { Chart, transformProps } = loaded; const { chartProps, preTransformProps, postTransformProps } = props; return ( diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartMetadata.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartMetadata.ts index 53f0a5f1a6b9f..9b02992aab729 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartMetadata.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartMetadata.ts @@ -2,6 +2,17 @@ interface LookupTable { [key: string]: boolean; } +export interface ChartMetadataConfig { + name: string; + canBeAnnotationTypes?: string[]; + credits?: string[]; + description?: string; + show?: boolean; + supportedAnnotationTypes?: string[]; + thumbnail: string; + useLegacyApi?: boolean; +} + export default class ChartMetadata { name: string; canBeAnnotationTypes?: string[]; @@ -13,16 +24,7 @@ export default class ChartMetadata { thumbnail: string; useLegacyApi: boolean; - constructor(config: { - name: string; - canBeAnnotationTypes?: string[]; - credits?: string[]; - description?: string; - show?: boolean; - supportedAnnotationTypes?: string[]; - thumbnail: string; - useLegacyApi?: boolean; - }) { + constructor(config: ChartMetadataConfig) { const { name, canBeAnnotationTypes = [], diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartPlugin.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartPlugin.ts index 01173a2305ebe..b741a1c9a962b 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartPlugin.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/models/ChartPlugin.ts @@ -1,47 +1,57 @@ +import { FunctionComponent, ComponentType } from 'react'; import { isRequired, Plugin } from '@superset-ui/core'; import ChartMetadata from './ChartMetadata'; -import ChartProps from './ChartProps'; import getChartMetadataRegistry from '../registries/ChartMetadataRegistrySingleton'; import getChartBuildQueryRegistry from '../registries/ChartBuildQueryRegistrySingleton'; import getChartComponentRegistry from '../registries/ChartComponentRegistrySingleton'; import getChartTransformPropsRegistry from '../registries/ChartTransformPropsRegistrySingleton'; import { ChartFormData } from '../types/ChartFormData'; -import { QueryContext } from '../types/Query'; +import { BuildQueryFunction, TransformProps } from '../types/Query'; const IDENTITY = (x: any) => x; -type PromiseOrValue = Promise | T; -type PromiseOrValueLoader = () => PromiseOrValue | PromiseOrValue<{ default: T }>; - -export type BuildQueryFunction = (formData: T) => QueryContext; - -export type TransformPropsFunction = ( - chartProps: ChartProps, -) => { - [key: string]: any; -}; +export type PromiseOrValue = Promise | T; +export type PromiseOrValueLoader = () => PromiseOrValue; +export type ChartType = ComponentType | FunctionComponent; +type ValueOrModuleWithValue = T | { default: T }; interface ChartPluginConfig { metadata: ChartMetadata; // use buildQuery for immediate value buildQuery?: BuildQueryFunction; // use loadBuildQuery for dynamic import (lazy-loading) - loadBuildQuery?: PromiseOrValueLoader>; + loadBuildQuery?: PromiseOrValueLoader>>; // use transformProps for immediate value - transformProps?: TransformPropsFunction; + transformProps?: TransformProps; // use loadTransformProps for dynamic import (lazy-loading) - loadTransformProps?: PromiseOrValueLoader; + loadTransformProps?: PromiseOrValueLoader>; // use Chart for immediate value - Chart?: Function; + Chart?: ChartType; // use loadChart for dynamic import (lazy-loading) - loadChart?: PromiseOrValueLoader; + loadChart?: PromiseOrValueLoader>; +} + +/** + * Loaders of the form `() => import('foo')` may return esmodules + * which require the value to be extracted as `module.default` + * */ +function sanitizeLoader( + loader: PromiseOrValueLoader>, +): PromiseOrValueLoader { + return () => { + const loaded = loader(); + + return loaded instanceof Promise + ? (loaded.then(module => ('default' in module && module.default) || module) as Promise) + : (loaded as T); + }; } export default class ChartPlugin extends Plugin { metadata: ChartMetadata; loadBuildQuery?: PromiseOrValueLoader>; - loadTransformProps: PromiseOrValueLoader; - loadChart: PromiseOrValueLoader; + loadTransformProps: PromiseOrValueLoader; + loadChart: PromiseOrValueLoader; constructor(config: ChartPluginConfig) { super(); @@ -55,11 +65,14 @@ export default class ChartPlugin extend loadChart, } = config; this.metadata = metadata; - this.loadBuildQuery = loadBuildQuery || (buildQuery ? () => buildQuery : undefined); - this.loadTransformProps = loadTransformProps || (() => transformProps); + this.loadBuildQuery = + (loadBuildQuery && sanitizeLoader(loadBuildQuery)) || + (buildQuery && sanitizeLoader(() => buildQuery)) || + undefined; + this.loadTransformProps = sanitizeLoader(loadTransformProps || (() => transformProps)); if (loadChart) { - this.loadChart = loadChart; + this.loadChart = sanitizeLoader(loadChart); } else if (Chart) { this.loadChart = () => Chart; } else { @@ -70,9 +83,11 @@ export default class ChartPlugin extend register() { const { key = isRequired('config.key') } = this.config; getChartMetadataRegistry().registerValue(key, this.metadata); - getChartBuildQueryRegistry().registerLoader(key, this.loadBuildQuery); getChartComponentRegistry().registerLoader(key, this.loadChart); getChartTransformPropsRegistry().registerLoader(key, this.loadTransformProps); + if (this.loadBuildQuery) { + getChartBuildQueryRegistry().registerLoader(key, this.loadBuildQuery); + } return this; } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartBuildQueryRegistrySingleton.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartBuildQueryRegistrySingleton.ts index ef72161ac1811..a1927e3ceb7a7 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartBuildQueryRegistrySingleton.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartBuildQueryRegistrySingleton.ts @@ -1,6 +1,10 @@ import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core'; +import { QueryContext } from '../types/Query'; -class ChartBuildQueryRegistry extends Registry { +// Ideally this would be +type BuildQuery = (formData: any) => QueryContext; + +class ChartBuildQueryRegistry extends Registry { constructor() { super({ name: 'ChartBuildQuery', overwritePolicy: OverwritePolicy.WARN }); } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartComponentRegistrySingleton.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartComponentRegistrySingleton.ts index 55594a6c2ae1c..589c0a1a611c2 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartComponentRegistrySingleton.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartComponentRegistrySingleton.ts @@ -1,6 +1,7 @@ import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core'; +import { ChartType } from '../models/ChartPlugin'; -class ChartComponentRegistry extends Registry { +class ChartComponentRegistry extends Registry { constructor() { super({ name: 'ChartComponent', overwritePolicy: OverwritePolicy.WARN }); } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartMetadataRegistrySingleton.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartMetadataRegistrySingleton.ts index 3b3646d8052d7..25dc8b87aab11 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartMetadataRegistrySingleton.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartMetadataRegistrySingleton.ts @@ -1,6 +1,7 @@ import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core'; +import ChartMetadata from '../models/ChartMetadata'; -class ChartMetadataRegistry extends Registry { +class ChartMetadataRegistry extends Registry { constructor() { super({ name: 'ChartMetadata', overwritePolicy: OverwritePolicy.WARN }); } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartTransformPropsRegistrySingleton.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartTransformPropsRegistrySingleton.ts index f65a6da367973..d4200b190e873 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartTransformPropsRegistrySingleton.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/registries/ChartTransformPropsRegistrySingleton.ts @@ -1,6 +1,7 @@ import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core'; +import { TransformProps } from '../types/Query'; -class ChartTransformPropsRegistry extends Registry { +class ChartTransformPropsRegistry extends Registry { constructor() { super({ name: 'ChartTransformProps', overwritePolicy: OverwritePolicy.WARN }); } diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/types/Query.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/types/Query.ts index 6d645422ed585..64e518a87f442 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/types/Query.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/types/Query.ts @@ -1,8 +1,8 @@ /* eslint camelcase: 0 */ -import ChartProps from '../models/ChartProps'; import { DatasourceType } from './Datasource'; import { ChartFormData } from './ChartFormData'; import { Metric } from './Metric'; +import ChartProps from '../models/ChartProps'; export interface QueryObject { granularity: string; @@ -32,10 +32,14 @@ export interface QueryContext { queries: QueryObject[]; } -export type BuildQueryFunction = (formData: T) => QueryContext; - -export type TransformPropsFunction = ( - chartProps: ChartProps, -) => { +export interface PlainProps { [key: string]: any; -}; +} + +type TransformFunction = (x: Input) => Output; + +export type PreTransformProps = TransformFunction; +export type TransformProps = TransformFunction; +export type PostTransformProps = TransformFunction; + +export type BuildQueryFunction = (formData: T) => QueryContext; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/clients/ChartClient.test.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/clients/ChartClient.test.ts index c3db3b43047b3..fecb1dc639594 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/clients/ChartClient.test.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/clients/ChartClient.test.ts @@ -7,6 +7,7 @@ import { buildQueryContext, ChartFormData, getChartMetadataRegistry, + ChartMetadata, } from '../../src'; import { SliceIdAndOrFormData } from '../../src/clients/ChartClient'; @@ -97,7 +98,10 @@ describe('ChartClient', () => { describe('.loadQueryData(formData, options)', () => { it('returns a promise of query data for known chart type', () => { - getChartMetadataRegistry().registerValue('word_cloud', { name: 'Word Cloud' }); + getChartMetadataRegistry().registerValue( + 'word_cloud', + new ChartMetadata({ name: 'Word Cloud', thumbnail: '' }), + ); getChartBuildQueryRegistry().registerValue('word_cloud', (formData: ChartFormData) => buildQueryContext(formData), @@ -129,10 +133,14 @@ describe('ChartClient', () => { it('fetches data from the legacy API if ChartMetadata has useLegacyApi=true,', () => { // note legacy charts do not register a buildQuery function in the registry - getChartMetadataRegistry().registerValue('word_cloud_legacy', { - name: 'Legacy Word Cloud', - useLegacyApi: true, - }); + getChartMetadataRegistry().registerValue( + 'word_cloud_legacy', + new ChartMetadata({ + name: 'Legacy Word Cloud', + thumbnail: '.png', + useLegacyApi: true, + }), + ); fetchMock.post('glob:*/api/v1/query/', () => Promise.reject(Error('Unexpected all to v1 API')), @@ -233,7 +241,10 @@ describe('ChartClient', () => { amet: true, }); - getChartMetadataRegistry().registerValue('line', { name: 'Line' }); + getChartMetadataRegistry().registerValue( + 'line', + new ChartMetadata({ name: 'Line', thumbnail: '.gif' }), + ); getChartBuildQueryRegistry().registerValue('line', (formData: ChartFormData) => buildQueryContext(formData), diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/components/SuperChart.test.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/components/SuperChart.test.tsx index 9ac1a25dd6de5..13e1b53bddc2f 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/components/SuperChart.test.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/components/SuperChart.test.tsx @@ -28,8 +28,10 @@ describe('SuperChart', () => { name: 'second-chart', thumbnail: '', }), + // this mirrors `() => import(module)` syntax loadChart: () => Promise.resolve({ default: TestComponent }), - transformProps: x => x, + // promise without .default + loadTransformProps: () => Promise.resolve((x: any) => x), }); } } @@ -42,7 +44,7 @@ describe('SuperChart', () => { thumbnail: '', }), loadChart: () => - new Promise(resolve => { + new Promise(resolve => { setTimeout(() => { resolve(TestComponent); }, 1000); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.tsx similarity index 90% rename from superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.ts rename to superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.tsx index 04af31099a15d..425358b8c5a69 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/models/ChartPlugin.test.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import { ChartPlugin, ChartMetadata, @@ -5,25 +7,27 @@ import { DatasourceType, ChartProps, BuildQueryFunction, - TransformPropsFunction, + TransformProps, } from '../../src'; describe('ChartPlugin', () => { + const FakeChart = () => test; + const metadata = new ChartMetadata({ name: 'test-chart', thumbnail: '', }); + const buildQuery = (_: ChartFormData) => ({ + datasource: { id: 1, type: DatasourceType.Table }, + queries: [{ granularity: 'day' }], + }); + it('exists', () => { expect(ChartPlugin).toBeDefined(); }); describe('new ChartPlugin()', () => { - const FakeChart = () => 'test'; - const buildQuery = (_: ChartFormData) => ({ - datasource: { id: 1, type: DatasourceType.Table }, - queries: [{ granularity: 'day' }], - }); const FORM_DATA = { datasource: '1__table', granularity: 'day', @@ -33,7 +37,7 @@ describe('ChartPlugin', () => { it('creates a new plugin', () => { const plugin = new ChartPlugin({ metadata, - Chart() {}, + Chart: FakeChart, }); expect(plugin).toBeInstanceOf(ChartPlugin); }); @@ -77,7 +81,8 @@ describe('ChartPlugin', () => { metadata, loadChart, }); - expect(plugin.loadChart).toBe(loadChart); + // the loader is sanitized, so assert on the value + expect(plugin.loadChart()).toBe(loadChart()); }); it('uses Chart field if specified', () => { const plugin = new ChartPlugin({ @@ -102,7 +107,7 @@ describe('ChartPlugin', () => { metadata, Chart: FakeChart, }); - const fn = plugin.loadTransformProps() as TransformPropsFunction; + const fn = plugin.loadTransformProps() as TransformProps; expect(fn(PROPS)).toBe(PROPS); }); it('uses loadTransformProps field if specified', () => { @@ -111,7 +116,7 @@ describe('ChartPlugin', () => { Chart: FakeChart, loadTransformProps: () => () => ({ field2: 2 }), }); - const fn = plugin.loadTransformProps() as TransformPropsFunction; + const fn = plugin.loadTransformProps() as TransformProps; expect(fn(PROPS)).toEqual({ field2: 2 }); }); it('uses transformProps field if specified', () => { @@ -120,7 +125,7 @@ describe('ChartPlugin', () => { Chart: FakeChart, transformProps: () => ({ field2: 2 }), }); - const fn = plugin.loadTransformProps() as TransformPropsFunction; + const fn = plugin.loadTransformProps() as TransformProps; expect(fn(PROPS)).toEqual({ field2: 2 }); }); }); @@ -129,7 +134,8 @@ describe('ChartPlugin', () => { describe('.register()', () => { const plugin = new ChartPlugin({ metadata, - Chart() {}, + Chart: FakeChart, + buildQuery, }); it('throws an error if key is not provided', () => { expect(() => plugin.register()).toThrowError(Error); diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/types/external.d.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/types/external.d.ts deleted file mode 100644 index cb8bb08e24f6c..0000000000000 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/types/external.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@superset-ui/core'; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/models/Registry.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/models/Registry.ts index 028044c552292..fbf1b9c0275ed 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/models/Registry.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/models/Registry.ts @@ -99,7 +99,7 @@ export default class Registry = V | Promise> { const item = this.items[key]; if (item !== undefined) { if ('loader' in item) { - return item.loader(); + return item.loader && item.loader(); } return item.value; diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-chart/ChartDataProviderStories.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-chart/ChartDataProviderStories.tsx index 5675c9a6fb2ff..4ec1bad596c67 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-chart/ChartDataProviderStories.tsx +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-chart/ChartDataProviderStories.tsx @@ -9,7 +9,6 @@ import LegacySunburstPlugin from '@superset-ui/legacy-plugin-chart-sunburst'; import LegacyWordCloudPlugin from '@superset-ui/legacy-plugin-chart-word-cloud'; import WordCloudPlugin from '@superset-ui/plugin-chart-word-cloud'; -import { DataProviderProvidedProps } from '@superset-ui/chart/src'; import { bigNumberFormData, sankeyFormData, @@ -59,7 +58,7 @@ export default [ {() => ( - {({ loading, payload, error }: DataProviderProvidedProps) => { + {({ loading, payload, error }) => { if (loading) return
Loading!
; if (error) return renderError(error);