Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 1ae2f6d

Browse files
Improved the selectable prefixlengths in dropdown
1 parent dd99f3e commit 1ae2f6d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/custom-surf/components/inputForms/SplitPrefix.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@ export default class SplitPrefix extends React.PureComponent<IProps> {
8383
};
8484

8585
render() {
86+
// IPv4 subnet size should be between /32 and /12
87+
// IPv6 subnet size should be between /128 and /32
8688
const { id, name, subnet, prefixlen, prefixMin, selectedSubnet } = this.props;
8789
const version = subnet.indexOf(":") === -1 ? 4 : 6;
88-
const max_for_version = version === 4 ? 32 : 64;
90+
const minPrefixLength = version === 4 ? 12 : 32;
91+
const minimalSelectablePrefixLength = minPrefixLength > prefixMin ? minPrefixLength : prefixMin;
92+
const maximalSelectablePrefixLength = version === 4 ? 32 : minimalSelectablePrefixLength + 12;
93+
8994
const { desiredPrefixlen } = this.state;
90-
const prefixlengths = range(max_for_version - prefixMin + 1).map((x) => prefixMin + x);
95+
const prefixlengths = range(maximalSelectablePrefixLength - minimalSelectablePrefixLength + 1).map(
96+
(x) => minimalSelectablePrefixLength + x
97+
);
98+
9199
const length_options: Option<number>[] = prefixlengths.map((pl) => ({ value: pl, label: pl.toString() }));
92100
const length_value = length_options.find((option) => option.value === desiredPrefixlen);
93101

0 commit comments

Comments
 (0)