11import React from 'react'
22import {
33 FormControl ,
4+ FormControlLabel ,
45 FormHelperText ,
56 Input ,
67 InputLabel ,
@@ -165,13 +166,17 @@ const Filter = () => {
165166 id = { constraintName }
166167 name = { constraintName }
167168 aria-describedby = { constraintName }
168- required = { _selectedProductData . constraints . required . includes ( constraintName ) }
169+ required = { _selectedProductData . constraints . required . includes (
170+ constraintName
171+ ) }
169172 onChange = { ( event , newValue ) => {
170173 store . dispatch (
171174 setSelectedProductFilters ( {
172175 ..._selectedProductFilters ,
173176 [ constraintName ] : event . target . value
174- } ) ) } }
177+ } )
178+ )
179+ } }
175180 />
176181 < FormHelperText > { constraint . description } </ FormHelperText >
177182 </ FormControl >
@@ -183,38 +188,39 @@ const Filter = () => {
183188 console . log ( constraint )
184189 filterContainer . push (
185190 < FormControl key = { constraintName } >
186- < InputLabel
187- htmlFor = { constraintName }
188- sx = { { color : '#FFF' , paddingTop : 0 } }
189- >
190- { constraint . title }
191- </ InputLabel >
192- < Switch
193- id = { constraintName }
194- name = { constraintName }
195- aria-describedby = { constraintName }
191+ < FormControlLabel
192+ control = {
193+ < Switch
194+ id = { constraintName }
195+ name = { constraintName }
196+ aria-describedby = { constraintName }
197+ checked = {
198+ _selectedProductFilters [ constraintName ] || constraint . default
199+ }
200+ onChange = { ( event ) => {
201+ store . dispatch (
202+ setSelectedProductFilters ( {
203+ ..._selectedProductFilters ,
204+ [ constraintName ] : event . target . checked
205+ } )
206+ )
207+ } }
208+ />
209+ }
210+ label = { constraint . title }
211+ labelPlacement = "top"
196212 />
213+
197214 < FormHelperText > { constraint . description } </ FormHelperText >
198215 </ FormControl >
199216 )
200217 continue
201218 }
202219
203220 if ( constraint . type === 'array' ) {
204- // TODO for umbras case we need to add a check for the $ref property, if it exists we need to get the enum values from the $ref object
205- // and populate the dropdown with those values
206- // otherwise just take the enum values from the parameter properties
207- // its not working for the last umbra json but maybe after the changes it will?
208-
209- let refItem = { }
210- if ( constraint . items . $ref ) {
211- const refName = constraint . items . $ref . split ( '/' ) . pop ( )
212- refItem = _selectedProductData . parameters . $defs [ refName ]
213- }
214-
215221 const options = [ ]
216222
217- for ( const option of refItem ?. enum || [ ] ) {
223+ for ( const option of constraint ?. items ?. enum || [ ] ) {
218224 options . push (
219225 < MenuItem key = { option } value = { option } >
220226 { option }
@@ -230,7 +236,21 @@ const Filter = () => {
230236 >
231237 { constraint . title }
232238 </ InputLabel >
233- < Select id = { constraintName } name = { constraintName } >
239+ < Select
240+ id = { constraintName }
241+ name = { constraintName }
242+ required = { _selectedProductData . constraints . required . includes (
243+ constraintName
244+ ) }
245+ onChange = { ( event ) => {
246+ store . dispatch (
247+ setSelectedProductFilters ( {
248+ ..._selectedProductFilters ,
249+ [ constraintName ] : event . target . value
250+ } )
251+ )
252+ } }
253+ >
234254 { options }
235255 </ Select >
236256 < FormHelperText > { constraint . description } </ FormHelperText >
0 commit comments