Skip to content

Commit 1914fea

Browse files
committed
added nesting for deeply nested properties
1 parent 95ed895 commit 1914fea

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

src/app/components/StateRoute/ComponentMap/ToolTipDataDisplay.tsx

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,46 @@ const ToolTipDataDisplay = ({ data }) => {
88
scheme: 'custom',
99
base00: 'transparent',
1010
base0B: '#1f2937', // dark navy for strings
11-
base0D: '#60a5fa', // Blue for keys
12-
base09: '#f59e0b', // Orange for numbers
13-
base0C: '#EF4444', // red for nulls
11+
base0D: '#60a5fa', // Keys
12+
base09: '#f59e0b', // Numbers
13+
base0C: '#EF4444', // Null values
14+
};
15+
16+
// Helper function to parse stringified JSON in object values
17+
const parseStringifiedValues = (obj) => {
18+
if (!obj || typeof obj !== 'object') return obj;
19+
20+
const parsed = { ...obj };
21+
for (const key in parsed) {
22+
if (typeof parsed[key] === 'string') {
23+
try {
24+
// Check if the string looks like JSON
25+
if (parsed[key].startsWith('{') || parsed[key].startsWith('[')) {
26+
const parsedValue = JSON.parse(parsed[key]);
27+
parsed[key] = parsedValue;
28+
}
29+
} catch (e) {
30+
// If parsing fails, keep original value
31+
continue;
32+
}
33+
} else if (typeof parsed[key] === 'object') {
34+
parsed[key] = parseStringifiedValues(parsed[key]);
35+
}
36+
}
37+
return parsed;
1438
};
1539

1640
const formatReducerData = (reducerStates) => {
41+
// Check if reducerStates exists and is an array
42+
if (!Array.isArray(reducerStates)) {
43+
return {};
44+
}
45+
1746
return reducerStates.reduce((acc, reducer) => {
18-
acc[reducer.hookName || 'Reducer'] = reducer.state;
47+
// Add additional type checking for reducer object
48+
if (reducer && typeof reducer === 'object') {
49+
acc[reducer.hookName || 'Reducer'] = reducer.state;
50+
}
1951
return acc;
2052
}, {});
2153
};
@@ -29,8 +61,18 @@ const ToolTipDataDisplay = ({ data }) => {
2961
return null;
3062
}
3163

32-
if (isReducer) {
33-
const formattedData = formatReducerData(content);
64+
// Parse any stringified JSON before displaying
65+
const parsedContent = parseStringifiedValues(content);
66+
67+
if (isReducer && parsedContent) {
68+
// Only try to format if we have valid content
69+
const formattedData = formatReducerData(parsedContent);
70+
71+
// Check if we have any formatted data to display
72+
if (Object.keys(formattedData).length === 0) {
73+
return null;
74+
}
75+
3476
return (
3577
<div className='tooltip-section'>
3678
{Object.entries(formattedData).map(([hookName, state]) => (
@@ -49,17 +91,17 @@ const ToolTipDataDisplay = ({ data }) => {
4991
<div className='tooltip-section'>
5092
<div className='tooltip-section-title'>{title}</div>
5193
<div className='tooltip-data'>
52-
<JSONTree data={content} theme={jsonTheme} hideRoot shouldExpandNode={() => true} />
94+
<JSONTree data={parsedContent} theme={jsonTheme} hideRoot shouldExpandNode={() => true} />
5395
</div>
5496
</div>
5597
);
5698
};
5799

58100
return (
59101
<div className='tooltip-container'>
60-
{renderSection('Props', data.componentData.props)}
61-
{renderSection('State', data.componentData.state || data.componentData.hooksState)}
62-
{renderSection(null, data.componentData.reducerStates, true)}
102+
{renderSection('Props', data.componentData?.props)}
103+
{renderSection('State', data.componentData?.state || data.componentData?.hooksState)}
104+
{renderSection(null, data.componentData?.reducerStates, true)}
63105
</div>
64106
);
65107
};

0 commit comments

Comments
 (0)