Skip to content

Commit 7ba1332

Browse files
committed
Also truncate ArrayGroup in nested objects
1 parent 9e85626 commit 7ba1332

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

dev-server/src/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ ReactDom.render(
242242
src={getLargeArrayForDemo()}
243243
/>
244244

245+
{/* Demo of numberOfArrayGroupsToDisplay with nested objects */}
246+
<JsonViewer
247+
theme='apathy:inverted'
248+
collapsed={false}
249+
name='nested_arrays_with_limited_groups'
250+
groupArraysAfterLength={5}
251+
numberOfArrayGroupsToDisplay={2}
252+
src={getNestedArraysForDemo()}
253+
/>
254+
245255
{/* Name as colored react component */}
246256
<JsonViewer
247257
collapsed
@@ -382,3 +392,23 @@ function getExampleWithStringEscapeSequences () {
382392
function getLargeArrayForDemo () {
383393
return new Array(25).fill().map((_, i) => `Item ${i + 1}`)
384394
}
395+
396+
function getNestedArraysForDemo () {
397+
return {
398+
users: new Array(25).fill().map((_, i) => ({
399+
id: i + 1,
400+
name: `User ${i + 1}`,
401+
email: `user${i + 1}@example.com`
402+
})),
403+
products: new Array(25).fill().map((_, i) => ({
404+
id: i + 1,
405+
name: `Product ${i + 1}`,
406+
price: Math.random() * 100
407+
})),
408+
categories: new Array(25).fill().map((_, i) => ({
409+
id: i + 1,
410+
name: `Category ${i + 1}`,
411+
description: `Description for category ${i + 1}`
412+
}))
413+
}
414+
}

src/js/components/DataTypes/Object.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class RjvObject extends React.PureComponent {
239239
parent_type,
240240
index_offset,
241241
groupArraysAfterLength,
242+
numberOfArrayGroupsToDisplay,
242243
namespace,
243244
showComma
244245
} = this.props
@@ -269,6 +270,7 @@ class RjvObject extends React.PureComponent {
269270
parent_type={object_type}
270271
isLast={isLast}
271272
showComma={showComma}
273+
numberOfArrayGroupsToDisplay={numberOfArrayGroupsToDisplay}
272274
{...props}
273275
/>
274276
)
@@ -293,6 +295,7 @@ class RjvObject extends React.PureComponent {
293295
parent_type={object_type}
294296
isLast={isLast}
295297
showComma={showComma}
298+
numberOfArrayGroupsToDisplay={numberOfArrayGroupsToDisplay}
296299
{...props}
297300
/>
298301
)

test/tests/js/components/ArrayGroup-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,6 @@ describe('<ArrayGroup />', function () {
179179
// Should not show ellipsis
180180
expect(wrapper.find('.object-key-val.array-group-ellipsis').length).to.equal(0)
181181
})
182+
183+
182184
})

test/tests/js/components/DataTypes/Object-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,32 @@ describe('<JsonObject />', function () {
466466
)
467467
expect(wrapper.find('span').someWhere(node => node.text() === ',')).to.be.false
468468
})
469+
470+
it('Object with nested arrays respects numberOfArrayGroupsToDisplay', function () {
471+
let src = {
472+
nestedArray: new Array(25).fill('test'),
473+
otherProp: 'value'
474+
}
475+
476+
const wrapper = render(
477+
<JsonObject
478+
src={src}
479+
theme='rjv-default'
480+
namespace={['root']}
481+
rjvId={rjvId}
482+
groupArraysAfterLength={5}
483+
numberOfArrayGroupsToDisplay={2}
484+
collapsed={false}
485+
indentWidth={1}
486+
depth={1}
487+
type='object'
488+
/>
489+
)
490+
491+
// Should only display 2 groups for the nested array
492+
expect(wrapper.find('.array-group').length).to.equal(2)
493+
494+
// Should show ellipsis for the nested array
495+
expect(wrapper.find('.object-key-val.array-group-ellipsis').length).to.equal(1)
496+
})
469497
})

0 commit comments

Comments
 (0)