1
1
import React from "react" ;
2
- import { ConformanceState , SpecEdition } from "../types" ;
2
+ import { ConformanceState , SortOption , SpecEdition } from "../types" ;
3
3
4
4
import styles from "./styles.module.css" ;
5
5
import Link from "@docusaurus/Link" ;
6
+ import { availableSortingOptions } from "../utils" ;
6
7
7
8
type ResultsNavProps = {
8
9
state : ConformanceState ;
9
10
sliceNavToIndex : ( number ) => void ;
10
11
setEcmaScriptFlag : ( string ) => void ;
12
+ setSortOption : ( string ) => void ;
11
13
} ;
12
14
13
15
export default function ResultNavigation ( props : ResultsNavProps ) : JSX . Element {
14
16
return (
15
17
< div className = { styles . resultsNav } >
16
18
< EcmaScriptVersionDropdown setEcmaScriptFlag = { props . setEcmaScriptFlag } esVersionValue = { props . state . ecmaScriptVersion } />
19
+ < SortingDropdown sortValue = { props . state . sortOption } setSortOption = { props . setSortOption } />
17
20
< NavBreadCrumbs
18
21
navPath = { props . state . testPath }
19
22
sliceNavToIndex = { props . sliceNavToIndex }
@@ -29,11 +32,11 @@ type BreadCrumbProps = {
29
32
30
33
function NavBreadCrumbs ( props : BreadCrumbProps ) {
31
34
return (
32
- < nav aria-label = "breadcrumbs" style = { { padding : "0.25em " } } >
35
+ < nav aria-label = "breadcrumbs" style = { { padding : "0.5em " } } >
33
36
< ul className = "breadcrumbs" >
34
37
{ props . navPath . map ( ( pathItem , idx , arr ) => {
35
38
return (
36
- < NavItem
39
+ < BreadCrumbItem
37
40
key = { pathItem }
38
41
itemName = { pathItem }
39
42
index = { idx }
@@ -51,14 +54,14 @@ function NavBreadCrumbs(props: BreadCrumbProps) {
51
54
) ;
52
55
}
53
56
54
- type NavItemProps = {
57
+ type BreadCrumbItemProps = {
55
58
itemName : string ;
56
59
index : number ;
57
60
breadcrumbValue : string ;
58
61
sliceNavToIndex : ( number ) => void ;
59
62
} ;
60
63
61
- function NavItem ( props : NavItemProps ) : JSX . Element {
64
+ function BreadCrumbItem ( props : BreadCrumbItemProps ) : JSX . Element {
62
65
return (
63
66
< li className = { props . breadcrumbValue } >
64
67
< Link
@@ -94,6 +97,7 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
94
97
95
98
return (
96
99
< div className = { styles . dropdownContainer } >
100
+ < h4 style = { { padding : "0.125rem 0.5rem" , height : "5" } } > ES Version:</ h4 >
97
101
< select value = { dropdownValue } onChange = { handleVersionSelection } >
98
102
< option value = { "" } > All</ option >
99
103
{ Object . keys ( SpecEdition )
@@ -109,3 +113,38 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
109
113
</ div >
110
114
) ;
111
115
}
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
+ }
0 commit comments