@@ -10,19 +10,25 @@ import { getContainerIdFromUrl } from "../utils";
10
10
import {
11
11
Button ,
12
12
createStyles ,
13
+ FormControlLabel ,
14
+ Grid ,
15
+ IconButton ,
16
+ Input ,
17
+ InputAdornment ,
13
18
makeStyles ,
14
19
Menu ,
15
20
MenuItem ,
16
- TextField ,
21
+ Switch ,
17
22
Theme
18
23
} from "@material-ui/core" ;
19
24
import {
20
25
PREFERRED_SOURCES_VIEW_ONLY ,
21
26
useAnchor
22
27
} from "../../../utils" ;
23
28
import { APISource } from "../../sources" ;
24
- import { AccountTreeOutlined , FolderOpen } from "@material-ui/icons" ;
29
+ import { AccountTreeOutlined , FolderOpen , Search as SearchIcon } from "@material-ui/icons" ;
25
30
import { APIDictionary } from '../../dictionaries/types' ;
31
+ import { VerifiedSource } from "../../../components/VerifiedSource" ;
26
32
27
33
interface Props {
28
34
containerType : string ;
@@ -32,6 +38,8 @@ interface Props {
32
38
children ?: React . ReactNode [ ] ;
33
39
sources : APISource [ ] ;
34
40
dictionaries : APIDictionary [ ] ;
41
+ showOnlyVerified : boolean ;
42
+ toggleShowVerified : React . ChangeEventHandler < HTMLInputElement > ;
35
43
}
36
44
37
45
const useStyles = makeStyles ( ( theme : Theme ) =>
@@ -60,6 +68,10 @@ const useStyles = makeStyles((theme: Theme) =>
60
68
marginRight : "0.2rem" ,
61
69
fill : "#8080809c"
62
70
} ,
71
+ searchInput : {
72
+ textAlign : "center" ,
73
+ fontSize : "larger"
74
+ } ,
63
75
} )
64
76
) ;
65
77
@@ -70,9 +82,12 @@ const ViewConceptsHeader: React.FC<Props> = ({
70
82
addConceptToDictionary,
71
83
children,
72
84
sources,
73
- dictionaries
85
+ dictionaries,
86
+ showOnlyVerified,
87
+ toggleShowVerified
74
88
} ) => {
75
89
const [ showSources , setShowSources ] = useState ( false ) ;
90
+ const [ search , setSearch ] = useState ( "" ) ;
76
91
const [ preferredSources , setPreferredSources ] = useState < { name : string ; url : string } [ ] > ( ) ;
77
92
useEffect ( ( ) => {
78
93
const defaultSources = Object . entries ( PREFERRED_SOURCES_VIEW_ONLY ) . map ( ( [ key , value ] ) => ( { name : key , url : value } ) ) ;
@@ -84,6 +99,7 @@ const ViewConceptsHeader: React.FC<Props> = ({
84
99
} else setPreferredSources ( defaultSources ) ;
85
100
} , [ showSources , sources , dictionaries ] ) ;
86
101
102
+
87
103
const classes = useStyles ( ) ;
88
104
const isSourceContainer = containerType === SOURCE_CONTAINER ;
89
105
const isAddToDictionary = isSourceContainer && ! ! addConceptToDictionary ;
@@ -92,7 +108,6 @@ const ViewConceptsHeader: React.FC<Props> = ({
92
108
handleSwitchSourceClick ,
93
109
handleSwitchSourceClose
94
110
] = useAnchor ( ) ;
95
-
96
111
const getTitleBasedOnContainerType = ( ) => {
97
112
return isAddToDictionary
98
113
? `Import existing concept from ${ getContainerIdFromUrl ( containerUrl ) } `
@@ -125,21 +140,53 @@ const ViewConceptsHeader: React.FC<Props> = ({
125
140
keepMounted
126
141
open = { Boolean ( switchSourceAnchor ) }
127
142
onClose = { handleSwitchSourceClose }
128
- >
129
- < TextField
130
- multiline
131
- className = { classes . textField }
132
- InputProps = { {
133
- className : classes . underline
134
- } }
135
- inputProps = { {
136
- className : classes . input
137
- } }
138
- value = {
139
- showSources ? "Choose a source/dictionary" : "Select a different source/dictionary"
140
- }
141
- onClick = { ( ) => setShowSources ( ! showSources ) }
143
+ >
144
+ < Grid
145
+ container
146
+ direction = "column" >
147
+ < Button
148
+ variant = "text"
149
+ onClick = { ( ) => setShowSources ( ! showSources ) }
150
+ >
151
+ { /* {showSources ? "Select a recommended source" : "Select an alternative source"} */ }
152
+ </ Button >
153
+ { showSources &&
154
+ < Input
155
+ color = "primary"
156
+ type = "search"
157
+ fullWidth
158
+ placeholder = { "Select an alternative source" }
159
+ value = { search }
160
+ onChange = { event => setSearch ( event . target . value ) }
161
+ data-testid = "switch-source"
162
+ endAdornment = {
163
+ < InputAdornment position = "end" >
164
+ < IconButton
165
+ onClick = { ( ) => setShowSources ( ! showSources ) }
166
+ data-testid = "searchButton"
167
+ >
168
+ < SearchIcon />
169
+ </ IconButton >
170
+ </ InputAdornment >
171
+ }
172
+ />
173
+ }
174
+
175
+ < FormControlLabel
176
+ control = {
177
+ < Switch
178
+ checkedIcon = { < VerifiedSource /> }
179
+ checked = { showOnlyVerified }
180
+ onChange = { toggleShowVerified }
181
+ color = "primary"
182
+ name = "displayVerified"
142
183
/>
184
+ }
185
+ label = {
186
+ showOnlyVerified ? `Showing verified S only` : `Show verified Sources only`
187
+ }
188
+ />
189
+ </ Grid >
143
190
{ preferredSources ?. map ( ( { name, url } ) => (
144
191
< MenuItem
145
192
// replace because we want to keep the back button useful
0 commit comments