From 47e11f9a8a2750599a4814ae550f92c8bc9473d8 Mon Sep 17 00:00:00 2001 From: Thibault Derousseaux Date: Wed, 18 Sep 2019 22:11:37 +0200 Subject: [PATCH] Only display node structure in JSONTree for arrays and empty objects --- packages/json-extension/src/component.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/json-extension/src/component.tsx b/packages/json-extension/src/component.tsx index a75d6d06f67f..9c7e68c92f56 100644 --- a/packages/json-extension/src/component.tsx +++ b/packages/json-extension/src/component.tsx @@ -71,13 +71,16 @@ export class Component extends React.Component { }} 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". + + {itemType} {itemString} + + ) : Object.keys(data).length === 0 ? ( + // Only display object type when it's empty i.e. "{}". {itemType} - ) : // Otherwise, the data speaks for itself. - null + ) : null } labelRenderer={([label, type]) => { // let className = 'cm-variable';