44
55import * as React from 'react'
66import { TreeView , TreeItem } from '@mui/lab'
7- import { Typography , Collapse , Checkbox , FormControlLabel } from '@mui/material'
7+ import { Typography , Collapse , Checkbox , FormControlLabel , CircularProgress , Box } from '@mui/material'
88import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
99import { faChevronDown , faChevronUp , faChevronRight , faSatellite } from '@fortawesome/free-solid-svg-icons'
1010import { useLocalStorage } from '../utilities'
@@ -16,24 +16,56 @@ interface RenderTree {
1616 name : string
1717 children ?: RenderTree [ ]
1818 disabled ?: boolean
19+ loading ?: boolean
1920}
2021
2122const treeviewRootId = 'treeview-provider-root'
2223
23- function buildTreeviewData ( providersDict , constellationDict ) : RenderTree {
24+ // function buildTreeviewData(providersDict, constellationDict): RenderTree {
25+ // return {
26+ // id: treeviewRootId,
27+ // name: 'Satellite Sources',
28+ // children: Object.keys(providersDict).map((providerKey: string) => ({
29+ // id: `treeview-provider-${providerKey}`,
30+ // name: providerKey,
31+ // children: providersDict[providerKey].map((constellationKey: string) => ({
32+ // id: `treeview-constellation-${providerKey}-${constellationKey}`,
33+ // name: `${constellationKey} - ${100 * (constellationDict[constellationKey]?.gsd ?? 0)}cm`,
34+ // disabled: !(providerKey === Providers.UP42),
35+ // })),
36+ // })),
37+ // }
38+ // }
39+
40+ function buildTreeviewData ( providersDict , constellationDict , isUp42Loading = false ) : RenderTree {
2441 return {
2542 id : treeviewRootId ,
2643 name : 'Satellite Sources' ,
27- children : Object . keys ( providersDict ) . map ( ( providerKey : string ) => ( {
28- id : `treeview-provider-${ providerKey } ` ,
29- name : providerKey ,
30- children : providersDict [ providerKey ] . map ( ( constellationKey : string ) => ( {
31- id : `treeview-constellation-${ providerKey } -${ constellationKey } ` ,
32- name : `${ constellationKey } - ${ 100 * ( constellationDict [ constellationKey ] ?. gsd ?? 0 ) } cm` ,
33- disabled : ! ( providerKey === Providers . UP42 ) ,
34- } ) ) ,
35- } ) ) ,
36- }
44+ children : Object . keys ( providersDict ) . map ( ( providerKey : string ) => {
45+
46+ if ( providerKey === Providers . UP42 && isUp42Loading ) {
47+ return {
48+ id : `treeview-provider-${ providerKey } ` ,
49+ name : `${ providerKey } (Loading...)` ,
50+ children : [ {
51+ id : `treeview-constellation-${ providerKey } -loading` ,
52+ name : 'Loading...' ,
53+ loading : true ,
54+ children : [ ]
55+ } ]
56+ } ;
57+ }
58+ return {
59+ id : `treeview-provider-${ providerKey } ` ,
60+ name : providerKey ,
61+ children : providersDict [ providerKey ] . map ( ( constellationKey : string ) => ( {
62+ id : `treeview-constellation-${ providerKey } -${ constellationKey } ` ,
63+ name : `${ constellationKey } - ${ 100 * ( constellationDict [ constellationKey ] ?. gsd ?? 0 ) } cm` ,
64+ // disabled: !(providerKey === Providers.UP42),
65+ } ) ) ,
66+ } ;
67+ } ) ,
68+ } ;
3769}
3870
3971const sourcesTreeviewInitialSelection = ( treeviewData : RenderTree ) : string [ ] => {
@@ -47,6 +79,7 @@ const sourcesTreeviewInitialSelection = (treeviewData: RenderTree): string[] =>
4779 return result
4880}
4981
82+
5083RecursiveTreeView . propTypes = {
5184 providersTreeviewDataSelection : PropTypes . any ,
5285 setProvidersTreeviewDataSelection : PropTypes . func ,
@@ -124,10 +157,10 @@ function RecursiveTreeView(props): React.ReactElement {
124157 }
125158
126159 const renderTree = ( nodes : RenderTree ) : React . ReactElement => {
160+
127161 const allSelectedChildren = parentMap [ nodes . id ] ?. every ( ( childNodeId : string ) => selectedSet . has ( childNodeId ) )
128162 const checked = selectedSet . has ( nodes . id ) || allSelectedChildren || false
129163 const indeterminate = parentMap [ nodes . id ] ?. some ( ( childNodeId : string ) => selectedSet . has ( childNodeId ) ) || false
130-
131164 if ( allSelectedChildren && ! selectedSet . has ( nodes . id ) ) {
132165 props . setProvidersTreeviewDataSelection ( [ ...props . providersTreeviewDataSelection , nodes . id ] )
133166 }
@@ -147,7 +180,13 @@ function RecursiveTreeView(props): React.ReactElement {
147180 disabled = { nodes . disabled }
148181 />
149182 }
150- label = { < Typography variant = "subtitle2" > { nodes . name } </ Typography > }
183+ // label={<Typography variant="subtitle2">{nodes.name}</Typography>}
184+ label = {
185+ < Box sx = { { display : 'flex' , alignItems : 'center' , gap : 1 } } >
186+ < Typography variant = "subtitle2" > { nodes . name } </ Typography >
187+ { nodes . loading && < CircularProgress size = { 16 } /> }
188+ </ Box >
189+ }
151190 key = { nodes . id }
152191 />
153192 }
@@ -184,16 +223,21 @@ function SatelliteImagerySourcesTreeview(props): React.ReactElement {
184223 Satellite Sources Selection
185224 { advancedSettingsCollapsed ? < FontAwesomeIcon icon = { faChevronDown } /> : < FontAwesomeIcon icon = { faChevronUp } /> }
186225 </ Typography >
226+ { /* <Collapse in={!advancedSettingsCollapsed} timeout="auto" unmountOnExit>
227+
228+ <RecursiveTreeView
229+ setProvidersTreeviewDataSelection={props.setProvidersTreeviewDataSelection}
230+ providersTreeviewDataSelection={props.providersTreeviewDataSelection}
231+ treeviewData={props.treeviewData}
232+ />
233+
234+ </Collapse> */ }
187235 < Collapse in = { ! advancedSettingsCollapsed } timeout = "auto" unmountOnExit >
188- { props . treeviewData ? (
189- < RecursiveTreeView
190- setProvidersTreeviewDataSelection = { props . setProvidersTreeviewDataSelection }
191- providersTreeviewDataSelection = { props . providersTreeviewDataSelection }
192- treeviewData = { props . treeviewData }
193- />
194- ) : (
195- < div > Loading...</ div >
196- ) }
236+ < RecursiveTreeView
237+ setProvidersTreeviewDataSelection = { props . setProvidersTreeviewDataSelection }
238+ providersTreeviewDataSelection = { props . providersTreeviewDataSelection }
239+ treeviewData = { props . treeviewData }
240+ />
197241 </ Collapse >
198242 </ >
199243 )
0 commit comments