Skip to content

Commit 4830ee0

Browse files
committed
Add sort option and misc adjustments
1 parent 3842ab5 commit 4830ee0

File tree

8 files changed

+105
-24
lines changed

8 files changed

+105
-24
lines changed

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

+2-1
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

+1-1
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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import React from "react";
2-
import { SuiteResult } from "@site/src/components/conformance/types";
2+
import { ConformanceState, SortOption, SuiteResult } from "@site/src/components/conformance/types";
33

44
import styles from "./styles.module.css";
5+
import { availableSortingOptions } from "../../../utils";
56

67
type SelectorProps = {
8+
state: ConformanceState;
79
suites: SuiteResult[];
8-
esFlag: string | null;
910
navigateToSuite: (string) => void;
1011
};
1112

1213
export default function SuiteSelector(props: SelectorProps): JSX.Element {
14+
const option: SortOption[] = availableSortingOptions.filter(v => v.id === props.state.sortOption);
1315
return (
1416
<div className={styles.suiteSelector}>
1517
{props.suites
16-
.sort((a, b) => a.name.localeCompare(b.name))
18+
.sort(option[0].callback)
1719
.map((suite) => {
1820
return (
1921
<SuiteItem
2022
key={suite.name}
2123
suite={suite}
22-
esFlag={props.esFlag}
24+
esFlag={props.state.ecmaScriptVersion}
2325
navigateToSuite={props.navigateToSuite}
2426
/>
2527
);

src/components/conformance/ResultsDisplay/index.tsx

+12-1
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,15 @@ 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(props.state.version, props.state.testPath, nulledFlag, props.state.sortOption),
118+
});
119+
};
120+
121+
// Sets the sorting option
122+
const setSortOption = (option: string) => {
123+
history.push({
124+
pathname: "/conformance",
125+
state: createState(props.state.version, props.state.testPath, props.state.ecmaScriptVersion, option),
117126
});
118127
};
119128

@@ -125,6 +134,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
125134
props.state.version,
126135
props.state.testPath,
127136
props.state.ecmaScriptVersion,
137+
props.state.sortOption,
128138
test,
129139
),
130140
});
@@ -146,6 +156,7 @@ export default function ResultsDisplay(props: ResultsProps): JSX.Element {
146156
state={props.state}
147157
sliceNavToIndex={sliceNavToIndex}
148158
setEcmaScriptFlag={setEcmaScriptFlag}
159+
setSortOption={setSortOption}
149160
/>
150161
{currentSuite ? (
151162
<SuiteDisplay

src/components/conformance/ResultsDisplay/nav.tsx

+44-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
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}>
1618
<EcmaScriptVersionDropdown setEcmaScriptFlag={props.setEcmaScriptFlag} esVersionValue={props.state.ecmaScriptVersion} />
19+
<SortingDropdown sortValue={props.state.sortOption} setSortOption={props.setSortOption} />
1720
<NavBreadCrumbs
1821
navPath={props.state.testPath}
1922
sliceNavToIndex={props.sliceNavToIndex}
@@ -29,11 +32,11 @@ type BreadCrumbProps = {
2932

3033
function NavBreadCrumbs(props: BreadCrumbProps) {
3134
return (
32-
<nav aria-label="breadcrumbs" style={{ padding: "0.25em" }}>
35+
<nav aria-label="breadcrumbs" style={{ padding: "0.5em" }}>
3336
<ul className="breadcrumbs">
3437
{props.navPath.map((pathItem, idx, arr) => {
3538
return (
36-
<NavItem
39+
<BreadCrumbItem
3740
key={pathItem}
3841
itemName={pathItem}
3942
index={idx}
@@ -51,14 +54,14 @@ function NavBreadCrumbs(props: BreadCrumbProps) {
5154
);
5255
}
5356

54-
type NavItemProps = {
57+
type BreadCrumbItemProps = {
5558
itemName: string;
5659
index: number;
5760
breadcrumbValue: string;
5861
sliceNavToIndex: (number) => void;
5962
};
6063

61-
function NavItem(props: NavItemProps): JSX.Element {
64+
function BreadCrumbItem(props: BreadCrumbItemProps): JSX.Element {
6265
return (
6366
<li className={props.breadcrumbValue}>
6467
<Link
@@ -94,6 +97,7 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
9497

9598
return (
9699
<div className={styles.dropdownContainer}>
100+
<h4 style={{padding: "0.125rem 0.5rem", height: "5"}}>ES Version:</h4>
97101
<select value={dropdownValue} onChange={handleVersionSelection}>
98102
<option value={""}>All</option>
99103
{Object.keys(SpecEdition)
@@ -109,3 +113,38 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
109113
</div>
110114
);
111115
}
116+
117+
type SortProps = {
118+
sortValue: string;
119+
setSortOption: (string)=>void;
120+
}
121+
122+
function SortingDropdown(props: SortProps): JSX.Element {
123+
const [sortValue, setSortValue] = React.useState<string | undefined>();
124+
125+
React.useEffect(()=>{
126+
setSortValue(props.sortValue)
127+
}, [props.sortValue])
128+
129+
const handleSortSelection = (e) => {
130+
setSortValue(e.target.value);
131+
const option = availableSortingOptions.filter((v) => v.id === e.target.value);
132+
props.setSortOption(option[0].id)
133+
}
134+
135+
return (
136+
<div className={styles.dropdownContainer}>
137+
<h4 style={{padding: "0.125rem 0.5rem", height: "5"}}>Sort:</h4>
138+
<select value={sortValue} onChange={handleSortSelection}>
139+
{availableSortingOptions
140+
.map((key) => {
141+
return (
142+
<option key={key.id} value={key.id}>
143+
{key.name}
144+
</option>
145+
);
146+
})}
147+
</select>
148+
</div>
149+
)
150+
}

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

+8-6
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

+15-6
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,12 +15,13 @@ export type VersionItem = {
1415
fetchUrl: string;
1516
};
1617

17-
export type TestStats = {
18-
total: number;
19-
passed: number;
20-
ignored: number;
21-
panic: number;
22-
};
18+
export type SortOption = {
19+
id: string;
20+
name: string;
21+
callback: (a:SuiteResult, b:SuiteResult) => number;
22+
}
23+
24+
// The below types are specific to test result types.
2325

2426
export type ResultInfo = {
2527
version: 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

+17
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)