@@ -9,7 +9,7 @@ export interface Option {
99 disabled ?: boolean ;
1010 value : string ;
1111 label : string ;
12- districtCode ?: string ;
12+ districtCode ?: string ; // extra field we don’t want leaking into DOM
1313}
1414
1515export default function FilterDropdownOptions ( {
@@ -32,13 +32,19 @@ export default function FilterDropdownOptions({
3232 const [ revenueCode , setRevenueCode ] = useQueryState ( 'revenue-code' ) ;
3333
3434 const getRevenueCircleOptionsForDistrict = ( districtCode : string ) => {
35- const filterRevenueCircles = RevCircleDropdownOptions . filter (
35+ return RevCircleDropdownOptions . filter (
3636 ( option : Option ) => option . districtCode === districtCode
3737 ) ;
38-
39- return filterRevenueCircles ;
4038 } ;
4139
40+ // helper: strip out custom props like districtCode
41+ const sanitizeOptions = ( options : Option [ ] ) =>
42+ options . map ( ( { value, label, disabled } ) => ( {
43+ value,
44+ label,
45+ disabled,
46+ } ) ) ;
47+
4248 let minDate , maxDate ;
4349 // Below is code to set limits to the calendar
4450 if ( timeLimits . data ) {
@@ -59,26 +65,24 @@ export default function FilterDropdownOptions({
5965 const [ selectedTimePeriod , setSelectedTimePeriod ] = useQueryState < string [ ] > (
6066 'time-period' ,
6167 {
62- parse : ( value ) => {
63- return value . split ( ',' ) ;
64- } ,
68+ parse : ( value ) => value . split ( ',' ) ,
6569 }
6670 ) ;
6771
68- const districtOptions = [
72+ const districtOptions = sanitizeOptions ( [
6973 { label : 'Select a district' , value : '' } ,
7074 ...DistrictDropDownOption ,
71- ] ;
75+ ] ) ;
7276
73- const revenueOptions = [
77+ const revenueOptions = sanitizeOptions ( [
7478 {
7579 label : ! districtCode
7680 ? 'Select a district to enable'
7781 : `Select a ${ toTitleCase ( currentSelectedState . child_type ) } ` ,
7882 value : '' ,
7983 } ,
8084 ...( getRevenueCircleOptionsForDistrict ( districtCode ) || [ ] ) ,
81- ] ;
85+ ] ) ;
8286
8387 return (
8488 < div >
@@ -94,6 +98,7 @@ export default function FilterDropdownOptions({
9498 } }
9599 options = { districtOptions }
96100 />
101+
97102 < Select
98103 label = { `Select ${ toTitleCase ( currentSelectedState . child_type ) } ` }
99104 value = { revenueCode || '' }
@@ -127,7 +132,9 @@ export default function FilterDropdownOptions({
127132 setSelectedTimePeriod (
128133 dates . map (
129134 ( date : any ) =>
130- `${ date . year } _${ date . month < 10 ? `0${ date . month } ` : `${ date . month } ` } `
135+ `${ date . year } _${
136+ date . month < 10 ? `0${ date . month } ` : `${ date . month } `
137+ } `
131138 )
132139 ) ;
133140 } }
@@ -149,7 +156,9 @@ export default function FilterDropdownOptions({
149156 onChange = { ( date : any ) => {
150157 setSelectedTimePeriod (
151158 [
152- `${ date . year } _${ date . month < 10 ? `0${ date . month } ` : `${ date . month } ` } ` ,
159+ `${ date . year } _${
160+ date . month < 10 ? `0${ date . month } ` : `${ date . month } `
161+ } `,
153162 ] ,
154163 { shallow : false }
155164 ) ;
0 commit comments