Skip to content

Commit 22f9055

Browse files
committed
moved all information into one tool tip display
1 parent 788104d commit 22f9055

File tree

3 files changed

+52
-93
lines changed

3 files changed

+52
-93
lines changed

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -514,25 +514,11 @@ export default function ComponentMap({
514514
}}
515515
>
516516
<div>
517-
<div>
518-
<strong>{tooltipData.name}</strong>
517+
<div className='tooltip-header'>
518+
<h3 className='tooltip-title'>{tooltipData.name}</h3>
519519
</div>
520520
<div>
521-
<ToolTipDataDisplay containerName='Props' dataObj={tooltipData.componentData.props} />
522-
<ToolTipDataDisplay
523-
containerName='State'
524-
dataObj={
525-
tooltipData.componentData.state || // for class components
526-
tooltipData.componentData.hooksState // for functional components
527-
}
528-
/>
529-
{/* Add this new container for reducer state */}
530-
{tooltipData.componentData.reducerStates && (
531-
<ToolTipDataDisplay
532-
containerName='Reducers'
533-
dataObj={tooltipData.componentData.reducerStates}
534-
/>
535-
)}
521+
<ToolTipDataDisplay data={tooltipData} />
536522
</div>
537523
</div>
538524
</TooltipInPortal>

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

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,65 @@
11
import React from 'react';
22
import { JSONTree } from 'react-json-tree';
33

