Skip to content

Commit c1dbbf3

Browse files
committed
fixed app crashing bug
1 parent b9af266 commit c1dbbf3

File tree

6 files changed

+55
-35
lines changed

6 files changed

+55
-35
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from "react";
2+
import { ParentSize } from '@visx/responsive';
3+
import AxTree from "./AxMap/Ax";
4+
5+
const AxContainer = (props) => {
6+
const {
7+
axSnapshots, // from 'tabs[currentTab]' object in 'MainContainer'
8+
snapshot, // from 'tabs[currentTab]' object in 'MainContainer'
9+
snapshots, // from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
10+
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
11+
} = props;
12+
13+
return (
14+
<div>
15+
<ParentSize className='componentMapContainer'>
16+
{({ width, height }) => {
17+
// eslint-disable-next-line react/prop-types
18+
const maxHeight: number = 1200;
19+
const h = Math.min(height, maxHeight);
20+
return (
21+
<AxTree
22+
axSnapshots={axSnapshots}
23+
snapshot={snapshot}
24+
snapshots={snapshots}
25+
currLocation={currLocation}
26+
width={width}
27+
height={h}
28+
/>
29+
);
30+
}}
31+
</ParentSize>
32+
</div>
33+
)
34+
}
35+
36+
export default AxContainer;

src/app/components/StateRoute/AxMap/Ax.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ export type LinkTypesProps = {
166166
export default function AxTree(props) {
167167
const { currLocation, axSnapshots, width, height } = props;
168168

169+
170+
169171
let margin = defaultMargin;
170172
let totalWidth = width;
171173
let totalHeight = height;
172174

173-
175+
if (axSnapshots[currLocation.index] === 'emptyAxSnap') return;
174176

175177
const toolTipTimeoutID = useRef(null); //useRef stores stateful data that’s not needed for rendering.
176178
const {
@@ -181,7 +183,7 @@ export default function AxTree(props) {
181183
showTooltip, // function to set tooltip state
182184
hideTooltip, // function to close a tooltip
183185
} = useTooltip(); // returns an object with several properties that you can use to manage the tooltip state of your component
184-
console.log('tool tip data: ', tooltipData);
186+
185187
// let nameVal = JSON.stringify(tooltipData)
186188
// console.log('nameVal', nameVal);
187189
const {
@@ -244,12 +246,9 @@ export default function AxTree(props) {
244246
}
245247
}
246248

247-
console.log('size width height ax: ', sizeWidth, sizeHeight);
248-
249249
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
250250

251251
const currAxSnapshot = JSON.parse(JSON.stringify(axSnapshots[currLocation.index]));
252-
console.log('currAxSnapshot: ', currAxSnapshot);
253252

254253
// root node of currAxSnapshot
255254
const rootAxNode = JSON.parse(JSON.stringify(currAxSnapshot[0]));
@@ -295,8 +294,6 @@ export default function AxTree(props) {
295294

296295
organizeAxTree(rootAxNode, currAxSnapshot);
297296

298-
console.log('rootAxNode: ', rootAxNode);
299-
300297
// store each individual node, now with children property in nodeAxArr
301298
// need to consider order, iterate through the children property first?
302299
const populateNodeAxArr = (currNode) => {
@@ -316,7 +313,6 @@ export default function AxTree(props) {
316313
};
317314

318315
populateNodeAxArr(rootAxNode);
319-
console.log('nodeAxArr: ', nodeAxArr);
320316

321317
// ax Legend
322318
const { axLegendButtonClicked } = useSelector((state: RootState) => state.axLegend);
@@ -468,7 +464,6 @@ export default function AxTree(props) {
468464
const handleMouseAndClickOver = (event): void => {
469465
const coords = localPoint(event.target.ownerSVGElement, event);
470466
const tooltipObj = { ...node.data };
471-
console.log("tooltipobj: ", tooltipObj);
472467

473468
showTooltip({
474469
tooltipLeft: coords.x,

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import PerformanceVisx from './PerformanceVisx/PerformanceVisx';
1616
import WebMetricsContainer from './WebMetrics/WebMetricsContainer';
1717
import { MainState, RootState, StateRouteProps } from '../../FrontendTypes';
1818
import AxTree from './AxMap/Ax';
19+
import AxContainer from './AxContainer';
20+
import { divide } from 'lodash';
1921

2022
/*
2123
Loads the appropriate StateRoute view and renders the Map, Performance, History, Webmetrics, and Tree navbar buttons after clicking on the 'State' button located near the top rightmost corner.
@@ -123,21 +125,15 @@ const StateRoute = (props: StateRouteProps) => {
123125
path='/accessibility'
124126
element={
125127
showTree ? (
126-
<ParentSize className='componentMapContainer'>
127-
{({ width, height }) => {
128-
// eslint-disable-next-line react/prop-types
129-
const maxHeight: number = 1200;
130-
const h = Math.min(height, maxHeight);
131-
return (
132-
<div>
133-
<input
128+
<div>
129+
<input
134130
type='radio'
135131
value='enable'
136132
checked={selectedValue === 'enable'}
137133
onChange={() => {
138134
enableAxTreeButton();
139135
}}
140-
/>{' '}
136+
/>
141137
<label htmlFor='enable'>Enable</label>
142138
<input
143139
type='radio'
@@ -148,18 +144,10 @@ const StateRoute = (props: StateRouteProps) => {
148144
}}
149145
/>
150146
<label htmlFor='disable'>Disable</label>
151-
<AxTree
152-
axSnapshots={axSnapshots}
153-
snapshot={snapshot}
154-
snapshots={snapshots}
155-
currLocation={currLocation}
156-
width={width}
157-
height={h}
158-
/>
159-
</div>
160-
);
161-
}}
162-
</ParentSize>
147+
{showTree && <AxContainer
148+
axSnapshots={axSnapshots}
149+
currLocation={currLocation}/>}
150+
</div>
163151
) : (
164152
<div>
165153
{showParagraph && (

src/app/containers/MainContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function MainContainer(): JSX.Element {
102102
break;
103103
}
104104
case 'sendSnapshots': {
105-
dispatch(setTab(sourceTab));
105+
dispatch(setTab(payload));
106106
// set state with the information received from the background script
107107
dispatch(addNewSnapshots(payload));
108108
break;
@@ -167,7 +167,6 @@ function MainContainer(): JSX.Element {
167167
tabs[currentTab]; // we destructure the currentTab object which is passed in from background.js
168168
//@ts-ignore
169169
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex]; // if viewIndex is -1, then use the sliderIndex instead
170-
171170
// cleaning hierarchy and snapshotView from stateless data
172171
const statelessCleaning = (obj: {
173172
name?: string;

src/app/slices/mainSlice.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ export const mainSlice = createSlice({
119119
tabs[currentTab] || {};
120120
const { payload } = action;
121121

122-
// console.log('mainSlice.ts: axSnapshots:', tabs[currentTab].axSnapshots);
123-
124122
Object.keys(payload).forEach((tab) => {
125123
// check if tab exists in memory
126124
// add new tab

src/extension/background.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,11 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
620620
);
621621
}
622622
}
623-
623+
console.log('postMessage sending snapshots from background js:', {
624+
action: 'sendSnapshots',
625+
payload: tabsObj,
626+
sourceTab,
627+
})
624628
// sends new tabs obj to devtools
625629
if (portsArr.length > 0) {
626630
portsArr.forEach((bg) =>

0 commit comments

Comments
 (0)