From fdd10fa062d48a93a76f79c30855a1d0016a7cad Mon Sep 17 00:00:00 2001 From: Conglei Date: Tue, 26 Mar 2019 09:18:32 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20type=20definition?= =?UTF-8?q?=20for=20chart=20plugin=20(#123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 Fixed typ definiton for chart plugin This PR is to fix the type definiton for transformProps and LoadData. * fix: 🐛 Type compatibility Change the output of preTransformProps to ChartProps * fix: 🐛 Fixed Test Fixed the test according to the changes: --- .../superset-ui/packages/superset-ui-chart/src/index.ts | 1 + .../packages/superset-ui-chart/src/models/ChartPlugin.ts | 2 +- .../packages/superset-ui-chart/src/types/Query.ts | 4 ++-- .../test/components/SuperChart.test.tsx | 9 ++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/index.ts b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/index.ts index eb4d379b528f..19e0dcb404de 100644 --- a/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/index.ts +++ b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/index.ts @@ -25,3 +25,4 @@ export * from './types/Annotation'; export * from './types/Datasource'; export * from './types/ChartFormData'; export * from './types/Query'; +export * from './types/Metric'; 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 b741a1c9a962..59151a4563b4 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 @@ -12,7 +12,7 @@ const IDENTITY = (x: any) => x; export type PromiseOrValue = Promise | T; export type PromiseOrValueLoader = () => PromiseOrValue; -export type ChartType = ComponentType | FunctionComponent; +export type ChartType = ComponentType | FunctionComponent; type ValueOrModuleWithValue = T | { default: T }; interface ChartPluginConfig { 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 64e518a87f44..fcb7577f63e7 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 @@ -38,8 +38,8 @@ export interface PlainProps { type TransformFunction = (x: Input) => Output; -export type PreTransformProps = TransformFunction; -export type TransformProps = TransformFunction; +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/components/SuperChart.test.tsx b/superset-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/test/components/SuperChart.test.tsx index 13e1b53bddc2..cd58d90e889b 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 @@ -110,8 +110,15 @@ describe('SuperChart', () => { }, 0); }); it('uses preTransformProps when specified', done => { + const chartPropsWithPayload = new ChartProps({ + payload: { character: 'hulk' }, + }); const wrapper = shallow( - ({ character: 'hulk' })} />, + chartPropsWithPayload} + overrideTransformProps={props => props.payload} + />, ); setTimeout(() => { expect(