Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Packet Broker settings #6639

Merged
merged 29 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8670662
console: Refactor packet broker view
ryaplots Oct 16, 2023
0cf3251
console: Determine initial values and submit form
ryaplots Oct 18, 2023
9fca6e6
console: Separate the forms
ryaplots Oct 18, 2023
d7f44d7
console: Update locales
ryaplots Oct 18, 2023
5105abc
console: Update e2e tests
ryaplots Oct 18, 2023
487eec6
console: Update locales
ryaplots Oct 18, 2023
ba91eb5
console: Remove custom radio buttons
ryaplots Oct 18, 2023
088fccc
console: Remove unnecessary request
ryaplots Oct 18, 2023
7f8cb36
console: Update locales
ryaplots Oct 18, 2023
210024c
console: Fix validation schema
ryaplots Oct 19, 2023
cf1af36
console: Fix e2e tests
ryaplots Oct 23, 2023
ceded37
console: Fix undefined and delete all policies on default
ryaplots Oct 23, 2023
1761a1d
console: Update messages
ryaplots Oct 23, 2023
838fd9c
console: Remove gateway visibility
ryaplots Oct 23, 2023
fdc9bae
console: Remove default gateway visibility form
ryaplots Oct 23, 2023
14c2c8c
console: Update locales
ryaplots Oct 23, 2023
e3854b4
console: Update e2e tests
ryaplots Oct 24, 2023
97d0b0a
console: Restore gateway visibility
ryaplots Oct 24, 2023
64a0fd1
console: Separate routing configuration to include gateway visibility
ryaplots Oct 24, 2023
6f3da98
console: Update locales
ryaplots Oct 24, 2023
190d14e
console: Fix messages
ryaplots Oct 24, 2023
111613d
console: Update e2e tests
ryaplots Oct 24, 2023
5a86cfc
console: Refactor routing logic in packet broker views
kschiffer Oct 26, 2023
866cf02
console: Add do not set a default policy and keep state
ryaplots Oct 30, 2023
ea28f01
console: Update e2e tests
ryaplots Oct 30, 2023
7a1a124
console: Fix messages
ryaplots Oct 30, 2023
62c5c57
Merge branch 'v3.28' into fix/packet-broker-view
ryaplots Oct 30, 2023
0b2401b
console: Update routes
ryaplots Oct 30, 2023
1e87d83
console: Fix messages
ryaplots Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cypress/e2e/console/admin-panel/packet-broker/networks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ describe('Packet Broker networks', () => {
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks`,
)
cy.findByLabelText('Use custom routing policies').check()

const { networks } = this.networks
const networksFiltered = networks.filter(
Expand Down Expand Up @@ -73,7 +78,11 @@ describe('Packet Broker networks', () => {
n => n.forwarder_id.net_id === 19 && n.forwarder_id.tenant_id === 'johan',
)

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19/johan`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19/johan`,
)

cy.findAllByText(`${network.id.net_id.toString(16).padStart(6, '0')}/${network.id.tenant_id}`)
cy.findByText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('Packet Broker registration', () => {
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByText('Packet Broker', { selector: 'h1' }).should('be.visible')
cy.findByText(/Packet Broker can be used to exchange traffic/).should('be.visible')
cy.findByText('Packet Broker documentation', { selector: 'a' }).should('be.visible')
cy.findByText(/Packet Broker is a service by The Things Industries/).should('be.visible')
cy.findByText('Packet Broker', { selector: 'a' }).should('be.visible')
cy.findByText('Packet Broker website', { selector: 'a' }).should('be.visible')
cy.findByText('Register network', { selector: 'span' }).should('be.visible')
cy.findByText('Enable Packet Broker', { selector: 'span' }).should('be.visible')
cy.findByTestId('switch')
.should('be.visible')
.and('not.be.checked')
.and('not.have.attr', 'disabled')
cy.findByText(/To enable peering/).should('be.visible')
cy.findByText(/Enabling will allow/).should('be.visible')

cy.findByText('Default routing policy').should('not.exist')
cy.findByText('Networks').should('not.exist')
Expand All @@ -89,18 +89,20 @@ describe('Packet Broker registration', () => {
cy.loginConsole({ user_id: 'admin', password: 'admin' })
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByText('Register network').click()
cy.findByText('Register network').next().findByTestId('switch').should('be.checked')
cy.findByText('List network publicly')
cy.findByText('Enable Packet Broker').click()
cy.findByText('Enable Packet Broker').next().findByTestId('switch').should('be.checked')
cy.findByText('List my network in Packet Broker publicly')
.should('be.visible')
.next()
.findByTestId('switch')
.should('be.checked')
cy.findByTestId('feature-info-forwarder-enabled').should('be.visible')
cy.findByTestId('feature-info-home-network-enabled').should('be.visible')
cy.findByTestId('tabs').findByText('Default routing policy').should('be.visible')
cy.findByTestId('tabs').findByText('Networks').should('be.visible')
cy.findByLabelText('Do not use a default routing policy for this network').should('be.checked')
cy.findByLabelText('Forward traffic to all networks registered in Packet Broker').should(
'exist',
)
cy.findByLabelText(
'Forward traffic to The Things Stack Sandbox (community network) only',
).should('exist')
cy.findByLabelText('Use custom routing policies').should('exist')

cy.findByTestId('error-notification').should('not.exist')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,63 @@ describe('Packet Broker routing policies', () => {
cy.loginConsole({ user_id: 'admin', password: 'admin' })
})

it('succeeds setting a default routing policy', () => {
it('succeeds setting a "traffic to all networks" routing configuration', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', { statusCode: 404 })
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19/johan', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Use default routing policy for this network').check()
cy.findByLabelText('Forward traffic to all networks registered in Packet Broker').check()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds setting a "only ttn" routing configuration', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', { statusCode: 404 })
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19/johan', {})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/19/ttn', {})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText(
'Forward traffic to The Things Stack Sandbox (community network) only',
).check()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds setting a custom routing configuration with a default routing policy', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', {
fixture: 'console/packet-broker/default-policy.json',
})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Use custom routing policies').check()

// Check routing policy form checkboxes.
cy.findByText('Uplink')
Expand All @@ -56,30 +107,35 @@ describe('Packet Broker routing policies', () => {
cy.findByLabelText('MAC data').check()
cy.findByLabelText('Application data').check()
})
cy.findByRole('button', { name: 'Save default policy' }).click()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing policy set')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds unsetting a default routing policy', () => {
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', {
fixture: 'console/packet-broker/default-policy.json',
fixture: 'console/packet-broker/default-custom-policy.json',
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/default', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Do not use a default routing policy for this network').check()
cy.findByRole('button', { name: 'Save default policy' }).click()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing policy set')
.findByText('Default routing configuration set')
.should('be.visible')
})

Expand All @@ -93,7 +149,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

// Check routing policy form checkboxes.
cy.findByLabelText('Use network specific routing policy').check()
Expand Down Expand Up @@ -138,7 +198,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

cy.findByLabelText('Do not use a routing policy for this network').check()
cy.findByRole('button', { name: 'Save routing policy' }).click()
Expand All @@ -161,7 +225,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

cy.findByLabelText('Use default routing policy for this network').check()
cy.findByRole('button', { name: 'Save routing policy' }).click()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"updated_at": "2021-06-21T12:09:26.810087Z",
"uplink": {
"join_request": true,
"mac_data": false,
"application_data": true,
"signal_quality": false,
"localization": false
},
"downlink": { "join_accept": true, "mac_data": false, "application_data": true }
}
118 changes: 118 additions & 0 deletions pkg/webui/console/components/default-routing-policy-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import React, { useCallback, useState } from 'react'
import { Col, Row } from 'react-grid-system'
import { defineMessages } from 'react-intl'

import Form, { useFormContext } from '@ttn-lw/components/form'
import Checkbox from '@ttn-lw/components/checkbox'
import Radio from '@ttn-lw/components/radio-button'

import Message from '@ttn-lw/lib/components/message'

import sharedMessages from '@ttn-lw/lib/shared-messages'

import policyMessages from '@console/lib/packet-broker/messages'

const m = defineMessages({
doNotUseADefaultPolicy: 'Do not use a default routing policy for this network',
})

const useDefaultEncode = val => val === 'default'
const useDefaultDecode = val => (val ? 'default' : 'no-default')

const DefaultRoutingPolicyForm = () => {
const { values } = useFormContext()
const [useDefault, setUseDefault] = useState(values._use_default_policy || false)
const handlePolicySourceChange = useCallback(setUseDefault, [setUseDefault])

return (
<Row>
<Col md={12}>
<Form.Field
component={Radio.Group}
className="mb-ls-s"
name="_use_default_policy"
onChange={handlePolicySourceChange}
encode={useDefaultEncode}
decode={useDefaultDecode}
>
<Radio label={m.doNotUseADefaultPolicy} value="no-default" />
<Radio label={sharedMessages.useDefaultPolicy} value="default" />
</Form.Field>
</Col>
{useDefault && (
<>
<Col md={6} xs={12}>
<Message content={sharedMessages.uplink} component="h4" className="mb-cs-xs" />
<Form.Field
name="policy.uplink.join_request"
component={Checkbox}
label={policyMessages.joinRequest}
description={policyMessages.joinRequestDesc}
/>
<Form.Field
name="policy.uplink.mac_data"
component={Checkbox}
label={sharedMessages.macData}
description={policyMessages.macDataDesc}
/>
<Form.Field
name="policy.uplink.application_data"
component={Checkbox}
label={sharedMessages.appData}
description={policyMessages.applicationDataDesc}
/>
<Form.Field
name="policy.uplink.signal_quality"
component={Checkbox}
label={policyMessages.signalQualityInformation}
description={policyMessages.signalQualityInformationDesc}
/>
<Form.Field
name="policy.uplink.localization"
component={Checkbox}
label={policyMessages.localizationInformation}
description={policyMessages.localizationInformationDesc}
/>
</Col>
<Col sm={6} xs={12}>
<Message content={sharedMessages.downlink} component="h4" className="mb-cs-xs" />
<Form.Field
name="policy.downlink.join_accept"
component={Checkbox}
label={sharedMessages.joinAccept}
description={policyMessages.joinAcceptDesc}
/>
<Form.Field
name="policy.downlink.mac_data"
component={Checkbox}
label={sharedMessages.macData}
description={policyMessages.macDataAllowDesc}
/>
<Form.Field
name="policy.downlink.application_data"
component={Checkbox}
label={sharedMessages.appData}
description={policyMessages.applicationDataAllowDesc}
/>
</Col>
</>
)}
</Row>
)
}

export default DefaultRoutingPolicyForm
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ const GatewayVisibilityForm = ({ onSubmit, initialValues, error }) => {
<Form.Field
name="visibility.contact_info"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayContactInfoLabel}
label={sharedMessages.contactInformation}
description={gatewayVisibilityMessages.gatewayContactInfoDescription}
/>
<Form.Field
name="visibility.status"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayStatusLabel}
label={sharedMessages.status}
description={gatewayVisibilityMessages.gatewayStatusDescription}
/>
<Form.Field
name="visibility.frequency_plan"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayFreqPlanLabel}
label={sharedMessages.frequencyPlan}
/>
<Form.Field
name="visibility.packet_rates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const m = defineMessages({
grpcFieldDescription: 'The address of the service to connect to',
appFormatter: 'Use application payload formatter',
appFormatterWarning: 'This option will affect both uplink and downlink formatter',
setupSubTitle: 'Setup',
defaultFormatter:
'Click <Link>here</Link> to modify the default payload formatter for this application. The payload formatter of this application is currently set to `{defaultFormatter}`',
pasteRepositoryFormatter: 'Paste repository formatter',
Expand Down Expand Up @@ -419,7 +418,7 @@ const PayloadFormattersForm = ({
>
{() => (
<>
<Form.SubTitle title={m.setupSubTitle} />
<Form.SubTitle title={sharedMessages.setup} />
<Form.Field
name={FIELD_NAMES.SELECT}
title={m.formatterType}
Expand Down
Loading
Loading