Skip to content

Commit 50aba93

Browse files
committed
Merge branch 'dev' into additionalMui
2 parents 6d57abf + 626b30b commit 50aba93

20 files changed

+340
-188
lines changed

src/app/FrontendTypes.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export interface TreeProps {
3333
stateSnaphot?: object;
3434
children?: any[];
3535
};
36-
snapshots?:[];
37-
currLocation?:object;
36+
snapshots?: [];
37+
currLocation?: object;
3838
}
3939

4040
export interface BarStackProp {
@@ -159,7 +159,7 @@ export interface ActionProps {
159159
last: boolean;
160160
index: number;
161161
sliderIndex: number;
162-
dispatch: (a: { type: string; payload: unknown; }) => void;
162+
dispatch: (a: { type: string; payload: unknown }) => void;
163163
displayName: string;
164164
componentName: string;
165165
componentData: { actualDuration: number } | undefined;
@@ -249,7 +249,7 @@ export interface LinkControlProps {
249249
setStepPercent: (percent: number) => void;
250250
setSelectedNode: (selectedNode: string) => void;
251251
snapShots: Record<string, unknown>;
252-
};
252+
}
253253

254254
export interface ControlStyles {
255255
fontSize: string;
@@ -270,7 +270,7 @@ export interface DropDownStyle {
270270

271271
export interface Node {
272272
children?: Node[];
273-
name?: string
273+
name?: string;
274274
// other properties here
275275
}
276276

@@ -286,7 +286,7 @@ export interface LinkTypesProps {
286286
margin?: { top: number; right: number; bottom: number; left: number };
287287
snapshots: Record<string, unknown>;
288288
currentSnapshot?: Record<string, unknown>;
289-
};
289+
}
290290

291291
export interface ToolTipStyles {
292292
defaultStyles: React.CSSProperties;
@@ -307,12 +307,12 @@ export interface OptionsCursorTrueWithMargin {
307307
shiftY: number;
308308
}
309309

310-
export interface StatelessCleanning {
310+
export interface StatelessCleaning {
311311
name?: string;
312312
componentData?: Record<string, unknown>;
313313
state?: string | {};
314314
stateSnaphot?: Record<string, unknown>;
315-
children?: StatelessCleanning[];
315+
children?: StatelessCleaning[];
316316
}
317317

318318
export interface Snapshots {
@@ -321,4 +321,4 @@ export interface Snapshots {
321321
component2: number;
322322
component3: number;
323323
'all others': number;
324-
}
324+
}

src/app/components/Action.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import ReactHover, { Trigger, Hover } from 'react-hover';
77
import { changeView, changeSlider } from '../actions/actions';
88
import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
99

10+
/*
11+
This render's the individual snapshot components on the left side column
12+
*/
13+
1014
/**
1115
* @function Action
1216
* @param selected : The selected action in the array of state changes
@@ -21,9 +25,9 @@ import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
2125
* @method handleOnkeyDown Executes key commands
2226
*
2327
*/
24-
// index and delta props were removed from Action.jsx */
25-
// viewIndex and handleonkeyDown added to props
28+
2629
const Action = (props: ActionProps): JSX.Element => {
30+
// We destructure the 'props' that were passed into this component
2731
const {
2832
selected,
2933
last,
@@ -41,34 +45,61 @@ const Action = (props: ActionProps): JSX.Element => {
4145
* @function cleanTime: Displays render times for state changes
4246
* @returns render display time in seconds in milliseconds
4347
*/
44-
const cleanTime = (): string => {
48+
49+
50+
const cleanTime = (): string => {
51+
// if there is no 'componentData' or 'componentData.actualDuration' return "NO TIME"
4552
if (!componentData || !componentData.actualDuration) {
4653
return 'NO TIME';
4754
}
55+
56+
// seconds is undefined but can take a number or a string
4857
let seconds: number | string;
58+
// milliseconds is of any type and taken from the 'componentData.actualDuration'
4959
let milliseconds: any = componentData.actualDuration;
60+
61+
// if the milliseconds is greater than 60
5062
if (Math.floor(componentData.actualDuration) > 60) {
63+
// we divide our milliseconds by 60 to determine our seconds
5164
seconds = Math.floor(componentData.actualDuration / 60);
65+
// and we convert our seconds into a string
5266
seconds = JSON.stringify(seconds);
67+
// if the seconds string is only a single digit
5368
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"'
5470
seconds = '0'.concat(seconds);
5571
}
72+
// Our true milliseconds then becomes the remainder of dividing our initial milliseconds by 60
5673
milliseconds = Math.floor(componentData.actualDuration % 60);
5774
} else {
75+
// if we haven't even reached one second yet, our seconds are 00
5876
seconds = '00';
5977
}
78+
79+
// we convert our milliseconds string into a floating point number that has up to two decimal places.
6080
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2);
81+
82+
// we split our milliseconds using the decimal and come out with an array of two numbers
6183
const arrayMilliseconds: string | number = milliseconds.split('.');
84+
85+
// if our millisecond string only has one digit
6286
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'
6388
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]);
6489
}
90+
// if this is the initial snapshot
6591
if (index === 0) {
92+
// we give it a timestamp
6693
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
6794
}
95+
// if these are succeeding snapshots, we add a '+' to the timestamp
6896
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
6997
};
98+
99+
// we run cleanTime on the creation of this component so that we can get the timestamp
70100
const displayTime: string = cleanTime();
71101

102+
// creates an options object that 'ReactHover' component will use to modify it's behaviour
72103
const optionsCursorTrueWithMargin: OptionsCursorTrueWithMargin = {
73104
followCursor: true,
74105
shiftX: 20,

src/app/components/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { InitialStateProps } from '../FrontendTypes';
99
// currentTabInApp is the current active tab within Reactime (Map, Performance, History, etc).
1010
// This is used to determine the proper tutorial to render when How To button is pressed.
1111

12+
// we initialize what our initialState is here
1213
const initialState: InitialStateProps = {
1314
port: null,
1415
currentTab: null,
@@ -19,8 +20,8 @@ const initialState: InitialStateProps = {
1920

2021
function App(): JSX.Element {
2122
return (
22-
<Router>
23-
<StoreContext.Provider value={useReducer(mainReducer, initialState)}>
23+
<Router> {/* we wrap our application with the <Router> tag so that all components that are nested will have the react-router context */}
24+
<StoreContext.Provider value={useReducer(mainReducer, initialState)}> {/* we wrap our MainContainer with the provider so that we will be able to use the store context. We create our store by using useReducer and passing it into the value property */}
2425
<MainContainer />
2526
</StoreContext.Provider>
2627
</Router>

src/app/components/Diff.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { diff, formatters } from 'jsondiffpatch';
33
import ReactHtmlParser from 'react-html-parser';
44
import { useStoreContext } from '../store';
5-
import { DiffProps, StatelessCleanning } from '../FrontendTypes';
5+
import { DiffProps, StatelessCleaning } from '../FrontendTypes';
66

77
/**
88
* Displays tree showing specific two versions of tree
@@ -26,7 +26,7 @@ function Diff(props: DiffProps): JSX.Element {
2626
}
2727

2828
// cleaning preview from stateless data
29-
const statelessCleanning = (obj: StatelessCleanning) => {
29+
const statelessCleaning = (obj: StatelessCleaning) => {
3030
const newObj = { ...obj };
3131
if (newObj.name === 'nameless') {
3232
delete newObj.name;
@@ -38,15 +38,15 @@ function Diff(props: DiffProps): JSX.Element {
3838
delete newObj.state;
3939
}
4040
if (newObj.stateSnaphot) {
41-
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
41+
newObj.stateSnaphot = statelessCleaning(obj.stateSnaphot);
4242
}
4343
if (newObj.children) {
4444
newObj.children = [];
4545
if (obj.children.length > 0) {
4646
obj.children.forEach(
4747
(element: { state?: Record<string, unknown> | string; children?: [] }) => {
4848
if (element.state !== 'stateless' || element.children.length > 0) {
49-
const clean = statelessCleanning(element);
49+
const clean = statelessCleaning(element);
5050
newObj.children.push(clean);
5151
}
5252
},
@@ -57,20 +57,21 @@ function Diff(props: DiffProps): JSX.Element {
5757
};
5858

5959
// displays stateful data
60-
const previousDisplay: StatelessCleanning = statelessCleanning(previous);
60+
const previousDisplay: StatelessCleaning = statelessCleaning(previous);
6161
// diff function returns a comparison of two objects, one has an updated change
6262
// just displays stateful data
63-
const delta: StatelessCleanning = diff(previousDisplay, snapshot);
63+
const delta: StatelessCleaning = diff(previousDisplay, snapshot);
6464
// returns html in string
6565
// just displays stateful data
66-
const html: StatelessCleanning = formatters.html.format(delta, previousDisplay);
66+
const html: StatelessCleaning = formatters.html.format(delta, previousDisplay);
6767
if (show) formatters.html.showUnchanged();
6868
else formatters.html.hideUnchanged();
6969
if (previous === undefined || delta === undefined) {
7070
return (
7171
<div className='no-data-message'>
7272
{' '}
73-
Make state changes and click on a Snapshot to see the difference between that snapshot and the previous one.{' '}
73+
Make state changes and click on a Snapshot to see the difference between that snapshot and
74+
the previous one.{' '}
7475
</div>
7576
);
7677
}

src/app/components/Dropdown.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import React from 'react';
22
import Select from 'react-select';
33
import { DropdownProps } from '../FrontendTypes'
44

5+
/*
6+
Allows the user to change the speed of the time-travel based on the selected dropdown value
7+
Component is created in the TravelContainer.tsx
8+
*/
9+
510
const Dropdown = (props: DropdownProps): JSX.Element => {
611
const { speeds, setSpeed, selectedSpeed } = props;
712
return (
813
<Select
914
className='react-select-container'
1015
classNamePrefix='react-select'
11-
value={selectedSpeed}
12-
onChange={setSpeed}
13-
options={speeds}
16+
value={selectedSpeed} // the text displayed will be based on the currently selected speed
17+
onChange={setSpeed} // allows the speed to change upon selection
18+
options={speeds} // custom speed options that are visible to the user
1419
menuPlacement='top'
1520
/>
1621
);

src/app/components/ErrorMsg.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
/* eslint-disable react/prop-types */
22
import React from 'react';
33

4+
/*
5+
This file determines what text will be displayed to the user if any one of the following fail to load:
6+
7+
1. if the content script has been launched on the current tab
8+
2. if React Dev Tools has been installed
9+
3. if target tab contains a compatible React app
10+
11+
*/
12+
413
// parses loadingArray and status and returns the correct message
514
function parseError(loadingArray: [], status: Record<string, unknown>): string {
615
let stillLoading = true;
716
loadingArray.forEach((e) => {
817
if (e === false) stillLoading = false;
918
});
10-
// As long as everything is still loading dont diplay an error message
11-
if (stillLoading) return 'default';
12-
// Return first status that fails
19+
20+
if (stillLoading) return 'default'; // As long as everything is still loading dont diplay an error message
21+
22+
// If we're done loading everything, return the first status that fails
1323
if (!status.contentScriptLaunched) return 'Content Script Error';
1424
if (!status.reactDevToolsInstalled) return 'RDT Error';
1525
if (!status.targetPageisaReactApp) return 'Not React App';
1626
return 'default';
1727
}
1828

1929
function ErrorMsg({ loadingArray, status, launchContent }): JSX.Element {
20-
switch (parseError(loadingArray, status)) {
30+
switch (parseError(loadingArray, status)) { // parseError returns a string based on the loadingArray and status. The returned string is matched to a case so that an appropriate error message will be displayed to the user
2131
case 'Content Script Error':
2232
return (
2333
<div>

src/app/components/Loader.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ import { ClipLoader } from 'react-spinners';
55
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
66
import { faCheck, faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
77

8-
// Displays the result of the check when loading is done
8+
/*
9+
This file is what decides what icon (loading, checkmark, exclamation point) is displayed next to the checks in the ErrorContainer loading screen:
10+
11+
1. if the content script has been launched on the current tab
12+
2. if React Dev Tools has been installed
13+
3. if target tab contains a compatible React app
14+
*/
15+
916
const handleResult = (result: boolean): JSX.Element =>
1017
result ? (
11-
<FontAwesomeIcon icon={faCheck} className='check' size='lg' />
18+
<FontAwesomeIcon icon={faCheck} className='check' size='lg' /> // if result boolean is true, we display a checkmark icon
1219
) : (
13-
<FontAwesomeIcon icon={faExclamationCircle} className='fail' size='lg' />
20+
<FontAwesomeIcon icon={faExclamationCircle} className='fail' size='lg' /> // if the result boolean is false, we display a fail icon
1421
);
1522

16-
// Returns the Loader component
1723
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24+
// Returns the 'Loader' component
1825
const Loader = ({ loading, result }): JSX.Element =>
1926
loading ? (
20-
<ClipLoader color='#123abc' size={30} loading={loading} />
27+
<ClipLoader color='#123abc' size={30} loading={loading} /> // if the loadingArray value is true, we display a loading icon
2128
) : (
22-
handleResult(result)
29+
handleResult(result) // else we display a component produced by 'handleResult' depending on if the result parameter (which takes an argument from the status object in 'ErrorContainer') is true or false
2330
);
2431

2532
export default Loader;

0 commit comments

Comments
 (0)