Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Provide full JSON key path in labelRenderer (in reverse order) #32

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/JSONArrayNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function getChildNodes({
styles,
theme,
valueRenderer,
allExpanded
allExpanded,
keyPath
}) {
const childNodes = [];
data.forEach((value, key) => {
Expand All @@ -36,7 +37,7 @@ function getChildNodes({

const node = grabNode({
getItemString,
key,
keyPath: [key, ...keyPath],
labelRenderer,
previousData: previousDataValue,
renderItemString,
Expand Down
5 changes: 3 additions & 2 deletions src/JSONIterableNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function getChildNodes({
styles,
theme,
valueRenderer,
allExpanded
allExpanded,
keyPath
}) {
const childNodes = [];
for (const entry of data) {
Expand All @@ -53,7 +54,7 @@ function getChildNodes({

const node = grabNode({
getItemString,
key,
keyPath: [key, ...keyPath],
labelRenderer,
previousData: previousDataValue,
styles,
Expand Down
2 changes: 1 addition & 1 deletion src/JSONNestedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class JSONNestedNode extends React.Component {
color: this.props.theme.base0D,
...this.props.styles.getLabelStyle(this.props.nodeType, this.state.expanded)
}} onClick={::this.handleClick}>
{this.props.labelRenderer(this.props.keyName)}:
{this.props.labelRenderer(...this.props.keyPath)}:
</label>
<span style={{
...spanStyle,
Expand Down
5 changes: 3 additions & 2 deletions src/JSONObjectNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function getChildNodes({
styles,
theme,
valueRenderer,
allExpanded
allExpanded,
keyPath
}) {
const childNodes = [];
for (let key in data) {
Expand All @@ -38,7 +39,7 @@ export function getChildNodes({

const node = grabNode({
getItemString,
key,
keyPath: [key, ...keyPath],
labelRenderer,
previousData: previousDataValue,
renderItemString,
Expand Down
2 changes: 1 addition & 1 deletion src/JSONValueNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class JSONValueNode extends React.Component {
color: this.props.theme.base0D,
...this.props.styles.getLabelStyle(this.props.nodeType, true)
}}>
{this.props.labelRenderer(this.props.keyName)}:
{this.props.labelRenderer(...this.props.keyPath)}:
</label>
<span style={{
color: this.props.valueColor,
Expand Down
8 changes: 4 additions & 4 deletions src/grab-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function({
getItemString,
initialExpanded = false,
allExpanded,
key,
keyPath,
labelRenderer,
previousData,
styles,
Expand All @@ -22,8 +22,8 @@ export default function({
const simpleNodeProps = {
getItemString,
initialExpanded,
key,
keyName: key,
key: keyPath[0],
keyPath,
labelRenderer,
nodeType,
previousData,
Expand All @@ -38,7 +38,7 @@ export default function({
data: value,
initialExpanded,
allExpanded,
keyName: key
keyPath
};

switch (nodeType) {
Expand Down
15 changes: 8 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class JSONTree extends React.Component {
expandRoot: true,
expandAll: false,
hideRoot: false,
keyName: 'root',
keyPath: ['root'],
theme: solarized,
getArrowStyle: getEmptyStyle,
getListStyle: getEmptyStyle,
Expand Down Expand Up @@ -71,19 +71,19 @@ export default class JSONTree extends React.Component {
getItemString,
labelRenderer,
valueRenderer,
keyName: key,
keyPath,
previousData,
theme
} = this.props;

var nodeToRender;
let nodeToRender;

if (!this.props.hideRoot) {
if (!this.props.hideRoot) {
nodeToRender = grabNode({
getItemString,
initialExpanded,
allExpanded,
key,
keyPath,
previousData,
styles: getStyles,
theme,
Expand All @@ -97,10 +97,11 @@ export default class JSONTree extends React.Component {
getItemString,
labelRenderer,
previousData,
styles:getStyles,
styles: getStyles,
theme,
valueRenderer,
allExpanded
allExpanded,
keyPath: []
});
}

Expand Down