Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

fix: typing issues surfaced by typescript 3.7 #260

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
],
"license": "Apache-2.0",
"devDependencies": {
"@superset-ui/build-config": "^0.1.3",
"@superset-ui/build-config": "^0.2.0",
"@superset-ui/commit-config": "^0.0.9",
"fast-glob": "^3.0.1",
"fs-extra": "^8.0.1",
Expand Down
14 changes: 9 additions & 5 deletions packages/superset-ui-chart/src/clients/ChartClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import getChartBuildQueryRegistry from '../registries/ChartBuildQueryRegistrySin
import getChartMetadataRegistry from '../registries/ChartMetadataRegistrySingleton';
import { QueryData } from '../models/ChartProps';
import { AnnotationLayerMetadata } from '../types/Annotation';
import { PlainObject } from '../types/Base';

// This expands to Partial<All> & (union of all possible single-property types)
type AtLeastOne<All, Each = { [K in keyof All]: Pick<All, K> }> = Partial<All> & Each[keyof Each];
Expand All @@ -21,12 +22,12 @@ export type SliceIdAndOrFormData = AtLeastOne<{
}>;

interface AnnotationData {
[key: string]: object;
[key: string]: PlainObject;
}

export interface ChartData {
annotationData: AnnotationData;
datasource: object;
datasource: PlainObject;
formData: QueryFormData;
queryData: QueryData;
}
Expand Down Expand Up @@ -73,7 +74,10 @@ export default class ChartClient {
: Promise.reject(new Error('At least one of sliceId or formData must be specified'));
}

async loadQueryData(formData: QueryFormData, options?: Partial<RequestConfig>): Promise<object> {
async loadQueryData(
formData: QueryFormData,
options?: Partial<RequestConfig>,
): Promise<QueryData> {
const { viz_type: visType } = formData;
const metaDataRegistry = getChartMetadataRegistry();
const buildQueryRegistry = getChartBuildQueryRegistry();
Expand Down Expand Up @@ -105,10 +109,10 @@ export default class ChartClient {
.then(response => response.json as Datasource);
}

loadAnnotation(annotationLayer: AnnotationLayerMetadata): Promise<object> {
loadAnnotation(annotationLayer: AnnotationLayerMetadata): Promise<AnnotationData> {
/* When annotation does not require query */
if (!isDefined(annotationLayer.sourceType)) {
return Promise.resolve({});
return Promise.resolve({} as AnnotationData);
}

// TODO: Implement
Expand Down
40 changes: 18 additions & 22 deletions packages/superset-ui-chart/src/components/ChartDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ type State = {

class ChartDataProvider extends React.PureComponent<Props, State> {
readonly chartClient: ChartClient;
state: State = { status: 'uninitialized' };

constructor(props: Props) {
super(props);
this.handleFetchData = this.handleFetchData.bind(this);
this.handleReceiveData = this.handleReceiveData.bind(this);
this.handleError = this.handleError.bind(this);
this.chartClient = new ChartClient({ client: props.client });
this.state = { status: 'uninitialized' };
}

componentDidMount() {
Expand All @@ -69,15 +66,11 @@ class ChartDataProvider extends React.PureComponent<Props, State> {

private extractSliceIdAndFormData() {
const { formData, sliceId } = this.props;
const result: any = {};

if (formData) result.formData = formData;
if (sliceId) result.sliceId = sliceId;

return result as SliceIdAndOrFormData;
return formData ? { formData } : { sliceId: sliceId! };
}

private handleFetchData() {
private handleFetchData = () => {
const {
loadDatasource,
formDataRequestOptions,
Expand All @@ -95,31 +88,34 @@ class ChartDataProvider extends React.PureComponent<Props, State> {
? this.chartClient.loadDatasource(formData.datasource, datasourceRequestOptions)
: Promise.resolve(undefined),
this.chartClient.loadQueryData(formData, queryRequestOptions),
]).then(([datasource, queryData]) => ({
datasource,
formData,
queryData,
})),
]).then(
([datasource, queryData]) =>
({
datasource,
formData,
queryData,
} as Payload),
),
)
.then(this.handleReceiveData)
.catch(this.handleError);
} catch (error) {
this.handleError(error);
}
});
}
};

handleReceiveData(data: Payload) {
private handleReceiveData = (payload?: Payload) => {
const { onLoaded } = this.props;
if (onLoaded) onLoaded(data);
this.setState({ payload: data, status: 'loaded' });
}
if (onLoaded) onLoaded(payload);
this.setState({ payload, status: 'loaded' });
};

handleError(error: ProvidedProps['error']) {
private handleError = (error: ProvidedProps['error']) => {
const { onError } = this.props;
if (onError) onError(error);
this.setState({ error, status: 'error' });
}
};

render() {
const { children } = this.props;
Expand Down