Skip to content

Commit f90ad7f

Browse files
authored
Merge pull request #12 from oslabs-beta/oliver/ax-time-travel
Oliver/ax time travel
2 parents 38f1117 + 4d4bba5 commit f90ad7f

File tree

4 files changed

+94
-63
lines changed

4 files changed

+94
-63
lines changed

src/app/components/StateRoute/Ax.tsx

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,52 @@ import { setCurrentTabInApp } from '../../slices/mainSlice';
44
import { useDispatch } from 'react-redux';
55

66
const theme = {
7-
scheme: 'monokai',
8-
author: 'wimer hazenberg (http://www.monokai.nl)',
9-
base00: '#272822',
10-
base01: '#383830',
11-
base02: '#49483e',
12-
base03: '#75715e',
13-
base04: '#a59f85',
14-
base05: '#f8f8f2',
15-
base06: '#f5f4f1',
16-
base07: '#f9f8f5',
17-
base08: '#f92672',
18-
base09: '#fd971f',
19-
base0A: '#f4bf75',
20-
base0B: '#a6e22e',
21-
base0C: '#a1efe4',
22-
base0D: '#66d9ef',
23-
base0E: '#ae81ff',
24-
base0F: '#cc6633',
25-
};
7+
scheme: 'monokai',
8+
author: 'wimer hazenberg (http://www.monokai.nl)',
9+
base00: '#272822',
10+
base01: '#383830',
11+
base02: '#49483e',
12+
base03: '#75715e',
13+
base04: '#a59f85',
14+
base05: '#f8f8f2',
15+
base06: '#f5f4f1',
16+
base07: '#f9f8f5',
17+
base08: '#f92672',
18+
base09: '#fd971f',
19+
base0A: '#f4bf75',
20+
base0B: '#a6e22e',
21+
base0C: '#a1efe4',
22+
base0D: '#66d9ef',
23+
base0E: '#ae81ff',
24+
base0F: '#cc6633',
25+
};
2626

