From 4a5825acf0cdee98b65f6a406d10440433c87410 Mon Sep 17 00:00:00 2001 From: Erik van Leeuwen Date: Mon, 4 Nov 2024 15:06:50 +0100 Subject: [PATCH] Sort the zones in autocomplete fields by depth and name --- lib/ZonesDb.ts | 10 ++++++++++ utils/handleZoneAutocomplete.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ZonesDb.ts b/lib/ZonesDb.ts index 6a2b638..057d8e7 100644 --- a/lib/ZonesDb.ts +++ b/lib/ZonesDb.ts @@ -113,4 +113,14 @@ export default class ZonesDb { } return this.zones.get(zoneId) || null; } + + /** + * Get all direct children of a zone. + */ + public async getDirectChildren(zoneId: string): Promise { + while (this.isUpdating) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return this.childMap.get(zoneId) || []; + } } \ No newline at end of file diff --git a/utils/handleZoneAutocomplete.ts b/utils/handleZoneAutocomplete.ts index 5f6907d..47e8bd7 100644 --- a/utils/handleZoneAutocomplete.ts +++ b/utils/handleZoneAutocomplete.ts @@ -24,7 +24,7 @@ export default async function handleZoneAutocomplete(query: string, zonesDb: Zon }); addedZoneIds.add(zone.id); - const children = await zonesDb.getAllChildren(zone.id); + const children = await zonesDb.getDirectChildren(zone.id); children.sort((a, b) => a.name.localeCompare(b.name)); for (const child of children) { await addZoneAndChildren(child);