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: "Functions are not valid as a React child" error in <Legend/> when a function is passed as the payload #3749 #3750

Merged
merged 2 commits into from Sep 12, 2023

Conversation

chris-mcdonald-dev
Copy link
Contributor

@chris-mcdonald-dev chris-mcdonald-dev commented Sep 10, 2023

Description

Small changes checking if the payload provided to <Legend/> is a function and calling it as needed. Otherwise, the original value is rendered. Also added accompanying tests.

Related Issue

#3749

Motivation and Context

When a function was provided as a payload to the <Legend/> component, it was not getting called before being rendered resulting in the error described in #3749. This ensures the payload is called if passed as a function.

How Has This Been Tested?

Unit tests included. Checks that values are correctly rendered both when passed as static values and as a function.

Screenshots (if appropriate):

Types of changes

  • 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:

  • 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.
  • All new and existing tests passed.

Copy link
Member

@ckifer ckifer left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

src/component/DefaultLegendContent.tsx Show resolved Hide resolved
@ckifer ckifer merged commit 21ce248 into recharts:master Sep 12, 2023
5 checks passed
@@ -169,6 +170,7 @@ export class DefaultLegendContent extends PureComponent<Props> {
return null;
}

const entryValue = _.isFunction(entry.value) ? entry.value() : entry.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

hi, I'm not sure if I understood correctly, but I don't think this is correct fix. the fn that is provided expects an argument which is not provided here - yeah, it would fix the warning but I believe it won't work correctly @ckifer don't you agree?

SShot from a debbuger of a provided CodeSandbox within the issue
image

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused. This should work fine - I'll pull it down later and check

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it be something like
const entryValue = _.isFunction(entry.value) ? entry.value(entry) : entry.value;
or
const entryValue = _.isFunction(entry.value) ? entry.value(entry.payload) : entry.value;
?

in given example - in the issue, the reporter set the handler as below:
row => row.pv

in this example and current code - what is row? wouldn't it throw 'row is undefined' ?

I might be wrong though.

Copy link
Member

Choose a reason for hiding this comment

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

yeah you're right, thanks for taking the extra care to check. Just need to fix this before the next release and should be okay

@chris-mcdonald-dev fyi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MateuszTrN Yeah, thanks for catching that. Looking into a solution now. We won't be able to get it from the entry or payload for the Legend component, since that doesn't seem to contain the chart data and just the payload for the legend elements.

Copy link
Member

Choose a reason for hiding this comment

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

we're really just trying to get the actual dataKey name here, not any actual values. When you have data => data.pv you don't really have great reference to the text pv

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I can't see the point of this being a function directly passed to the Legend component either.

I'll spend some time thinking of a solution. The only initial idea I have is rendering an empty string when a function is derived from a chart component's dataKey and printing a warning message to the console saying to pass a payload value as a string to <Legend/> whenever that's the case.

Otherwise, I'm not sure how we'd have any way of knowing what that legend is supposed to be labeled since functions won't necessarily have to follow the format of () => someObject.theValue

Copy link
Member

Choose a reason for hiding this comment

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

It does also use the "name" property before the dataKey property in the Legend. If the dataKey is a function we could print a warning that name is required for a label to appear in the legend

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah true! I'll create an issue and open a matching PR with tests in a bit.

@ckifer
Copy link
Member

ckifer commented Sep 14, 2023

I'm thinking we don't actually want the value prop of Legend to be able to be a function. We want it as a string, however we have to get it as a string somehow before the dataKey is passed to legend

ckifer pushed a commit that referenced this pull request Sep 15, 2023
<!--- Provide a general summary of your changes in the Title above -->
## Description
Always renders static string in `<Legend/>` when functions are passed as
a dataKey to sibling cartesian components. Prompts the API user to
include the `name` property when `entry.value` is a function.
<!--- Describe your changes in detail -->

