Skip to content

Commit

Permalink
console: Add default values to static adr
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelJankoski committed Feb 18, 2025
1 parent abb3dfc commit 183e10c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
20 changes: 17 additions & 3 deletions pkg/webui/console/components/mac-settings-section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ const maxDutyCycleOptions = [
{ value: 'DUTY_CYCLE_16384', label: '0.006%' },
]

const encodeAdrMode = value => ({ [value]: {} })
const decodeAdrMode = value => (value !== undefined ? Object.keys(value)[0] : null)

const MacSettingsSection = props => {
const {
activationMode,
Expand Down Expand Up @@ -238,6 +235,20 @@ const MacSettingsSection = props => {
[values],
)

const getEncodedAdrModeValue = useCallback(mode => {
if (mode === 'static') {
return {
data_rate_index: 0,
tx_power_index: 0,
nb_trans: 1,
}
}
return {}
}, [])

const encodeAdrMode = value => ({ [value]: getEncodedAdrModeValue(value) })
const decodeAdrMode = value => (value !== undefined ? Object.keys(value)[0] : null)

return (
<Form.CollapseSection
id="mac-settings"
Expand Down Expand Up @@ -697,13 +708,16 @@ const MacSettingsSection = props => {
component={Input}
type="number"
inputWidth="xs"
max={15}
/>
<Form.Field
title={m.adrUplinks}
name="mac_settings.adr.static.nb_trans"
component={Input}
type="number"
inputWidth="xs"
min={1}
max={15}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,13 @@ const validationSchema = Yup.object()
return Yup.object().shape({
static: Yup.object().shape({
data_rate_index: Yup.number().nullable(),
tx_power_index: Yup.number().nullable(),
nb_trans: Yup.number().nullable(),
tx_power_index: Yup.number()
.nullable()
.max(15, Yup.passValues(sharedMessages.validateNumberLte)),
nb_trans: Yup.number()
.nullable()
.min(1, Yup.passValues(sharedMessages.validateNumberGte))
.max(15, Yup.passValues(sharedMessages.validateNumberLte)),
}),
})
} else if (value && 'disabled' in value) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/js/src/service/devices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Devices {
}
}

if (paths.includes('mac_settings')) {
if (paths.some(path => path.includes('mac_settings'))) {
const { mac_settings = {} } = device

if (
Expand All @@ -137,7 +137,7 @@ class Devices {
}

if (typeof mac_settings.adr.static.nb_trans === 'undefined') {
mac_settings.adr.static.nb_trans = 0
mac_settings.adr.static.nb_trans = 1
}

if (typeof mac_settings.adr.static.tx_power_index === 'undefined') {
Expand Down

0 comments on commit 183e10c

Please sign in to comment.