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

This commit accounts for differences in JSONTree's renderer callbacks. #41

Merged
merged 1 commit into from
Dec 10, 2018
Merged

This commit accounts for differences in JSONTree's renderer callbacks. #41

merged 1 commit into from
Dec 10, 2018

Conversation

arcin
Copy link
Contributor

@arcin arcin commented Nov 9, 2018

valueRenderer: passes a scalar value as an argument to the callback you provide.
labelRenderer: passes a array value as an argument to the callback you provide.
This array value is the key ancestry of the json tree.

The Problem:

The name formating issue in FilterableState.js was caused by rendering the
entire key ancestry array as a string for every key, instead of just the name of the key.

Example:
when trying to render the "child" from this piece of state

{
  grandParent: {
    parent: {
      child: { /*...*/ }
    }
  }
}

the labelRenderer callback, you provided, will be given the key and its ancestry as a value.

function labelRenderer (value) {
  // value == ["child", "parent", "grandParent"]
  return value;
}

JSONTree takes the return of labelRenderer and renders it as a
string. So the above return value becomes "childparentgrandParent".

This is why you get the visual bug in the preview of state for the LogMonitor.

The Solution:

return the first key, instead of the entire key ancestry, to get the
correctly formatted label.

valueRenderer: passes a scalar value as an argument to the callback you provide.
labelRenderer: passes a array value as an argument to the callback you provide.
               This array value is the key ancestry of the json tree.

The Problem:
===
The name formating issue in FilterableState.js was caused by rendering the
**entire** key ancestry array as a string for every key, instead of just the name of the key.

Example:
when trying to render the "child" from this piece of state
```javascript
{
  grandParent: {
    parent: {
      child: { /*...*/ }
    }
  }
}
```

the `labelRenderer` callback, you provided, will be given the key and its ancestry as a value.
```javascript
function labelRenderer (value) {
  // value == ["child", "parent", "grandParent"]
  return value;
}
```

`JSONTree` takes the return of `labelRenderer` and renders it as a
string. So the above return value becomes "childparentgrandParent".

This is why you get the visual bug in the preview of state for the LogMonitor.

The Solution:
===
return the first key, instead of the entire key ancestry, to get the
correctly formatted label.
@arcin arcin mentioned this pull request Nov 9, 2018
@bvaughn
Copy link
Owner

bvaughn commented Nov 9, 2018

Hey @arcin. Thanks a ton for contributing! Any idea if we need to bump the redux dependency range with this change? I'm not sure when it got broken.

@arcin
Copy link
Contributor Author

arcin commented Nov 10, 2018

No problem @bvaughn! So it looks like we don't need a bump because the issue was introduced by this commit

redux-devtools-log-monitor actually had the same issue as this project.

In version 0.5.6 of react-json-tree, the labelRenderer was changed so that callers get access to the full json keypath. You can see the PR here

If you scroll to the bottom of the comment thread you'll see that it broke redux-devtools-log-monitor, as well.

This project predates the feature in react-json-tree and the break/fix in redux-devtools-log-monitor, so I'm assuming that the version bump in react-json-tree is the culprit here too :)

@bvaughn
Copy link
Owner

bvaughn commented Dec 10, 2018

Sorry, I dropped the ball with this PR.

I'm a little confused why a change in 0.5.6 of react-json-tree impacted this library, considering we declare a dependency on ^0.11.0 of that library– and that last release was a year ago– around the same time I updated this package (faf10d8).

Sorry if I'm being dense here, but can you explain?

@bvaughn
Copy link
Owner

bvaughn commented Dec 10, 2018

Sorry, after looking a little closer I think I see what you're talking about now.

@bvaughn bvaughn merged commit 24298d9 into bvaughn:master Dec 10, 2018
@bvaughn
Copy link
Owner

bvaughn commented Dec 10, 2018

Fix published in version 0.8.1. Sorry again for the delay. I guess I lost track of this because of conference stuff.

@arcin arcin deleted the fix-json-label-formatting-issue branch March 29, 2019 21:12
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.

2 participants