Skip to content

Commit 3842ab5

Browse files
authored
Refactor Conformance page to allow back and forward history (#150)
* refactor: add history/location functionality * Add basic alphabetical sorting * Fix ECMAScript version flag issue
1 parent 4e20c71 commit 3842ab5

File tree

16 files changed

+354
-210
lines changed

16 files changed

+354
-210
lines changed

src/components/HomepageFeatures/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const FeatureList: FeatureItem[] = [
1717
title: "Written in Rust",
1818
Svg: new_logo_black,
1919
description: (
20-
<>Boa brings Rust's memory safety guarantees to the world of JS engines.</>
20+
<>
21+
Boa brings Rust's memory safety guarantees to the world of JS engines.
22+
</>
2123
),
2224
},
2325
{

src/components/benchmarks/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ChartJS.register(
2525
Tooltip,
2626
Legend,
2727
Colors,
28-
BarElement
28+
BarElement,
2929
);
3030

3131
export function BenchmarkGraphs() {
@@ -52,7 +52,7 @@ export function BenchmarkGraphs() {
5252

5353
const buildChartFromBenchmark = async (name: string) => {
5454
const data = await fetchData(
55-
`https://raw.githubusercontent.com/boa-dev/data/main/bench/results/${name}.json`
55+
`https://raw.githubusercontent.com/boa-dev/data/main/bench/results/${name}.json`,
5656
);
5757

5858
const barData = getBarChartData(data);
@@ -79,7 +79,7 @@ const fetchData = async (url: string) => {
7979
const data = await response.json();
8080
return {
8181
labels: data.labels.map((epoch: number) =>
82-
new Date(epoch).toLocaleDateString()
82+
new Date(epoch).toLocaleDateString(),
8383
),
8484
datasets: [
8585
{

src/components/conformance/Banner/index.tsx renamed to src/components/conformance/HeroBanner/index.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import React from "react";
2-
import { VersionItem, TestStats } from "@site/src/components/conformance/types";
3-
import { mapToTestStats } from "@site/src/components/conformance/utils";
2+
import {
3+
VersionItem,
4+
TestStats,
5+
ConformanceState,
6+
} from "@site/src/components/conformance/types";
7+
import {
8+
createState,
9+
mapToTestStats,
10+
} from "@site/src/components/conformance/utils";
11+
import { useHistory } from "@docusaurus/router";
412
import Heading from "@theme/Heading";
513

614
import styles from "./styles.module.css";
715

816
interface BannerProps {
917
focusItems: VersionItem[];
10-
setNewVersion: (newVersion: VersionItem) => void;
1118
}
1219

13-
export default function ConformanceBanner(props: BannerProps): JSX.Element {
20+
export default function ConformanceHeroBanner(props: BannerProps): JSX.Element {
1421
return (
1522
<div className={styles.bannerSection}>
1623
{props.focusItems.map((item) => {
17-
return (
18-
<BannerCard
19-
key={item.tagName}
20-
setNewVersion={props.setNewVersion}
21-
item={item}
22-
/>
23-
);
24+
return <BannerCard key={item.tagName} item={item} />;
2425
})}
2526
</div>
2627
);
@@ -29,6 +30,8 @@ export default function ConformanceBanner(props: BannerProps): JSX.Element {
2930
function BannerCard(props) {
3031
const [stats, setStats] = React.useState<TestStats | null>(null);
3132

33+
const history = useHistory<ConformanceState>();
34+
3235
React.useEffect(() => {
3336
const fetchStats = async () => {
3437
const response = await fetch(props.item.fetchUrl);
@@ -81,7 +84,12 @@ function BannerCard(props) {
8184
<div className="card__footer">
8285
<button
8386
className="button button--block button--primary"
84-
onClick={() => props.setNewVersion(props.item)}
87+
onClick={() =>
88+
history.push({
89+
pathname: "/conformance",
90+
state: createState(props.item),
91+
})
92+
}
8593
>
8694
View Results
8795
</button>

src/components/conformance/ResultsDisplay/components/SuiteDataContainer/cards/TestGrid/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import {
44
TestOutcome,
55
TestResult,
66
SuiteResult,
7+
ConformanceState,
78
} from "@site/src/components/conformance/types";
89
import Heading from "@theme/Heading";
910
import styles from "./styles.module.css";
1011

1112
type TestsGridProps = {
13+
state: ConformanceState;
1214
suite: SuiteResult;
13-
esFlag: string | null;
1415
selectTest: (string) => void;
1516
};
1617

@@ -26,7 +27,7 @@ export default function TestsGrid(props: TestsGridProps): JSX.Element {
2627
<div className={cardBodyClass}>
2728
<Grid
2829
tests={props.suite.tests}
29-
esFlag={props.esFlag}
30+
esFlag={props.state.ecmaScriptVersion}
3031
selectTest={props.selectTest}
3132
/>
3233
</div>

src/components/conformance/ResultsDisplay/components/SuiteDataContainer/index.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
import React from "react";
22
import TestsGrid from "./cards/TestGrid";
33
import TestViewer from "./cards/TestViewer";
4-
import { SuiteResult } from "@site/src/components/conformance/types";
4+
import {
5+
ConformanceState,
6+
SuiteResult,
7+
} from "@site/src/components/conformance/types";
58

69
import styles from "./styles.module.css";
710

811
type SuiteDataProps = {
912
suite: SuiteResult;
10-
esFlag: string | null;
13+
state: ConformanceState;
1114
t262Path: string;
15+
setSelectedTest: (string) => void;
1216
};
1317

1418
export default function SuiteDataContainer(props: SuiteDataProps): JSX.Element {
15-
const [selectedTest, setSelectedTest] = React.useState<string | null>(null);
16-
17-
// Unselect a test if the underlying test262 path has been changed.
18-
React.useEffect(() => {
19-
setSelectedTest(null);
20-
}, [props.t262Path]);
21-
2219
// Set the user's selected test to be displayed in the ViewPort.
2320
const selectTest = (testName: string) => {
24-
setSelectedTest(testName);
21+
props.setSelectedTest(testName);
2522
};
2623

2724
const clearTest = () => {
28-
setSelectedTest(null);
25+
props.setSelectedTest(undefined);
2926
};
3027

3128
// Add a TestViewer to look up and display the test262.
3229
return (
3330
<div className={styles.dataContainer}>
34-
{selectedTest ? (
31+
{props.state.selectedTest ? (
3532
<TestViewer
36-
testName={selectedTest}
33+
testName={props.state.selectedTest}
3734
t262Path={props.t262Path}
3835
backToGrid={() => clearTest()}
3936
/>

src/components/conformance/ResultsDisplay/components/SuiteDisplay/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import React from "react";
22
import SuiteSelector from "../SuiteSelector";
33
import SuiteDataContainer from "../SuiteDataContainer";
4-
import { SuiteResult } from "@site/src/components/conformance/types";
4+
import {
5+
ConformanceState,
6+
SuiteResult,
7+
} from "@site/src/components/conformance/types";
58

69
import styles from "./styles.module.css";
710

811
type SuiteDisplayProps = {
912
currentSuite: SuiteResult;
10-
esFlag: string | null;
13+
state: ConformanceState;
1114
t262Path: string;
1215
navigateToSuite: (string) => void;
16+
setSelectedTest: (string) => void;
1317
};
1418

1519
export default function SuiteDisplay(props: SuiteDisplayProps): JSX.Element {
@@ -18,15 +22,16 @@ export default function SuiteDisplay(props: SuiteDisplayProps): JSX.Element {
1822
{props.currentSuite.suites ? (
1923
<SuiteSelector
2024
suites={props.currentSuite.suites}
21-
esFlag={props.esFlag}
25+
esFlag={props.state.ecmaScriptVersion}
2226
navigateToSuite={props.navigateToSuite}
2327
/>
2428
) : null}
2529
{props.currentSuite.tests ? (
2630
<SuiteDataContainer
31+
state={props.state}
2732
suite={props.currentSuite}
28-
esFlag={props.esFlag}
2933
t262Path={props.t262Path}
34+
setSelectedTest={props.setSelectedTest}
3035
/>
3136
) : null}
3237
</div>

src/components/conformance/ResultsDisplay/components/SuiteSelector/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ type SelectorProps = {
1212
export default function SuiteSelector(props: SelectorProps): JSX.Element {
1313
return (
1414
<div className={styles.suiteSelector}>
15-
{props.suites.map((suite) => {
16-
return (
17-
<SuiteItem
18-
key={suite.name}
19-
suite={suite}
20-
esFlag={props.esFlag}
21-
navigateToSuite={props.navigateToSuite}
22-
/>
23-
);
24-
})}
15+
{props.suites
16+
.sort((a, b) => a.name.localeCompare(b.name))
17+
.map((suite) => {
18+
return (
19+
<SuiteItem
20+
key={suite.name}
21+
suite={suite}
22+
esFlag={props.esFlag}
23+
navigateToSuite={props.navigateToSuite}
24+
/>
25+
);
26+
})}
2527
</div>
2628
);
2729
}

0 commit comments

Comments
 (0)