## Related Issue
#3757
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
Addresses problems brought up in #3750.
## How Has This Been Tested?
Includes unit tests checking that name prop is rendered when functions
are passed and when the name prop is missing.
<!--- 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.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
renovate bot added a commit to SAP/ui5-webcomponents-react that referenced this pull request Oct 18, 2023
[![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.8.0` ->
`2.9.0`](https://renovatebot.com/diffs/npm/recharts/2.8.0/2.9.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/recharts/2.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/recharts/2.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/recharts/2.8.0/2.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/recharts/2.8.0/2.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.8.0...v2.9.0)

#### What's Changed

Quite a lot this minor release! We sent out a cry for help and many
answered - thank you so much for that 🙌🏼

This release aims at internal maintainability, long lingering bugs, and
needed improvements. Highlights include equidistant tick improvements,
an active bar feature, and an ~85k/~9kb (gzipped) bundle size reduction
🚀

##### Feat

- `Bar`: Implement activeBar for Bar component by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3756
- `CartesianGrid`: add `syncWithticks`, `horizonalValues`, and
`verticalValues` props to allow more grid line customization by
[@&#8203;morozovkirill](https://togithub.com/morozovkirill) in
[recharts/recharts#3746
solves
[recharts/recharts#2153
- `CartesianAxis`: Improve interval option 'equidistantPreserveStart' by
[@&#8203;nikolasrieble](https://togithub.com/nikolasrieble) in
[recharts/recharts#3768
- `CartesianAxis`: Throw an invariant when axisIds do not match between
chart and axis components by
[@&#8203;ckifer](https://togithub.com/ckifer)
- `Brush`: add onDragEnd event to Brush component by
[@&#8203;simkesd](https://togithub.com/simkesd) in
[recharts/recharts#3774

##### Fix

-   Active Shape improvements
- `Funnel`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3772
- `Scatter`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3839
- `Pie`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3818
- `RadialBar`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3803
- `CartesianGrid`: Remove offset attribute from lines by
[@&#8203;branberry](https://togithub.com/branberry) in
[recharts/recharts#3854
solves
[recharts/recharts#3810
- `ResponsiveContainer`: style prop is now passed down correctly by
[@&#8203;d-gottlieb](https://togithub.com/d-gottlieb) in
[recharts/recharts#3726
- `Legend`: "Functions are not valid as a React child" error in
<Legend/> when a function is passed as the payload
[#&#8203;3749](https://togithub.com/recharts/recharts/issues/3749) by
[@&#8203;chris-mcdonald-dev](https://togithub.com/chris-mcdonald-dev) in
[recharts/recharts#3750
- `Tooltip`: Fix tooltip position when container uses transform scale by
[@&#8203;MateuszTrN](https://togithub.com/MateuszTrN) in
[recharts/recharts#3748
- `Tooltip`: Tooltip does not include data from all charts when a
separate dataset is passed to chart prop data and specified on
Line/Area/etc prop data by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3733
fixes
[recharts/recharts#3669

##### Refactor

Impossible to mention all of the great refactoring done this release
thanks to [@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) (33
PRs in one month!!) and others! Notable improvements include
(non-breaking) type safety enhancements and source code file size
reductions, and unit test improvements that will help reduce
regressions.

##### Chore

- Upgrade react-smooth to 2.0.5 - potentially fixes
[recharts/recharts#1135
(edit: this was already fixed)
- Add performance testing tool by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#3829
- remove reduceCSSCalc by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#3820

##### Storybook

- Add storybook-addon-performance by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#3826
-   many storybook improvements and fixes

#### 🚀 New Contributors (!!) 🚀

- [@&#8203;d-gottlieb](https://togithub.com/d-gottlieb) made their first
contribution in
[recharts/recharts#3726
- [@&#8203;andrewangelle](https://togithub.com/andrewangelle) made their
first contribution in
[recharts/recharts#3733
- [@&#8203;wanisramdani](https://togithub.com/wanisramdani) made their
first contribution in
[recharts/recharts#3751
- [@&#8203;MateuszTrN](https://togithub.com/MateuszTrN) made their first
contribution in
[recharts/recharts#3748
- [@&#8203;chris-mcdonald-dev](https://togithub.com/chris-mcdonald-dev)
made their first contribution in
[recharts/recharts#3750
- [@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) made their
first contribution in
[recharts/recharts#3759
- [@&#8203;simkesd](https://togithub.com/simkesd) made their first
contribution in
[recharts/recharts#3774
- [@&#8203;samtmorgan](https://togithub.com/samtmorgan) made their first
contribution in
[recharts/recharts#3778
- [@&#8203;Shashangbhagat](https://togithub.com/Shashangbhagat) made
their first contribution in
[recharts/recharts#3786
- [@&#8203;morozovkirill](https://togithub.com/morozovkirill) made their
first contribution in
[recharts/recharts#3746
- [@&#8203;branberry](https://togithub.com/branberry) made their first
contribution in
[recharts/recharts#3854
- [@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) made their
first contribution in
[recharts/recharts#3820

**Full Changelog**:
recharts/recharts@v2.8.0...v2.9.0

</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:eyJjcmVhdGVkSW5WZXIiOiIzNy44LjEiLCJ1cGRhdGVkSW5WZXIiOiIzNy4xOS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Lukas Harbarth <lukas.harbarth@sap.com>
bodinsamuel pushed a commit to specfy/specfy that referenced this pull request Nov 13, 2023
[![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.8.0` ->
`2.9.3`](https://renovatebot.com/diffs/npm/recharts/2.8.0/2.9.3) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/recharts/2.9.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/recharts/2.9.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/recharts/2.8.0/2.9.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/recharts/2.8.0/2.9.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

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

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

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

#### Fix

`Brush`: Fix an issue where after 2.9 `Brush` does not correctly slice
data when using `Line` components - fixes
[recharts/recharts#3929
- thank you [@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo)

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

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.9.1...v2.9.2)

Fix another TS issue from 2.9.

##### Fix

- `Line/ActiveDot`: Fix breaking type change for the `onClick` function
of `activeDot` on `Line` - this resolves
[recharts/recharts#3922
- thank you [@&#8203;andrewangelle](https://togithub.com/andrewangelle)
for the quick turnaround

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

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.9.0...v2.9.1)

Bug fixes following 2.9.0

#### Fix

- `TypeScript`: fix breaking change in `ActiveShape` types - fixes
[recharts/recharts#3911
- thanks [@&#8203;andrewangelle](https://togithub.com/andrewangelle)
- `CartesianGrid`: fix breaking change where you could no longer render
`CartesianGrid` without a y-axis - fixes
[recharts/recharts#3907
- thanks [@&#8203;akamfoad](https://togithub.com/akamfoad)
- `Line`: fix infinite loop when `strokeDasharray` is `'0'` on `Line` -
fixes
[recharts/recharts#3899
(and maybe others)

**Full Changelog**:
recharts/recharts@v2.9.0...v2.9.1

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

[Compare
Source](https://togithub.com/recharts/recharts/compare/v2.8.0...v2.9.0)

#### What's Changed

Quite a lot this minor release! We sent out a cry for help and many
answered - thank you so much for that 🙌🏼

This release aims at internal maintainability, long lingering bugs, and
needed improvements. Highlights include equidistant tick improvements,
an active bar feature, and an ~85k/~9kb (gzipped) bundle size reduction
🚀

##### Feat

- `Bar`: Implement activeBar for Bar component by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3756
- `CartesianGrid`: add `syncWithticks`, `horizonalValues`, and
`verticalValues` props to allow more grid line customization by
[@&#8203;morozovkirill](https://togithub.com/morozovkirill) in
[recharts/recharts#3746
solves
[recharts/recharts#2153
- `CartesianAxis`: Improve interval option 'equidistantPreserveStart' by
[@&#8203;nikolasrieble](https://togithub.com/nikolasrieble) in
[recharts/recharts#3768
- `CartesianAxis`: Throw an invariant when axisIds do not match between
chart and axis components by
[@&#8203;ckifer](https://togithub.com/ckifer)
- `Brush`: add onDragEnd event to Brush component by
[@&#8203;simkesd](https://togithub.com/simkesd) in
[recharts/recharts#3774

##### Fix

-   Active Shape improvements
- `Funnel`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3772
- `Scatter`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3839
- `Pie`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3818
- `RadialBar`: activeShape should work with Tooltip by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3803
- `CartesianGrid`: Remove offset attribute from lines by
[@&#8203;branberry](https://togithub.com/branberry) in
[recharts/recharts#3854
solves
[recharts/recharts#3810
- `ResponsiveContainer`: style prop is now passed down correctly by
[@&#8203;d-gottlieb](https://togithub.com/d-gottlieb) in
[recharts/recharts#3726
- `Legend`: "Functions are not valid as a React child" error in
<Legend/> when a function is passed as the payload
[#&#8203;3749](https://togithub.com/recharts/recharts/issues/3749) by
[@&#8203;chris-mcdonald-dev](https://togithub.com/chris-mcdonald-dev) in
[recharts/recharts#3750
- `Tooltip`: Fix tooltip position when container uses transform scale by
[@&#8203;MateuszTrN](https://togithub.com/MateuszTrN) in
[recharts/recharts#3748
- `Tooltip`: Tooltip does not include data from all charts when a
separate dataset is passed to chart prop data and specified on
Line/Area/etc prop data by
[@&#8203;andrewangelle](https://togithub.com/andrewangelle) in
[recharts/recharts#3733
fixes
[recharts/recharts#3669

##### Refactor

Impossible to mention all of the great refactoring done this release
thanks to [@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) (33
PRs in one month!!) and others! Notable improvements include
(non-breaking) type safety enhancements and source code file size
reductions, and unit test improvements that will help reduce
regressions.

##### Chore

- Upgrade react-smooth to 2.0.5 - potentially fixes
[recharts/recharts#1135
(edit: this was already fixed)
- Add performance testing tool by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#3829
- remove reduceCSSCalc by
[@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) in
[recharts/recharts#3820

##### Storybook

- Add storybook-addon-performance by
[@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) in
[recharts/recharts#3826
-   many storybook improvements and fixes

#### 🚀 New Contributors (!!) 🚀

- [@&#8203;d-gottlieb](https://togithub.com/d-gottlieb) made their first
contribution in
[recharts/recharts#3726
- [@&#8203;andrewangelle](https://togithub.com/andrewangelle) made their
first contribution in
[recharts/recharts#3733
- [@&#8203;wanisramdani](https://togithub.com/wanisramdani) made their
first contribution in
[recharts/recharts#3751
- [@&#8203;MateuszTrN](https://togithub.com/MateuszTrN) made their first
contribution in
[recharts/recharts#3748
- [@&#8203;chris-mcdonald-dev](https://togithub.com/chris-mcdonald-dev)
made their first contribution in
[recharts/recharts#3750
- [@&#8203;PavelVanecek](https://togithub.com/PavelVanecek) made their
first contribution in
[recharts/recharts#3759
- [@&#8203;simkesd](https://togithub.com/simkesd) made their first
contribution in
[recharts/recharts#3774
- [@&#8203;samtmorgan](https://togithub.com/samtmorgan) made their first
contribution in
[recharts/recharts#3778
- [@&#8203;Shashangbhagat](https://togithub.com/Shashangbhagat) made
their first contribution in
[recharts/recharts#3786
- [@&#8203;morozovkirill](https://togithub.com/morozovkirill) made their
first contribution in
[recharts/recharts#3746
- [@&#8203;branberry](https://togithub.com/branberry) made their first
contribution in
[recharts/recharts#3854
- [@&#8203;HHongSeungWoo](https://togithub.com/HHongSeungWoo) made their
first contribution in
[recharts/recharts#3820

**Full Changelog**:
recharts/recharts@v2.8.0...v2.9.0

</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:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6ImNob3JlL3Jlbm92YXRlQmFzZUJyYW5jaCJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
GMer78 pushed a commit to GMer78/recharts-1 that referenced this pull request Nov 24, 2023
…en a function is passed as the payload recharts#3749 (recharts#3750)

<!--- Provide a general summary of your changes in the Title above -->
## Description
<!--- Describe your changes in detail -->
Small changes checking if the payload provided to `<Legend/>` is a
function and calling it as needed. Otherwise, the original value is
rendered. Also added accompanying tests.

## Related Issue
recharts#3749 
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context
When a function was provided as a payload to the `<Legend/>` component,
it was not getting called before being rendered resulting in the error
described in recharts#3749. This ensures the payload is called if passed as a
function.

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

## How Has This Been Tested?
Unit tests included. Checks that values are correctly rendered both when
passed as static values and as a function.
<!--- 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.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
GMer78 pushed a commit to GMer78/recharts-1 that referenced this pull request Nov 24, 2023
<!--- Provide a general summary of your changes in the Title above -->
## Description
Always renders static string in `<Legend/>` when functions are passed as
a dataKey to sibling cartesian components. Prompts the API user to
include the `name` property when `entry.value` is a function.
<!--- Describe your changes in detail -->

## Related Issue
recharts#3757
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
Addresses problems brought up in recharts#3750.
## How Has This Been Tested?
Includes unit tests checking that name prop is rendered when functions
are passed and when the name prop is missing.
<!--- 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.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
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