Skip to content

Commit

Permalink
refactor: separate transform function types into a new file (apache#169)
Browse files Browse the repository at this point in the history
* refactor: separate transform function types into a new file

* fix: import
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 24, 2021
1 parent 0c56199 commit 531b7f9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import getChartTransformPropsRegistry from '../registries/ChartTransformPropsReg
import ChartProps from '../models/ChartProps';
import createLoadableRenderer, { LoadableRenderer } from './createLoadableRenderer';
import { ChartType } from '../models/ChartPlugin';
import { PreTransformProps, TransformProps, PostTransformProps } from '../types/Query';
import { PreTransformProps, TransformProps, PostTransformProps } from '../types/TransformFunction';
import { HandlerFunction } from '../types/Base';

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

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

type HandlerFunction = (...args: any[]) => void;

interface LoadingProps {
error: any;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export * from './types/ChartFormData';
export * from './types/Datasource';
export * from './types/Metric';
export * from './types/Query';
export * from './types/TransformFunction';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getChartBuildQueryRegistry from '../registries/ChartBuildQueryRegistrySin
import getChartComponentRegistry from '../registries/ChartComponentRegistrySingleton';
import getChartTransformPropsRegistry from '../registries/ChartTransformPropsRegistrySingleton';
import { ChartFormData } from '../types/ChartFormData';
import { BuildQueryFunction, TransformProps } from '../types/Query';
import { BuildQueryFunction, TransformProps } from '../types/TransformFunction';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { createSelector } from 'reselect';
import { convertKeysToCamelCase } from '@superset-ui/core';

interface PlainObject {
[key: string]: any;
}
import { HandlerFunction, PlainObject } from '../types/Base';

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

interface ChartPropsConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core';
import { TransformProps } from '../types/Query';
import { TransformProps } from '../types/TransformFunction';

class ChartTransformPropsRegistry extends Registry<TransformProps> {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type HandlerFunction = (...args: any[]) => void;

export interface PlainObject {
[key: string]: any;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint camelcase: 0 */
import { DatasourceType } from './Datasource';
import { ChartFormData } from './ChartFormData';
import { AdhocMetric } from './Metric';
import ChartProps from '../models/ChartProps';
import { BinaryOperator, SetOperator, UnaryOperator } from './Operator';
import { TimeRange } from './Time';

Expand Down Expand Up @@ -83,15 +81,3 @@ export interface QueryContext {
};
queries: QueryObject[];
}

export interface PlainProps {
[key: string]: any;
}

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

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
@@ -0,0 +1,15 @@
import { ChartFormData } from './ChartFormData';
import ChartProps from '../models/ChartProps';
import { QueryContext } from './Query';

export interface PlainProps {
[key: string]: any;
}

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

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

export type BuildQueryFunction<T extends ChartFormData> = (formData: T) => QueryContext;

0 comments on commit 531b7f9

Please sign in to comment.