Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(radar): typing for custom functions #1089

Merged
merged 3 commits into from Oct 30, 2020
Merged

Conversation

AlaaZorkane
Copy link
Contributor

  • Exported all custom elements.
  • Changed GridLabelCustomFunction to CustomGridLabel (for consistency).
  • Made CustomGridLabel and CurstomDotSymbol function components and typed their props according to docs.
  • Made legends optional.
  • Fixed typo IndexByCustomFunction instead of IndexByCustomFunctiono

- Exported all custom elements.
- Changed `GridLabelCustomFunction` to `CustomGridLabel` (for consistency).
- Made `CustomGridLabel` and `CurstomDotSymbol` function components and typed their props according to docs.
- Made `legends` optional. 
- Fixed typo `IndexByCustomFunction` instead of `IndexByCustomFunctiono`
type IndexByCustomFunction<D = any> = (datum: D) => string | number
export type CustomGridLabel = React.FC<GridLabelProps>
export type CustomDotSymbol = React.FC<DotSymbolProps>
export type CustomDotLabel = (...args: any[]) => React.ReactNode
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these (CustomDotLabel and CustomFormatter) should be strictly typed too, I never used them and I honestly don't have enough knowledge about them to type them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I guess we can add this later, what you updated is already a good addition.

@@ -55,7 +67,7 @@ declare module '@nivo/radar' {
isInteractive?: boolean
tooltipFormat?: string | CustomFormatter

legends: LegendProps[]
legends?: LegendProps[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anything in the docs about whether the legends are optional or not, but there are some examples in the storybook with no legends (https://nivo.rocks/storybook/?path=/story/radar--custom-label-component) and I am already using them without legends in the project I am working on, actually typescript threw me an error because of this one lol.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're not, and lacking doc :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. They are optional.

}

type IndexByCustomFunction<D = any> = (datum: D) => string | number
export type CustomGridLabel = React.FC<GridLabelProps>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docs this must return an SVG element, I didn't want to strictly type that, maybe we can a have a discussion about this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the implementation is SVG only, enforcing an SVG element would be good, but I think it's fine to use the generic ReactNode type.

@wyze
Copy link
Contributor

wyze commented Oct 29, 2020

@AlaaZorkane I remember looking through this PR, I guess I didn't do a formal review or comment. Would you mind resolving the conflicts and I can get this merged?

Copy link
Owner

@plouc plouc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -55,7 +67,7 @@ declare module '@nivo/radar' {
isInteractive?: boolean
tooltipFormat?: string | CustomFormatter

legends: LegendProps[]
legends?: LegendProps[]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they're not, and lacking doc :/

}

type IndexByCustomFunction<D = any> = (datum: D) => string | number
export type CustomGridLabel = React.FC<GridLabelProps>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the implementation is SVG only, enforcing an SVG element would be good, but I think it's fine to use the generic ReactNode type.

type IndexByCustomFunction<D = any> = (datum: D) => string | number
export type CustomGridLabel = React.FC<GridLabelProps>
export type CustomDotSymbol = React.FC<DotSymbolProps>
export type CustomDotLabel = (...args: any[]) => React.ReactNode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I guess we can add this later, what you updated is already a good addition.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6f8fc90:

Sandbox Source
nivo Configuration

@wyze wyze merged commit 20a5c12 into plouc:master Oct 30, 2020
@wyze
Copy link
Contributor

wyze commented Oct 30, 2020

Thanks @AlaaZorkane!

ddavydov pushed a commit to netronixgroup/nivo that referenced this pull request Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants