@@ -4,6 +4,8 @@ import RenderingFrequency from './RenderingFrequency';
4
4
import FormControlLabel from '@material-ui/core/FormControlLabel' ;
5
5
import Switch from '@material-ui/core/Switch' ;
6
6
import BarGraph from './BarGraph' ;
7
+ import { save } from '../actions/actions' ;
8
+ import { useStoreContext } from '../store' ;
7
9
8
10
/* NOTES
9
11
Issue - Not fully compatible with recoil apps. Reference the recoil-todo-test.
@@ -26,39 +28,42 @@ interface BarStackProps {
26
28
/* DATA HANDLING HELPER FUNCTIONS */
27
29
const traverse = ( snapshot , data , currTotalRender = 0 ) => {
28
30
if ( ! snapshot . children [ 0 ] ) return ;
29
-
31
+ console . log ( 'data in PerformanceVisx >>>' , data ) ;
30
32
// loop through snapshots
31
33
snapshot . children . forEach ( ( child , idx ) => {
32
34
const componentName = child . name + - [ idx + 1 ] ;
33
35
34
36
// Get component Rendering Time
35
- const renderTime = Number ( Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 ) ) ;
37
+ const renderTime = Number (
38
+ Number . parseFloat ( child . componentData . actualDuration ) . toPrecision ( 5 )
39
+ ) ;
36
40
// sums render time for all children
37
41
currTotalRender += renderTime ;
38
- // components as keys and set the value to their rendering time
39
- data [ 'barStack' ] [ data . barStack . length - 1 ] [ componentName ] = renderTime ;
40
-
42
+ // components as keys and set the value to their rendering time
43
+ data [ 'barStack' ] [ data . barStack . length - 1 ] [ componentName ] = renderTime ;
44
+
41
45
// Get component stateType
42
46
if ( ! data . componentData [ componentName ] ) {
43
47
data . componentData [ componentName ] = {
44
48
stateType : 'stateless' ,
45
49
renderFrequency : 0 ,
46
50
totalRenderTime : 0 ,
47
- rtid : ''
51
+ rtid : '' ,
48
52
} ;
49
- if ( child . state !== 'stateless' ) data . componentData [ componentName ] . stateType = 'stateful' ;
53
+ if ( child . state !== 'stateless' )
54
+ data . componentData [ componentName ] . stateType = 'stateful' ;
50
55
}
51
56
// increment render frequencies
52
57
if ( renderTime > 0 ) {
53
58
data . componentData [ componentName ] . renderFrequency ++ ;
54
59
}
55
60
56
- // add to total render time
61
+ // add to total render time
57
62
data . componentData [ componentName ] . totalRenderTime += renderTime ;
58
- // Get rtid for the hovering feature
63
+ // Get rtid for the hovering feature
59
64
data . componentData [ componentName ] . rtid = child . rtid ;
60
65
traverse ( snapshot . children [ idx ] , data , currTotalRender ) ;
61
- } )
66
+ } ) ;
62
67
// reassigns total render time to max render time
63
68
data . maxTotalRender = Math . max ( currTotalRender , data . maxTotalRender ) ;
64
69
return data ;
@@ -67,7 +72,7 @@ const traverse = (snapshot, data, currTotalRender = 0) => {
67
72
const getSnapshotIds = ( obj , snapshotIds = [ ] ) : string [ ] => {
68
73
snapshotIds . push ( `${ obj . name } .${ obj . branch } ` ) ;
69
74
if ( obj . children ) {
70
- obj . children . forEach ( child => {
75
+ obj . children . forEach ( ( child ) => {
71
76
getSnapshotIds ( child , snapshotIds ) ;
72
77
} ) ;
73
78
}
@@ -82,44 +87,66 @@ const getPerfMetrics = (snapshots, snapshotsIds): {} => {
82
87
maxTotalRender : 0 ,
83
88
} ;
84
89
snapshots . forEach ( ( snapshot , i ) => {
85
- perfData . barStack . push ( { snapshotId : snapshotsIds [ i ] } ) ;
90
+ perfData . barStack . push ( { snapshotId : snapshotsIds [ i ] } ) ;
86
91
traverse ( snapshot , perfData ) ;
87
92
} ) ;
88
93
return perfData ;
89
94
} ;
90
-
95
+
96
+ // interface saveData {
97
+ // snapshots: [];
98
+ // }
99
+
91
100
/* EXPORT COMPONENT */
92
101
const PerformanceVisx = ( props : BarStackProps ) => {
93
102
// hook used to dispatch onhover action in rect
94
103
const { width, height, snapshots, hierarchy } = props ;
95
104
105
+ // const [dispatch] = useStoreContext();
106
+ const [ { tabs, currentTab } , dispatch ] = useStoreContext ( ) ;
107
+
108
+ console . log ( 'tabs' , tabs )
109
+ console . log ( 'currentTabs' , currentTab )
110
+
96
111
const [ isToggled , setIsToggled ] = useState ( 'barStack' ) ;
97
112
const toggleView = ( ) => {
98
- isToggled === 'frequencyCards' ? setIsToggled ( 'barStack' ) : setIsToggled ( 'frequencyCards' ) ;
99
- }
113
+ isToggled === 'frequencyCards'
114
+ ? setIsToggled ( 'barStack' )
115
+ : setIsToggled ( 'frequencyCards' ) ;
116
+ } ;
117
+
100
118
// filter and structure incoming data for VISX
101
119
const data = getPerfMetrics ( snapshots , getSnapshotIds ( hierarchy ) ) ;
102
-
103
- // if performance tab is too small it will not return VISX component
104
- return (
105
- < div className = 'renderTab' >
106
- < FormControlLabel style = { { "margin-left" :"30px" , "margin-top" : "0px" } }
120
+
121
+ const toStorage = {
122
+ currentTab,
123
+ title : tabs [ currentTab ] [ 'title' ] ,
124
+ data,
125
+ }
126
+
127
+ // Extract individual data from chrome.locals.storage and visualize
128
+ // Need to setup dropdown menu . Fill dropdown with tabsID (sessions)
129
+ // When you select dropdown, change view with ReactRouter
130
+ // have side-by-side comparison with visx bargraphs in alternate view
131
+
132
+ // if performance tab is too small it will not return VISX component
133
+ return (
134
+ < div className = "renderTab" >
135
+ < FormControlLabel
136
+ style = { { 'margin-left' : '30px' , 'margin-top' : '0px' } }
107
137
control = {
108
- < Switch
109
- onChange = { toggleView }
110
- name = "checkedB"
111
- color = "primary"
112
- />
138
+ < Switch onChange = { toggleView } name = "checkedB" color = "primary" />
113
139
}
114
140
label = "Component Details"
115
141
/>
116
- { /* <button onClick={toggleView}>Toggle Button</button> */ }
117
- < div style = { { "display" : "flex" , "justify-content" : "center" } } >
118
- { isToggled === 'frequencyCards'
119
- ? < RenderingFrequency data = { data . componentData } />
120
- : < BarGraph data = { data } width = { width } height = { height } />
121
- }
122
- </ div >
142
+ < button onClick = { ( ) => dispatch ( save ( toStorage ) ) } > Save Series</ button >
143
+ < div style = { { display : 'flex' , 'justify-content' : 'center' } } >
144
+ { isToggled === 'frequencyCards' ? (
145
+ < RenderingFrequency data = { data . componentData } />
146
+ ) : (
147
+ < BarGraph data = { data } width = { width } height = { height } />
148
+ ) }
149
+ </ div >
123
150
</ div >
124
151
) ;
125
152
} ;
0 commit comments