4-
const ToolTipDataDisplay = ({ containerName, dataObj }) => {
5-
if (
6-
!dataObj ||
7-
(Array.isArray(dataObj) && dataObj.length === 0) ||
8-
Object.keys(dataObj).length === 0
9-
) {
10-
return null;
11-
}
4+
const ToolTipDataDisplay = ({ data }) => {
5+
if (!data) return null;
6+
7+
const jsonTheme = {
8+
scheme: 'custom',
9+
base00: 'transparent',
10+
base0B: '#14b8a6', // Teal for strings
11+
base0D: '#60a5fa', // Blue for keys
12+
base09: '#f59e0b', // Orange for numbers
13+
base0C: '#EF4444', // red for nulls
14+
};
1215

1316
const formatReducerData = (reducerStates) => {
14-
// Transform the array of reducers into an object with hook names as keys
1517
return reducerStates.reduce((acc, reducer) => {
16-
// Use the hookName as the key and only include the state
1718
acc[reducer.hookName || 'Reducer'] = reducer.state;
1819
return acc;
1920
}, {});
2021
};
2122

22-
const renderValue = (value) => {
23-
if (typeof value === 'object' && value !== null) {
24-
return (
25-
<JSONTree
26-
data={value}
27-
theme={{
28-
scheme: 'custom',
29-
base00: 'transparent',
30-
base0B: '#14b8a6', // Teal for strings
31-
base0D: '#60a5fa', // Blue for keys
32-
base09: '#f59e0b', // Orange for numbers
33-
base0C: '#EF4444', // red for nulls
34-
}}
35-
hideRoot
36-
shouldExpandNode={() => true}
37-
/>
38-
);
23+
const renderSection = (title, content, isReducer = false) => {
24+
if (
25+
!content ||
26+
(Array.isArray(content) && content.length === 0) ||
27+
Object.keys(content).length === 0
28+
) {
29+
return null;
3930
}
40-
return <span className='tooltip-value'>{String(value)}</span>;
41-
};
4231

43-
const renderContent = () => {
44-
if (containerName === 'Reducers') {
45-
const formattedData = formatReducerData(dataObj);
32+
if (isReducer) {
33+
const formattedData = formatReducerData(content);
4634
return (
47-
<div className='tooltip-content'>
35+
<div className='tooltip-section'>
4836
{Object.entries(formattedData).map(([hookName, state]) => (
49-
<div key={hookName} className='tooltip-reducer-item'>
50-
<div className='tooltip-reducer-name'>{hookName}</div>
51-
<div className='tooltip-reducer-state'>{renderValue(state)}</div>
37+
<div key={hookName}>
38+
<div className='tooltip-section-title'>{hookName}</div>
39+
<div className='tooltip-data'>
40+
<JSONTree data={state} theme={jsonTheme} hideRoot shouldExpandNode={() => true} />
41+
</div>
5242
</div>
5343
))}
5444
</div>
5545
);
5646
}
5747

5848
return (
59-
<div className='tooltip-content'>
60-
{Object.entries(dataObj).map(([key, value]) => (
61-
<div key={key} className='tooltip-item'>
62-
<div className='tooltip-data'>
63-
<span className='tooltip-key'>{key}</span>
64-
{renderValue(value)}
65-
</div>
66-
</div>
67-
))}
49+
<div className='tooltip-section'>
50+
<div className='tooltip-section-title'>{title}</div>
51+
<div className='tooltip-data'>
52+
<JSONTree data={content} theme={jsonTheme} hideRoot shouldExpandNode={() => true} />
53+
</div>
6854
</div>
6955
);
7056
};
7157

7258
return (
7359
<div className='tooltip-container'>
74-
<div className='tooltip-header'>
75-
<h3 className='tooltip-title'>{containerName}</h3>
76-
</div>
77-
{renderContent()}
60+
{renderSection('Props', data.componentData.props)}
61+
{renderSection('State', data.componentData.state || data.componentData.hooksState)}
62+
{renderSection(null, data.componentData.reducerStates, true)}
7863
</div>
7964
);
8065
};

src/app/styles/layout/_stateContainer.scss

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
// tool tip styles
102102
.tooltip-container {
103103
width: 300px;
104-
background-color: #1f2937;
104+
background-color: #111827;
105105
border-radius: 8px;
106106
box-shadow:
107107
0 4px 6px -1px rgba(0, 0, 0, 0.1),
@@ -112,47 +112,41 @@
112112
margin: 4px 0;
113113
}
114114

115-
.tooltip-header {
115+
.tooltip-section {
116116
padding: 12px 16px;
117-
background-color: #111827;
118117
border-bottom: 1px solid rgba(107, 114, 128, 0.2);
119118
}
120119

121-
.tooltip-title {
122-
margin: 0;
123-
font-size: 16px;
120+
.tooltip-section:last-child {
121+
border-bottom: none;
122+
}
123+
124+
.tooltip-section-title {
125+
font-size: 14px;
124126
font-weight: 500;
125-
color: #f9fafb;
127+
color: #14b8a6;
128+
margin-bottom: 8px;
126129
}
127130

128131
.tooltip-content {
129132
max-height: 400px;
130133
overflow-y: auto;
131134
}
132135

133-
/* Reducer specific styling */
134-
.tooltip-reducer-item {
135-
padding: 12px 16px;
136-
border-bottom: 1px solid rgba(107, 114, 128, 0.2);
136+
.tooltip-item {
137+
padding: 8px 0;
138+
border-bottom: 1px solid rgba(107, 114, 128, 0.1);
137139
}
138140

139-
.tooltip-reducer-item:last-child {
141+
.tooltip-item:last-child {
140142
border-bottom: none;
141143
}
142144

143-
.tooltip-reducer-name {
144-
font-size: 14px;
145-
font-weight: 500;
146-
color: #14b8a6;
147-
margin-bottom: 8px;
148-
}
149-
150-
.tooltip-reducer-state {
145+
.tooltip-data {
151146
padding-left: 12px;
152147
border-left: 2px solid rgba(20, 184, 166, 0.4);
153148
}
154149

155-
/* Scrollbar styling */
156150
.tooltip-content::-webkit-scrollbar {
157151
width: 4px;
158152
}
@@ -178,9 +172,3 @@
178172
margin: 0 !important;
179173
padding-left: 16px !important;
180174
}
181-
182-
.tooltip-value {
183-
font-size: 14px;
184-
color: #e5e7eb;
185-
word-break: break-word;
186-
}

0 commit comments

Comments
 (0)