Skip to content

Commit af15341

Browse files
fix: add nested objects check for compact class
1 parent 35f5ab6 commit af15341

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

static/app/views/explore/components/traceItemAttributes/attributesTreeValue.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ describe('AttributesTreeValue', () => {
208208
expect(pre).toHaveClass('compact');
209209
});
210210

211+
it('renders short JSON with nested objects without compact class', () => {
212+
const jsonContent = {
213+
...defaultProps.content,
214+
value: '{"a":{"b":{"c":{"d":1}}}}',
215+
};
216+
217+
render(<AttributesTreeValue {...defaultProps} content={jsonContent} />);
218+
219+
const pre = screen.getByText('a').closest('pre');
220+
expect(pre).not.toHaveClass('compact');
221+
});
222+
211223
it('renders long JSON without compact class', () => {
212224
const jsonContent = {
213225
...defaultProps.content,

static/app/views/explore/components/traceItemAttributes/attributesTreeValue.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ function tryParseJson(value: unknown) {
2828
}
2929
}
3030

31+
function hasNestedObject(value: unknown) {
32+
if (typeof value !== 'object' || value === null) {
33+
return false;
34+
}
35+
const values = Array.isArray(value) ? value : Object.values(value);
36+
return values.some(v => typeof v === 'object' && v !== null);
37+
}
38+
3139
export function AttributesTreeValue<RendererExtra extends RenderFunctionBaggage>({
3240
config,
3341
content,
@@ -79,7 +87,9 @@ export function AttributesTreeValue<RendererExtra extends RenderFunctionBaggage>
7987
data={parsedJson}
8088
maxDefaultDepth={2}
8189
withAnnotatedText={false}
82-
className={value.length <= 48 ? 'compact' : undefined}
90+
className={
91+
value.length <= 48 && !hasNestedObject(parsedJson) ? 'compact' : undefined
92+
}
8393
/>
8494
);
8595
}

0 commit comments

Comments
 (0)