11import T from 'prop-types' ;
2- import { useCallback } from 'react' ;
2+ import { useCallback , useMemo } from 'react' ;
3+
4+ import { useCollections , StacApi } from "stac-react" ;
35
46import { PrimaryButton } from "../../components/buttons" ;
57import { Checkbox , Legend } from '../../components/form' ;
68import { H2 } from "../../components/headers" ;
79import Panel from "../../layout/Panel" ;
810import Section from '../../layout/Section' ;
911
10- import { collectionsOptions } from '../../config' ;
11-
1212function QueryBuilder ( {
1313 setIsBboxDrawEnabled,
14- collections,
14+ collections : selectedCollections ,
1515 setCollections,
1616 handleSubmit,
1717 dateRangeFrom,
@@ -20,25 +20,33 @@ function QueryBuilder ({
2020 setDateRangeTo
2121} ) {
2222 const handleEnableBbox = useCallback ( ( ) => setIsBboxDrawEnabled ( true ) , [ setIsBboxDrawEnabled ] ) ;
23-
23+
2424 const handleRangeFromChange = useCallback ( ( e ) => setDateRangeFrom ( e . target . value ) , [ setDateRangeFrom ] ) ;
2525 const handleRangeToChange = useCallback ( ( e ) => setDateRangeTo ( e . target . value ) , [ setDateRangeTo ] ) ;
26+
27+ const stacApi = useMemo ( ( ) => new StacApi ( process . env . REACT_APP_STAC_API ) , [ ] ) ;
28+ const { collections } = useCollections ( stacApi ) ;
29+
30+ const collectionOptions = useMemo (
31+ ( ) => collections ? collections . collections . map ( ( { id, title } ) => ( { value : id , label : title } ) ) : [ ] ,
32+ [ collections ]
33+ ) ;
2634
2735 return (
28- < Panel >
29- < H2 > Query Builder</ H2 >
36+ < Panel className = "py-4 grid grid-rows-[min-content_auto_min-content_min-content_min-content] gap-4 h-[calc(100vh_-_90px)]" >
37+ < H2 className = "px-4" > Query Builder</ H2 >
3038
31- < Section >
39+ < Section className = "px-4 overflow-x-hidden overflow-y-auto" >
3240 < Checkbox
3341 label = "Select Collections"
3442 name = "collections"
35- options = { collectionsOptions }
36- values = { collections }
43+ options = { collectionOptions }
44+ values = { selectedCollections }
3745 onChange = { setCollections }
3846 />
3947 </ Section >
4048
41- < Section >
49+ < Section className = "px-4" >
4250 < fieldset >
4351 < Legend > Select Date Range</ Legend >
4452 < label htmlFor = 'date_from' > From</ label >
@@ -48,11 +56,11 @@ function QueryBuilder ({
4856 </ fieldset >
4957 </ Section >
5058
51- < Section >
59+ < Section className = "px-4" >
5260 < PrimaryButton onClick = { handleEnableBbox } > Set bbox</ PrimaryButton >
5361 </ Section >
5462
55- < Section >
63+ < Section className = "px-4" >
5664 < PrimaryButton onClick = { handleSubmit } > Submit</ PrimaryButton >
5765 </ Section >
5866 </ Panel >
0 commit comments