forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [build] fix typescript builds * [typescript] ensure types pass in build * [typescript][connection] declare modules in tests * [typescript][connection] fix ts errors in tests * [typescript][connection] test/types.ts => types/external.d.ts * [chart][typescript] add @types/react-loadable * [chart][components] convert to ts * [charts][tests][broken] convert to ts * [chart][typescript] re-write component generics * [chart][typescript] fix reactify generic, add react-dom types * [chart][typescript] more iteration * - Tweaking reactify types (using Readonly types). - Uncovered an issue in which ReactifyProps and Props can collide on id and className. - Move @types/react-loadable to dev dependency - Fixing a lint error * [chart][deps] add @types/fetch-mock * [client][typescript] add and export SupersetClientInterface * [chart][clients] fix ts * [charts][components] more ts iterations * [chart][client] assert FormData type * [chart][deps] try adding newest @types/react * [chart][components][ts] fix reactify prop TS * [chart] lint * [chart][ts] lint #2, move @types to deps not dev-deps * [chart][jest] fix tests * [chart][tests] up branch coverage * [chart][ts][test] null => undefined * [chart][tests] hundo * [chart][tests] update name * [chart][ts] ChartClient type fixes
- Loading branch information
1 parent
97ccc8e
commit 63c5fc6
Showing
23 changed files
with
273 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 0 additions & 47 deletions
47
...perset_ui/superset-ui/packages/superset-ui-chart/src/components/createLoadableRenderer.js
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
...perset_ui/superset-ui/packages/superset-ui-chart/src/components/createLoadableRenderer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Loadable from 'react-loadable'; | ||
|
||
export type LoadableRendererProps = { | ||
onRenderFailure?: Function; | ||
onRenderSuccess?: Function; | ||
}; | ||
|
||
const defaultProps = { | ||
onRenderFailure() {}, | ||
onRenderSuccess() {}, | ||
}; | ||
|
||
export interface LoadableRenderer<Props, Exports> | ||
extends React.ComponentClass<Props & LoadableRendererProps>, | ||
Loadable.LoadableComponent {} | ||
|
||
export default function createLoadableRenderer<Props, Exports>( | ||
options: Loadable.OptionsWithMap<Props, Exports>, | ||
): LoadableRenderer<Props, Exports> { | ||
// eslint-disable-next-line babel/new-cap | ||
const LoadableRenderer = Loadable.Map(options) as LoadableRenderer<Props, Exports>; | ||
|
||
// Extends the behavior of LoadableComponent to provide post-render listeners | ||
class CustomLoadableRenderer extends LoadableRenderer { | ||
static defaultProps: object; | ||
|
||
componentDidMount() { | ||
this.afterRender(); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.afterRender(); | ||
} | ||
|
||
afterRender() { | ||
const { loaded, loading, error } = this.state; | ||
const { onRenderFailure, onRenderSuccess } = this.props; | ||
if (!loading) { | ||
if (error) { | ||
(onRenderFailure as Function)(error); | ||
} else if (loaded && Object.keys(loaded).length > 0) { | ||
(onRenderSuccess as Function)(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
CustomLoadableRenderer.defaultProps = defaultProps; | ||
CustomLoadableRenderer.preload = LoadableRenderer.preload; | ||
|
||
return CustomLoadableRenderer; | ||
} |
51 changes: 0 additions & 51 deletions
51
.../temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/reactify.jsx
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
.../temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/components/reactify.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
|
||
// TODO: Note that id and className can collide between Props and ReactifyProps | ||
// leading to (likely) unexpected behaviors. We should either require Props to not | ||
// contain an id/className, or not combine them (via intersection), instead preferring | ||
// wrapping (composition). As an example: | ||
// interface MyProps { | ||
// id: number; | ||
// } | ||
// function myRender(container: HTMLDivElement, props: Readonly<MyProps>): void { | ||
// props.id // unusable: id is string & number | ||
// } | ||
// new (reactify(myRender))({ id: 5 }); // error: id has to be string & number | ||
|
||
export type ReactifyProps = { | ||
id: string; | ||
className?: string; | ||
}; | ||
|
||
export interface RenderFuncType<Props> { | ||
(container: HTMLDivElement, props: Readonly<Props & ReactifyProps>): void; | ||
displayName?: string; | ||
defaultProps?: Partial<Props & ReactifyProps>; | ||
propTypes?: React.WeakValidationMap<Props & ReactifyProps>; | ||
} | ||
|
||
export default function reactify<Props extends object>( | ||
renderFn: RenderFuncType<Props>, | ||
): React.ComponentClass<Props & ReactifyProps> { | ||
class ReactifiedComponent extends React.Component<Props & ReactifyProps> { | ||
// eslint-disable-next-line react/sort-comp | ||
container?: HTMLDivElement; | ||
|
||
constructor(props: Props & ReactifyProps) { | ||
super(props); | ||
this.setContainerRef = this.setContainerRef.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
this.execute(); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.execute(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.container = undefined; | ||
} | ||
|
||
setContainerRef(ref: HTMLDivElement) { | ||
this.container = ref; | ||
} | ||
|
||
execute() { | ||
if (this.container) { | ||
renderFn(this.container, this.props); | ||
} | ||
} | ||
|
||
render() { | ||
const { id, className } = this.props; | ||
|
||
return <div id={id} className={className} ref={this.setContainerRef} />; | ||
} | ||
} | ||
|
||
const ReactifiedClass: React.ComponentClass<Props & ReactifyProps> = ReactifiedComponent; | ||
|
||
if (renderFn.displayName) { | ||
ReactifiedClass.displayName = renderFn.displayName; | ||
} | ||
// eslint-disable-next-line react/forbid-foreign-prop-types | ||
if (renderFn.propTypes) { | ||
ReactifiedClass.propTypes = { ...ReactifiedClass.propTypes, ...renderFn.propTypes }; | ||
} | ||
if (renderFn.defaultProps) { | ||
ReactifiedClass.defaultProps = renderFn.defaultProps; | ||
} | ||
|
||
return ReactifiedComponent; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.