Skip to content

Commit 077477a

Browse files
committed
commented diff back out bc i couldn't get it to load formatters correctly. Got pages to stop expanding infinitely by removing unstyled parent divs where possible. Got performance tab to render by commenting out the useEffect that is needed for the tutorial. Now have issue where sub-paths are not rendering, rather it pushes you back out to component map.
1 parent 7f25337 commit 077477a

File tree

7 files changed

+73
-191
lines changed

7 files changed

+73
-191
lines changed

src/app/components/Diff.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import { diff } from 'jsondiffpatch';
3-
const jsondiffpatch = require('jsondiffpatch')
2+
import { diff, formatters} from 'jsondiffpatch';
3+
const jsondiffpatch = require('jsondiffpatch');
44
import ReactHtmlParser from 'html-react-parser';
55
import { CurrentTab, DiffProps, MainState, RootState, StatelessCleaning } from '../FrontendTypes';
66
import { useSelector } from 'react-redux';
@@ -83,9 +83,9 @@ function Diff(props: DiffProps): JSX.Element {
8383

8484
const previousDisplay: StatelessCleaning = statelessCleaning(previous); // displays stateful data from the first snapshot that was taken before our current snapshot.
8585

86-
const delta: StatelessCleaning = diff(previousDisplay, snapshot); // diff function from 'jsondiffpatch' returns the difference in state between 'previousDisplay' and 'snapshot'
86+
const delta = diff(previousDisplay, snapshot); // diff function from 'jsondiffpatch' returns the difference in state between 'previousDisplay' and 'snapshot'
8787

88-
const html: StatelessCleaning = jsondiffpatch.formatters(delta, previousDisplay); // formatters function from 'jsondiffpatch' returns an html string that shows the difference between delta and the previousDisplay
88+
const html = jsondiffpatch.formatters.format(delta, previousDisplay); // formatters function from 'jsondiffpatch' returns an html string that shows the difference between delta and the previousDisplay
8989

9090
if (show)
9191
jsondiffpatch.formatters.showUnchanged(); // shows unchanged values if we're on the '/diffRaw' path

src/app/components/DiffRoute.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import { DiffRouteProps } from '../FrontendTypes';
1111
const DiffRoute = (props: DiffRouteProps): JSX.Element => (
1212
<div className='diff-container'>
1313
<div className='navbar'>
14-
<NavLink className='router-link' activeClassName='is-active' to='/'>
14+
<NavLink className='router-link' to='/'>
1515
Tree
1616
</NavLink>
17-
<NavLink className='router-link' activeClassName='is-active' to='/diffRaw'>
17+
<NavLink className='router-link' to='/diffRaw'>
1818
Raw
1919
</NavLink>
2020
</div>
2121
<Routes>
22-
<Route path='/diffRaw' element={() => <Diff snapshot={props.snapshot} show />} />
23-
<Route path='/' element={() => <Diff snapshot={props.snapshot} show={false} />} />
22+
<Route path='/diffRaw' element={<Diff snapshot={props.snapshot} show />} />
23+
<Route path='/' element={<Diff snapshot={props.snapshot} show={false} />} />
2424
</Routes>
2525
</div>
2626
);

src/app/components/StateRoute/PerformanceVisx/PerformanceVisx.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
195195

196196
getActions();
197197

198-
useEffect(() => {
199-
dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
200-
}, [dispatch]);
198+
// useEffect(() => {
199+
// dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
200+
// }, [dispatch]);
201201

202202
const allRoutes = []; // create allRoutes variable to hold urls
203203
const filteredSnapshots = [];
@@ -270,7 +270,7 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
270270

271271
<Routes>
272272
<Route
273-
path='comparison'
273+
path='/comparison'
274274
element={
275275
hierarchy && series !== false ? (
276276
<BarGraphComparison

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 36 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* eslint-disable max-len */
77
/* eslint-disable object-curly-newline */
88
import React from 'react';
9-
import { MemoryRouter as Router, Route, NavLink, Routes } from 'react-router-dom';
9+
import { MemoryRouter as Router, Route, NavLink, Routes, Outlet, Link } from 'react-router-dom';
1010
import { ParentSize } from '@visx/responsive';
1111
import Tree from './Tree';
1212
import ComponentMap from './ComponentMap/ComponentMap';
@@ -41,158 +41,15 @@ const StateRoute = (props: StateRouteProps) => {
4141
const hierarchy = propsHierarchy || tabsHierarchy; //JR: RETURN TO THIS: alias to deconstruct from props and tab with the same name, aliases were deleted above
4242
const viewIndex = propsViewIndex || tabsViewIndex;
4343

44-
// const renderComponentMap = () => {
45-
// if (hierarchy) {
46-
// // if hierarchy was initialized/created render the Map
47-
// return (
48-
// <ParentSize className='componentMapContainer'>
49-
// {({ width, height }) => (
50-
// // eslint-disable-next-line react/prop-types
51-
// <ComponentMap
52-
// currentSnapshot={currLocation.stateSnapshot}
53-
// width={width}
54-
// height={height}
55-
// />
56-
// )}
57-
// </ParentSize>
58-
// );
59-
// }
60-
// return <div className='noState'>{NO_STATE_MSG}</div>; // otherwise, inform the user that there has been no state change in the target/hooked application.
61-
// };
62-
63-
64-
65-
// const renderTree = () => {
66-
// if (hierarchy) {
67-
// // if a hierarchy has been created/initialized, render the appropriate tree based on the active snapshot
68-
// return <Tree snapshot={snapshot} snapshots={snapshots} currLocation={currLocation} />;
69-
// }
70-
// return <div className='noState'>{NO_STATE_MSG}</div>; // otherwise, inform the user that there has been no state change in the target/hooked application.
71-
// };
72-
73-
// let LCPColor: String;
74-
// let FIDColor: String;
75-
// let FCPColor: String;
76-
// let TTFBColor: String;
77-
// let CLSColor: String;
78-
// let INPColor: String;
79-
80-
// // adjust the strings that represent colors of the webmetrics performance bar for 'Largest Contentful Paint (LCP)', 'First Input Delay (FID)', 'First Contentfuly Paint (FCP)', 'Time to First Byte (TTFB)', 'Cumulative Layout Shift (CLS)', and 'Interaction to Next Paint (INP)' based on webMetrics outputs.
81-
// if (webMetrics.LCP <= 2500) LCPColor = '#0bce6b';
82-
// if (webMetrics.LCP > 2500 && webMetrics.LCP <= 4000) LCPColor = '#fc5a03';
83-
// if (webMetrics.LCP > 4000) LCPColor = '#fc2000';
84-
85-
// if (webMetrics.FID <= 100) FIDColor = '#0bce6b';
86-
// if (webMetrics.FID > 100 && webMetrics.FID <= 300) FIDColor = '#fc5a03';
87-
// if (webMetrics.FID > 300) FIDColor = '#fc2000';
88-
89-
// if (webMetrics.FCP <= 1800) FCPColor = '#0bce6b';
90-
// if (webMetrics.FCP > 1800 && webMetrics.FCP <= 3000) FCPColor = '#fc5a03';
91-
// if (webMetrics.FCP > 3000) FCPColor = '#fc2000';
92-
93-
// if (webMetrics.TTFB <= 800) TTFBColor = '#0bce6b';
94-
// if (webMetrics.TTFB > 800 && webMetrics.TTFB <= 1800) TTFBColor = '#fc5a03';
95-
// if (webMetrics.TTFB > 1800) TTFBColor = '#fc2000';
96-
97-
// if (webMetrics.CLS <= 0.1) CLSColor = '#0bce6b';
98-
// if (webMetrics.CLS > 0.1 && webMetrics.CLS <= 0.25) CLSColor = '#fc5a03';
99-
// if (webMetrics.CLS > 0.25) CLSColor = '#fc2000';
100-
101-
// if (webMetrics.INP <= 200) INPColor = '#0bce6b';
102-
// if (webMetrics.INP > 200 && webMetrics.INP <= 500) INPColor = '#fc5a03';
103-
// if (webMetrics.INP > 500) INPColor = '#fc2000';
104-
105-
// return (
106-
// <div className='web-metrics-container'>
107-
// <WebMetrics
108-
// color={LCPColor}
109-
// series={webMetrics.LCP ? [webMetrics.LCP / 70 < 100 ? webMetrics.LCP / 70 : 100] : 0}
110-
// formatted={(_) =>
111-
// typeof webMetrics.LCP !== 'number' ? '- ms' : `${webMetrics.LCP.toFixed(2)} ms`
112-
// }
113-
// score={['2500 ms', '4000 ms']}
114-
// overLimit={webMetrics.LCP > 7000}
115-
// label='Largest Contentful Paint'
116-
// name='Largest Contentful Paint'
117-
// description='Measures loading performance.'
118-
// />
119-
// <WebMetrics
120-
// color={FIDColor}
121-
// series={webMetrics.FID ? [webMetrics.FID / 5 < 100 ? webMetrics.FID / 5 : 100] : 0}
122-
// formatted={(_) =>
123-
// typeof webMetrics.FID !== 'number' ? '- ms' : `${webMetrics.FID.toFixed(2)} ms`
124-
// }
125-
// score={['100 ms', '300 ms']}
126-
// overLimit={webMetrics.FID > 500}
127-
// label='First Input Delay'
128-
// name='First Input Delay'
129-
// description='Measures interactivity.'
130-
// />
131-
// <WebMetrics
132-
// color={FCPColor}
133-
// series={webMetrics.FCP ? [webMetrics.FCP / 50 < 100 ? webMetrics.FCP / 50 : 100] : 0}
134-
// formatted={(_) =>
135-
// typeof webMetrics.FCP !== 'number' ? '- ms' : `${webMetrics.FCP.toFixed(2)} ms`
136-
// }
137-
// score={['1800 ms', '3000 ms']}
138-
// overLimit={webMetrics.FCP > 5000}
139-
// label='First Contentful Paint'
140-
// name='First Contentful Paint'
141-
// description='Measures the time it takes the browser to render the first piece of DOM content.'
142-
// />
143-
// <WebMetrics
144-
// color={TTFBColor}
145-
// series={webMetrics.TTFB ? [webMetrics.TTFB / 30 < 100 ? webMetrics.TTFB / 30 : 100] : 0}
146-
// formatted={(_) =>
147-
// typeof webMetrics.TTFB !== 'number' ? '- ms' : `${webMetrics.TTFB.toFixed(2)} ms`
148-
// }
149-
// score={['800 ms', '1800 ms']}
150-
// overLimit={webMetrics.TTFB > 3000}
151-
// label='Time To First Byte'
152-
// name='Time to First Byte'
153-
// description='Measures the time it takes for a browser to receive the first byte of page content.'
154-
// />
155-
// <WebMetrics
156-
// color={CLSColor}
157-
// series={webMetrics.CLS ? [webMetrics.CLS * 200 < 100 ? webMetrics.CLS * 200 : 100] : 0}
158-
// formatted={(_) =>
159-
// `CLS Score: ${
160-
// typeof webMetrics.CLS !== 'number'
161-
// ? 'N/A'
162-
// : `${webMetrics.CLS < 0.01 ? '~0' : webMetrics.CLS.toFixed(2)}`
163-
// }`
164-
// }
165-
// score={['0.1', '0.25']}
166-
// overLimit={webMetrics.CLS > 0.5}
167-
// label='Cumulative Layout Shift'
168-
// name='Cumulative Layout Shift'
169-
// description={`Quantifies the visual stability of a web page by measuring layout shifts during the application's loading and interaction.`}
170-
// />
171-
// <WebMetrics
172-
// color={INPColor}
173-
// series={webMetrics.INP ? [webMetrics.INP / 7 < 100 ? webMetrics.INP / 7 : 100] : 0}
174-
// formatted={(_) =>
175-
// typeof webMetrics.INP !== 'number' ? '- ms' : `${webMetrics.INP.toFixed(2)} ms`
176-
// }
177-
// score={['200 ms', '500 ms']}
178-
// overLimit={webMetrics.INP > 700}
179-
// label='Interaction to Next Paint'
180-
// name='Interaction to Next Paint'
181-
// description={`Assesses a page's overall responsiveness to user interactions by observing the latency of all click, tap, and keyboard interactions that occur throughout the lifespan of a user's visit to a page`}
182-
// />
183-
// </div>
184-
// );
185-
186-
18744
return (
18845
<div className='app-body'>
18946
<div className='navbar'>
19047
<NavLink to='/' className='router-link map-tab' end>
19148
Map
19249
</NavLink>
193-
<NavLink className='router-link performance-tab' to='performance'>
50+
<Link className='router-link performance-tab' to='/performance'>
19451
Performance
195-
</NavLink>
52+
</Link>
19653
<NavLink className='router-link history-tab' to='/history'>
19754
History
19855
</NavLink>
@@ -205,21 +62,7 @@ const StateRoute = (props: StateRouteProps) => {
20562
</div>
20663
<div className='app-content'>
20764
<Routes>
208-
<Route path='performance' element={hierarchy ?
209-
<ParentSize>
210-
{({ width, height }) => (
211-
<PerformanceVisx
212-
width={width}
213-
height={height}
214-
snapshots={snapshots}
215-
// note: is propdrilled within Performance Visx, but doesn't seem to be used
216-
changeSlider={changeSlider}
217-
changeView={changeView}
218-
hierarchy={hierarchy}
219-
/>
220-
)}
221-
</ParentSize> : <div className='noState'>{NO_STATE_MSG}</div>
222-
} />
65+
22366
<Route path='/history' element={ hierarchy ?
22467
<ParentSize>
22568
{({ width, height }) => (
@@ -236,20 +79,41 @@ const StateRoute = (props: StateRouteProps) => {
23679
/>
23780
)}
23881
</ParentSize> : <div className='noState'>{NO_STATE_MSG}</div>} />
82+
<Route path='/performance/*' element={hierarchy ?
83+
<div style={{height: "100%"}}>
84+
<ParentSize className='performanceContainer'>
85+
{({ width, height }) => (
86+
<PerformanceVisx
87+
width={width}
88+
height={height}
89+
snapshots={snapshots}
90+
// note: is propdrilled within Performance Visx, but doesn't seem to be used
91+
changeSlider={changeSlider}
92+
changeView={changeView}
93+
hierarchy={hierarchy}
94+
/>
95+
)}
96+
</ParentSize>
97+
<Outlet/>
98+
</div>
99+
: <div className='noState'>{NO_STATE_MSG}</div>
100+
} />
239101
<Route path='/webMetrics' element={<WebMetricsContainer webMetrics={webMetrics} />} />
240102
<Route path='/tree' element={<Tree snapshot={snapshot} snapshots={snapshots} currLocation={currLocation} />} />
241-
<Route path='*' element={hierarchy ? <div>
242-
{/* <ParentSize className='componentMapContainer'>
243-
{({ width, height }) => (
244-
// eslint-disable-next-line react/prop-types */}
245-
<ComponentMap
103+
<Route path='*' element={hierarchy ?
104+
<ParentSize className='componentMapContainer'>
105+
{({ width, height }) => {
106+
// eslint-disable-next-line react/prop-types
107+
const maxHeight: number = 1200;
108+
const h = Math.min(height, maxHeight)
109+
return (<ComponentMap
246110
currentSnapshot={currLocation.stateSnapshot}
247-
// width={width}
248-
// height={height}
249-
/>
250-
{/* )} */}
251-
{/* </ParentSize> */}
252-
</div> : null} />
111+
width={width}
112+
height={h}
113+
/>)
114+
}}
115+
</ParentSize>
116+
: null} />
253117
</Routes>
254118
</div>
255119
</div>

src/app/containers/StateContainer.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
2222

2323
return (
2424
<div className='state-container'>
25-
<div className='main-navbar-container'>
25+
{/* <div className='main-navbar-container'>
2626
<div className='main-navbar-text' />
2727
<div className='main-navbar'>
2828
<NavLink className='main-router-link' to='/'>
@@ -34,10 +34,15 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
3434
</div>
3535
</div>
3636
<Routes>
37-
<Route path='/diff' element={<DiffRoute snapshot={snapshot} />} />
37+
<Route path='/diff/*' element={
38+
<div>
39+
<DiffRoute snapshot={snapshot} />
40+
<Outlet/>
41+
</div>} />
3842
<Route
39-
path='/'
40-
element={
43+
path='*'
44+
element={
45+
<div>*/}
4146
<StateRoute
4247
webMetrics={webMetrics}
4348
viewIndex={viewIndex}
@@ -46,9 +51,11 @@ const StateContainer = (props: StateContainerProps): JSX.Element => {
4651
snapshots={snapshots}
4752
currLocation={currLocation}
4853
/>
49-
}
54+
<Outlet/>
55+
{/*</div>
56+
}
5057
/>
51-
</Routes>
58+
</Routes> */}
5259
</div>
5360
);
5461
};

src/app/jsondiffpatch.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'jsondiffpatch/formatters/html' {
2+
export * as formatters from 'jsondiffpatch/lib/formatters/html';
3+
}

src/app/styles/layout/_stateContainer.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
align-items: center;
114114
height: 30px;
115115
position: sticky;
116-
top: 40px; //JR 12.16.23 @12:15pm: this hardcoding is not best practice, should revisit to figure out a more dynamic way of sticking the navbar to the bottom of the main-navbar
116+
top: 0px; //JR 12.16.23 @12:15pm: this hardcoding is not best practice, should revisit to figure out a more dynamic way of sticking the navbar to the bottom of the main-navbar
117117
left: 0px;
118118
z-index: 1;
119119
@extend %disable-highlight;
@@ -249,3 +249,11 @@
249249
.tooltipData-JSONTree::-webkit-scrollbar-track {
250250
background: #51565e;
251251
}
252+
253+
.app-body {
254+
height: 100%;
255+
}
256+
257+
.app-content {
258+
height: 100%;
259+
}

0 commit comments

Comments
 (0)