Skip to content

Commit 01c27bb

Browse files
committed
console: Gateway status panel
1 parent 0d23e10 commit 01c27bb

3 files changed

Lines changed: 19 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import React, { useEffect, useMemo } from 'react'
15+
import React, { useMemo } from 'react'
1616
import classnames from 'classnames'
1717
import { FormattedNumber, defineMessages } from 'react-intl'
18-
import { useDispatch, useSelector } from 'react-redux'
18+
import { useSelector } from 'react-redux'
1919

2020
import Icon, { IconArrowsSort, IconBroadcast } from '@ttn-lw/components/icon'
2121
import Status from '@ttn-lw/components/status'
@@ -35,8 +35,6 @@ import { isNotFoundError, isTranslated } from '@ttn-lw/lib/errors/utils'
3535
import { selectGsConfig } from '@ttn-lw/lib/selectors/env'
3636
import getHostFromUrl from '@ttn-lw/lib/host-from-url'
3737

38-
import { startGatewayStatistics, stopGatewayStatistics } from '@console/store/actions/gateways'
39-
4038
import {
4139
selectGatewayById,
4240
selectGatewayStatistics,
@@ -73,17 +71,8 @@ const GatewayConnection = props => {
7371
const lastSeen = useSelector(selectGatewayLastSeen)
7472
const isOtherCluster = consoleGsAddress !== gatewayServerAddress
7573

76-
const dispatch = useDispatch()
77-
7874
useConnectionReactor(gtwId)
7975

80-
useEffect(() => {
81-
dispatch(startGatewayStatistics(gtwId))
82-
return () => {
83-
dispatch(stopGatewayStatistics())
84-
}
85-
}, [dispatch, gtwId])
86-
8776
const status = useMemo(() => {
8877
const statsNotFound = Boolean(error) && isNotFoundError(error)
8978
const isDisconnected = Boolean(statistics) && Boolean(statistics.disconnected_at)

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,16 @@ const GatewayStatusPanel = () => {
108108
const error = useSelector(selectGatewayStatisticsError)
109109
const fetching = useSelector(selectGatewayStatisticsIsFetching)
110110
const isDisconnected = Boolean(gatewayStats?.disconnected_at)
111-
const isConnected = Boolean(gatewayStats?.connected_at) && !isDisconnected
112111
const isFetching = !Boolean(gatewayStats) && fetching
113-
const hasStatistics = Boolean(gatewayStats)
114112
const noConnectionYet = useMemo(
115113
() => isBackend(error) && getBackendErrorName(error).includes('not_connected'),
116114
[error],
117115
)
116+
const hasStatistics = Boolean(gatewayStats)
117+
const isConnected = Boolean(gatewayStats?.connected_at) && !isDisconnected && !noConnectionYet
118118

119119
const hasError = Boolean(error) && Boolean(error.message)
120-
const isUnavailable = hasError && error.message === 'Unavailable' && !fetching && !gatewayStats
121-
const isLoadingWithError = hasError && error.message === 'Unavailable' && !gatewayStats
120+
const isUnavailable = hasError && error.message === 'Unavailable'
122121

123122
const maxRoundTripTime = useMemo(
124123
() =>
@@ -156,7 +155,7 @@ const GatewayStatusPanel = () => {
156155
status={
157156
isDisconnected
158157
? 'bad'
159-
: isFetching || noConnectionYet || isLoadingWithError
158+
: isFetching || noConnectionYet
160159
? 'mediocre'
161160
: isConnected
162161
? 'green'
@@ -191,15 +190,7 @@ const GatewayStatusPanel = () => {
191190
</div>
192191
</div>
193192
)}
194-
{isUnavailable && (
195-
<div className="d-flex j-center al-center flex-grow">
196-
<div className="d-flex direction-column j-center al-center text-center w-60 gap-cs-m mb-ls-m">
197-
<Message content={m.isUnavailable} className="fw-bold fs-l lh-xs3" component="div" />
198-
<Message content={m.isUnavailableDesc} className="c-text-neutral-light lh-xxs" />
199-
</div>
200-
</div>
201-
)}
202-
{hasStatistics && !isFetching && !noConnectionYet && !isUnavailable && (
193+
{hasStatistics && !isFetching && !isUnavailable && (
203194
<>
204195
<div className={style.gtwStatusPanelUpperContainer}>
205196
<div className="d-flex direction-column j-between w-full sm-md:j-start">
@@ -249,7 +240,7 @@ const GatewayStatusPanel = () => {
249240
</div>
250241
</>
251242
)}
252-
{!hasStatistics && !isFetching && !noConnectionYet && !isUnavailable && (
243+
{(isUnavailable || (!hasStatistics && !isFetching && !noConnectionYet)) && (
253244
<EmptyState title={m.isUnavailable} message={m.isUnavailableDesc} />
254245
)}
255246
</Panel>

pkg/webui/console/views/gateway/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {
4545
stopGatewayEventsStream,
4646
getGatewaysRightsList,
4747
getGatewayClaimInfoByEui,
48+
startGatewayStatistics,
49+
stopGatewayStatistics,
4850
} from '@console/store/actions/gateways'
4951
import { getGsFrequencyPlans } from '@console/store/actions/configuration'
5052
import { trackRecencyFrequencyItem } from '@console/store/actions/recency-frequency-items'
@@ -86,12 +88,20 @@ const Gateway = () => {
8688
await dispatch(getGsFrequencyPlans())
8789

8890
const { ids } = await dispatch(attachPromise(getGateway(gtwId, selector)))
91+
await dispatch(startGatewayStatistics(gtwId))
8992

9093
await dispatch(attachPromise(getGatewayClaimInfoByEui(ids.eui, true)))
9194
},
9295
[gtwId],
9396
)
94-
useEffect(() => () => dispatch(stopGatewayEventsStream(gtwId)), [gtwId, dispatch])
97+
98+
useEffect(
99+
() => () => {
100+
dispatch(stopGatewayStatistics())
101+
dispatch(stopGatewayEventsStream(gtwId))
102+
},
103+
[dispatch, gtwId],
104+
)
95105

96106
// Track gateway access.
97107
useEffect(() => {

0 commit comments

Comments
 (0)