Skip to content

Commit 9ffb6e9

Browse files
committed
Add sort option and misc adjustments
1 parent 3842ab5 commit 9ffb6e9

File tree

8 files changed

+142
-38
lines changed

8 files changed

+142
-38
lines changed

src/components/conformance/ResultsDisplay/components/SuiteDataContainer/styles.module.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
display: flex;
33
flex-direction: column;
44
width: 85%;
5-
height: 70vh;
5+
height: 75vh;
6+
padding: 0.5rem;
67
}
78

89
@media screen and (max-width: 996px) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default function SuiteDisplay(props: SuiteDisplayProps): JSX.Element {
2121
<div className={styles.suiteDisplay}>
2222
{props.currentSuite.suites ? (
2323
<SuiteSelector
24+
state={props.state}
2425
suites={props.currentSuite.suites}
25-
esFlag={props.state.ecmaScriptVersion}
2626
navigateToSuite={props.navigateToSuite}
2727
/>
2828
) : null}

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import React from "react";
2-
import { SuiteResult } from "@site/src/components/conformance/types";
2+
import {
3+
ConformanceState,
4+
SortOption,
5+
SuiteResult,
6+
} from "@site/src/components/conformance/types";
37

48
import styles from "./styles.module.css";
9+
import { availableSortingOptions } from "../../../utils";
510

611
type SelectorProps = {
12+
state: ConformanceState;
713
suites: SuiteResult[];
8-
esFlag: string | null;
914
navigateToSuite: (string) => void;
1015
};
1116

1217
export default function SuiteSelector(props: SelectorProps): JSX.Element {
18+
const option: SortOption[] = availableSortingOptions.filter(
19+
(v) => v.id === props.state.sortOption,
20+
);
1321
return (
1422
<div className={styles.suiteSelector}>
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-
})}
23+
{props.suites.sort(option[0].callback).map((suite) => {
24+
return (
25+
<SuiteItem
26+
key={suite.name}
27+
suite={suite}
28+
esFlag={props.state.ecmaScriptVersion}
29+
navigateToSuite={props.navigateToSuite}
30+
/>
31+
);
32+
})}
2733
</div>
2834
);
2935
}

src/components/conformance/ResultsDisplay/index.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
VersionItem,
66
SuiteResult,
77
ConformanceState,
8+
SortOption,
89
} from "@site/src/components/conformance/types";
910
import ResultNavigation from "./nav";
1011
import {
@@ -113,7 +114,25 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
113114
const nulledFlag = flag ? flag : undefined;
114115
history.push({
115116
pathname: "/conformance",
116-
state: createState(props.state.version, props.state.testPath, nulledFlag),
117+
state: createState(
118+
props.state.version,
119+
props.state.testPath,
120+
nulledFlag,
121+
props.state.sortOption,
122+
),
123+
});
124+
};
125+
126+
// Sets the sorting option
127+
const setSortOption = (option: string) => {
128+
history.push({
129+
pathname: "/conformance",
130+
state: createState(
131+
props.state.version,
132+
props.state.testPath,
133+
props.state.ecmaScriptVersion,
134+
option,
135+
),
117136
});
118137
};
119138

