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
- < EcmaScriptVersionDropdown
17
- setEcmaScriptFlag = { props . setEcmaScriptFlag }
18
- esVersionValue = { props . state . ecmaScriptVersion }
19
- />
20
- < NavBreadCrumbs
21
- navPath = { props . state . testPath }
22
- sliceNavToIndex = { props . sliceNavToIndex }
23
- />
18
+ < div className = { styles . navSection } >
19
+ < EcmaScriptVersionDropdown
20
+ setEcmaScriptFlag = { props . setEcmaScriptFlag }
21
+ esVersionValue = { props . state . ecmaScriptVersion }
22
+ />
23
+ < SortingDropdown
24
+ sortValue = { props . state . sortOption }
25
+ setSortOption = { props . setSortOption }
26
+ />
27
+ </ div >
28
+ < div className = { styles . navSection } >
29
+ < NavBreadCrumbs
30
+ navPath = { props . state . testPath }
31
+ sliceNavToIndex = { props . sliceNavToIndex }
32
+ />
33
+ </ div >
24
34
</ div >
25
35
) ;
26
36
}
@@ -32,11 +42,11 @@ type BreadCrumbProps = {
32
42
33
43
function NavBreadCrumbs ( props : BreadCrumbProps ) {
34
44
return (
35
- < nav aria-label = "breadcrumbs" style = { { padding : "0.25em " } } >
45
+ < nav aria-label = "breadcrumbs" style = { { padding : "0.5em " } } >
36
46
< ul className = "breadcrumbs" >
37
47
{ props . navPath . map ( ( pathItem , idx , arr ) => {
38
48
return (
39
- < NavItem
49
+ < BreadCrumbItem
40
50
key = { pathItem }
41
51
itemName = { pathItem }
42
52
index = { idx }
@@ -54,14 +64,14 @@ function NavBreadCrumbs(props: BreadCrumbProps) {
54
64
) ;
55
65
}
56
66
57
- type NavItemProps = {
67
+ type BreadCrumbItemProps = {
58
68
itemName : string ;
59
69
index : number ;
60
70
breadcrumbValue : string ;
61
71
sliceNavToIndex : ( number ) => void ;
62
72
} ;
63
73
64
- function NavItem ( props : NavItemProps ) : JSX . Element {
74
+ function BreadCrumbItem ( props : BreadCrumbItemProps ) : JSX . Element {
65
75
return (
66
76
< li className = { props . breadcrumbValue } >
67
77
< Link
@@ -99,6 +109,7 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
99
109
100
110
return (
101
111
< div className = { styles . dropdownContainer } >
112
+ < h4 style = { { padding : "0.125rem 0.5rem" , height : "5" } } > ES Version:</ h4 >
102
113
< select value = { dropdownValue } onChange = { handleVersionSelection } >
103
114
< option value = { "" } > All</ option >
104
115
{ Object . keys ( SpecEdition )
@@ -114,3 +125,39 @@ function EcmaScriptVersionDropdown(props: DropDownProps): JSX.Element {
114
125
</ div >
115
126
) ;
116
127
}
128
+
129
+ type SortProps = {
130
+ sortValue : string ;
131
+ setSortOption : ( string ) => void ;
132
+ } ;
133
+
134
+ function SortingDropdown ( props : SortProps ) : JSX . Element {
135
+ const [ sortValue , setSortValue ] = React . useState < string > ( props . sortValue ? props . sortValue : "alpha" ) ;
136
+
137
+ React . useEffect ( ( ) => {
138
+ setSortValue ( props . sortValue ) ;
139
+ } , [ props . sortValue ] ) ;
140
+
141
+ const handleSortSelection = ( e ) => {
142
+ setSortValue ( e . target . value ) ;
143
+ const option = availableSortingOptions . filter (
144
+ ( v ) => v . id === e . target . value ,
145
+ ) ;
146
+ props . setSortOption ( option [ 0 ] . id ) ;
147
+ } ;
148
+
149
+ return (
150
+ < div className = { styles . dropdownContainer } >
151
+ < h4 style = { { padding : "0.125rem 0.5rem" , height : "5" } } > Sort:</ h4 >
152
+ < select value = { sortValue } onChange = { handleSortSelection } >
153
+ { availableSortingOptions . map ( ( key ) => {
154
+ return (
155
+ < option key = { key . id } value = { key . id } >
156
+ { key . name }
157
+ </ option >
158
+ ) ;
159
+ } ) }
160
+ </ select >
161
+ </ div >
162
+ ) ;
163
+ }
0 commit comments