Skip to content

Commit 4d5b562

Browse files
passed props to ProvConTainer
1 parent da3451c commit 4d5b562

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

src/app/FrontendTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ export interface ActionContainerProps {
108108
actionView: boolean;
109109
setActionView: React.Dispatch<React.SetStateAction<boolean>>;
110110
toggleActionContainer: () => void;
111+
snapshots: any
112+
currLocation: any
113+
}
114+
115+
export interface ProvConContainerProps {
116+
currentSnapshot: any;
111117
}
112118

113119
export interface StateContainerProps {

src/app/containers/ActionContainer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
3636
const {
3737
toggleActionContainer, // function that handles Time Jump Sidebar view from MainContainer
3838
actionView, // local state declared in MainContainer
39-
setActionView, // function to update actionView state declared in MainContainer
39+
setActionView, // function to update actionView state declared in MainContainer,
40+
snapshots,
4041
} = props;
4142
const [recordingActions, setRecordingActions] = useState(true); // We create a local state 'recordingActions' and set it to true
4243
let actionsArr: JSX.Element[] = []; // we create an array 'actionsArr' that will hold elements we create later on
@@ -248,7 +249,8 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
248249
Clear
249250
</Button>
250251
</div>
251-
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
252+
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer currentSnapshot={currLocation.stateSnapshot}
253+
/>}
252254
{dropdownSelection === 'TimeJump' &&
253255
Object.keys(routes).map((route, i) => (
254256
<RouteDescription key={`route${i}`} actions={routes[route]} />

src/app/containers/MainContainer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ function MainContainer(): JSX.Element {
212212
actionView={actionView}
213213
setActionView={setActionView}
214214
toggleActionContainer={toggleActionContainer}
215+
snapshots={snapshots}
216+
currLocation={currLocation}
215217
/>
216218
{/* @ts-ignore */}
217219
{snapshots.length ? (
Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,90 @@
1-
import React from "react";
1+
import { width } from '@mui/system';
2+
import React, {useState} from 'react';
3+
import { ProvConContainerProps} from '../FrontendTypes';
24

3-
const ProvConContainer = (): JSX.Element => {
4-
return (
5-
<div>
6-
hello
5+
6+
const ProvConContainer = (props: ProvConContainerProps): JSX.Element => {
7+
8+
const { currentSnapshot } = props
9+
10+
console.log('currentSnapshot', currentSnapshot)
11+
12+
const keepContextAndProviderNodes = (node) => {
13+
if (!node) return null;
14+
15+
// Check if this node should be kept
16+
const hasContext =
17+
node?.componentData?.context && Object.keys(node.componentData.context).length > 0;
18+
const isProvider = node?.name && node.name.endsWith('Provider');
19+
const shouldKeepNode = hasContext || isProvider;
20+
21+
// Process children first
22+
let processedChildren = [];
23+
if (node.children) {
24+
processedChildren = node.children
25+
.map((child) => keepContextAndProviderNodes(child))
26+
.filter(Boolean); // Remove null results
27+
}
28+
29+
// If this node should be kept or has kept children, return it
30+
if (shouldKeepNode || processedChildren.length > 0) {
31+
return {
32+
...node,
33+
children: processedChildren,
34+
};
35+
}
36+
37+
// If neither the node should be kept nor it has kept children, filter it out
38+
return null;
39+
};
40+
const contextProvidersOnly = keepContextAndProviderNodes(currentSnapshot);
41+
console.log('context only', contextProvidersOnly)
42+
43+
const [visibleKeys, setVisibleKeys] = useState({});
44+
45+
const toggleInfo = (key:string) => {
46+
setVisibleKeys((prev) => ({
47+
...prev, //copies all current keys and their visibility from prev object
48+
[key]: !prev[key] // adds or updates the key in the visibleKeys object.
49+
}))
50+
};
51+
const someInfo = {
52+
ThemeProvider: {
53+
UserProvider: {
54+
UserContext: 'some info herecdxjchffhdjhfdfdfhdjhfdjhfdjhfvhhhh',
55+
},
56+
ThemeContext1: {
57+
Nested: 'some info here'},
58+
ThemeConext2: 'some info here'
59+
},
60+
}
61+
62+
63+
// Recursive function to render nested objects
64+
const renderNestedObjec = (obj, parentKey = '') => { //parentKey is unique keys that represent the hierarchy of the object.
65+
return Object.keys(obj).map((key) => {
66+
const fullKey = parentKey ? `${parentKey}.${key}` : key; // if parentKey does not exisit --> fullKey = key, else fullKey=ParentKey.Key
67+
return (
68+
// each key is rendered as a div
69+
<div key={fullKey} style={{width: '100%', backgroundColor: 'red'}} >
70+
<div
71+
style={{ color: 'blue', cursor: 'pointer' }}
72+
onClick={() => toggleInfo(fullKey)} // Pass the unique key to toggle visibility
73+
>
74+
<strong>{key}</strong>
75+
</div>
76+
{visibleKeys[fullKey] && // Check if the key is visible
77+
(typeof obj[key] === 'object' //check if the value of the key is an object
78+
? renderNestedObjec(obj[key], fullKey) // Recursive rendering for nested objects
79+
//if value is not an object
80+
: <div >{obj[key]}</div>)}
781
</div>
8-
)
9-
}
82+
);
83+
});
84+
};
85+
86+
return <div style={{width: '100%'}}>{renderNestedObjec(someInfo)}</div>;
87+
};
88+
1089

1190
export default ProvConContainer;

0 commit comments

Comments
 (0)