Skip to content

Commit 93e0dda

Browse files
Front-end pseudocode 90%+ complete, beginning work on processing data for BarGraphComparisonActions
1 parent ba2db1c commit 93e0dda

File tree

10 files changed

+74
-165
lines changed

10 files changed

+74
-165
lines changed

src/app/components/StateRoute/History.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const defaultMargin: DefaultMargin = {
2424
// below we destructure the props
2525
function History(props: Record<string, unknown>): JSX.Element {
2626
const {
27-
width: totalWidth,
28-
height: totalHeight,
27+
width: totalWidth, // from ParentSize provided in StateRoute
28+
height: totalHeight, // from ParentSize provided in StateRoute
2929
margin = defaultMargin,
3030
hierarchy, // from 'tabs[currentTab]' object in 'MainContainer'
3131
dispatch, // from useStoreContext in 'StateRoute'

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@ import { useTheme } from '@mui/material/styles';
1818
import { Button } from '@mui/material';
1919
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
2020
import { useStoreContext } from '../../../store';
21-
import {
22-
snapshot,
23-
TooltipData,
24-
Margin,
25-
BarGraphComparisonProps,
26-
ActionObj,
27-
Series,
28-
} from '../../../FrontendTypes';
21+
import { snapshot, TooltipData, Margin, BarGraphComparisonProps, ActionObj, Series } from '../../../FrontendTypes';
2922

3023
/* DEFAULTS */
3124
const margin: Margin = {
@@ -49,8 +42,8 @@ const tooltipStyles = {
4942
const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
5043
const [{ tabs, currentTab }, dispatch] = useStoreContext();
5144
const {
52-
width, // from stateRoute container
53-
height, // from stateRoute container
45+
width, // from ParentSize provided in StateRoute
46+
height, // from ParentSize provided in StateRoute
5447
data, // Acquired from getPerfMetrics(snapshots, getSnapshotIds(hierarchy)) in 'PerformanceVisx'
5548
comparison, // result from invoking 'allStorage' in 'PerformanceVisx'
5649
setSeries, // setter function to update the state located in 'PerfomanceVisx'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const tooltipStyles = {
4040
const BarGraphComparisonActions = (props: BarGraphComparisonAction) => {
4141
const [dispatch] = useStoreContext(); // used to get the dispatch function from our storeContext
4242
const {
43-
width, // from stateRoute container
44-
height, // from stateRoute container
43+
width, // from ParentSize provided in StateRoute
44+
height, // from ParentSize provided in StateRoute
4545
data,
4646
comparison, // returned value from invoking 'allStorage()' in 'PerformanceVisx' which is an array of objects
4747
setSeries, // setter function to update the state located in 'PerfomanceVisx'

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

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -150,33 +150,18 @@ const getPerfMetrics = (snapshots, snapshotsIds): PerfData => {
150150
return perfData;
151151
};
152152

153-
/* EXPORT COMPONENT */
154-
const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
155-
// hook used to dispatch onhover action in react
156-
const { width, height, snapshots, hierarchy } = props;
157-
const [{ currentTabInApp }, dispatch] = useStoreContext();
158-
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
159-
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
160-
const [series, setSeries] = useState(true);
161-
const [action, setAction] = useState(false);
162-
163-
const [route, setRoute] = useState('All Routes');
164-
const [snapshot, setSnapshot] = useState('All Snapshots');
165-
// snapshots = 3.0
166-
useEffect(() => {
167-
dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
168-
}, [dispatch]);
169-
170-
// Creates the actions array used to populate the compare actions dropdown
171-
const getActions = () => {
153+
const getActions = () => { // Creates the actions array used to populate the compare actions dropdown (WORK IN PROGRESS)
172154
const project = localStorage.getItem('project');
173155
const seriesArr: Series[] = project === null ? [] : JSON.parse(project);
174156
const actionsArr = [];
175157

158+
console.log("Project:", project)
159+
console.log('seriesArr:', seriesArr)
160+
176161
if (seriesArr.length) {
177162
for (let i = 0; i < seriesArr.length; i += 1) {
178163
for (const actionObj of seriesArr[i].data.barStack) {
179-
if (actionObj.name === action) {
164+
if (actionObj.name === 'action') {
180165
actionObj.seriesName = seriesArr[i].name;
181166
actionsArr.push(actionObj);
182167
}
@@ -186,6 +171,29 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
186171
return actionsArr;
187172
};
188173

174+
/* EXPORT COMPONENT */
175+
const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
176+
// hook used to dispatch onhover action in react
177+
const {
178+
width, // from ParentSize provided in StateRoute
179+
height, // from ParentSize provided in StateRoute
180+
snapshots, // from 'tabs[currentTab]' object in 'MainContainer'
181+
hierarchy // from 'tabs[currentTab]' object in 'MainContainer'
182+
} = props;
183+
const [{ currentTabInApp }, dispatch] = useStoreContext();
184+
const NO_STATE_MSG = 'No state change detected. Trigger an event to change state';
185+
const data = getPerfMetrics(snapshots, getSnapshotIds(hierarchy));
186+
const [series, setSeries] = useState(true);
187+
const [action, setAction] = useState(false);
188+
const [route, setRoute] = useState('All Routes');
189+
const [snapshot, setSnapshot] = useState('All Snapshots');
190+
191+
getActions();
192+
193+
useEffect(() => {
194+
dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
195+
}, [dispatch]);
196+
189197
const renderComparisonBargraph = () => {
190198
if (hierarchy && series !== false) {
191199
return (
@@ -212,35 +220,29 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
212220
/>
213221
);
214222
};
215-
// create allRoutes variable to hold urls
216-
const allRoutes = [];
223+
224+
const allRoutes = []; // create allRoutes variable to hold urls
217225
const filteredSnapshots = [];
218-
// loop through data.barStack
219-
for (let i = 0; i < data.barStack.length; i += 1) {
220-
// set url variable to new route url
221-
const url = new URL(data.barStack[i].route);
222-
// if all the routes do not have the pathname property on url then push it onto all routes array
223-
if (!allRoutes.includes(url.pathname)) {
226+
227+
for (let i = 0; i < data.barStack.length; i += 1) { // loop through data.barStack
228+
const url = new URL(data.barStack[i].route); // set url variable to new route url
229+
if (!allRoutes.includes(url.pathname)) { // if all the routes do not have the pathname property on url then push it onto all routes array
224230
allRoutes.push(url.pathname);
225231
}
226-
// if the route exists and it is equal to url.pathname then push data.barstack at i into filteredSnapshots array
227-
if (route && route === url.pathname) {
232+
if (route && route === url.pathname) { // if the route exists and it is equal to url.pathname then push data.barstack at i into filteredSnapshots array
228233
filteredSnapshots.push(data.barStack[i]);
229234
}
230235
}
231-
// if route does not equal to All Routes, set data.barstack to filteredSnapshots array
232-
if (route !== 'All Routes') {
236+
if (route !== 'All Routes') { // if route does not equal to All Routes, set data.barstack to filteredSnapshots array
233237
data.barStack = filteredSnapshots;
234238
}
235239

236-
// maxheight is referring to the max height in render time to choose the scaling size for graph
237-
let maxHeight = 0;
240+
let maxHeight = 0; // maxheight is referring to the max height in render time to choose the scaling size for graph
238241
if (snapshot !== 'All Snapshots') {
239-
// filter barStack to make it equal to an array of length 1 with object matching snapshot ID to mirror the data.barStack object's shape
240-
const checkData = [data.barStack.find((comp) => comp.snapshotId === snapshot)];
242+
const checkData = [data.barStack.find((comp) => comp.snapshotId === snapshot)]; // filter barStack to make it equal to an array of length 1 with object matching snapshot ID to mirror the data.barStack object's shape
241243
const holdData = [];
242-
// looping through checkData which is composed of a single snapshot while pushing key/values to a new object and setting maxHeight
243-
for (const key in checkData[0]) {
244+
245+
for (const key in checkData[0]) { // looping through checkData which is composed of a single snapshot while pushing key/values to a new object and setting maxHeight
244246
if (key !== 'route' && key !== 'snapshotId') {
245247
if (maxHeight < checkData[0][key]) maxHeight = checkData[0][key];
246248
const name = {};
@@ -250,11 +252,9 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
250252
holdData[holdData.length - 1].snapshotId = key;
251253
}
252254
}
253-
// maxTotalRender height of bar is aligned to y-axis
254-
// 1.15 adjusts the numbers on the y-axis so the max bar's true height never reaches the max of the y-axis
255-
data.maxTotalRender = maxHeight * 1.15;
256-
// assign holdData to data.barStack to be used later to create graph
257-
if (holdData) data.barStack = holdData;
255+
256+
data.maxTotalRender = maxHeight * 1.15; // maxTotalRender height of bar is aligned to y-axis. 1.15 adjusts the numbers on the y-axis so the max bar's true height never reaches the max of the y-axis
257+
if (holdData) data.barStack = holdData; // assign holdData to data.barStack to be used later to create graph
258258
}
259259

260260
const renderBargraph = (): JSX.Element | null => {
@@ -285,8 +285,7 @@ const PerformanceVisx = (props: PerformanceVisxProps): JSX.Element => {
285285
return <div className='noState'>{NO_STATE_MSG}</div>;
286286
};
287287

288-
// This will redirect to the proper tabs during the tutorial
289-
const renderForTutorial = () => {
288+
const renderForTutorial = () => { // This will redirect to the proper tabs during the tutorial
290289
if (currentTabInApp === 'performance') return <Redirect to='/' />;
291290
if (currentTabInApp === 'performance-comparison') return <Redirect to='/comparison' />;
292291
return null;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import { useStoreContext } from '../../../store';
1212
const RenderingFrequency = (props) => {
1313
const perfData = props.data;
1414
const [store, dispatch] = useStoreContext();
15+
1516
useEffect(() => {
1617
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison' to facilitate render.
1718
}, []);
19+
1820
return (
1921
<div>
2022
{Object.keys(perfData).map((componentName) => {

src/app/containers/ButtonsContainer.tsx

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,95 +9,44 @@ import LockOpenIcon from '@mui/icons-material/LockOpen';
99
import FileDownloadIcon from '@mui/icons-material/FileDownload';
1010
import FileUploadIcon from '@mui/icons-material/FileUpload';
1111

12+
function exportHandler(snapshots: []): void { // function that takes in our tabs[currentTab] object to be exported as a JSON file. NOTE: TypeScript needs to be updated
13+
const fileDownload: HTMLAnchorElement = document.createElement('a'); // invisible HTML element that will hold our tabs[currentTab] object
1214

13-
// function exportHandler takes in a parameter snapshots which is typed as an array
14-
// the function does not return anything so the type is void
15-
function exportHandler(snapshots: []): void {
16-
// create invisible download anchor link
17-
// fileDownload is typed as HTMLAnchorElement
18-
// HTML anchor element has the <a></a> tag
19-
const fileDownload: HTMLAnchorElement = document.createElement('a');
20-
21-
// set file in anchor link
22-
// href is the reference to the URL object created from the Blob
23-
fileDownload.href = URL.createObjectURL(
24-
// Blob obj is raw data, json is raw, stringify the snapshots as json so the Blob can access the raw data
25-
new Blob([JSON.stringify(snapshots)], { type: 'application/json' }),
15+
fileDownload.href = URL.createObjectURL( // href is the reference to the URL object created from the Blob
16+
new Blob([JSON.stringify(snapshots)], { type: 'application/json' }), // Blob obj is raw data. The tabs[currentTab] object is stringified so the Blob can access the raw data
2617
);
2718

28-
// set anchor as file download and click it
29-
// anchor element has a download attribute
30-
// snapshot.json is what the file name will be once the file is downloaded locally
31-
fileDownload.setAttribute('download', 'snapshot.json');
32-
// click is a method on all HTML elements
33-
// simulates a mouse click, triggering the element's click event
34-
fileDownload.click();
19+
fileDownload.setAttribute('download', 'snapshot.json'); // We set a download attribute with snapshots.json as the file name. This allows us to download the file when the element is 'clicked.' The file will be named snapshots.json once the file is downloaded locally
20+
fileDownload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
3521

36-
// remove file url
37-
// after file is downloaded, remove the href
38-
URL.revokeObjectURL(fileDownload.href);
22+
URL.revokeObjectURL(fileDownload.href); // after file is downloaded, remove the href
3923
}
4024

41-
function importHandler(dispatch: (a: unknown) => void): void {
42-
// create input element
43-
// fileUpload is HTMLInputElement, which is an interface for HTML input elements
44-
// accepts data from user
45-
const fileUpload = document.createElement('input');
46-
// file is a type attribute on the input element, allows users to select a file
47-
console.log('fileUpload element:', fileUpload)
48-
fileUpload.setAttribute('type', 'file');
49-
50-
// onChange is when value of HTML element is changed
51-
// parameter for onChange is an event
52-
fileUpload.onchange = (e: Event) => {
53-
// FileReader is an object
54-
// reads contents of local files in async
55-
// can use file or blob objects
56-
const reader = new FileReader();
57-
console.log('on change triggered')
58-
//console.log('reader :', reader);
25+
function importHandler(dispatch: (a: unknown) => void): void { // function handles the importing of a tabs[currentTab] object when the upload button is selected
26+
const fileUpload = document.createElement('input'); // invisible HTML element that will hold our uploaded tabs[currentTab] object
27+
fileUpload.setAttribute('type', 'file'); // Attributes added to HTML element
5928

60-
const eventFiles = e.target as HTMLInputElement;
61-
// console.log('e.target:', e.target)
62-
// console.log('event files:', eventFiles.files[0]);
29+
fileUpload.onchange = (e: Event) => { // onChange is when value of HTML element is changed
30+
const reader = new FileReader(); // FileReader is an object that reads contents of local files in async. It can use file or blob objects
31+
const eventFiles = e.target as HTMLInputElement; // uploaded tabs[currentTab] object is stored as the event.target
6332

64-
if (eventFiles) {
65-
reader.readAsText(eventFiles.files[0]);
33+
if (eventFiles) { // if the fileUpload element has an eventFiles
34+
reader.readAsText(eventFiles.files[0]); // the reader parses the file into a string and stores it within the reader object
6635
}
6736

6837
reader.onload = () => {
69-
// once the local file has been loaded, result property on FileReader object returns the file's contents
70-
// then take contents and convert to a string
71-
console.log('on load triggered:')
72-
const test = reader.result.toString();
73-
// dispatch sends the result of calling importSnapshots on the json parsed data from the file contents from the new FileReader object
74-
// importSnapshots defined in actions/actions.ts/line 71, it returns an action object with a type and payload, payload is newSnaps parameter
75-
// dispatch function is being called with that action object which gets sent to the reducer in reducers/mainReducer.js/line 203
76-
// this updates the current tab
77-
return dispatch(importSnapshots(JSON.parse(test)));
38+
const test = reader.result.toString(); // once the local file has been loaded, result property on FileReader object returns the file's contents and then converts the file contents to a string
39+
return dispatch(importSnapshots(JSON.parse(test))); // dispatch sends the result of of converting our tabs[currentTab] object => string => JSON Object. This updates the current tab
7840
};
79-
// const eventFiles = e.target as HTMLInputElement;
80-
// if (eventFiles?.hasOwnProperty('files')) {
81-
// // const eventFiles = target as HTMLInputElement;
82-
// if (eventFiles) {
83-
// reader.readAsText(eventFiles.files[0]);
84-
// }
85-
// }
8641
};
8742

88-
fileUpload.click();
89-
//console.log('dispatch importSnapshots successful')
43+
fileUpload.click(); // click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
9044
}
9145

9246
function ButtonsContainer(): JSX.Element {
9347
const [{ tabs, currentTab, currentTabInApp }, dispatch] = useStoreContext();
94-
const {
95-
snapshots,
96-
mode: { paused },
97-
} = tabs[currentTab];
98-
99-
console.log('----state after any change----', tabs[currentTab])
100-
48+
const { snapshots, mode: { paused }} = tabs[currentTab];
49+
10150
return (
10251
<div className='buttons-container'>
10352
<Button

src/app/reducers/mainReducer.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ export default (state, action) =>
88
const { port, currentTab, tabs } = draft;
99
const { hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex } =
1010
tabs[currentTab] || {};
11-
12-
// console.log('----consoles before reducer funcs!-----')
13-
// console.log('state:', state)
14-
//console.log(tabs[currentTab]);
15-
//console.log('properties of tabs[currentTab]:', hierarchy, snapshots, mode, intervalId, viewIndex, sliderIndex)
16-
17-
//console.log('reducer file!', 'hierarchy:', hierarchy, 'tabs:', tabs)
18-
19-
// eslint-disable-next-line max-len
20-
// function that finds the index in the hierarchy and extracts the name of the equivalent index to add to the post message
2111
// eslint-disable-next-line consistent-return
22-
23-
// (action.payload, hierarchy)
2412
const findName = (index, obj) => {
2513
// eslint-disable-next-line eqeqeq
2614
if (obj && obj.index == index) {
@@ -44,7 +32,6 @@ export default (state, action) =>
4432
switch (action.type) {
4533
// This saves the series user wants to save to chrome local storage
4634
case types.SAVE: {
47-
console.log('save action reducer!', 'payload:', action.payload);
4835
const { newSeries, newSeriesName } = action.payload;
4936
if (!tabs[currentTab].seriesSavedStatus) {
5037
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'inputBoxOpen' };
@@ -192,9 +179,6 @@ export default (state, action) =>
192179
}
193180

194181
case types.EMPTY: {
195-
console.log('-----clear snapshots reducer----');
196-
console.log('state before:', state.tabs[currentTab]);
197-
198182
port.postMessage({ action: 'emptySnap', tabId: currentTab }); //communicate with background.js (service worker)
199183

200184
// properties associated with timetravel + seek bar
@@ -223,17 +207,12 @@ export default (state, action) =>
223207

224208
case types.IMPORT: {
225209
// Log the value of tabs[currentTab].snapshots before the update
226-
console.log('-----import snapshots reducer----');
227-
console.log('state before:', state.tabs[currentTab]);
228-
console.log('action payload:', action.payload);
229-
230210
port.postMessage({
231211
action: 'import',
232212
payload: action.payload, //.snapshots,
233213
tabId: currentTab,
234214
});
235215

236-
//============
237216
const savedSnapshot = action.payload;
238217

239218
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
@@ -255,14 +234,6 @@ export default (state, action) =>
255234
tabs[currentTab].currParent = savedSnapshot.currParent;
256235
tabs[currentTab].currBranch = savedSnapshot.Branch;
257236
tabs[currentTab].seriesSavedStatus = false;
258-
259-
//============
260-
//tabs[currentTab].snapshots = action.payload.snapshots;
261-
262-
// console.log('New snapshots:', action.payload);
263-
// console.log('updated tabs[CurrentTab].snapshots:', tabs[currentTab].snapshots)
264-
//console.log('state after:', state)
265-
266237
break;
267238
}
268239
case types.TOGGLE_MODE: {

0 commit comments

Comments
 (0)