1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- import React , { useEffect , useMemo } from 'react'
16- import { useDispatch , useSelector } from 'react-redux'
15+ import React , { useMemo } from 'react'
16+ import { useSelector } from 'react-redux'
1717import { defineMessages } from 'react-intl'
18- import { useParams } from 'react-router-dom'
1918
2019import Panel from '@ttn-lw/components/panel'
2120import Icon , { IconGateway , IconInfoCircle , IconBolt , IconRouterOff } from '@ttn-lw/components/icon'
@@ -31,8 +30,6 @@ import PropTypes from '@ttn-lw/lib/prop-types'
3130import sharedMessages from '@ttn-lw/lib/shared-messages'
3231import { getBackendErrorName , isBackend } from '@ttn-lw/lib/errors/utils'
3332
34- import { startGatewayStatistics , stopGatewayStatistics } from '@console/store/actions/gateways'
35-
3633import {
3734 selectGatewayStatistics ,
3835 selectGatewayStatisticsError ,
@@ -107,13 +104,13 @@ EmptyState.propTypes = {
107104}
108105
109106const GatewayStatusPanel = ( ) => {
110- const dispatch = useDispatch ( )
111- const { gtwId } = useParams ( )
112107 const gatewayStats = useSelector ( selectGatewayStatistics )
113108 const error = useSelector ( selectGatewayStatisticsError )
114109 const fetching = useSelector ( selectGatewayStatisticsIsFetching )
115110 const isDisconnected = Boolean ( gatewayStats ?. disconnected_at )
111+ const isConnected = Boolean ( gatewayStats ?. connected_at ) && ! isDisconnected
116112 const isFetching = ! Boolean ( gatewayStats ) && fetching
113+ const hasStatistics = Boolean ( gatewayStats )
117114 const noConnectionYet = useMemo (
118115 ( ) => isBackend ( error ) && getBackendErrorName ( error ) . includes ( 'not_connected' ) ,
119116 [ error ] ,
@@ -142,13 +139,6 @@ const GatewayStatusPanel = () => {
142139 const showRoundTripTimes = Boolean ( gatewayStats ?. round_trip_times )
143140 const showDutyCycleUtilization = Boolean ( gatewayStats ?. sub_bands )
144141
145- useEffect ( ( ) => {
146- dispatch ( startGatewayStatistics ( gtwId ) )
147- return ( ) => {
148- dispatch ( stopGatewayStatistics ( ) )
149- }
150- } , [ dispatch , gtwId ] )
151-
152142 return (
153143 < Panel
154144 title = { sharedMessages . gatewayStatus }
@@ -165,9 +155,11 @@ const GatewayStatusPanel = () => {
165155 status = {
166156 isDisconnected
167157 ? 'bad'
168- : isFetching || hasError || noConnectionYet
158+ : isFetching || noConnectionYet
169159 ? 'mediocre'
170- : 'green'
160+ : isConnected
161+ ? 'green'
162+ : 'unknown'
171163 }
172164 pulse
173165 big
@@ -206,7 +198,7 @@ const GatewayStatusPanel = () => {
206198 </ div >
207199 </ div >
208200 ) }
209- { ! isFetching && ! noConnectionYet && ! isUnavailable && (
201+ { hasStatistics && ! isFetching && ! noConnectionYet && ! isUnavailable && (
210202 < >
211203 < div className = { style . gtwStatusPanelUpperContainer } >
212204 < div className = "d-flex direction-column j-between w-full sm-md:j-start" >
@@ -256,6 +248,9 @@ const GatewayStatusPanel = () => {
256248 </ div >
257249 </ >
258250 ) }
251+ { ! hasStatistics && ! isFetching && ! noConnectionYet && ! isUnavailable && (
252+ < EmptyState title = { m . isUnavailable } message = { m . isUnavailableDesc } />
253+ ) }
259254 </ Panel >
260255 )
261256}
0 commit comments