Skip to content

Commit

Permalink
[#1208] Extracted pools are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Nov 24, 2023
1 parent 142de9c commit c1f82e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
22 changes: 11 additions & 11 deletions webui/src/app/subnets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,23 @@ describe('subnets', () => {
},
},
{
pool: '3000::10-3000::15',
pool: '3000::40-3000::65',
},
{
pool: '3000::20-3000::35',
},
{
pool: '3000::40-3000::65',
pool: '3000::10-3000::15',
},
],
prefixDelegationPools: [
{
prefix: '3003::/64',
delegatedLength: 80,
keaConfigPoolParameters: {
clientClass: 'bar',
},
},
{
prefix: '3001::/64',
delegatedLength: 80,
Expand All @@ -197,13 +204,6 @@ describe('subnets', () => {
delegatedLength: 80,
excludedPrefix: '3002::/96',
},
{
prefix: '3003::/64',
delegatedLength: 80,
keaConfigPoolParameters: {
clientClass: 'bar',
},
},
],
},
{
Expand All @@ -217,10 +217,10 @@ describe('subnets', () => {
},
},
{
pool: '3000::10-3000::15',
pool: '3000::20-3000::35',
},
{
pool: '3000::20-3000::35',
pool: '3000::10-3000::15',
},
{
pool: '3000::70-3000::85',
Expand Down
17 changes: 16 additions & 1 deletion webui/src/app/subnets.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AddressRange } from './address-range'
import { DelegatedPrefixPool, KeaConfigPoolParameters, LocalSubnet, Pool, SharedNetwork, Subnet } from './backend'

/**
Expand Down Expand Up @@ -209,7 +210,21 @@ export function extractUniqueSubnetPools(subnets: Subnet[] | Subnet): SubnetWith
}
}
}
convertedSubnet.pools = pools.sort()
convertedSubnet.pools = pools.sort((a, b) => {
try {
const range1 = AddressRange.fromStringRange(a.pool)
const range2 = AddressRange.fromStringRange(b.pool)
if (range1.first.isLessThan(range2.first)) {
return -1
} else if (range1.first.isGreaterThan(range2.first)) {
return 1
}
} catch (_) {
// Parsing error is very unlikely but we have to handle it.
return 1
}
return 0
})
convertedSubnet.prefixDelegationPools = prefixDelegationPools.sort((a, b) => a.prefix.localeCompare(b.prefix))
}
return convertedSubnets
Expand Down

0 comments on commit c1f82e5

Please sign in to comment.