Skip to content

Commit c46a852

Browse files
Merge pull request #7729 from TheThingsNetwork/fix/gateway-status
Fix gateway status in the overview
2 parents 6e75317 + d270f02 commit c46a852

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

pkg/webui/console/containers/gateway-connection/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ const GatewayConnection = props => {
109109
} else if (isFetching) {
110110
statusIndicator = 'mediocre'
111111
message = sharedMessages.connecting
112-
} else if (isUnavailable) {
113-
statusIndicator = 'unknown'
114-
message = error.message
115-
if (isOtherCluster) {
116-
tooltipMessage = m.otherClusterTooltip
117-
docPath = '/gateways/troubleshooting/#my-gateway-shows-a-other-cluster-status-why'
118-
}
119112
} else if (hasStatistics) {
120113
message = sharedMessages.connected
121114
statusIndicator = 'good'
@@ -127,6 +120,13 @@ const GatewayConnection = props => {
127120
tooltipMessage = m.connectedTooltip
128121
}
129122
docTitle = sharedMessages.moreInformation
123+
} else if (isUnavailable) {
124+
statusIndicator = 'unknown'
125+
message = error.message
126+
if (isOtherCluster) {
127+
tooltipMessage = m.otherClusterTooltip
128+
docPath = '/gateways/troubleshooting/#my-gateway-shows-a-other-cluster-status-why'
129+
}
130130
} else {
131131
message = sharedMessages.unknown
132132
statusIndicator = 'unknown'

pkg/webui/console/containers/gateway-status-panel/index.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
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'
1717
import { defineMessages } from 'react-intl'
18-
import { useParams } from 'react-router-dom'
1918

2019
import Panel from '@ttn-lw/components/panel'
2120
import Icon, { IconGateway, IconInfoCircle, IconBolt, IconRouterOff } from '@ttn-lw/components/icon'
@@ -31,8 +30,6 @@ import PropTypes from '@ttn-lw/lib/prop-types'
3130
import sharedMessages from '@ttn-lw/lib/shared-messages'
3231
import { getBackendErrorName, isBackend } from '@ttn-lw/lib/errors/utils'
3332

34-
import { startGatewayStatistics, stopGatewayStatistics } from '@console/store/actions/gateways'
35-
3633
import {
3734
selectGatewayStatistics,
3835
selectGatewayStatisticsError,
@@ -107,13 +104,13 @@ EmptyState.propTypes = {
107104
}
108105

109106
const 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
}

pkg/webui/console/store/middleware/logics/gateways.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const startGatewayStatisticsLogic = createLogic({
254254
}),
255255
)
256256
done()
257+
return
257258
}
258259

259260
let gtwGsAddress
@@ -273,6 +274,7 @@ const startGatewayStatisticsLogic = createLogic({
273274
}),
274275
)
275276
done()
277+
return
276278
}
277279

278280
if (gtwGsAddress !== consoleGsAddress) {
@@ -282,6 +284,7 @@ const startGatewayStatisticsLogic = createLogic({
282284
}),
283285
)
284286
done()
287+
return
285288
}
286289

287290
dispatch(gateways.startGatewayStatisticsSuccess())

0 commit comments

Comments
 (0)