11import T from 'prop-types' ;
22import { useCallback , useMemo } from 'react' ;
33
4- import { useCollections , StacApi } from "stac-react" ;
5-
64import { PrimaryButton } from "../../components/buttons" ;
75import { Checkbox , Legend } from '../../components/form' ;
86import { H2 } from "../../components/headers" ;
@@ -11,7 +9,8 @@ import Section from '../../layout/Section';
119
1210function QueryBuilder ( {
1311 setIsBboxDrawEnabled,
14- collections : selectedCollections ,
12+ collections,
13+ selectedCollections,
1514 setCollections,
1615 handleSubmit,
1716 dateRangeFrom,
@@ -24,15 +23,8 @@ function QueryBuilder ({
2423 const handleRangeFromChange = useCallback ( ( e ) => setDateRangeFrom ( e . target . value ) , [ setDateRangeFrom ] ) ;
2524 const handleRangeToChange = useCallback ( ( e ) => setDateRangeTo ( e . target . value ) , [ setDateRangeTo ] ) ;
2625
27- const headers = useMemo ( ( ) => ( {
28- Authorization : "Basic " + btoa ( process . env . REACT_APP_STAC_API_TOKEN + ":" )
29- } ) , [ ] ) ;
30-
31- const stacApi = useMemo ( ( ) => new StacApi ( process . env . REACT_APP_STAC_API , { headers } ) , [ headers ] ) ;
32- const { collections } = useCollections ( stacApi ) ;
33-
3426 const collectionOptions = useMemo (
35- ( ) => collections ? collections . collections . map ( ( { id, title } ) => ( { value : id , label : title } ) ) : [ ] ,
27+ ( ) => collections . collections ? collections . collections . map ( ( { id, title } ) => ( { value : id , label : title } ) ) : [ ] ,
3628 [ collections ]
3729 ) ;
3830
@@ -45,7 +37,7 @@ function QueryBuilder ({
4537 label = "Select Collections"
4638 name = "collections"
4739 options = { collectionOptions }
48- values = { selectedCollections }
40+ values = { selectedCollections || [ ] }
4941 onChange = { setCollections }
5042 />
5143 </ Section >
@@ -74,7 +66,8 @@ function QueryBuilder ({
7466QueryBuilder . propTypes = {
7567 setIsBboxDrawEnabled : T . func . isRequired ,
7668 handleSubmit : T . func . isRequired ,
77- collections : T . arrayOf ( T . string ) ,
69+ collections : T . object ,
70+ selectedCollections : T . arrayOf ( T . string ) ,
7871 setCollections : T . func . isRequired ,
7972 dateRangeFrom : T . string . isRequired ,
8073 setDateRangeFrom : T . func . isRequired ,
0 commit comments