Skip to content

Commit 02d35b4

Browse files
morahgeistbrok3turtl3yididiaketema
committed
mg merged with dev, to merge MUI changes into dev
Co-authored-by: Sean Kelly <[email protected]> Co-authored-by: yididiaketema <[email protected]>
2 parents f182b8f + 72f3d63 commit 02d35b4

26 files changed

+424
-359
lines changed

src/app/components/Action.tsx

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
2929
const Action = (props: ActionProps): JSX.Element => {
3030
// We destructure the 'props' that were passed into this component
3131
const {
32-
selected,
33-
last,
34-
index,
35-
sliderIndex,
32+
selected, // boolean on whether the current index is the same as the viewIndex from 'ActionContainer'
33+
last, // boolean on (whether the view index is less than 0) AND if (the index is the same as the last snapshot's index value in hierarchyArr) from 'ActionContainer'
34+
index, // from snapshot.index in "ActionContainer's" 'hierarchyArr'
35+
sliderIndex, // from tabs[currentTab] object from 'ActionContainer'
3636
dispatch,
37-
displayName,
38-
componentData,
39-
viewIndex,
37+
displayName, // from snapshot.displayName in "ActionContainer's" 'hierarchyArr'
38+
componentData, // from snapshot.componentData in "ActionContainer's" 'hierarchyArr'
39+
viewIndex, // from tabs[currentTab] object from 'ActionContainer'
4040
isCurrIndex,
41-
handleOnkeyDown,
41+
handleOnkeyDown, // function that allows arrows keys to jump between snapshots defined in 'ActionContainer.tsx'
4242
} = props;
4343

4444
/**
@@ -48,56 +48,42 @@ const Action = (props: ActionProps): JSX.Element => {
4848

4949

5050
const cleanTime = (): string => {
51-
// if there is no 'componentData' or 'componentData.actualDuration' return "NO TIME"
52-
if (!componentData || !componentData.actualDuration) {
51+
if (!componentData || !componentData.actualDuration) { // if there is no 'componentData' or 'componentData.actualDuration'
5352
return 'NO TIME';
5453
}
5554

56-
// seconds is undefined but can take a number or a string
57-
let seconds: number | string;
58-
// milliseconds is of any type and taken from the 'componentData.actualDuration'
59-
let milliseconds: any = componentData.actualDuration;
60-
61-
// if the milliseconds is greater than 60
62-
if (Math.floor(componentData.actualDuration) > 60) {
63-
// we divide our milliseconds by 60 to determine our seconds
64-
seconds = Math.floor(componentData.actualDuration / 60);
65-
// and we convert our seconds into a string
66-
seconds = JSON.stringify(seconds);
67-
// if the seconds string is only a single digit
68-
if (seconds.length < 2) {
69-
// we can add a 0 in front of it so that if 'seconds = "1"' it will come out as 'seconds = "01"'
70-
seconds = '0'.concat(seconds);
71-
}
72-
// Our true milliseconds then becomes the remainder of dividing our initial milliseconds by 60
73-
milliseconds = Math.floor(componentData.actualDuration % 60);
55+
let seconds: number | string; // seconds is undefined but can take a number or a string
56+
let milliseconds: any = componentData.actualDuration; // milliseconds is of any type and taken from the 'componentData.actualDuration'
57+
58+
if (Math.floor(componentData.actualDuration) > 60) { // if the milliseconds is greater than 60
59+
seconds = Math.floor(componentData.actualDuration / 60); // we divide our milliseconds by 60 to determine our seconds
60+
seconds = JSON.stringify(seconds); // and we convert our seconds into a string
61+
62+
if (seconds.length < 2) { // if the seconds string is only a single digit
63+
seconds = '0'.concat(seconds); // we can add a 0 in front of it so that if 'seconds = "1"' it will come out as 'seconds = "01"'
64+
}
65+
milliseconds = Math.floor(componentData.actualDuration % 60); // Our true milliseconds then becomes the remainder of dividing our initial milliseconds by 60
66+
7467
} else {
75-
// if we haven't even reached one second yet, our seconds are 00
76-
seconds = '00';
68+
seconds = '00'; // if we haven't even reached one second yet, our seconds are 00
7769
}
7870

79-
// we convert our milliseconds string into a floating point number that has up to two decimal places.
80-
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2);
71+
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2); // we convert our milliseconds string into a floating point number that has up to two decimal places.
72+
const arrayMilliseconds: string | number = milliseconds.split('.'); // we split our milliseconds using the decimal and come out with an array of two numbers
8173

82-
// we split our milliseconds using the decimal and come out with an array of two numbers
83-
const arrayMilliseconds: string | number = milliseconds.split('.');
84-
85-
// if our millisecond string only has one digit
86-
if (arrayMilliseconds[0].length < 2) {
87-
// we add a 0 in front of it so that in the a sample number of '1' becomes '01'
88-
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]);
74+
75+
if (arrayMilliseconds[0].length < 2) { // if our millisecond string only has one digit
76+
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]); // we add a 0 in front of it so that in the a sample number of '1' becomes '01'
8977
}
90-
// if this is the initial snapshot
91-
if (index === 0) {
92-
// we give it a timestamp
93-
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
78+
79+
if (index === 0) { // if this is the initial snapshot
80+
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`; // we give it a timestamp
9481
}
95-
// if these are succeeding snapshots, we add a '+' to the timestamp
96-
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
82+
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`; // if these are succeeding snapshots, we add a '+' to the timestamp
9783
};
9884

99-
// we run cleanTime on the creation of this component so that we can get the timestamp
100-
const displayTime: string = cleanTime();
85+
const displayTime: string = cleanTime(); // we run cleanTime on the creation of this component so that we can get the timestamp
86+
10187

10288
// creates an options object that 'ReactHover' component will use to modify it's behaviour
10389
const optionsCursorTrueWithMargin: OptionsCursorTrueWithMargin = {
@@ -109,7 +95,6 @@ const Action = (props: ActionProps): JSX.Element => {
10995
return (
11096
<div className='individual-action'>
11197
<div
112-
// Invoking keyboard functionality; functionality is in ActionContainer;
11398
onKeyDown={(e):void => handleOnkeyDown(e, viewIndex)}
11499
className={selected || last ? 'action-component selected' : 'action-component'}
115100
onClick={() => {

src/app/components/App.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import mainReducer from '../reducers/mainReducer.js';
66
import { InitialStateProps } from '../FrontendTypes';
77
import { ThemeProvider } from '@mui/material/styles';
88
import theme from './theme';
9-
// currentTab is the current active tab within Google Chrome.
10-
// This is used to decide what tab Reactime should be monitoring. This can be "locked"
11-
// currentTabInApp is the current active tab within Reactime (Map, Performance, History, etc).
12-
// This is used to determine the proper tutorial to render when How To button is pressed.
139

14-
// we initialize what our initialState is here
15-
const initialState: InitialStateProps = {
10+
/*
11+
'currentTab' is the current active tab within Google Chrome.
12+
This is used to decide what tab Reactime should be monitoring. This can be "locked" currentTabInApp is the current active tab within Reactime (Map, Performance, History, etc).
13+
This is used to determine the proper tutorial to render when How To button is pressed.
14+
*/
15+
16+
const initialState: InitialStateProps = { // we initialize what our initialState is here
1617
port: null,
1718
currentTab: null,
1819
currentTitle: 'No Target',

src/app/components/Diff.tsx

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,62 @@ import { useStoreContext } from '../store';
55
import { DiffProps, StatelessCleaning } from '../FrontendTypes';
66

77
/**
8-
* Displays tree showing specific two versions of tree
8+
* Displays tree showing two specific versions of tree:
99
* one with specific state changes, the other the whole tree
1010
* @param props props from maincontainer
1111
* @returns a diff tree or a string stating no state changes have happened
1212
*/
13+
1314
function Diff(props: DiffProps): JSX.Element {
14-
const { snapshot, show } = props;
15-
const [mainState] = useStoreContext();
16-
const { currentTab, tabs } = mainState; // k/v pairs of mainstate store object being created
15+
const {
16+
snapshot, // snapshot from 'tabs[currentTab]' object in 'MainContainer'
17+
show // boolean that is dependent on the 'Route' path; true if 'Route' path === '/diffRaw'
18+
} = props;
19+
const [mainState] = useStoreContext(); // useStoreContext() returns our global state object (which was initialized as 'initialState' in 'App.tsx')
20+
const { currentTab, tabs } = mainState; // 'currentTab' (type: number) and 'tabs' (type: object) are destructured from 'mainState'
1721
const { snapshots, viewIndex, sliderIndex } = tabs[currentTab];
18-
let previous: unknown;
1922

20-
// previous follows viewIndex or sliderIndex
21-
if (viewIndex !== -1) {
22-
// if tab isnt selected, view index is set to -1
23-
previous = snapshots[viewIndex - 1];
23+
let previous: unknown// = (viewIndex !== -1) ? snapshots[viewIndex - 1] : previous = snapshots[sliderIndex - 1]
24+
25+
if (viewIndex !== -1) { // snapshots should not have any property < 0. A viewIndex of '-1' means that we had a snapshot index that occurred before the initial snapshot of the application state... which is impossible. '-1' therefore means reset to the last/most recent snapshot.
26+
previous = snapshots[viewIndex - 1]; // set previous to the snapshot that is before the one we are currently viewing
2427
} else {
25-
previous = snapshots[sliderIndex - 1];
28+
previous = snapshots[sliderIndex - 1]; // if viewIndex was an impossible index, we will get our snapshots index using 'sliderIndex.' sliderIndex should have already been reset to the latest snapshot index. Previous is then set to the snapshot that occurred immediately before our most recent snapshot.
2629
}
30+
31+
/*
32+
State snapshot objects have the following structure:
33+
{
34+
children: array of objects
35+
componentData: object
36+
isExpanded: Boolean
37+
name: string
38+
route: object
39+
state: string
40+
}
2741
28-
// cleaning preview from stateless data
42+
// cleaning preview from stateless data
43+
*/
2944
const statelessCleaning = (obj: StatelessCleaning) => {
30-
const newObj = { ...obj };
31-
if (newObj.name === 'nameless') {
32-
delete newObj.name;
45+
const newObj = { ...obj }; // duplicate our input object into a new object
46+
47+
if (newObj.name === 'nameless') { // if our new object's name is nameless
48+
delete newObj.name; // delete the name property
3349
}
34-
if (newObj.componentData) {
35-
delete newObj.componentData;
50+
if (newObj.componentData) { // if our new object has a componentData property
51+
delete newObj.componentData; // delete the componentData property
3652
}
37-
if (newObj.state === 'stateless') {
38-
delete newObj.state;
53+
if (newObj.state === 'stateless') { // if if our new object's state is stateless
54+
delete newObj.state; // delete the state property
3955
}
40-
if (newObj.stateSnaphot) {
41-
newObj.stateSnaphot = statelessCleaning(obj.stateSnaphot);
56+
57+
if (newObj.stateSnaphot) { // if our new object has a stateSnaphot property
58+
newObj.stateSnaphot = statelessCleaning(obj.stateSnaphot); // run statelessCleaning on the stateSnapshot
4259
}
43-
if (newObj.children) {
60+
61+
if (newObj.children) { // if our new object has a children property
4462
newObj.children = [];
45-
if (obj.children.length > 0) {
63+
if (obj.children.length > 0) { // and if our input object's children property is non-empty, go through each children object from our input object and determine, if the object being iterated on either has a stateless state or has a children array with a non-zero amount of objects. Objects that fulfill the above that need to be cleaned through statelessCleaning. Those that are cleaned through this process are then pushed to the new object's children array.
4664
obj.children.forEach(
4765
(element: { state?: Record<string, unknown> | string; children?: [] }) => {
4866
if (element.state !== 'stateless' || element.children.length > 0) {
@@ -53,20 +71,19 @@ function Diff(props: DiffProps): JSX.Element {
5371
);
5472
}
5573
}
56-
return newObj;
74+
return newObj; // return the cleaned state snapshot(s)
5775
};
5876

59-
// displays stateful data
60-
const previousDisplay: StatelessCleaning = statelessCleaning(previous);
61-
// diff function returns a comparison of two objects, one has an updated change
62-
// just displays stateful data
63-
const delta: StatelessCleaning = diff(previousDisplay, snapshot);
64-
// returns html in string
65-
// just displays stateful data
66-
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay);
67-
if (show) formatters.html.showUnchanged();
68-
else formatters.html.hideUnchanged();
69-
if (previous === undefined || delta === undefined) {
77+
const previousDisplay: StatelessCleaning = statelessCleaning(previous); // displays stateful data from the first snapshot that was taken before our current snapshot.
78+
79+
const delta: StatelessCleaning = diff(previousDisplay, snapshot); // diff function from 'jsondiffpatch' returns the difference in state between 'previousDisplay' and 'snapshot'
80+
81+
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay); // formatters function from 'jsondiffpatch' returns an html string that shows the difference between delta and the previousDisplay
82+
83+
if (show) formatters.html.showUnchanged(); // shows unchanged values if we're on the '/diffRaw' path
84+
else formatters.html.hideUnchanged(); // hides unchanged values
85+
86+
if (previous === undefined || delta === undefined) { // if there has been no state changes on the target/hooked application, previous and delta would be undefined.
7087
return (
7188
<div className='no-data-message'>
7289
{' '}
@@ -75,7 +92,7 @@ function Diff(props: DiffProps): JSX.Element {
7592
</div>
7693
);
7794
}
78-
return <div>{ReactHtmlParser(html)}</div>;
95+
return <div>{ReactHtmlParser(html)}</div>; // ReactHTMLParser from 'react-html-parser' package converts the HTML string into a react component.
7996
}
8097

8198
export default Diff;

src/app/components/DiffRoute.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { MemoryRouter as Router, Route, NavLink, Switch } from 'react-router-dom
33
import Diff from './Diff';
44
import { DiffRouteProps } from '../FrontendTypes';
55

6+
/*
7+
Loads the appropriate DiffRoute view and renders the 'Tree' and 'Raw' navbar buttons after clicking on the 'Diff' button located near the top rightmost corner.
8+
*/
9+
10+
// 'DiffRoute' only passed in prop is 'snapshot' from 'tabs[currentTab]' object in 'MainContainer'
611
const DiffRoute = (props: DiffRouteProps): JSX.Element => (
712
<Router>
8-
<div className='navbar'>
13+
<div className='navbar'>
914
<NavLink className='router-link' activeClassName='is-active' exact to='/'>
1015
Tree
1116
</NavLink>

src/app/components/RouteDescription.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type RouteProps = {
1010

1111
const RouteDescription = (props: RouteProps): JSX.Element => {
1212
const { actions } = props;
13-
// Use new URL to use the url.pathname method.
14-
const url: URL = new URL(actions[0].props.routePath);
13+
14+
const url: URL = new URL(actions[0].props.routePath); // Use new URL to use the url.pathname method.
1515
return (
1616
<div className='routedescription'>
1717
<h3 className='route'>Route: {url.pathname}</h3>

0 commit comments

Comments
 (0)