2727
const AxTree = (props) => {
28-
const {
29-
snapshot, // from 'tabs[currentTab]' object in 'MainContainer'
30-
snapshots, // from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
31-
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
32-
axSnapshots,
33-
} = props;
28+
const {
29+
snapshot, // from 'tabs[currentTab]' object in 'MainContainer'
30+
snapshots, // from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
31+
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
32+
axSnapshots,
33+
} = props;
3434

35-
const dispatch = useDispatch();
35+
const dispatch = useDispatch();
3636

37-
useEffect(() => {
38-
dispatch(setCurrentTabInApp('AxTree')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'tree' to facilitate render.
39-
}, []);
37+
useEffect(() => {
38+
dispatch(setCurrentTabInApp('AxTree')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'tree' to facilitate render.
39+
}, []);
4040

41-
//removing/adding snapshot at beginning of return statement didn't change anything
42-
return(
43-
<> {snapshot && (
44-
<JSONTree
45-
data={axSnapshots}
46-
// shouldExpandNodeInitially={() => true}
47-
theme = {theme}
48-
/>
49-
)}
50-
</>
51-
)
52-
}
53-
export default AxTree;
41+
//removing/adding snapshot at beginning of return statement didn't change anything
42+
return (
43+
<>
44+
{' '}
45+
{snapshot && (
46+
<JSONTree
47+
data={axSnapshots[currLocation.index]}
48+
shouldExpandNodeInitially={() => true}
49+
theme={theme}
50+
/>
51+
)}
52+
</>
53+
);
54+
};
55+
export default AxTree;

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,29 @@ const StateRoute = (props: StateRouteProps) => {
8787
Tree
8888
</NavLink>
8989
<NavLink
90-
className = {(navData) =>
91-
navData.isActive ? 'is-active router-link accessibility-tab' : 'router-link accessibility-tab'
92-
}
93-
to = '/accessibility'
90+
className={(navData) =>
91+
navData.isActive
92+
? 'is-active router-link accessibility-tab'
93+
: 'router-link accessibility-tab'
94+
}
95+
to='/accessibility'
9496
>
9597
Accessibility
9698
</NavLink>
9799
</div>
98100
<div className='app-content'>
99101
<Routes>
100102
<Route
101-
path = '/accessibility'
102-
element = {<AxTree
103-
axSnapshots={axSnapshots}
104-
snapshot={snapshot}
105-
snapshots={snapshots}
106-
currLocation={currLocation}/>}
107-
>
108-
</Route>
103+
path='/accessibility'
104+
element={
105+
<AxTree
106+
axSnapshots={axSnapshots}
107+
snapshot={snapshot}
108+
snapshots={snapshots}
109+
currLocation={currLocation}
110+
/>
111+
}
112+
></Route>
109113
<Route
110114
path='/history'
111115
element={

src/backend/models/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class Routes {
103103
);
104104
// If the target route is not found, throw an error
105105
if (targetIndex === -1) {
106-
throw new Error('Error at Routes.navigage: targetIndex is undefined');
106+
throw new Error('Error at Routes.navigate: targetIndex is undefined');
107107
}
108108
// Calculate the difference in index between the current route and the target route
109109
const delta: number = targetIndex - this.current;

src/extension/background.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function createTabObj(title) {
9393
// 1. param 'obj' : arg request.payload, which is an object containing a tree from snapShot.ts and a route property
9494
// 2. param tabObj: arg tabsObj[tabId], which is an object that holds info about a specific tab. Should change the name of tabObj to tabCollection or something
9595
class HistoryNode {
96-
constructor(obj, tabObj) {
96+
constructor(tabObj, newStateSnapshot, newAxSnapshot) {
9797
// continues the order of number of total state changes
9898
this.index = tabObj.index;
9999
tabObj.index += 1;
@@ -102,8 +102,8 @@ class HistoryNode {
102102
this.name = tabObj.currParent;
103103
// marks from what branch this node is originated
104104
this.branch = tabObj.currBranch;
105-
this.stateSnapshot = obj;
106-
this.axSnapshot = tabObj.axSnapshots[tabObj.axSnapshots.length - 1];
105+
this.stateSnapshot = newStateSnapshot;
106+
this.axSnapshot = newAxSnapshot;
107107
this.children = [];
108108
}
109109
}
@@ -250,9 +250,11 @@ chrome.runtime.onConnect.addListener((port) => {
250250
case 'import': // create a snapshot property on tabId and set equal to tabs object
251251
// may need do something like filter payload from stateless
252252
tabsObj[tabId].snapshots = payload.snapshots; // reset snapshots to page last state recorded
253+
tabsObj[tabId].axSnapshots = payload.axSnapshots; // TRYING to import axsnapshots
253254
// tabsObj[tabId].hierarchy = savedSnapshot.hierarchy; // why don't we just use hierarchy? Because it breaks everything...
254255
tabsObj[tabId].hierarchy.children = payload.hierarchy.children; // resets hierarchy to last state recorded
255256
tabsObj[tabId].hierarchy.stateSnapshot = payload.hierarchy.stateSnapshot; // resets hierarchy to last state recorded
257+
tabsObj[tabId].hierarchy.axSnapshot = payload.hierarchy.axSnapshot; // TRYING to import hierarchy axsnapshot
256258
tabsObj[tabId].currLocation = payload.currLocation; // resets currLocation to last state recorded
257259
tabsObj[tabId].index = payload.index; //reset index to last state recorded
258260
tabsObj[tabId].currParent = payload.currParent; // reset currParent to last state recorded
@@ -268,10 +270,17 @@ chrome.runtime.onConnect.addListener((port) => {
268270
// resets hierarchy to page last state recorded
269271
...tabsObj[tabId].snapshots[0],
270272
};
273+
tabsObj[tabId].axSnapshots =
274+
tabsObj[tabId].axSnapshots[tabsObj[tabId].axSnapshots.length - 1];
275+
tabsObj[tabId].hierarchy.axSnapshot = tabsObj[tabId].axSnapshots[0]; //what about other hierarchy properties? Shouldn't those be reset as well?
271276
tabsObj[tabId].currLocation = tabsObj[tabId].hierarchy; // resets currLocation to page last state recorded
272277
tabsObj[tabId].index = 1; //reset index
273278
tabsObj[tabId].currParent = 0; // reset currParent
274279
tabsObj[tabId].currBranch = 1; // reset currBranch
280+
console.log(
281+
'background.js: bottom of emptySnap: tabsObj[tabId]:',
282+
JSON.parse(JSON.stringify(tabsObj[tabId])),
283+
);
275284
return true; // return true so that port remains open
276285

277286
case 'setPause': // Pause = lock on tab
@@ -405,6 +414,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
405414
function addAxSnap(snap) {
406415
const pruned = pruneAxTree(snap);
407416
tabsObj[tabId].axSnapshots.push(pruned);
417+
return pruned;
408418
}
409419

410420
function attachDebugger(tabId, version) {
@@ -448,8 +458,9 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
448458
await attachDebugger(tabId, '1.3');
449459
await sendDebuggerCommand(tabId, 'Accessibility.enable');
450460
const response = await sendDebuggerCommand(tabId, 'Accessibility.getFullAXTree');
451-
addAxSnap(response.nodes);
461+
const addedAxSnap = addAxSnap(response.nodes);
452462
await detachDebugger(tabId);
463+
return addedAxSnap;
453464
} catch (error) {
454465
console.error('axRecord debugger command failed:', error);
455466
}
@@ -458,12 +469,19 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
458469
tabsObj[tabId].webMetrics = metrics;
459470

460471
if (!firstSnapshotReceived[tabId]) {
461-
await axRecord(tabId);
462472
firstSnapshotReceived[tabId] = true;
463473
reloaded[tabId] = false;
464474
tabsObj[tabId].webMetrics = metrics;
465475
tabsObj[tabId].snapshots.push(request.payload);
466-
sendToHierarchy(tabsObj[tabId], new HistoryNode(request.payload, tabsObj[tabId]));
476+
const addedAxSnap = await axRecord(tabId);
477+
sendToHierarchy(
478+
tabsObj[tabId],
479+
new HistoryNode(tabsObj[tabId], request.payload, addedAxSnap),
480+
);
481+
console.log(
482+
'background.js: bottom of recordSnap: tabsObj[tabId]:',
483+
JSON.parse(JSON.stringify(tabsObj[tabId])),
484+
);
467485
if (portsArr.length > 0) {
468486
portsArr.forEach((bg) =>
469487
bg.postMessage({
@@ -492,8 +510,15 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
492510
tabsObj[tabId].snapshots.push(request.payload);
493511
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
494512
if (!tabsObj[tabId][index]) {
495-
await axRecord(tabId);
496-
sendToHierarchy(tabsObj[tabId], new HistoryNode(request.payload, tabsObj[tabId]));
513+
const addedAxSnap = await axRecord(tabId);
514+
sendToHierarchy(
515+
tabsObj[tabId],
516+
new HistoryNode(tabsObj[tabId], request.payload, addedAxSnap),
517+
);
518+
console.log(
519+
'background.js: bottom of recordSnap: tabsObj[tabId]:',
520+
JSON.parse(JSON.stringify(tabsObj[tabId])),
521+
);
497522
}
498523
}
499524

0 commit comments

Comments
 (0)