Skip to content

Commit 72fa443

Browse files
authored
Merge pull request #11 from oslabs-beta/feature/garrett
Feature/garrett
2 parents d5183ba + f6eaf44 commit 72fa443

File tree

18 files changed

+389
-703
lines changed

18 files changed

+389
-703
lines changed

src/app/App.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import { MemoryRouter as Router } from 'react-router-dom';
33
import MainContainer from './containers/MainContainer';
4-
import { ThemeProvider } from '@mui/material/styles';
5-
import theme from './styles/theme';
64

75
/*
86
'currentTab' is the current active tab within Google Chrome.
@@ -12,12 +10,10 @@ import theme from './styles/theme';
1210

1311
function App(): JSX.Element {
1412
return (
15-
<ThemeProvider theme={theme}>
16-
<Router>
17-
{/* we wrap our application with the <Router> tag so that all components that are nested will have the react-router context */}
18-
<MainContainer />
19-
</Router>
20-
</ThemeProvider>
13+
<Router>
14+
{/* we wrap our application with the <Router> tag so that all components that are nested will have the react-router context */}
15+
<MainContainer />
16+
</Router>
2117
);
2218
}
2319

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='current-snap' type='button'>
92+
{`Snapshot: ${displayName}`}
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/components/Actions/RouteDescription.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,19 @@ const RouteDescription = (props: RouteProps): JSX.Element => {
1616
const url: URL = new URL(actions[0].props.routePath); // Use new URL to use the url.pathname method.
1717

1818
return (
19-
<div className='routedescription' >
20-
<h3 className='route'>Route: {url.pathname}</h3>
21-
<div style={{
22-
// div that contains slider and snapshots
23-
display: 'flex',
24-
flexDirection: 'row',
25-
height: `${actions.length * 30}px`,
26-
marginBottom: '50px'
27-
}}>
28-
<div style={{maxWidth: '50px'}}>
29-
<VerticalSlider className='main-slider' snapshots={actions} />
30-
</div>
31-
<div style={{marginTop: '10px'}}>
32-
{/* actual snapshots per route */}
33-
{actions}
34-
</div>
35-
</div>
19+
<div className='route-container'>
20+
<div className='route-header'>Route: {url.pathname}</div>
21+
<div className='route-content' style={{ height: `${actions.length * 40.5}px` }}>
22+
<div>
23+
<VerticalSlider className='main-slider' snapshots={actions} />
24+
</div>
25+
<div className='actions-container'>
26+
{/* actual snapshots per route */}
27+
{actions}
28+
</div>
3629
</div>
30+
</div>
3731
);
3832
};
3933

