Skip to content

Commit

Permalink
fix: 馃悰 Fixed type definition for chart plugin (#123)
Browse files Browse the repository at this point in the history
* 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:
  • Loading branch information
conglei authored and zhaoyongjie committed Nov 26, 2021
1 parent 9dd30b0 commit fdd10fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './types/Annotation';
export * from './types/Datasource';
export * from './types/ChartFormData';
export * from './types/Query';
export * from './types/Metric';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const IDENTITY = (x: any) => x;

export type PromiseOrValue<T> = Promise<T> | T;
export type PromiseOrValueLoader<T> = () => PromiseOrValue<T>;
export type ChartType = ComponentType | FunctionComponent;
export type ChartType = ComponentType<any> | FunctionComponent<any>;
type ValueOrModuleWithValue<T> = T | { default: T };

interface ChartPluginConfig<T extends ChartFormData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface PlainProps {

type TransformFunction<Input = PlainProps, Output = PlainProps> = (x: Input) => Output;

export type PreTransformProps = TransformFunction<ChartProps>;
export type TransformProps = TransformFunction;
export type PreTransformProps = TransformFunction<ChartProps, ChartProps>;
export type TransformProps = TransformFunction<ChartProps>;
export type PostTransformProps = TransformFunction;

export type BuildQueryFunction<T extends ChartFormData> = (formData: T) => QueryContext;
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ describe('SuperChart', () => {
}, 0);
});
it('uses preTransformProps when specified', done => {
const chartPropsWithPayload = new ChartProps({
payload: { character: 'hulk' },
});
const wrapper = shallow(
<SuperChart chartType="my-chart" preTransformProps={() => ({ character: 'hulk' })} />,
<SuperChart
chartType="my-chart"
preTransformProps={() => chartPropsWithPayload}
overrideTransformProps={props => props.payload}
/>,
);
setTimeout(() => {
expect(
Expand Down

0 comments on commit fdd10fa

Please sign in to comment.