forked from boa-dev/boa-dev.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
231 lines (210 loc) · 6.35 KB
/
index.tsx
File metadata and controls
231 lines (210 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import React from "react";
import SuiteDisplay from "./components/SuiteDisplay";
import {
ResultInfo,
VersionItem,
SuiteResult,
ConformanceState,
FilterOption,
} from "@site/src/components/conformance/types";
import ResultNavigation from "./nav";
import {
createState,
createSearchParams,
mapToResultInfo,
} from "@site/src/components/conformance/utils";
import { useHistory } from "@docusaurus/router";
import styles from "./styles.module.css";
type ResultsProps = {
state: ConformanceState;
};
export default function ResultsDisplay(props: ResultsProps): React.ReactNode {
const [currentSuite, setCurrentSuite] = React.useState<SuiteResult | null>(
null,
);
// Refs
const activeResults = React.useRef<undefined | ResultInfo>(undefined);
// History handling
const history = useHistory<ConformanceState>();
const pushStateToHistory = (
search: string,
state: ConformanceState,
): void => {
history.push({
pathname: "/conformance",
search,
state,
});
};
React.useEffect(() => {
// If the version is correctly synced
if (props.state.version.tagName !== activeResults.current?.version) {
updateActiveResults().then((results) => {
activeResults.current = results;
const foundSuite = findResultsFromPath(results);
setCurrentSuite(foundSuite);
});
// Return to prevent further execution.
return;
}
// TODO / NOTE: there may be a bug with version swapping. TBD.
// Return early if for some reason activeResults.current is undefined
if (!activeResults.current) return;
// Results should be defined from the check on activeResults.current
const foundSuite = findResultsFromPath(activeResults.current);
setCurrentSuite(foundSuite);
}, [props.state]);
// Fetches the version results
const fetchResults = async (version: VersionItem) => {
const response = await fetch(version.fetchUrl);
return await response.json();
};
const updateActiveResults = async (): Promise<ResultInfo> => {
const data = await fetchResults(props.state.version);
return mapToResultInfo(props.state.version.tagName, data);
};
const findResultsFromPath = (activeResultsInfo: ResultInfo): SuiteResult => {
let newSuiteTarget: SuiteResult | undefined = undefined;
for (const target of props.state.testPath) {
if (target === props.state.version.tagName) {
newSuiteTarget = activeResultsInfo.results;
continue;
}
// Suites must exist here for the path value to be valid.
for (const suite of newSuiteTarget.suites) {
if (suite.name === target) {
newSuiteTarget = suite;
}
}
}
return newSuiteTarget;
};
// Navigates to a suite by adding the SuiteName to the test path array.
const navigateToSuite = (newSuiteName: string) => {
const newPath = [...props.state.testPath, newSuiteName];
pushStateToHistory(
createSearchParams(props.state.version, newPath),
createState(
props.state.version,
newPath,
props.state.ecmaScriptVersion,
props.state.sortOption,
props.state.filterOption,
),
);
};
// Removes a value or values from the test path array.
//
// Used by breadcrumbs for navigation.
const sliceNavToIndex = (nonInclusiveIndex: number) => {
const slicedPath = [...props.state.testPath.slice(0, nonInclusiveIndex)];
pushStateToHistory(
createSearchParams(props.state.version, slicedPath),
createState(
props.state.version,
slicedPath,
props.state.ecmaScriptVersion,
props.state.sortOption,
props.state.filterOption,
),
);
};
// Sets the ECMAScript version flag value.
const setEcmaScriptFlag = (flag: string) => {
const nulledFlag = flag ? flag : undefined;
pushStateToHistory(
createSearchParams(
props.state.version,
props.state.testPath,
props.state.selectedTest,
),
createState(
props.state.version,
props.state.testPath,
nulledFlag,
props.state.sortOption,
props.state.filterOption,
),
);
};
// Sets the sorting option
const setSortOption = (option: string) => {
pushStateToHistory(
createSearchParams(
props.state.version,
props.state.testPath,
props.state.selectedTest,
),
createState(
props.state.version,
props.state.testPath,
props.state.ecmaScriptVersion,
option,
props.state.filterOption,
),
);
};
// Sets the filter option.
//
// This filters the tests shown in the selection cards and tests grid
const setFilterOption = (option: string) => {
pushStateToHistory(
createSearchParams(
props.state.version,
props.state.testPath,
props.state.selectedTest,
),
createState(
props.state.version,
props.state.testPath,
props.state.ecmaScriptVersion,
props.state.sortOption,
option as FilterOption,
),
);
};
// Sets a selected test.
const setSelectedTest = (test: string | undefined) => {
pushStateToHistory(
createSearchParams(props.state.version, props.state.testPath, test),
createState(
props.state.version,
props.state.testPath,
props.state.ecmaScriptVersion,
props.state.sortOption,
props.state.filterOption,
test,
),
);
};
// Create the t262 URL from testPath with the results commit
const t262Path = (): string => {
// NOTE: testPath[0] === activeBoaReleaseTag
return [
activeResults.current.test262Commit,
"test",
...props.state.testPath.slice(1, props.state.testPath.length),
].join("/");
};
return (
<div className={styles.resultsDisplay}>
<ResultNavigation
state={props.state}
editions={currentSuite ? Object.keys(currentSuite.versionedStats) : []}
sliceNavToIndex={sliceNavToIndex}
setEcmaScriptFlag={setEcmaScriptFlag}
setSortOption={setSortOption}
setFilterOption={setFilterOption}
/>
{currentSuite ? (
<SuiteDisplay
state={props.state}
currentSuite={currentSuite}
t262Path={t262Path()}
navigateToSuite={navigateToSuite}
setSelectedTest={(test) => setSelectedTest(test)}
/>
) : null}
</div>
);
}