Skip to content

Commit

Permalink
Merge pull request #6747 from TheThingsNetwork/feature/multiple-frequ…
Browse files Browse the repository at this point in the history
…ency-plans-same-band-id

Allow to only set frequency plans within the same band
  • Loading branch information
ryaplots committed Dec 7, 2023
2 parents fe015cd + 9e2a710 commit 47f3303
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For details about compatibility between different releases, see the **Commitment

- Rate limiting classes for individual HTTP paths.
- Rate limiting keys for HTTP endpoints now contain the caller API key ID when available. The caller IP is still available as a fallback.
- Allow users to set multiple frequency plans only in the same band in the Console.

### Changed

Expand Down
9 changes: 7 additions & 2 deletions cypress/e2e/console/gateways/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ describe('Gateway create', () => {
.first()
.selectOption(gateway.frequency_plan)
cy.findByRole('button', { name: /Add frequency plan/ }).click()
cy.findByText('Frequency plan').parent().parent().find('input').eq(2).selectOption('US_902_928')
cy.findByText('Frequency plan')
.parent()
.parent()
.find('input')
.eq(2)
.selectOption('EU_863_870_TTN')
cy.findByRole('button', { name: 'Register gateway' }).click()

cy.findByTestId('error-notification').should('not.exist')
Expand All @@ -169,7 +174,7 @@ describe('Gateway create', () => {
)
cy.findByRole('heading', { name: `eui-${gateway.eui}` })
cy.findByText('Frequency plan')
cy.findByText('EU_863_870 , US_902_928_FSB_1').should('be.visible')
cy.findByText('EU_863_870 , EU_863_870_TTN').should('be.visible')
cy.findByTestId('error-notification').should('not.exist')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/console/gateways/edit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('Gateway general settings', () => {
})

it('succeeds editing multiple frequency plans', () => {
const newFrequencyPlan = 'Asia 920-923 MHz'
const newFrequencyPlan = 'Europe 863-870 MHz, 6 channels for roaming (Draft)'
cy.loginConsole({ user_id: user.ids.user_id, password: user.password })
cy.visit(
`${Cypress.config('consoleRootPath')}/gateways/${gateway2.ids.gateway_id}/general-settings`,
Expand Down
14 changes: 12 additions & 2 deletions pkg/webui/components/key-value-map/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Entry = ({
removeMessage,
distinctOptions,
atLeastOneEntry,
filterByTag,
}) => {
const [currentValue, setCurrentValue] = useState(value)
const [newOptions, setNewOptions] = useState(undefined)
Expand Down Expand Up @@ -98,8 +99,15 @@ const Entry = ({
} else {
newOptions = options.filter(v => !fieldValue.includes(v.value))
}
setNewOptions(newOptions)
}, [currentValue, options, fieldValue])

let taggedOptions = newOptions
if (fieldValue.length >= 2 && filterByTag) {
const selectedOption = options.find(v => v.value === fieldValue[0])
taggedOptions = newOptions.filter(v => selectedOption.tag === v.tag)
}

setNewOptions(taggedOptions)
}, [currentValue, options, fieldValue, filterByTag])

const showRemoveButton = atLeastOneEntry ? index !== 0 : true

Expand Down Expand Up @@ -157,6 +165,7 @@ Entry.propTypes = {
atLeastOneEntry: PropTypes.bool,
distinctOptions: PropTypes.bool,
fieldValue: PropTypes.any,
filterByTag: PropTypes.bool,
index: PropTypes.number.isRequired,
indexAsKey: PropTypes.bool.isRequired,
inputElement: PropTypes.elementType.isRequired,
Expand Down Expand Up @@ -184,6 +193,7 @@ Entry.defaultProps = {
distinctOptions: false,
fieldValue: undefined,
atLeastOneEntry: false,
filterByTag: false,
}

export default Entry
4 changes: 4 additions & 0 deletions pkg/webui/components/key-value-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const KeyValueMap = ({
valuePlaceholder,
distinctOptions,
atLeastOneEntry,
filterByTag,
}) => {
const handleEntryChange = useCallback(
(index, newValues) => {
Expand Down Expand Up @@ -98,6 +99,7 @@ const KeyValueMap = ({
removeMessage={removeMessage}
distinctOptions={distinctOptions}
atLeastOneEntry={atLeastOneEntry}
filterByTag={filterByTag}
/>
))}
</div>
Expand All @@ -122,6 +124,7 @@ KeyValueMap.propTypes = {
className: PropTypes.string,
disabled: PropTypes.bool,
distinctOptions: PropTypes.bool,
filterByTag: PropTypes.bool,
indexAsKey: PropTypes.bool,
inputElement: PropTypes.elementType,
isReadOnly: PropTypes.func,
Expand Down Expand Up @@ -157,6 +160,7 @@ KeyValueMap.defaultProps = {
removeMessage: undefined,
distinctOptions: false,
atLeastOneEntry: false,
filterByTag: false,
}

export default KeyValueMap
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const GatewayFrequencyPlansSelect = () => {
additionalInputProps={{ options: freqPlanOptions }}
distinctOptions
atLeastOneEntry
filterByTag
required
/>
)
Expand Down
5 changes: 3 additions & 2 deletions pkg/webui/console/containers/freq-plans-select/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

import { defineMessages } from 'react-intl'

export const formatOptions = plans => plans.map(plan => ({ value: plan.id, label: plan.name }))
export const formatOptions = plans =>
plans.map(plan => ({ value: plan.id, label: plan.name, tag: plan.band_id }))
export const m = defineMessages({
warning: 'Frequency plans unavailable',
none: 'Do not set a frequency plan',
selectFrequencyPlan: 'Select a frequency plan...',
addFrequencyPlan: 'Add frequency plan',
frequencyPlanDescription:
'Note: most gateways use a single frequency plan. Some 16 and 64 channel gateways however allow setting multiple.',
'Note: most gateways use a single frequency plan. Some 16 and 64 channel gateways however allow setting multiple within the same band.',
})
2 changes: 1 addition & 1 deletion pkg/webui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@
"console.containers.freq-plans-select.utils.none": "Do not set a frequency plan",
"console.containers.freq-plans-select.utils.selectFrequencyPlan": "Select a frequency plan...",
"console.containers.freq-plans-select.utils.addFrequencyPlan": "Add frequency plan",
"console.containers.freq-plans-select.utils.frequencyPlanDescription": "Note: most gateways use a single frequency plan. Some 16 and 64 channel gateways however allow setting multiple.",
"console.containers.freq-plans-select.utils.frequencyPlanDescription": "Note: most gateways use a single frequency plan. Some 16 and 64 channel gateways however allow setting multiple within the same band.",
"console.containers.gateway-connection.index.lastSeenAvailableTooltip": "The elapsed time since the network registered the last activity of this gateway. This is determined from received uplinks, or sent status messages of this gateway.",
"console.containers.gateway-connection.index.disconnectedTooltip": "The gateway has currently no TCP connection established with the Gateway Server. For (rare) UDP based gateways, this can also mean that the gateway initiated no pull/push data request within the last 30 seconds.",
"console.containers.gateway-connection.index.connectedTooltip": "This gateway is connected to the Gateway Server but the network has not registered any activity (sent uplinks or status messages) from it yet.",
Expand Down

0 comments on commit 47f3303

Please sign in to comment.