1
1
// React imports
2
2
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react'
3
- import { useMediaQuery } from 'react-responsive'
4
3
import ButtonGroup from 'react-bootstrap/ButtonGroup'
5
4
import Dropdown from 'react-bootstrap/Dropdown'
6
5
import DropdownButton from 'react-bootstrap/DropdownButton'
@@ -20,10 +19,6 @@ const PlanningScene = () => {
20
19
// Get relevant global state variables
21
20
const setSettingsState = useGlobalState ( ( state ) => state . setSettingsState )
22
21
23
- // Flag to check if the current orientation is portrait
24
- const isPortrait = useMediaQuery ( { query : '(orientation: portrait)' } )
25
- // Indicator of how to arrange screen elements based on orientation
26
- let dimension = isPortrait ? 'column' : 'row'
27
22
// Rendering variables
28
23
let textFontSize = '3.5vh'
29
24
@@ -42,19 +37,24 @@ const PlanningScene = () => {
42
37
createROSService ( ros . current , PLANNING_SCENE_GET_PARAMETERS_SERVICE_NAME , PLANNING_SCENE_GET_PARAMETERS_SERVICE_TYPE )
43
38
)
44
39
const [ planningSceneNamespaces , setPlanningSceneNamespaces ] = useState ( [ ] )
45
- useEffect ( ( ) => {
40
+ const getPlanningSceneNamespaces = useCallback ( ( ) => {
46
41
let service = getParametersService . current
47
42
let request = createROSServiceRequest ( {
48
43
names : [ 'namespaces' ]
49
44
} )
45
+ console . log ( 'PlanningScene: Requesting planning scene namespaces' , service , request )
50
46
service . callService ( request , ( response ) => {
47
+ console . log ( 'PlanningScene: Received planning scene namespaces' , request , response )
51
48
if ( response . values . length > 0 && response . values [ 0 ] . type === 9 ) {
52
49
setPlanningSceneNamespaces ( getValueFromParameter ( response . values [ 0 ] ) )
53
50
} else {
54
51
console . error ( 'PlanningScene: Error getting planning scene namespaces' )
55
52
}
56
53
} )
57
54
} , [ getParametersService , setPlanningSceneNamespaces ] )
55
+ useEffect ( ( ) => {
56
+ getPlanningSceneNamespaces ( )
57
+ } , [ getPlanningSceneNamespaces ] )
58
58
59
59
// Render the settings for the planning scene
60
60
const renderPlanningSceneSettings = useCallback ( ( ) => {
@@ -79,13 +79,14 @@ const PlanningScene = () => {
79
79
< View
80
80
style = { {
81
81
flex : 1 ,
82
- flexDirection : dimension ,
82
+ flexDirection : 'column' ,
83
83
justifyContent : 'center' ,
84
84
alignItems : 'center' ,
85
85
width : '100%' ,
86
86
height : '100%'
87
87
} }
88
88
>
89
+ < h5 style = { { textAlign : 'center' , fontSize : textFontSize } } > Select Planning Scene:</ h5 >
89
90
< DropdownButton
90
91
as = { ButtonGroup }
91
92
key = 'planningSceneOptions'
@@ -94,6 +95,11 @@ const PlanningScene = () => {
94
95
variant = 'secondary'
95
96
title = { currentParams [ 0 ] }
96
97
size = 'lg'
98
+ onClick = { ( ) => {
99
+ if ( planningSceneNamespaces . length === 0 ) {
100
+ getPlanningSceneNamespaces ( )
101
+ }
102
+ } }
97
103
>
98
104
{ planningSceneNamespaces . map ( ( namespace ) => (
99
105
< Dropdown . Item key = { namespace } onClick = { ( ) => setCurrentParams ( [ namespace ] ) } active = { namespace === currentParams [ 0 ] } >
@@ -104,7 +110,7 @@ const PlanningScene = () => {
104
110
</ View >
105
111
)
106
112
}
107
- } , [ currentParams , dimension , planningSceneNamespaces , setCurrentParams , textFontSize ] )
113
+ } , [ currentParams , planningSceneNamespaces , getPlanningSceneNamespaces , setCurrentParams , textFontSize ] )
108
114
109
115
return (
110
116
< SettingsPageParent
0 commit comments