@@ -125,6 +144,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
125144
props.state.version,
126145
props.state.testPath,
127146
props.state.ecmaScriptVersion,
147+
props.state.sortOption,
128148
test,
129149
),
130150
});
@@ -146,6 +166,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
146166
state={props.state}
147167
sliceNavToIndex={sliceNavToIndex}
148168
setEcmaScriptFlag={setEcmaScriptFlag}
169+
setSortOption={setSortOption}
149170
/>
150171
{currentSuite ? (
151172
<SuiteDisplay

src/components/conformance/ResultsDisplay/nav.tsx

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import React from "react";
2-
import { ConformanceState, SpecEdition } from "../types";
2+
import { ConformanceState, SortOption, SpecEdition } from "../types";
33

44
import styles from "./styles.module.css";
55
import Link from "@docusaurus/Link";
6+
import { availableSortingOptions } from "../utils";
67

78
type ResultsNavProps = {
89
state: ConformanceState;
910
sliceNavToIndex: (number) => void;
1011
setEcmaScriptFlag: (string) => void;
12+
setSortOption: (string) => void;
1113
};
1214

1315
export default function ResultNavigation(props: ResultsNavProps): JSX.Element {
1416
return (
1517
<div className={styles.resultsNav}>
16-
<EcmaScriptVersionDropdown setEcmaScriptFlag={props.setEcmaScriptFlag} esVersionValue={props.state.ecmaScriptVersion} />
18+
<EcmaScriptVersionDropdown
19+
setEcmaScriptFlag={props.setEcmaScriptFlag}
20+
esVersionValue={props.state.ecmaScriptVersion}
21+
/>
22+
<SortingDropdown
23+
sortValue={props.state.sortOption}
24+
setSortOption={props.setSortOption}
25+
/>
1726
<NavBreadCrumbs
1827
navPath={props.state.testPath}
1928
sliceNavToIndex={props.sliceNavToIndex}
@@ -29,11 +38,11 @@ type BreadCrumbProps = {
2938

3039
function NavBreadCrumbs(props: BreadCrumbProps) {
3140
return (
32-
<nav aria-label="breadcrumbs" style={{ padding: "0.25em" }}>
41+
<nav aria-label="breadcrumbs" style={{ padding: "0.5em" }}>
3342
<ul className="breadcrumbs">
3443
{props.navPath.map((pathItem, idx, arr) => {
3544
return (
36-
<NavItem
45+
<BreadCrumbItem
3746
key={pathItem}
3847
itemName={pathItem}
3948
index={idx}
@@ -51,14 +60,14 @@ function NavBreadCrumbs(props: BreadCrumbProps) {
5160
);
5261
}
5362

54-
type NavItemProps = {
63+
type BreadCrumbItemProps = {
5564
itemName: string;
5665
index: number;
5766
breadcrumbValue: string;
5867
sliceNavToIndex: (number) => void;
5968
};
6069

61-
function NavItem(props: NavItemProps): JSX.Element {
70+
function BreadCrumbItem(props: BreadCrumbItemProps): JSX.Element {
6271
return (
6372
<li className={props.breadcrumbValue}>
6473
<Link
@@ -79,12 +88,14 @@ type DropDownProps = {
7988
};
8089

8190
function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
82-
const [dropdownValue, setDropdownValue] = React.useState(props.esVersionValue ? props.esVersionValue : "");
91+
const [dropdownValue, setDropdownValue] = React.useState(
92+
props.esVersionValue ? props.esVersionValue : "",
93+
);
8394

8495
// Update the flag when props.esVersionValue is changed
85-
React.useEffect(()=>{
86-
setDropdownValue(props.esVersionValue)
87-
}, [props.esVersionValue])
96+
React.useEffect(() => {
97+
setDropdownValue(props.esVersionValue);
98+
}, [props.esVersionValue]);
8899

89100
const handleVersionSelection = (e) => {
90101
// Update the display value and set the flag.
@@ -94,6 +105,7 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
94105

95106
return (
96107
<div className={styles.dropdownContainer}>
108+
<h4 style={{ padding: "0.125rem 0.5rem", height: "5" }}>ES Version:</h4>
97109
<select value={dropdownValue} onChange={handleVersionSelection}>
98110
<option value={""}>All</option>
99111
{Object.keys(SpecEdition)
@@ -109,3 +121,39 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
109121
</div>
110122
);
111123
}
124+
125+
type SortProps = {
126+
sortValue: string;
127+
setSortOption: (string) => void;
128+
};
129+
130+
function SortingDropdown(props: SortProps): JSX.Element {
131+
const [sortValue, setSortValue] = React.useState<string | undefined>();
132+
133+
React.useEffect(() => {
134+
setSortValue(props.sortValue);
135+
}, [props.sortValue]);
136+
137+
const handleSortSelection = (e) => {
138+
setSortValue(e.target.value);
139+
const option = availableSortingOptions.filter(
140+
(v) => v.id === e.target.value,
141+
);
142+
props.setSortOption(option[0].id);
143+
};
144+
145+
return (
146+
<div className={styles.dropdownContainer}>
147+
<h4 style={{ padding: "0.125rem 0.5rem", height: "5" }}>Sort:</h4>
148+
<select value={sortValue} onChange={handleSortSelection}>
149+
{availableSortingOptions.map((key) => {
150+
return (
151+
<option key={key.id} value={key.id}>
152+
{key.name}
153+
</option>
154+
);
155+
})}
156+
</select>
157+
</div>
158+
);
159+
}

src/components/conformance/ResultsDisplay/styles.module.css

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.resultsNav {
1111
display: flex;
1212
flex-direction: row;
13-
height: 5vh;
13+
height: 3.5rem;
1414
width: 100%;
1515
padding: 0.75em;
1616
}
@@ -20,8 +20,11 @@
2020
}
2121

2222
.dropdownContainer {
23-
width: 6em;
24-
padding: 0.25em;
23+
display: flex;
24+
flex-direction: row;
25+
width: 12rem;
26+
height: 2.5rem;
27+
padding: 0.5rem 0;
2528
}
2629

2730
@media screen and (max-height: 996px) {
@@ -32,9 +35,8 @@
3235
}
3336

3437
.resultsNav {
35-
min-height: 3.5rem;
36-
height: auto;
38+
height: 3.5rem;
3739
width: 100vw;
38-
padding: 1rem auto;
40+
padding: 0.75rem auto;
3941
}
4042
}

src/components/conformance/types.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ConformanceState = {
66
version: VersionItem;
77
testPath: string[];
88
ecmaScriptVersion: string | undefined;
9+
sortOption: string;
910
selectedTest: string | undefined;
1011
};
1112

@@ -14,13 +15,14 @@ export type VersionItem = {
1415
fetchUrl: string;
1516
};
1617

17-
export type TestStats = {
18-
total: number;
19-
passed: number;
20-
ignored: number;
21-
panic: number;
18+
export type SortOption = {
19+
id: string;
20+
name: string;
21+
callback: (a: SuiteResult, b: SuiteResult) => number;
2222
};
2323

24+
// The below types are specific to test result types.
25+
2426
export type ResultInfo = {
2527
version: string;
2628
commit: string;
@@ -49,6 +51,13 @@ export type VersionedStats = {
4951
es13: TestStats;
5052
};
5153

54+
export type TestStats = {
55+
total: number;
56+
passed: number;
57+
ignored: number;
58+
panic: number;
59+
};
60+
5261
export type TestResult = {
5362
name: string;
5463
edition: SpecEdition;

src/components/conformance/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ConformanceState,
33
ResultInfo,
4+
SortOption,
45
SpecEdition,
56
SuiteResult,
67
TestOutcome,
@@ -15,17 +16,33 @@ export function createState(
1516
version: VersionItem,
1617
testPath?: string[],
1718
ecmaScriptVersion?: string,
19+
sortOption?: string,
1820
selectedTest?: string,
1921
): ConformanceState {
2022
testPath = testPath ? testPath : [version.tagName];
23+
sortOption = sortOption ? sortOption : availableSortingOptions[0].id;
2124
return {
2225
version,
2326
testPath,
2427
ecmaScriptVersion,
28+
sortOption,
2529
selectedTest,
2630
};
2731
}
2832

33+
export const availableSortingOptions: SortOption[] = [
34+
{
35+
id: "alpha",
36+
name: "Alphabetical",
37+
callback: (a, b) => a.name.localeCompare(b.name),
38+
},
39+
{
40+
id: "reverse",
41+
name: "Reverse Alpha",
42+
callback: (a, b) => -a.name.localeCompare(b.name),
43+
},
44+
];
45+
2946
// Interface for the http response of boa_tester's `ResultInfo`
3047
interface HttpResultInfo {
3148
c: string;

0 commit comments

Comments
 (0)