1
1
// @ts -nocheck
2
2
import React from 'react' ;
3
3
import Action from '../components/Action' ;
4
+ import { diff , formatters } from "jsondiffpatch" ;
4
5
import SwitchAppDropdown from '../components/SwitchApp' ;
5
6
import { emptySnapshots , changeView , changeSlider } from '../actions/actions' ;
6
7
import { useStoreContext } from '../store' ;
@@ -15,13 +16,95 @@ const resetSlider = () => {
15
16
16
17
function ActionContainer ( props ) {
17
18
const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
18
- const { hierarchy, sliderIndex, viewIndex } = tabs [ currentTab ] ;
19
+ const { hierarchy, sliderIndex, viewIndex, snapshots } = tabs [ currentTab ] ;
19
20
const { toggleActionContainer, actionView, setActionView } = props ;
20
21
let actionsArr = [ ] ;
21
22
const hierarchyArr : any [ ] = [ ] ;
22
23
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
+ }
24
106
107
+ findDiff ( 2 ) ;
25
108
// function to traverse state from hiararchy and also getting information on display name and component name
26
109
const displayArray = ( obj : {
27
110
stateSnapshot : { children : any [ ] } ;
@@ -40,9 +123,9 @@ function ActionContainer(props) {
40
123
index : obj . index ,
41
124
displayName : `${ obj . name } .${ obj . branch } ` ,
42
125
state : obj . stateSnapshot . children [ 0 ] . state ,
43
- // componentName: obj.stateSnapshot.children[0].name,
126
+ componentName : obj . stateSnapshot . children [ 0 ] . name ,
44
127
// nathan testing new entries for component name, original above
45
- componentName : obj . stateSnapshot ,
128
+ // componentName: findDiff( obj.index) ,
46
129
componentData :
47
130
JSON . stringify ( obj . stateSnapshot . children [ 0 ] . componentData ) === '{}'
48
131
? ''
0 commit comments