Skip to content

Commit 61cbc29

Browse files
prov/con container complete
1 parent b2770d3 commit 61cbc29

File tree

1 file changed

+81
-68
lines changed

1 file changed

+81
-68
lines changed

src/app/containers/ProvConContainer.tsx

Lines changed: 81 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { color, width } from '@mui/system';
21
import React, {useState} from 'react';
32
import { ProvConContainerProps} from '../FrontendTypes';
43

54

65
const ProvConContainer = (props: ProvConContainerProps): JSX.Element => {
76

7+
//deconstruct props
88
const { currentSnapshot } = props;
99

10+
//parse through node
1011
const keepContextAndProviderNodes = (node) => {
1112
if (!node) return null;
1213

@@ -51,61 +52,6 @@ const ProvConContainer = (props: ProvConContainerProps): JSX.Element => {
5152
}));
5253
};
5354

54-
// // Recursive function to render nested objects
55-
// const renderNestedObject = (node, depth = 0) => {
56-
// const isExpanded = expandedNodes[node.name];
57-
58-
// return (
59-
// <div key={node.name} style={{ marginLeft: `${depth * 20}px` }}>
60-
// <p
61-
// onClick={() => toggleExpand(node.name)}
62-
// style={{
63-
// cursor: "pointer",
64-
// fontWeight: "bold",
65-
// textDecoration: "underline",
66-
// color: isExpanded ? "green" : "blue",
67-
// }}
68-
// >
69-
// {node.name}
70-
// </p>
71-
72-
// {isExpanded &&
73-
// node?.children?.[0]?.componentData?.context &&
74-
// node?.children?.[0]?.componentData?.props?.value && (
75-
// <div>
76-
// <p>
77-
// Context Property:{" "}
78-
// {JSON.stringify(
79-
// node.children[0].componentData.context
80-
// )}
81-
// </p>
82-
// <p>
83-
// Context Value:{" "}
84-
// {JSON.stringify(
85-
// node.children[0].componentData.props.value
86-
// )}
87-
// </p>
88-
// </div>
89-
// )}
90-
91-
// {/* Recursively render children */}
92-
// {isExpanded &&
93-
// node.children &&
94-
// node.children.map((child) =>
95-
// renderNestedObject(child, depth + 1)
96-
// )}
97-
// </div>
98-
// );
99-
// };
100-
const style = {
101-
whiteSpace: "normal", // Allow text to wrap
102-
overflowWrap: "break-word", // Break long words
103-
width: "300px", // Limit container width
104-
border: "1px solid black", // Optional: Visualize container
105-
padding: "10px", // Optional: Add padding
106-
};
107-
108-
10955
const renderNestedObject = (node, depth = 0) => {
11056
const isExpanded = expandedNodes[node.name];
11157

@@ -123,29 +69,96 @@ const ProvConContainer = (props: ProvConContainerProps): JSX.Element => {
12369
>
12470
{node.name}
12571
</p>
126-
12772
{/* Render HookState if it exists */}
12873
{isExpanded && node.componentData?.hooksState && (
12974
<div>
130-
{/* <h1 style={{fontWeight: "bold"}}>State:</h1> */}
131-
<p style={{ whiteSpace: "normal" , overflowWrap: "break-word", padding: "20px"}}>
132-
State: {JSON.stringify(node.componentData.hooksState)}
133-
</p>
75+
<h1 style={{fontWeight: "bold"}}>State: {'{}'}</h1>
76+
<ul>
77+
{Object.entries(node.componentData.hooksState).map(([key, value]) => (
78+
<li style={{ whiteSpace: "normal" , overflowWrap: "break-word", listStyleType: "none" }}>
79+
<strong>{key}:</strong> {typeof value === 'object'? JSON.stringify(value, null,2): value.toString()}
80+
</li>
81+
))}
82+
</ul>
13483
</div>
13584
)}
13685

13786
{/* Render Context Property if it exists */}
13887
{isExpanded && node.componentData?.context && Object.keys(node.componentData?.context).length !== 0 && (
139-
<p style={{ whiteSpace: "normal", overflowWrap: "break-word", padding: "20px"}}>
140-
Context Property: {JSON.stringify(node.componentData.context)}
141-
</p>
88+
<div>
89+
<h1 style={{fontWeight: "bold"}}>Context Property: {'{}'} </h1>
90+
<ul>
91+
{Object.entries(node.componentData.context).map(([key, value]) => {
92+
// Parse if the value is a JSON string
93+
let parsedValue = value;
94+
if (typeof value === "string") {
95+
try {
96+
parsedValue = JSON.parse(value);
97+
} catch {
98+
parsedValue = value; // Keep the original value if parsing fails
99+
}
100+
}
101+
return (
102+
<li key={key} style={{ whiteSpace: "normal", overflowWrap: "break-word", listStyleType: "none" }}>
103+
<strong>{key}:</strong>{" "}
104+
{typeof parsedValue === "object" && parsedValue !== null ? (
105+
<ul style={{ listStyleType: "none", paddingLeft: "1rem" }}>
106+
{Object.entries(parsedValue).map(([nestedKey, nestedValue]) => (
107+
<li key={nestedKey}>
108+
<strong>{nestedKey}:</strong> {nestedValue === null ? "null" : nestedValue.toString()}
109+
</li>
110+
))}
111+
</ul>
112+
) : (
113+
parsedValue === null ? "null" : parsedValue.toString()
114+
)}
115+
</li>
116+
);
117+
})}
118+
</ul>
119+
</div>
120+
142121
)}
143122

144123
{/* Render Context Value if it exists */}
145124
{isExpanded && node.componentData?.props?.value && (
146-
<p style={{ whiteSpace: "normal" , overflowWrap: "break-word", padding: "10px"}}>
147-
Context Value: {JSON.stringify(node.componentData.props.value)}
148-
</p>
125+
<div>
126+
<h1 style={{fontWeight: "bold"}}>Context Value: {'{}'}</h1>
127+
<ul>
128+
{(() => {
129+
try {
130+
const parsedValue = JSON.parse(node.componentData.props.value); // Parse the JSON string
131+
return Object.entries(parsedValue).map(([key, value]) => (
132+
<li key={key} style={{ whiteSpace: "normal", overflowWrap: "break-word", listStyleType: "none" }}>
133+
{/* <strong>{key}:</strong> {typeof value === 'object' ? JSON.stringify(value, null, 2) : value?.toString()} */}
134+
135+
<strong>{key}:</strong>{" "}
136+
{value === null ? (
137+
"null"
138+
) : typeof value === "object" ? (
139+
<ul style={{ listStyleType: "none", paddingLeft: "1rem" }}>
140+
{Object.entries(value).map(([nestedKey, nestedValue]) => (
141+
<li key={nestedKey}>
142+
<strong>{nestedKey}:</strong> {nestedValue === null ? "null" : nestedValue?.toString()}
143+
</li>
144+
))}
145+
</ul>
146+
) : (
147+
value?.toString()
148+
)}
149+
</li>
150+
));
151+
} catch (error) {
152+
return (
153+
<li style={{ color: "red" }}>
154+
Error parsing value: {error.message}
155+
</li>
156+
);
157+
}
158+
})()}
159+
</ul>
160+
</div>
161+
149162
)}
150163

151164
{/* Recursively Render Children */}
@@ -158,7 +171,7 @@ const ProvConContainer = (props: ProvConContainerProps): JSX.Element => {
158171

159172

160173
return (
161-
<div style={{ width: "260px"}}>
174+
<div style={{ width: "260px", marginLeft: "25px"}}>
162175
{renderNestedObject(contextProvidersOnly)}
163176
</div>
164177
);

0 commit comments

Comments
 (0)