From c1f82e58e25d3928c1bceefcab750307862988dc Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Fri, 24 Nov 2023 15:23:20 +0100 Subject: [PATCH] [#1208] Extracted pools are sorted --- webui/src/app/subnets.spec.ts | 22 +++++++++++----------- webui/src/app/subnets.ts | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/webui/src/app/subnets.spec.ts b/webui/src/app/subnets.spec.ts index 2306737ce..7299369c9 100644 --- a/webui/src/app/subnets.spec.ts +++ b/webui/src/app/subnets.spec.ts @@ -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, @@ -197,13 +204,6 @@ describe('subnets', () => { delegatedLength: 80, excludedPrefix: '3002::/96', }, - { - prefix: '3003::/64', - delegatedLength: 80, - keaConfigPoolParameters: { - clientClass: 'bar', - }, - }, ], }, { @@ -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', diff --git a/webui/src/app/subnets.ts b/webui/src/app/subnets.ts index 0280defcd..05e46606d 100644 --- a/webui/src/app/subnets.ts +++ b/webui/src/app/subnets.ts @@ -1,3 +1,4 @@ +import { AddressRange } from './address-range' import { DelegatedPrefixPool, KeaConfigPoolParameters, LocalSubnet, Pool, SharedNetwork, Subnet } from './backend' /** @@ -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