Skip to content

Commit e61b053

Browse files
authored
Merge pull request #39 from oslabs-beta/ReactimeCleanUp
Removed console logs and any outdated comments
2 parents 0699ba2 + f84e61f commit e61b053

File tree

11 files changed

+434
-517
lines changed

11 files changed

+434
-517
lines changed

src/app/RTKslices.tsx

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const findName = (index, obj) => {
2424
objChildArray.push(findName(index, objChild));
2525
}
2626
}
27-
console.log(objChildArray);
2827
// eslint-disable-next-line no-restricted-syntax
2928
for (const objChildName of objChildArray) {
3029
if (objChildName) {
@@ -40,36 +39,37 @@ export const mainSlice = createSlice({
4039

4140
emptySnapshots: (state) => {
4241
const { tabs, currentTab, port } = state;
43-
console.log("this is state 2", current(state));
4442

45-
port.postMessage({ action: 'emptySnap', tabId: currentTab });
43+
port.postMessage({ action: 'emptySnap', tabId: currentTab }); //communicate with background.js (service worker)
4644

45+
// properties associated with timetravel + seek bar
4746
tabs[currentTab].sliderIndex = 0;
4847
tabs[currentTab].viewIndex = 0;
4948
tabs[currentTab].playing = false;
5049

51-
const lastSnapshot = tabs[currentTab].snapshots[tabs[currentTab].snapshots.length - 1];
50+
const lastSnapshot = tabs[currentTab].snapshots[tabs[currentTab].snapshots.length - 1]; // the most recent snapshot
5251

53-
tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot };
54-
tabs[currentTab].hierarchy.children = [];
55-
tabs[currentTab].snapshots = [lastSnapshot];
52+
tabs[currentTab].hierarchy.stateSnapshot = { ...lastSnapshot }; // resets hierarchy to page last state recorded
53+
tabs[currentTab].hierarchy.children = []; // resets hierarchy
54+
tabs[currentTab].snapshots = [lastSnapshot]; // resets snapshots to page last state recorded
5655

56+
// resets currLocation to page last state recorded
5757
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
58-
console.log('tabsHieracyh', tabs[currentTab].hierarchy);
5958
tabs[currentTab].index = 1;
6059
tabs[currentTab].currParent = 0;
6160
tabs[currentTab].currBranch = 1;
6261
tabs[currentTab].seriesSavedStatus = false;
6362
},
6463

6564
addNewSnapshots: (state, action) => {
66-
const { tabs } = state;
65+
const { tabs, currentTab } = state;
6766

6867
const { payload } = action;
6968
Object.keys(tabs).forEach(tab => {
7069
if (!payload[tab])
7170
delete tabs[tab];
7271
else {
72+
// maintain isExpanded prop from old stateSnapshot to preserve componentMap expansion
7373
const persistIsExpanded = (newNode, oldNode) => {
7474
newNode.isExpanded = oldNode ? oldNode.isExpanded : true;
7575
if (newNode.children) {
@@ -91,6 +91,10 @@ export const mainSlice = createSlice({
9191
};
9292
}
9393
});
94+
95+
// only set first tab if current tab is non existent
96+
const firstTab = parseInt(Object.keys(payload)[0], 10);
97+
if (currentTab === undefined || currentTab === null) state.currentTab = firstTab;
9498
},
9599

96100
initialConnect: (state, action) => {
@@ -117,9 +121,7 @@ export const mainSlice = createSlice({
117121
},
118122

119123
setPort: (state, action) => {
120-
console.log('port start: ', current(state))
121124
state.port = action.payload;
122-
console.log('port end: ', current(state))
123125
},
124126

125127
setTab: (state, action) => {
@@ -174,43 +176,18 @@ export const mainSlice = createSlice({
174176

175177
changeView: (state, action) => {
176178
const {tabs, currentTab} = state;
177-
console.log('this is state:', current(state))
178-
console.log('this is tabs:', tabs)
179-
console.log('this is currentabs:', currentTab)
180-
console.log('this is tabs[currentab]', tabs[currentTab])
181179
const {viewIndex} = tabs[currentTab] || {};
182-
console.log('hi this is viewIndex:', viewIndex);
183-
console.log('this is action payload', action.payload)
180+
// unselect view if same index was selected
184181
tabs[currentTab].viewIndex = viewIndex === action.payload ? -1 : action.payload;
185-
// if (viewIndex === action.payload) tabs[currentTab].viewIndex = -1;
186-
// else tabs[currentTab].viewIndex = action.payload;
187-
// tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
188-
189-
// case types.CHANGE_VIEW: {
190-
// // unselect view if same index was selected
191-
// // console.log('action:', action)
192-
// // console.log('state: ', state)
193-
// if (viewIndex === action.payload) tabs[currentTab].viewIndex = -1;
194-
// else tabs[currentTab].viewIndex = action.payload;
195-
// // update currLocation
196-
// // tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
197-
// break;
198-
// }
199-
200182
},
201183

202184
changeSlider: (state, action) => {
203185
const { port, currentTab, tabs } = state;
204186
const { hierarchy, snapshots } = tabs[currentTab] || {};
205187

206-
console.log('this is PORT', port);
207-
console.log('this is hierarchy', hierarchy);
208-
console.log('this is SNapshots', snapshots);
209-
188+
// finds the name by the action.payload parsing through the hierarchy to send to background.js the current name in the jump action
210189
const nameFromIndex = findName(action.payload, hierarchy);
211-
212-
// console.log('this is action payload', action.payload);
213-
// console.log('this is nameFromIndex', nameFromIndex);
190+
// nameFromIndex is a number based on which jump button is pushed
214191

215192
port.postMessage({
216193
action: 'jumpToSnap',
@@ -234,8 +211,6 @@ export const mainSlice = createSlice({
234211
clearInterval(intervalId);
235212
tabs[currentTab].playing = false;
236213
tabs[currentTab].intervalId = null;
237-
console.log('pause: state end', current(state));
238-
239214
},
240215

241216
launchContentScript: (state, action) => {
@@ -408,7 +383,7 @@ export const mainSlice = createSlice({
408383

409384
tutorialSaveSeriesToggle: (state, action) => {
410385
const { tabs, currentTab } = state;
411-
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
386+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload } // sets the tab[currentTab]'s 'seriesSavedStatus' property to the payload.
412387
},
413388

414389
onHover: (state, action) => {
@@ -437,7 +412,6 @@ export const mainSlice = createSlice({
437412
const { newSeries, newSeriesName } = action.payload;
438413
if (!tabs[currentTab].seriesSavedStatus) {
439414
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'inputBoxOpen' };
440-
//testing return to fix save functionality
441415
return;
442416
}
443417
// Runs if series name input box is active.
@@ -449,7 +423,6 @@ export const mainSlice = createSlice({
449423
seriesArray.push(newSeries);
450424
localStorage.setItem('project', JSON.stringify(seriesArray));
451425
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'saved' };
452-
//testing return to fix save functionality instead of break
453426
return;
454427
}
455428
},

src/app/__tests__/ButtonContainer.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ describe('Unit testing for ButtonContainer', () => {
176176
test('it should have 5 buttons', () => {
177177
customInitialState.main.connectionStatus = true;
178178
render(<ButtonsContainer />);
179-
// console.log(screen.getAllByRole('button')[4])
180179
expect(screen.getAllByRole('button')).toHaveLength(5);
181180
expect(screen.getAllByRole('button')[0]).toHaveTextContent('Locked');
182181
expect(screen.getAllByRole('button')[1]).toHaveTextContent('Download');

src/app/__tests__/TravelForwardBackward.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ jest.mock('react-redux', () => ({
152152

153153
test('Clicking < Button button will trigger button', () => {
154154
let buttons = screen.getAllByRole('button');
155-
console.log(buttons);
156155
fireEvent.click(buttons[1]);
157156
expect(dummyDispatch).toHaveBeenCalledTimes(1);
158157
});

src/app/components/StateRoute/History.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ function History(props: Record<string, unknown>): JSX.Element {
185185
.style('cursor', 'pointer')
186186
.attr('class', `snapshotNode`)
187187
.on('click', (event, d) => {
188-
console.log('d.data.index: ', d.data.index)
189188
dispatch(changeView(d.data.index));
190189
dispatch(changeSlider(d.data.index));
191190
/*

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,11 @@ const BarGraph = (props: BarGraphProps): JSX.Element => {
111111
});
112112

113113
const saveSeriesClickHandler = () => { // function to save the currently selected series
114-
console.log('we are in save series click handler')
115114
if (tabs[currentTab].seriesSavedStatus === 'inputBoxOpen') {
116-
console.log('we are inside the conditional within saveSeriesClickHandler')
117-
console.log('this is the comparison.length', comparison.length)
118115
const actionNames = document.getElementsByClassName('actionname');
119116
for (let i = 0; i < actionNames.length; i += 1) {
120117
toStorage.data.barStack[i].name = actionNames[i].value;
121118
}
122-
console.log('this is seriesnameINput', seriesNameInput);
123-
console.log('this is toStorage', toStorage);
124119
dispatch(save({ newSeries: toStorage, newSeriesName: seriesNameInput })); // saves the series under seriesName
125120
setSeriesNameInput(`Series ${comparison.length}`); // sends a reducer that saves the series/toStorage object the user wants to chrome local storage
126121
return;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ const traverse = (snapshot, data, snapshots, currTotalRender: currNum = 0): void
122122
const allStorage = (): Series[] => {
123123
let values = localStorage.getItem('project');
124124
const newValues: Series[] = values === null ? [] : JSON.parse(values);
125-
console.log('this is newValues', newValues);
126125
return newValues;
127126
};
128127

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ const StateRoute = (props: StateRouteProps) => {
114114
if (webMetrics.INP <= 200) INPColor = '#0bce6b';
115115
if (webMetrics.INP <= 500) INPColor = '#E56543';
116116
if (webMetrics.INP > 500) INPColor = '#fc2000';
117-
console.log('WEBMETRICS YOOO', webMetrics);
118117

119118
return (
120119
<div className='web-metrics-container'>

src/app/containers/MainContainer.tsx

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,53 +48,13 @@ function MainContainer(): JSX.Element {
4848
}
4949
};
5050

51-
52-
53-
51+
// Function handles when Reactime unexpectedly disconnects
5452
const handleDisconnect = (msg): void => {
55-
if (msg === 'portDisconnect') {
56-
console.log('unexpected port disconnection');
53+
if (msg === 'portDisconnect')
5754
dispatch(disconnected());
58-
}
59-
}
60-
61-
const handleConnect = () => {
62-
const maxRetries = 10;
63-
const retryInterval = 1000;
64-
const maxTimeout = 15000;
65-
66-
return new Promise((resolve) => {
67-
let port: chrome.runtime.Port;
68-
console.log('init port: ', port)
69-
70-
const attemptReconnection = (retries: number, startTime: number) => {
71-
// console.log('WORKING')
72-
if (retries <= maxRetries && Date.now() - startTime < maxTimeout) {
73-
if (retries === 1)
74-
port = chrome.runtime.connect();
75-
// console.log('HITTING IF');
76-
chrome.runtime.sendMessage({ action: 'attemptReconnect' }, (response) => {
77-
if (response && response.success) {
78-
console.log('Reconnect Success: ', response.success);
79-
resolve(port);
80-
} else {
81-
console.log('Reconnect failed: ', !response && response.success);
82-
83-
setTimeout(() => {
84-
console.log('trying!', retries)
85-
attemptReconnection(retries + 1, startTime);
86-
}, retryInterval);
87-
}
88-
});
89-
} else {
90-
console.log('PORT CONNECT FAILED');
91-
resolve(null);
92-
}
93-
};
94-
attemptReconnection(1, Date.now());
95-
});
9655
}
9756

57+
// Function to listen for a message containing snapshots from the /extension/build/background.js service worker
9858
const messageListener = (message: {
9959
action: string;
10060
payload: Record<string, unknown>;
@@ -120,7 +80,6 @@ function MainContainer(): JSX.Element {
12080
break;
12181
}
12282
case 'changeTab': {
123-
console.log('received changeTab message')
12483
dispatch(setTab(payload));
12584
break;
12685
}
@@ -145,18 +104,21 @@ function MainContainer(): JSX.Element {
145104
useEffect(() => {
146105
if (port) return; // only open port once so if it exists, do not run useEffect again
147106

107+
// Connect ot port and assign evaluated result (obj) to currentPort
148108
const currentPort = chrome.runtime.connect();
149109

150-
while (chrome.runtime.onMessage.hasListener(messageListener))
151-
chrome.runtime.onMessage.removeListener(messageListener);
110+
// If messageListener exists on currentPort, remove it
111+
while (currentPort.onMessage.hasListener(messageListener))
112+
currentPort.onMessage.removeListener(messageListener);
152113

153-
// listen for a message containing snapshots from the /extension/build/background.js service worker
114+
// Add messageListener to the currentPort
154115
currentPort.onMessage.addListener(messageListener);
155116

117+
// If handleDisconnect exists on chrome.runtime, remove it
156118
while (chrome.runtime.onMessage.hasListener(handleDisconnect))
157119
chrome.runtime.onMessage.removeListener(handleDisconnect);
158120

159-
// used to track when the above connection closes unexpectedly. Remember that it should persist throughout the application lifecycle
121+
// add handleDisconnect to chrome.runtime
160122
chrome.runtime.onMessage.addListener(handleDisconnect);
161123

162124
// assign port to state so it could be used by other components

0 commit comments

Comments
 (0)