Skip to content

Commit b6c8ca0

Browse files
author
nonbots
committed
feat-search-params
1 parent efa9762 commit b6c8ca0

File tree

6 files changed

+81
-7
lines changed

6 files changed

+81
-7
lines changed

src/components/conformance/HeroBanner/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import {
88
createState,
99
mapToTestStats,
10+
createSearchParams
1011
} from "@site/src/components/conformance/utils";
1112
import { useHistory } from "@docusaurus/router";
1213
import Heading from "@theme/Heading";
@@ -86,6 +87,7 @@ function BannerCard(props) {
8687
className="button button--block button--primary"
8788
onClick={() =>
8889
history.push({
90+
search: createSearchParams(props.item),
8991
pathname: "/conformance",
9092
state: createState(props.item),
9193
})

src/components/conformance/ResultsDisplay/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
import ResultNavigation from "./nav";
1010
import {
1111
createState,
12+
createSearchParams,
1213
mapToResultInfo,
1314
} from "@site/src/components/conformance/utils";
14-
import { useHistory } from "@docusaurus/router";
15+
import { useHistory, useLocation } from "@docusaurus/router";
1516

1617
import styles from "./styles.module.css";
1718

@@ -20,6 +21,7 @@ type ResultsProps = {
2021
};
2122

2223
export default function ResultsDisplay(props: ResultsProps): JSX.Element {
24+
const location = useLocation<ConformanceState>()
2325
const [currentSuite, setCurrentSuite] = React.useState<SuiteResult | null>(
2426
null,
2527
);
@@ -30,9 +32,10 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
3032
// History handling
3133
const history = useHistory<ConformanceState>();
3234

33-
const pushStateToHistory = (state: ConformanceState): void => {
35+
const pushStateToHistory = (search: string, state: ConformanceState): void => {
3436
history.push({
3537
pathname: "/conformance",
38+
search,
3639
state,
3740
});
3841
};
@@ -91,6 +94,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
9194
const navigateToSuite = (newSuiteName: string) => {
9295
const newPath = [...props.state.testPath, newSuiteName];
9396
pushStateToHistory(
97+
createSearchParams(props.state.version, newPath),
9498
createState(
9599
props.state.version,
96100
newPath,
@@ -106,6 +110,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
106110
const sliceNavToIndex = (nonInclusiveIndex: number) => {
107111
const slicedPath = [...props.state.testPath.slice(0, nonInclusiveIndex)];
108112
pushStateToHistory(
113+
createSearchParams(props.state.version, slicedPath),
109114
createState(
110115
props.state.version,
111116
slicedPath,
@@ -119,6 +124,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
119124
const setEcmaScriptFlag = (flag: string) => {
120125
const nulledFlag = flag ? flag : undefined;
121126
pushStateToHistory(
127+
createSearchParams(props.state.version, props.state.testPath, props.state.selectedTest),
122128
createState(
123129
props.state.version,
124130
props.state.testPath,
@@ -131,6 +137,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
131137
// Sets the sorting option
132138
const setSortOption = (option: string) => {
133139
pushStateToHistory(
140+
createSearchParams(props.state.version, props.state.testPath, props.state.selectedTest),
134141
createState(
135142
props.state.version,
136143
props.state.testPath,
@@ -143,6 +150,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
143150
// Sets a selected test.
144151
const setSelectedTest = (test: string | undefined) => {
145152
pushStateToHistory(
153+
createSearchParams(props.state.version, props.state.testPath, test),
146154
createState(
147155
props.state.version,
148156
props.state.testPath,

src/components/conformance/VersionSelector/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
VersionItem,
66
} from "@site/src/components/conformance/types";
77
import styles from "./styles.module.css";
8-
import { createState } from "../utils";
8+
import { createState, createSearchParams } from "../utils";
99

1010
interface SelectorProps {
1111
availableVersions: VersionItem[];
@@ -38,6 +38,7 @@ function Version(props: VersionProps): JSX.Element {
3838
onClick={() =>
3939
history.push({
4040
pathname: "/conformance",
41+
search: createSearchParams(props.version),
4142
state: createState(props.version),
4243
})
4344
}

src/components/conformance/types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
12
// The main global state of the conformance page.
23
//
34
// This state is fed into the History object and dictates
45
// what renders.
56
export type ConformanceState = {
6-
version: VersionItem;
7-
testPath: string[];
7+
version: VersionItem; // REMOVED (???) -> Connected to displaying specific results
8+
testPath: string[]; // REMOVED (???) -> Navigation / breadcrumbs
89
ecmaScriptVersion: string | undefined;
910
sortOption: string;
10-
selectedTest: string | undefined;
11+
selectedTest: string | undefined; // REMOVED (???) -> "TestViewer"
1112
};
1213

14+
export type UrlState = {
15+
versionTag: string | undefined,
16+
testPath: string[] | undefined,
17+
selectedTest: string | undefined,
18+
}
19+
1320
export type VersionItem = {
1421
tagName: string;
1522
fetchUrl: string;

src/components/conformance/utils.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,56 @@ import {
77
TestOutcome,
88
TestResult,
99
TestStats,
10+
UrlState,
1011
VersionedStats,
1112
VersionItem,
1213
} from "@site/src/components/conformance/types";
1314

15+
16+
// Take a search param and create a state object
17+
export function createUrlState(search: string): UrlState {
18+
const params = new URLSearchParams(search);
19+
console.log(`testPath: ${params.get("testPath")}`)
20+
return {
21+
versionTag: params.get("version") ?? undefined,
22+
testPath: params.get("testPath")?.split("/") ?? undefined,
23+
selectedTest: params.get("selectedTest") ?? undefined
24+
}
25+
}
26+
27+
export function updateInitialConformanceState(urlState: UrlState, conformanceState: ConformanceState) {
28+
29+
if (!conformanceState && (urlState.versionTag || urlState.testPath || urlState.selectedTest)) {
30+
const fetchUrl = urlState.versionTag === "main" ? `https://raw.githubusercontent.com/boa-dev/data/main/test262/refs/heads/main/latest.json` : `https://raw.githubusercontent.com/boa-dev/data/main/test262/refs/tags/${urlState.versionTag}/latest.json`;
31+
32+
const testPath = urlState.testPath || [];
33+
return {
34+
version: { tagName: urlState.versionTag, fetchUrl },
35+
testPath: [urlState.versionTag, ...testPath],
36+
ecmaScriptVersion: undefined,
37+
sortOption: availableSortingOptions[0].id,
38+
selectedTest: urlState.selectedTest
39+
}
40+
}
41+
return conformanceState;
42+
}
43+
44+
export function createSearchParams(
45+
version: VersionItem,
46+
testPath?: string[],
47+
selectedTest?: string,
48+
) {
49+
const search = new URLSearchParams()
50+
search.append("version", version.tagName);
51+
if (testPath) {
52+
search.append("testPath", testPath.slice(1).join("/"));
53+
}
54+
if (selectedTest) {
55+
search.append("selectedTest", selectedTest)
56+
}
57+
return search.toString()
58+
}
59+
1460
// Creates the state object from provided args
1561
export function createState(
1662
version: VersionItem,

src/pages/conformance/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import ConformanceView from "@site/src/components/conformance";
22
import {
33
VersionItem,
44
ConformanceState,
5+
UrlState,
56
} from "@site/src/components/conformance/types";
7+
import {
8+
createUrlState,
9+
updateInitialConformanceState
10+
} from "@site/src/components/conformance/utils";
611
import { useLocation } from "@docusaurus/router";
712
import Layout from "@theme/Layout";
813
import React from "react";
@@ -21,6 +26,8 @@ export default function Conformance() {
2126
VersionItem[] | undefined
2227
>(null);
2328

29+
const urlState = createUrlState(location.search);
30+
2431
// Initial Render useEffect
2532
React.useEffect(() => {
2633
const validateReleaseVersion = (releaseTag: string) => {
@@ -61,11 +68,14 @@ export default function Conformance() {
6168
);
6269
}, []);
6370

71+
72+
const resolvedState = updateInitialConformanceState(urlState, location.state)
73+
6474
return (
6575
<Layout title="Conformance" description="Boa Conformance Page">
6676
<main className={styles.mainLayout}>
6777
{releaseRecords ? (
68-
<ConformanceView state={location.state} records={releaseRecords} />
78+
<ConformanceView state={resolvedState} records={releaseRecords} />
6979
) : null}
7080
</main>
7181
</Layout>

0 commit comments

Comments
 (0)