Skip to content

Commit

Permalink
Only display node structure in JSONTree for arrays and empty objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex committed Sep 18, 2019
1 parent 8013d19 commit 47e11f9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/json-extension/src/component.tsx
Expand Up @@ -71,13 +71,16 @@ export class Component extends React.Component<IProps, IState> {
}}
invertTheme={false}
keyPath={[root]}
getItemString={(type, data, itemType) =>
((Array.isArray(data) && data) || Object.keys(data)).length ===
0 ? (
// When there is no data, we display the collection type ("{}" or "[]").
getItemString={(type, data, itemType, itemString) =>
Array.isArray(data) ? (
// Always display array type and the number of items i.e. "[] 2 items".
<span>
{itemType} {itemString}
</span>
) : Object.keys(data).length === 0 ? (
// Only display object type when it's empty i.e. "{}".
<span>{itemType}</span>
) : // Otherwise, the data speaks for itself.
null
) : null
}
labelRenderer={([label, type]) => {
// let className = 'cm-variable';
Expand Down

0 comments on commit 47e11f9

Please sign in to comment.