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

Custom Legend's props is missing in Typescript #2909

Closed
leadq opened this issue Jul 19, 2022 · 7 comments
Closed

Custom Legend's props is missing in Typescript #2909

leadq opened this issue Jul 19, 2022 · 7 comments
Labels
bug General bug label P1 High priority issues typescript PRs or Issues surrounding Types or TS refactoring

Comments

@leadq
Copy link

leadq commented Jul 19, 2022

I render custom Legend component and using Typescript. When I log payload data of CustomLegend I can see that "dataKey" property is there, but Payload type which comes from "DefaultLegendContent.d.ts" does not include that property. Is there here wrong or am I wrong? I am providing screenshots but not the code, because I can't open codesandbox or smth from my laptop.

image

image

After this issue, I tried to find a solution but couldn't do. Also I saw that "Payload" in "DefaultTooltipContent.d.ts", it takes TValue and TName as a generic type and passes to "value" and "name" type, but Legend not. Maybe the payload property should be same on both

DefaultTooltipContent.d.ts
image

EDIT:
By the way, you can see that there is one more "payload" property in nested object (in chrome devtools screenshot), I can see that it also has dataKey property, but Payload type in DefaultLegendContent does not include it. It is like this:

interface Payload {
  ... // some props
  ...
  type?: LegendType;
  color?: string;
  payload?: {
    strokeDasharray: ReactText;  // here
  }
  ... // some props
  ...
 }
@TooMuchLagWillKillYou
Copy link

TooMuchLagWillKillYou commented Aug 8, 2022

dataKey has the ? sign on its declaration, that means it could be null. If you're sure that dataKey would never be null, just add the ! like this:
<li key={`item-${entry.dataKey!}`}>

@leadq
Copy link
Author

leadq commented Nov 3, 2022

You should read carefully. I wrote it for Legend's type. Then, I explained different type which has dataKey? property, but legend has not
Legend's payload is extending the following type:

{
   value: any
   id?: string
   type?: LegendType
   color: string
   payload: {
     strokeDashArray: ReactText
   }
   formetter?: Formetter
   inactive?: boolean
   legendIcon: ReactElement<SVGElement>
}

@SharonGrossman
Copy link

👍 for this, any insights?

@ckifer ckifer added the typescript PRs or Issues surrounding Types or TS refactoring label Jan 3, 2023
@ckifer
Copy link
Member

ckifer commented Jan 3, 2023

If we can get a simple reproduction of this someone can take a look

@pgaret
Copy link

pgaret commented Nov 29, 2023

If we can get a simple reproduction of this someone can take a look

I realize that I am coming to this somewhat late, but here: https://github.com/pgaret/recharts-legend-datakey

I've been unable to get CSB to show ts-lint errors, sorry, if you can get that to happen feel free to just copy the contents of App.tsx over there and install recharts

Edit: another note on this, I'm not going to spend time now to create a separate recreation, but for the DefaultLegendContent Payload prop, the payload field is an object with strokeDasharray and value, but the documentation shows it as an array and that is also what I see when I console log it out

const renderLegend = (props) => {
  const { payload } = props;

  return (
    <ul>
      {
        payload.map((entry, index) => (
          <li key={`item-${index}`}>{entry.value}</li>
        ))
      }
    </ul>
  );
}
<Legend content={renderLegend} />

@ckifer
Copy link
Member

ckifer commented Nov 29, 2023

Yeah I think this issue is mostly from the fact that recharts used to be JS only and the refactor to TS wasn't 100% completed and then the fact that that was true got lost when things were handed off to other people, etc.

The differences need analyzed and things need to be updated to what is currently true. This shouldn't be a huge effort if someone wants to take it on!

@ckifer ckifer added bug General bug label P1 High priority issues labels Nov 29, 2023
ckifer pushed a commit that referenced this issue Jan 3, 2024
<!--- Provide a general summary of your changes in the Title above -->

## Description

<!--- Describe your changes in detail -->

## Related Issue

#2909
## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] I have added a storybook story or extended an existing story to
show my changes
- [x] All new and existing tests passed.
@ckifer
Copy link
Member

ckifer commented Jan 3, 2024

Added in #4035

Should be out in next patch or minor

