Skip to content

Commit e79c3c1

Browse files
committed
fixed snapshot naming and current status of snapshots
1 parent 4c1c412 commit e79c3c1

File tree

2 files changed

+31
-61
lines changed

2 files changed

+31
-61
lines changed

src/app/components/Actions/Action.tsx

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,59 @@
1-
/* eslint-disable react/require-default-props */
2-
/* eslint-disable @typescript-eslint/no-explicit-any */
3-
/* eslint-disable react/no-unused-prop-types */
4-
51
import React from 'react';
62
import ReactHover, { Trigger, Hover } from 'react-hover';
73
import { changeView, changeSlider } from '../../slices/mainSlice';
84
import { ActionProps, OptionsCursorTrueWithMargin } from '../../FrontendTypes';
95
import { useDispatch } from 'react-redux';
106

11-
/*
12-
This renders the individual snapshot components on the left side column
13-
*/
14-
15-
/**
16-
* @function Action
17-
* @param selected : The selected action in the array of state changes
18-
* @param displayName : Label showing sequence number of state change, reflects changes in Chart.tsx
19-
* @param componentName : Displays the name of compenent's state being changed
20-
* @param last : The last index in the array
21-
* @param sliderIndex: Index of the slider in the array of state changes
22-
* (clicking the block changes the slider, related to MainSlider.tsx slider)
23-
* @param componentData: Displays react fiber data
24-
* @param viewIndex: Index of the tab in the array when timejump is made
25-
* @method dispatch Executes actions that changes state in reactime
26-
* @method handleOnkeyDown Executes key commands
27-
*
28-
*/
29-
307
const Action = (props: ActionProps): JSX.Element => {
31-
//here we are adding useSelector and useDispatch for RTK state conversion
328
const dispatch = useDispatch();
339

34-
// We destructure the 'props' that were passed into this component
3510
const {
36-
selected, // boolean on whether the current index is the same as the viewIndex in 'ActionContainer'
37-
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) in 'ActionContainer'
38-
index, // from snapshot.index in "ActionContainer's" 'hierarchyArr'
39-
sliderIndex, // from tabs[currentTab] object in 'ActionContainer'
40-
displayName, // from snapshot.displayName in "ActionContainer's" 'hierarchyArr'
41-
componentData, // from snapshot.componentData in "ActionContainer's" 'hierarchyArr'
42-
viewIndex, // from tabs[currentTab] object in 'ActionContainer'
11+
selected,
12+
last,
13+
index,
14+
sliderIndex,
15+
displayName,
16+
componentData,
17+
viewIndex,
4318
isCurrIndex,
44-
handleOnkeyDown, // function that allows arrows keys to jump between snapshots defined in 'ActionContainer.tsx'
19+
handleOnkeyDown,
4520
} = props;
4621

47-
/**
48-
* @function cleanTime: Displays render times for state changes
49-
* @returns render display time in seconds in milliseconds
50-
*/
51-
5222
const cleanTime = (): string => {
5323
if (!componentData || !componentData.actualDuration) {
54-
// if there is no 'componentData' or 'componentData.actualDuration'
5524
return 'NO TIME';
5625
}
5726

58-
let seconds: number | string; // seconds is undefined but can take a number or a string
59-
let milliseconds: any = componentData.actualDuration; // milliseconds is of any type and taken from the 'componentData.actualDuration'
27+
let seconds: number | string;
28+
let milliseconds: any = componentData.actualDuration;
6029

6130
if (Math.floor(componentData.actualDuration) > 60) {
62-
// if the milliseconds is greater than 60
63-
seconds = Math.floor(componentData.actualDuration / 60); // we divide our milliseconds by 60 to determine our seconds
64-
seconds = JSON.stringify(seconds); // and we convert our seconds into a string
31+
seconds = Math.floor(componentData.actualDuration / 60);
32+
seconds = JSON.stringify(seconds);
6533

6634
if (seconds.length < 2) {
67-
// if the seconds string is only a single digit
68-
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"'
35+
seconds = '0'.concat(seconds);
6936
}
70-
milliseconds = Math.floor(componentData.actualDuration % 60); // Our true milliseconds then becomes the remainder of dividing our initial milliseconds by 60
37+
milliseconds = Math.floor(componentData.actualDuration % 60);
7138
} else {
72-
seconds = '00'; // if we haven't even reached one second yet, our seconds are 00
39+
seconds = '00';
7340
}
7441

75-
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.
76-
const arrayMilliseconds: [string, number] = milliseconds.split('.'); // we split our milliseconds using the decimal and come out with an array of two numbers
42+
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2);
43+
const arrayMilliseconds: [string, number] = milliseconds.split('.');
7744

7845
if (arrayMilliseconds[0].length < 2) {
79-
// if our millisecond string only has one digit
80-
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'
46+
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]);
8147
}
8248

8349
if (index === 0) {
84-
// if this is the initial snapshot
85-
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`; // we give it a timestamp
50+
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
8651
}
87-
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`; // if these are succeeding snapshots, we add a '+' to the timestamp
52+
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
8853
};
8954

90-
const displayTime: string = cleanTime(); // we run cleanTime on the creation of this component so that we can get the timestamp
55+
const displayTime: string = cleanTime();
9156

92-
// creates an options object that 'ReactHover' component will use to modify it's behaviour
9357
const optionsCursorTrueWithMargin: OptionsCursorTrueWithMargin = {
9458
followCursor: true,
9559
shiftX: 20,
@@ -123,9 +87,15 @@ const Action = (props: ActionProps): JSX.Element => {
12387
placeholder={`Snapshot: ${displayName}`}
12488
/>
12589
</div>
126-
<button className='time-button' type='button'>
127-
{displayTime}
128-
</button>
90+
{isCurrIndex ? (
91+
<button className='time-button' type='button'>
92+
Current
93+
</button>
94+
) : (
95+
<button className='time-button' type='button'>
96+
{displayTime}
97+
</button>
98+
)}
12999
{isCurrIndex ? (
130100
<button className='current-location' type='button'>
131101
Current

src/app/containers/ActionContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
6969
//This utility can be used to map the properties of a type to another type) and populate it's properties with
7070
//relevant values from our argument 'obj'.
7171
index: obj.index,
72-
displayName: `${obj.name}.${obj.branch}`,
72+
displayName: `${obj.index + 1}`,
7373
state: obj.stateSnapshot.children[0].state,
7474
componentName: obj.stateSnapshot.children[0].name,
7575
routePath: obj.stateSnapshot.route.url,

0 commit comments

Comments
 (0)