5
5
VersionItem ,
6
6
SuiteResult ,
7
7
ConformanceState ,
8
- SortOption ,
9
8
} from "@site/src/components/conformance/types" ;
10
9
import ResultNavigation from "./nav" ;
11
10
import {
@@ -28,8 +27,16 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
28
27
// Refs
29
28
const activeResults = React . useRef < undefined | ResultInfo > ( ) ;
30
29
30
+ // History handling
31
31
const history = useHistory < ConformanceState > ( ) ;
32
32
33
+ const pushStateToHistory = ( state : ConformanceState ) : void => {
34
+ history . push ( {
35
+ pathname : "/conformance" ,
36
+ state,
37
+ } ) ;
38
+ } ;
39
+
33
40
React . useEffect ( ( ) => {
34
41
// If the version is correctly synced
35
42
if ( props . state . version . tagName !== activeResults . current ?. version ) {
@@ -60,7 +67,6 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
60
67
const updateActiveResults = async ( ) : Promise < ResultInfo > => {
61
68
const data = await fetchResults ( props . state . version ) ;
62
69
return mapToResultInfo ( props . state . version . tagName , data ) ;
63
- // setCurrentSuite(resultInfo.results);
64
70
} ;
65
71
66
72
const findResultsFromPath = ( activeResultsInfo : ResultInfo ) : SuiteResult => {
@@ -84,72 +90,67 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
84
90
// Navigates to a suite by adding the SuiteName to the test path array.
85
91
const navigateToSuite = ( newSuiteName : string ) => {
86
92
const newPath = [ ...props . state . testPath , newSuiteName ] ;
87
- history . push ( {
88
- pathname : "/conformance" ,
89
- state : createState (
93
+ pushStateToHistory (
94
+ createState (
90
95
props . state . version ,
91
96
newPath ,
92
97
props . state . ecmaScriptVersion ,
93
98
props . state . sortOption ,
94
99
) ,
95
- } ) ;
100
+ ) ;
96
101
} ;
97
102
98
103
// Removes a value or values from the test path array.
99
104
//
100
105
// Used by breadcrumbs for navigation.
101
106
const sliceNavToIndex = ( nonInclusiveIndex : number ) => {
102
107
const slicedPath = [ ...props . state . testPath . slice ( 0 , nonInclusiveIndex ) ] ;
103
- history . push ( {
104
- pathname : "/conformance" ,
105
- state : createState (
108
+ pushStateToHistory (
109
+ createState (
106
110
props . state . version ,
107
111
slicedPath ,
108
112
props . state . ecmaScriptVersion ,
109
113
props . state . sortOption ,
110
114
) ,
111
- } ) ;
115
+ ) ;
112
116
} ;
113
117
114
118
// Sets the ECMAScript version flag value.
115
119
const setEcmaScriptFlag = ( flag : string ) => {
116
120
const nulledFlag = flag ? flag : undefined ;
117
- history . push ( {
118
- pathname : "/conformance" ,
119
- state : createState (
121
+ pushStateToHistory (
122
+ createState (
120
123
props . state . version ,
121
124
props . state . testPath ,
122
125
nulledFlag ,
123
126
props . state . sortOption ,
124
127
) ,
125
- } ) ;
128
+ ) ;
126
129
} ;
127
130
128
131
// Sets the sorting option
129
132
const setSortOption = ( option : string ) => {
130
- history . push ( {
131
- pathname : "/conformance" ,
132
- state : createState (
133
+ pushStateToHistory (
134
+ createState (
133
135
props . state . version ,
134
136
props . state . testPath ,
135
137
props . state . ecmaScriptVersion ,
136
138
option ,
137
139
) ,
138
- } ) ;
140
+ ) ;
139
141
} ;
140
142
141
143
// Sets a selected test.
142
144
const setSelectedTest = ( test : string | undefined ) => {
143
- history . push ( {
144
- pathname : "/conformance" ,
145
- state : createState (
145
+ pushStateToHistory (
146
+ createState (
146
147
props . state . version ,
147
148
props . state . testPath ,
148
149
props . state . ecmaScriptVersion ,
149
150
props . state . sortOption ,
150
151
test ,
151
152
) ,
152
- } ) ;
153
+ ) ;
153
154
} ;
154
155
155
156
// Create the t262 URL from testPath with the results commit
0 commit comments