@ckifer ckifer closed this as completed Jan 3, 2024
renovate bot added a commit to SAP/ui5-webcomponents-react that referenced this issue Jan 10, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [recharts](https://togithub.com/recharts/recharts) | [`2.10.3` ->
`2.10.4`](https://renovatebot.com/diffs/npm/recharts/2.10.3/2.10.4) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/recharts/2.10.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/recharts/2.10.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/recharts/2.10.3/2.10.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/recharts/2.10.3/2.10.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>recharts/recharts (recharts)</summary>

###
[`v2.10.4`](https://togithub.com/recharts/recharts/releases/tag/v2.10.4)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.10.3...v2.10.4)

#### What's Changed

Fix some older bugs annoying bugs, TS typings, update to the storybook
theme, and more

##### Fix

- `ResponsiveContainer`: fix `ref.current.current` without breaking
users using current implementation by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#4008
- closes
[recharts/recharts#3718
- `Brush`: Allow Brush to be controlled with start and end index via
state by [@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4034
- closes
[recharts/recharts#2404
- `Legend`: TypeScript - Add the dataKey type to legend props by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#4035
- closes
[recharts/recharts#2909
- `Pie`: TypeScript - added `payload` to `PieSectorDataItem` type by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#4030
- `Pie`: unique sector keys fix by
[@&#8203;imagineLife](https://togithub.com/imagineLife) in
[recharts/recharts#4009
closes
[recharts/recharts#3273
- `RadialBar`: allow className to be passed to Radial Bar background by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4027
- closes
[recharts/recharts#4011

##### Storybook

- Storybook: Added Legend component story! by
[@&#8203;AnujSharma141](https://togithub.com/AnujSharma141) in
[recharts/recharts#4039
- Storybook: add controlled brush storybook entry by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4032
- Storybook: Custom Storybook theme for Recharts brand by
[@&#8203;csdiehl](https://togithub.com/csdiehl) in
[recharts/recharts#4016

#### New Contributors

- [@&#8203;csdiehl](https://togithub.com/csdiehl) made their first
contribution in
[recharts/recharts#4016
- [@&#8203;AnujSharma141](https://togithub.com/AnujSharma141) made their
first contribution in
[recharts/recharts#4039

**Full Changelog**:
recharts/recharts@v2.10.3...v2.10.4

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/SAP/ui5-webcomponents-react).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMjcuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEyNy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to specfy/specfy that referenced this issue Feb 21, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [recharts](https://togithub.com/recharts/recharts) | [`2.9.3` ->
`2.12.1`](https://renovatebot.com/diffs/npm/recharts/2.9.3/2.12.1) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/recharts/2.12.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/recharts/2.12.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/recharts/2.9.3/2.12.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/recharts/2.9.3/2.12.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>recharts/recharts (recharts)</summary>

###
[`v2.12.1`](https://togithub.com/recharts/recharts/releases/tag/v2.12.1)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.12.0...v2.12.1)

#### What's Changed

Unintentional regression broke panoramic/compact Brush in 2.11.0 and
2.12.0, backport the fix to 2.x as we work on 3.x

##### Fix

- fix: compact render should read from context, fixes brush panorama by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4194
fixes
[recharts/recharts#4193

**Full Changelog**:
recharts/recharts@v2.12.0...v2.12.1

###
[`v2.12.0`](https://togithub.com/recharts/recharts/releases/tag/v2.12.0)

[Compare
Source](https://togithub.com/recharts/recharts/compare/36c14c63d271d05b701e1d32ac931de0fd30b360...v2.12.0)

#### What's Changed

Bug fixes and a few small new features.

Releasing 2.12.0 to create a "clean slate" as contributors are
discussing next moves for recharts.

We will try to focus on upgrades, architectural changes, and
long-pending breaking changes so we can release a recharts v3. This will
not be a large major version, or one hard to upgrade to, but rather a
major version bump to prevent us from breaking people with library
upgrades, large refactors, etc. Feature parity should hold. Thanks!

#### Features

- `Bar`: Accept a callback function for `minPointSize` so it can be
determined by data by [@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4099
closes
[recharts/recharts#2819
- `Accessibility`: Enable screen reader support with accessibilityLayer
and default tooltip by
[@&#8203;julianna-langston](https://togithub.com/julianna-langston) in
[recharts/recharts#4077

#### Fix

- `Bar`: `activeBar` should not be true by default, fixes a breaking
change from 2.9.0 by [@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4139
- fixes
[recharts/recharts#4103
and
[recharts/recharts#4101
- `Scatter`: fix non-unique key errors by
[@&#8203;imagineLife](https://togithub.com/imagineLife) in
[recharts/recharts#4087
- fixes
[recharts/recharts#4151
and
[recharts/recharts#4060
- `Pie`: fix non-unique key errors by
[@&#8203;imagineLife](https://togithub.com/imagineLife) in
[recharts/recharts#4106
- `Tooltip`: fix bug that caused throttled tooltip to stay active when
moving mouse quickly by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#4100
fixes
[recharts/recharts#4093

#### Chore

- Cleanup, tests, and refactoring work. Thanks
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek)
- Upgrade react smooth, remove `translateStyle`, remove prop-types as a
peerDep
- **NOTE**: animations will no longer have browser prefixes on them.
Browsers have good support for this
(https://caniuse.com/?search=transforms)
-   Upgrade dev dependencies
    -   Upgrade TypeScript to 4.9.5 (no definition changes from upgrade)

#### Storybook

-   New storybook stories and doc updates

#### New Contributors

- [@&#8203;TRFielder](https://togithub.com/TRFielder) made their first
contribution in
[recharts/recharts#4088

**Full Changelog**:
recharts/recharts@v2.11...v2.12.0

###
[`v2.11.0`](https://togithub.com/recharts/recharts/compare/v2.10.4...36c14c63d271d05b701e1d32ac931de0fd30b360)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.10.4...36c14c63d271d05b701e1d32ac931de0fd30b360)

###
[`v2.10.4`](https://togithub.com/recharts/recharts/releases/tag/v2.10.4)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.10.3...v2.10.4)

#### What's Changed

Fix some older bugs annoying bugs, TS typings, update to the storybook
theme, and more

##### Fix

- `ResponsiveContainer`: fix `ref.current.current` without breaking
users using current implementation by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#4008
- closes
[recharts/recharts#3718
- `Brush`: Allow Brush to be controlled with start and end index via
state by [@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4034
- closes
[recharts/recharts#2404
- `Legend`: TypeScript - Add the dataKey type to legend props by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#4035
- closes
[recharts/recharts#2909
- `Pie`: TypeScript - added `payload` to `PieSectorDataItem` type by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#4030
- `Pie`: unique sector keys fix by
[@&#8203;imagineLife](https://togithub.com/imagineLife) in
[recharts/recharts#4009
closes
[recharts/recharts#3273
- `RadialBar`: allow className to be passed to Radial Bar background by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4027
- closes
[recharts/recharts#4011

##### Storybook

- Storybook: Added Legend component story! by
[@&#8203;AnujSharma141](https://togithub.com/AnujSharma141) in
[recharts/recharts#4039
- Storybook: add controlled brush storybook entry by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#4032
- Storybook: Custom Storybook theme for Recharts brand by
[@&#8203;csdiehl](https://togithub.com/csdiehl) in
[recharts/recharts#4016

#### New Contributors

- [@&#8203;csdiehl](https://togithub.com/csdiehl) made their first
contribution in
[recharts/recharts#4016
- [@&#8203;AnujSharma141](https://togithub.com/AnujSharma141) made their
first contribution in
[recharts/recharts#4039

**Full Changelog**:
recharts/recharts@v2.10.3...v2.10.4

###
[`v2.10.3`](https://togithub.com/recharts/recharts/releases/tag/v2.10.3)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.10.2...v2.10.3)

#### What's Changed

- Fix non-unique react `key` bug(s) by
[@&#8203;imagineLife](https://togithub.com/imagineLife) in
[recharts/recharts#4006
- closes
[recharts/recharts#4004

#### New Contributors

- [@&#8203;hkmarques](https://togithub.com/hkmarques) made their first
contribution in
[recharts/recharts#4002

**Full Changelog**:
recharts/recharts@v2.10.2...v2.10.3

###
[`v2.10.2`](https://togithub.com/recharts/recharts/releases/tag/v2.10.2)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.10.1...v2.10.2)

#### What's Changed

Patch some bugs from 2.9 / 2.10

##### Fix

- `Tooltip`: Fix tooltip rendering crash when activeItem is undefined by
[@&#8203;tran-simon](https://togithub.com/tran-simon) in
[recharts/recharts#3982
- `Cursor`: should no longer show gray background on hover where there
was none previously
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#3992
- `Tooltip`: show tooltip when `data` prop is on individual cartesian
component by [@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo)
in
[recharts/recharts#3988
- `LabelList` - TypeScript: LabelList offset prop issue by
[@&#8203;ckifer](https://togithub.com/ckifer) in
[recharts/recharts#3999

##### Accessibility

- `Brush`: set default aria-label and allow value override by
[@&#8203;enriquetamames-cpi](https://togithub.com/enriquetamames-cpi) in
[recharts/recharts#3950

##### Refactor / Cleanup

- Removing some eslint errors for "no array index key" by
[@&#8203;imagineLife](https://togithub.com/imagineLife)

#### New Contributors

- [@&#8203;tran-simon](https://togithub.com/tran-simon) made their first
contribution in
[recharts/recharts#3982
- [@&#8203;enriquetamames-cpi](https://togithub.com/enriquetamames-cpi)
made their first contribution in
[recharts/recharts#3950

**Full Changelog**:
recharts/recharts@v2.10.1...v2.10.2

###
[`v2.10.1`](https://togithub.com/recharts/recharts/releases/tag/v2.10.1):
Patch: Do not include types from test folder

[Compare
Source](https://togithub.com/recharts/recharts/compare/15328ec11b78968c847b43b646767b7b0c0d9e36...v2.10.1)

Fixes
[recharts/recharts#3978

**Full Changelog**:
recharts/recharts@v2.10...v2.10.1

###
[`v2.10.0`](https://togithub.com/recharts/recharts/compare/v2.9.3...15328ec11b78968c847b43b646767b7b0c0d9e36)

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.9.3...15328ec11b78968c847b43b646767b7b0c0d9e36)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm every weekday" in timezone
Europe/Paris, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/specfy/specfy).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44MS4zIiwidXBkYXRlZEluVmVyIjoiMzcuMjAwLjAiLCJ0YXJnZXRCcmFuY2giOiJjaG9yZS9yZW5vdmF0ZUJhc2VCcmFuY2gifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug General bug label P1 High priority issues typescript PRs or Issues surrounding Types or TS refactoring
Projects
None yet
Development

No branches or pull requests

6 participants