Skip to content

Commit 7fc201f

Browse files
added in delta functions in actionContainer
1 parent de5fbb5 commit 7fc201f

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

src/app/containers/ActionContainer.tsx

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-nocheck
22
import React from 'react';
33
import Action from '../components/Action';
4+
import { diff, formatters } from "jsondiffpatch";
45
import SwitchAppDropdown from '../components/SwitchApp';
56
import { emptySnapshots, changeView, changeSlider } from '../actions/actions';
67
import { useStoreContext } from '../store';
@@ -15,13 +16,95 @@ const resetSlider = () => {
1516

1617
function ActionContainer(props) {
1718
const [{ tabs, currentTab }, dispatch] = useStoreContext();
18-
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
19+
const { hierarchy, sliderIndex, viewIndex, snapshots } = tabs[currentTab];
1920
const { toggleActionContainer, actionView, setActionView } = props;
2021
let actionsArr = [];
2122
const hierarchyArr: any[] = [];
2223

23-
24+
function findDiff(index) {
25+
const statelessCleanning = (obj: {
26+
name?: string;
27+
componentData?: object;
28+
state?: string | any;
29+
stateSnaphot?: object;
30+
children?: any[];
31+
}) => {
32+
const newObj = { ...obj };
33+
if (newObj.name === "nameless") {
34+
delete newObj.name;
35+
}
36+
if (newObj.componentData) {
37+
delete newObj.componentData;
38+
}
39+
if (newObj.state === "stateless") {
40+
delete newObj.state;
41+
}
42+
if (newObj.stateSnaphot) {
43+
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
44+
}
45+
if (newObj.children) {
46+
newObj.children = [];
47+
if (obj.children.length > 0) {
48+
obj.children.forEach(
49+
(element: { state?: object | string; children?: [] }) => {
50+
if (
51+
element.state !== "stateless" ||
52+
element.children.length > 0
53+
) {
54+
const clean = statelessCleanning(element);
55+
newObj.children.push(clean);
56+
}
57+
}
58+
);
59+
}
60+
}
61+
// nathan test
62+
return newObj;
63+
};
64+
// displays stateful data
65+
//console.log("snapshots: ", snapshots);
66+
const previousDisplay = statelessCleanning(snapshots[index - 1]);
67+
//const currentDisplay = statelessCleanning(snapshots[index]);
68+
//console.log("AC previos display: ", previousDisplay);
69+
// diff function returns a comparison of two objects, one has an updated change
70+
// just displays stateful data
71+
const delta = diff(previousDisplay, snapshots[index]);
72+
console.log("AC delta", delta);
73+
// return delta
74+
const changedState = findStateChangeObj(delta);
75+
//const previousDisplayState = findStateChangeObj(previousDisplay);
76+
//return formatDeltaPopUp(changedState, previousDisplayState);
77+
console.log('AC Changed State: ', changedState);
78+
return changedState;
79+
}
80+
81+
// function findStateChangeObj2(delta, changedState = []) {
82+
// while (delta.children) {
83+
// Object.keys(delta.children).forEach((child) => {
84+
// if (child.state && child.state[0] !== "stateless") {
85+
// console.log('stateful child: ', child);
86+
// changedState.push(child.state);
87+
// }
88+
// return changedState.push(findStateChangeObj2(child, changedState));
89+
// });
90+
// }
91+
// return changedState;
92+
// }
93+
94+
function findStateChangeObj(delta, changedState = []) {
95+
96+
if (!delta.children) {
97+
// console.log('snapshot', snapshot);
98+
return changedState;
99+
}
100+
if (delta.state && delta.state[0] !== 'stateless') {
101+
changedState.push(delta.state);
102+
}
103+
// console.log('snapshot outside if', snapshot);
104+
return findStateChangeObj(delta.children[0], changedState);
105+
}
24106

107+
findDiff(2);
25108
// function to traverse state from hiararchy and also getting information on display name and component name
26109
const displayArray = (obj: {
27110
stateSnapshot: { children: any[] };
@@ -40,9 +123,9 @@ function ActionContainer(props) {
40123
index: obj.index,
41124
displayName: `${obj.name}.${obj.branch}`,
42125
state: obj.stateSnapshot.children[0].state,
43-
// componentName: obj.stateSnapshot.children[0].name,
126+
componentName: obj.stateSnapshot.children[0].name,
44127
// nathan testing new entries for component name, original above
45-
componentName: obj.stateSnapshot,
128+
//componentName: findDiff(obj.index),
46129
componentData:
47130
JSON.stringify(obj.stateSnapshot.children[0].componentData) === '{}'
48131
? ''

0 commit comments

Comments
 (0)