Skip to content

Commit

Permalink
console: Refactor routing logic in packet broker views
Browse files Browse the repository at this point in the history
  • Loading branch information
kschiffer committed Oct 26, 2023
1 parent 111613d commit c0b533a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import React, { useCallback, useState } from 'react'
import { Container, Col, Row } from 'react-grid-system'
import { useSelector, useDispatch } from 'react-redux'
import { Routes, Route } from 'react-router-dom'
import { Routes, Route, Navigate } from 'react-router-dom'
import classnames from 'classnames'

import PacketBrokerLogo from '@assets/misc/packet-broker.svg'
Expand Down Expand Up @@ -69,7 +69,7 @@ const PacketBroker = () => {
} else {
setDeregisterModalVisible(true)
}
}, [dispatch, registered, setDeregisterModalVisible])
}, [dispatch, registered])

const handleDeregisterModalComplete = useCallback(
approved => {
Expand Down Expand Up @@ -102,8 +102,9 @@ const PacketBroker = () => {
const tabs = [
{
title: m.routingConfig,
link: '/admin-panel/packet-broker',
link: '/admin-panel/packet-broker/routing-configuration',
name: 'default',
exact: false,
},
{
title: m.defaultGatewayVisibility,
Expand Down Expand Up @@ -221,8 +222,9 @@ const PacketBroker = () => {
<Col md={12} style={{ position: 'relative' }} className="mt-cs-xxl">
<Tabs tabs={tabs} active={activeTab} onTabChange={setActiveTab} divider />
<Routes>
<Route index path="/*" Component={RoutingConfigurationView} />
<Route path="routing-configuration/*" Component={RoutingConfigurationView} />
<Route path="default-gateway-visibility" Component={DefaultGatewayVisibilityView} />
<Route path="/" element={<Navigate to="routing-configuration" />} />
<Route path="*" component={GenericNotFound} />
</Routes>
</Col>
Expand Down
2 changes: 1 addition & 1 deletion pkg/webui/console/views/admin-packet-broker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const PacketBrokerRouter = () => {
<RequireRequest requestAction={getPacketBrokerInfo()}>
<Routes>
<Route
path="networks/:netId/:tenantId?"
path="routing-configuration/networks/:netId/:tenantId?"
element={
<ValidateRouteParam
check={{ tenantId: pathIdRegexp, netId: /^\d+$/ }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import sharedMessages from '@ttn-lw/lib/shared-messages'

const NetworkRoutingPoliciesView = () => {
useBreadcrumbs(
'admin-panel.packet-broker.networks',
<Breadcrumb path={'/admin-panel/packet-broker/networks'} content={sharedMessages.networks} />,
'admin-panel.packet-broker.routing-configuration.networks',
<Breadcrumb
path={'/admin-panel/packet-broker/routing-configuration/networks'}
content={sharedMessages.networks}
/>,
)

return <PacketBrokerNetworksTable />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ const NetworkRoutingPolicyViewInner = () => {
const defaultRoutingPolicy = useSelector(selectHomeNetworkDefaultRoutingPolicy)

useBreadcrumbs(
'admin-panel.packet-broker.networks.single',
'admin-panel.packet-broker.routing-configuration.networks.single',
<>
<Breadcrumb path={'/admin-panel/packet-broker/networks'} content={sharedMessages.networks} />
<Breadcrumb
path={`/admin-panel/packet-broker/networks/${netId}${tenantId ? `/${tenantId}` : ''}`}
path={'/admin-panel/packet-broker/routing-configuration/networks'}
content={sharedMessages.networks}
/>
<Breadcrumb
path={`/admin-panel/packet-broker/routing-configuration/networks/${netId}${
tenantId ? `/${tenantId}` : ''
}`}
content={network.name || displayId}
/>
</>,
Expand Down Expand Up @@ -160,7 +165,11 @@ const NetworkRoutingPolicyViewInner = () => {
<Row>
<Col md={12}>
<PageTitle title={m.network} values={{ network: network.name || displayId }}>
<Link to="/admin-panel/packet-broker/networks" secondary className={style.backLink}>
<Link
to="/admin-panel/packet-broker/routing-configuration/networks"
secondary
className={style.backLink}
>
<Message content={m.backToAllNetworks} />
</Link>
</PageTitle>
Expand Down Expand Up @@ -228,7 +237,10 @@ const NetworkRoutingPolicyView = () => {
const registered = useSelector(selectRegistered)

return (
<Require condition={registered} otherwise={{ redirect: '/admin-panel/packet-broker' }}>
<Require
condition={registered}
otherwise={{ redirect: '/admin-panel/packet-broker/routing-configuration' }}
>
<RequireRequest
requestAction={[
getPacketBrokerNetwork(combinedId, { fetchPolicies: true }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ const RoutingConfigurationView = () => {
const dispatch = useDispatch()
const [activeTab, setActiveTab] = useState('default-routing-policy')
const tabs = [
{ title: m.defaultRoutingPolicy, link: '/admin-panel/packet-broker', name: 'default' },
{
title: m.defaultRoutingPolicy,
link: '/admin-panel/packet-broker/routing-configuration',
name: 'default',
},
{
title: sharedMessages.networks,
link: '/admin-panel/packet-broker/networks',
link: '/admin-panel/packet-broker/routing-configuration/networks',
name: 'networks',
exact: false,
},
Expand Down

0 comments on commit c0b533a

Please sign in to comment.