Skip to content

Commit f86872a

Browse files
authored
refactor: separate transform function types into a new file (apache-superset#169)
* refactor: separate transform function types into a new file * fix: import
1 parent 32f8dd3 commit f86872a

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

packages/superset-ui-chart/src/components/SuperChart.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import getChartTransformPropsRegistry from '../registries/ChartTransformPropsReg
55
import ChartProps from '../models/ChartProps';
66
import createLoadableRenderer, { LoadableRenderer } from './createLoadableRenderer';
77
import { ChartType } from '../models/ChartPlugin';
8-
import { PreTransformProps, TransformProps, PostTransformProps } from '../types/Query';
8+
import { PreTransformProps, TransformProps, PostTransformProps } from '../types/TransformFunction';
9+
import { HandlerFunction } from '../types/Base';
910

1011
const IDENTITY = (x: any) => x;
1112

@@ -23,8 +24,6 @@ const defaultProps = {
2324
};
2425
/* eslint-enable sort-keys */
2526

26-
type HandlerFunction = (...args: any[]) => void;
27-
2827
interface LoadingProps {
2928
error: any;
3029
}

packages/superset-ui-chart/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ export * from './types/ChartFormData';
2626
export * from './types/Datasource';
2727
export * from './types/Metric';
2828
export * from './types/Query';
29+
export * from './types/TransformFunction';

packages/superset-ui-chart/src/models/ChartPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import getChartBuildQueryRegistry from '../registries/ChartBuildQueryRegistrySin
66
import getChartComponentRegistry from '../registries/ChartComponentRegistrySingleton';
77
import getChartTransformPropsRegistry from '../registries/ChartTransformPropsRegistrySingleton';
88
import { ChartFormData } from '../types/ChartFormData';
9-
import { BuildQueryFunction, TransformProps } from '../types/Query';
9+
import { BuildQueryFunction, TransformProps } from '../types/TransformFunction';
1010

1111
const IDENTITY = (x: any) => x;
1212

packages/superset-ui-chart/src/models/ChartProps.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { createSelector } from 'reselect';
22
import { convertKeysToCamelCase } from '@superset-ui/core';
3-
4-
interface PlainObject {
5-
[key: string]: any;
6-
}
3+
import { HandlerFunction, PlainObject } from '../types/Base';
74

85
// TODO: more specific typing for these fields of ChartProps
96
type AnnotationData = PlainObject;
@@ -13,7 +10,6 @@ type CamelCaseFormData = PlainObject;
1310
type SnakeCaseFormData = PlainObject;
1411
export type QueryData = PlainObject;
1512
type Filters = any[];
16-
type HandlerFunction = (...args: any[]) => void;
1713
type ChartPropsSelector = (c: ChartPropsConfig) => ChartProps;
1814

1915
interface ChartPropsConfig {

packages/superset-ui-chart/src/registries/ChartTransformPropsRegistrySingleton.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core';
2-
import { TransformProps } from '../types/Query';
2+
import { TransformProps } from '../types/TransformFunction';
33

44
class ChartTransformPropsRegistry extends Registry<TransformProps> {
55
constructor() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type HandlerFunction = (...args: any[]) => void;
2+
3+
export interface PlainObject {
4+
[key: string]: any;
5+
}

packages/superset-ui-chart/src/types/Query.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint camelcase: 0 */
22
import { DatasourceType } from './Datasource';
3-
import { ChartFormData } from './ChartFormData';
43
import { AdhocMetric } from './Metric';
5-
import ChartProps from '../models/ChartProps';
64
import { BinaryOperator, SetOperator, UnaryOperator } from './Operator';
75
import { TimeRange } from './Time';
86

@@ -83,15 +81,3 @@ export interface QueryContext {
8381
};
8482
queries: QueryObject[];
8583
}
86-
87-
export interface PlainProps {
88-
[key: string]: any;
89-
}
90-
91-
type TransformFunction<Input = PlainProps, Output = PlainProps> = (x: Input) => Output;
92-
93-
export type PreTransformProps = TransformFunction<ChartProps, ChartProps>;
94-
export type TransformProps = TransformFunction<ChartProps>;
95-
export type PostTransformProps = TransformFunction;
96-
97-
export type BuildQueryFunction<T extends ChartFormData> = (formData: T) => QueryContext;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ChartFormData } from './ChartFormData';
2+
import ChartProps from '../models/ChartProps';
3+
import { QueryContext } from './Query';
4+
5+
export interface PlainProps {
6+
[key: string]: any;
7+
}
8+
9+
type TransformFunction<Input = PlainProps, Output = PlainProps> = (x: Input) => Output;
10+
11+
export type PreTransformProps = TransformFunction<ChartProps, ChartProps>;
12+
export type TransformProps = TransformFunction<ChartProps>;
13+
export type PostTransformProps = TransformFunction;
14+
15+
export type BuildQueryFunction<T extends ChartFormData> = (formData: T) => QueryContext;

0 commit comments

Comments
 (0)