40-
4134
export default RouteDescription;

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ export default function ComponentMap({
201201
};
202202

203203
let filtered = processTreeData(currentSnapshot);
204-
console.log('filtered', filtered);
205-
collectNodes(filtered);
204+
collectNodes(currentSnapshot);
206205

207206
const keepContextAndProviderNodes = (node) => {
208207
if (!node) return null;
@@ -234,7 +233,6 @@ export default function ComponentMap({
234233
};
235234

236235
const contextProvidersOnly = keepContextAndProviderNodes(currentSnapshot);
237-
console.log('context only', contextProvidersOnly);
238236

239237
// @ts
240238
// find the node that has been selected and use it as the root

src/app/components/TimeTravel/VerticalSlider.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const handle = (props: HandleProps): JSX.Element => {
2929

3030
function VerticalSlider(props: MainSliderProps): JSX.Element {
3131
const dispatch = useDispatch();
32-
const { snapshots} = props; // destructure props to get our total number of snapshots
32+
const { snapshots } = props; // destructure props to get our total number of snapshots
3333
const [sliderIndex, setSliderIndex] = useState(0); // create a local state 'sliderIndex' and set it to 0.
3434
const { tabs, currentTab }: MainState = useSelector((state: RootState) => state.main);
3535
const { currLocation } = tabs[currentTab]; // we destructure the currentTab object
@@ -39,27 +39,25 @@ function VerticalSlider(props: MainSliderProps): JSX.Element {
3939
// if we have a 'currLocation'
4040
let correctedSliderIndex;
4141

42-
for (let i = 0; i<snapshots.length; i++){
42+
for (let i = 0; i < snapshots.length; i++) {
4343
//@ts-ignore -- ignores the errors on the next line
44-
if (snapshots[i].props.index === currLocation.index){
44+
if (snapshots[i].props.index === currLocation.index) {
4545
correctedSliderIndex = i;
4646
}
4747
}
48-
setSliderIndex(correctedSliderIndex)
49-
48+
setSliderIndex(correctedSliderIndex);
5049
} else {
5150
setSliderIndex(0); // just set the thumb position to the beginning
5251
}
5352
}, [currLocation]); // if currLocation changes, rerun useEffect
54-
5553

5654
return (
5755
<Slider
5856
className='travel-slider'
5957
color='#0af548'
60-
vertical = 'true'
61-
reverse = 'true'
62-
height = '100%'
58+
vertical='true'
59+
reverse='true'
60+
height='100%'
6361
min={0} // index of our first snapshot
6462
max={snapshots.length - 1} // index of our last snapshot
6563
value={sliderIndex} // currently slider thumb position

src/app/containers/ActionContainer.tsx

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@ import { Button, Switch } from '@mui/material';
1414
This file renders the 'ActionContainer'. The action container is the leftmost column in the application. It includes the button that shrinks and expands the action container, a dropdown to select the active site, a clear button, the current selected Route, and a list of selectable snapshots with timestamps.
1515
*/
1616

17-
1817
// resetSlider locates the rc-slider elements on the document and resets it's style attributes
19-
const resetSlider = () => {
20-
const slider = document.querySelector('.rc-slider-handle');
21-
const sliderTrack = document.querySelector('.rc-slider-track');
22-
if (slider && sliderTrack) {
23-
slider.setAttribute('style', 'left: 0');
24-
sliderTrack.setAttribute('style', 'width: 0');
25-
}
26-
};
2718

2819
function ActionContainer(props: ActionContainerProps): JSX.Element {
29-
3020
const [dropdownSelection, setDropdownSelection] = useState('TimeJump');
3121

3222
const dispatch = useDispatch();
@@ -43,23 +33,6 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
4333
// we create an array 'hierarchyArr' that will hold objects and numbers
4434
const hierarchyArr: (number | {})[] = [];
4535

46-
/*
47-
function to traverse state from hierarchy and also getting information on display name and component name
48-
49-
the obj parameter is an object with the following structure:
50-
{
51-
stateSnapshot: {
52-
route: any;
53-
children: any[];
54-
};
55-
name: number;
56-
branch: number;
57-
index: number;
58-
children?: [];
59-
}
60-
*/
61-
62-
6336
const displayArray = (obj: Obj): void => {
6437
if (
6538
obj.stateSnapshot.children.length > 0 && // if the 'stateSnapshot' has a non-empty 'children' array
@@ -72,7 +45,7 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
7245
//This utility can be used to map the properties of a type to another type) and populate it's properties with
7346
//relevant values from our argument 'obj'.
7447
index: obj.index,
75-
displayName: `${obj.name}.${obj.branch}`,
48+
displayName: `${obj.index + 1}`,
7649
state: obj.stateSnapshot.children[0].state,
7750
componentName: obj.stateSnapshot.children[0].name,
7851
routePath: obj.stateSnapshot.route.url,
@@ -231,31 +204,29 @@ function ActionContainer(props: ActionContainerProps): JSX.Element {
231204
</a>
232205
<SwitchAppDropdown />
233206
{/* add new component here for dropdown menu for useStae/ useReducer- ragad */}
234-
<DropDown
235-
dropdownSelection = {dropdownSelection}
236-
setDropdownSelection={setDropdownSelection}
237-
/>
238-
<div className='action-component exclude'>
207+
<DropDown
208+
dropdownSelection={dropdownSelection}
209+
setDropdownSelection={setDropdownSelection}
210+
/>
211+
<div className='clear-button-container'>
239212
<Button
240-
className='clear-button'
241-
variant='contained'
242-
//style={{ backgroundColor: '#ff6569' }}
213+
className='clear-button-modern'
214+
variant='text'
243215
onClick={() => {
244216
dispatch(emptySnapshots()); // set slider back to zero, visually
245-
resetSlider();
217+
dispatch(changeSlider(0));
246218
}}
247219
type='button'
248220
>
249221
Clear
250222
</Button>
251223
</div>
252224
<div className='snapshots'>
253-
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer/>}
254-
{dropdownSelection === 'TimeJump' &&
225+
{dropdownSelection === 'Provider/Consumer' && <ProvConContainer />}
226+
{dropdownSelection === 'TimeJump' &&
255227
Object.keys(routes).map((route, i) => (
256228
<RouteDescription key={`route${i}`} actions={routes[route]} />
257-
))
258-
}
229+
))}
259230
</div>
260231
</div>
261232
) : null}

src/app/containers/MainContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function MainContainer(): JSX.Element {
3333
const { connectionStatus }: MainState = useSelector((state: RootState) => state.main);
3434

3535
// JR 12.22.23: so far this log always returns true
36-
// console.log('MainContainer connectionStatus at initialization: ', connectionStatus);
36+
console.log('MainContainer connectionStatus at initialization: ', connectionStatus);
3737

3838
const [actionView, setActionView] = useState(true); // We create a local state 'actionView' and set it to true
3939

0 commit comments

Comments
 (0)