55/* eslint-disable @typescript-eslint/no-var-requires */
66/* eslint-disable max-len */
77/* eslint-disable object-curly-newline */
8- import React from 'react' ;
8+ import React , { useState } from 'react' ;
99import { MemoryRouter as Router , Route , NavLink , Routes , Outlet , Link } from 'react-router-dom' ;
1010import { ParentSize } from '@visx/responsive' ;
1111import Tree from './Tree' ;
1212import ComponentMap from './ComponentMap/ComponentMap' ;
13- import { changeView , changeSlider } from '../../slices/mainSlice' ;
14- import { useSelector } from 'react-redux' ;
13+ import { changeView , changeSlider , toggleAxTree , setCurrentTabInApp } from '../../slices/mainSlice' ;
14+ import { useDispatch , useSelector } from 'react-redux' ;
1515import PerformanceVisx from './PerformanceVisx/PerformanceVisx' ;
1616import WebMetricsContainer from './WebMetrics/WebMetricsContainer' ;
1717import { MainState , RootState , StateRouteProps } from '../../FrontendTypes' ;
@@ -35,11 +35,33 @@ const StateRoute = (props: StateRouteProps) => {
3535 currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
3636 } = props ;
3737
38+
3839 const { tabs, currentTab } : MainState = useSelector ( ( state : RootState ) => state . main ) ;
3940 const { hierarchy : tabsHierarchy , sliderIndex, viewIndex : tabsViewIndex } = tabs [ currentTab ] ;
4041 const hierarchy = propsHierarchy || tabsHierarchy ;
4142 const viewIndex = propsViewIndex || tabsViewIndex ;
4243
44+ const dispatch = useDispatch ( ) ;
45+ const [ showTree , setShowTree ] = useState ( false ) ;
46+ const [ selectedValue , setSelectedValue ] = useState ( 'disable' ) ;
47+ const [ showParagraph , setShowParagraph ] = useState ( true ) ;
48+
49+ const enableAxTreeButton = ( ) => {
50+ dispatch ( toggleAxTree ( 'toggleAxRecord' ) ) ;
51+ dispatch ( setCurrentTabInApp ( 'AxTree' ) ) ;
52+ setSelectedValue ( 'enable' ) ;
53+ setShowParagraph ( false ) ;
54+ setShowTree ( true ) ;
55+ } ;
56+
57+ const disableAxTree = ( ) => {
58+ dispatch ( toggleAxTree ( 'toggleAxRecord' ) ) ;
59+ setSelectedValue ( 'disable' ) ;
60+ setShowParagraph ( true ) ;
61+ setShowTree ( false ) ;
62+ } ;
63+
64+
4365 return (
4466 < div className = 'app-body' >
4567 < div className = 'navbar' >
@@ -102,7 +124,7 @@ const StateRoute = (props: StateRouteProps) => {
102124 < Route
103125 path = '/accessibility'
104126 element = {
105- hierarchy ? (
127+ showTree ? (
106128 < ParentSize className = 'componentMapContainer' >
107129 { ( { width, height } ) => {
108130 // eslint-disable-next-line react/prop-types
@@ -121,7 +143,40 @@ const StateRoute = (props: StateRouteProps) => {
121143 ) ;
122144 } }
123145 </ ParentSize >
124- ) : null
146+ ) : < div >
147+ { showParagraph && (
148+ < p >
149+ A Note to Developers: Reactime is using the Chrome Debugger API in order to grab the
150+ Accessibility Tree. Enabling this option will allow you to record Accessibility Tree
151+ snapshots, but will result in the Chrome browser notifying you that the Chrome Debugger
152+ has started.
153+ </ p >
154+ ) }
155+ < div >
156+ {
157+ < input
158+ type = 'radio'
159+ value = 'enable'
160+ checked = { selectedValue === 'enable' }
161+ onChange = { ( ) => {
162+ enableAxTreeButton ( ) ;
163+ } }
164+ />
165+ }
166+ < label htmlFor = 'enable' > Enable</ label >
167+ {
168+ < input
169+ type = 'radio'
170+ value = 'disable'
171+ checked = { selectedValue === 'disable' }
172+ onChange = { ( ) => {
173+ disableAxTree ( ) ;
174+ } }
175+ />
176+ }
177+ < label htmlFor = 'disable' > Disable</ label >
178+ </ div >
179+ </ div >
125180 }
126181 > </ Route >
127182 < Route
0 commit comments