Skip to content

Commit

Permalink
Sort the zones in autocomplete fields by depth and name
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvl87 committed Nov 4, 2024
1 parent 2dce2da commit 4a5825a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/ZonesDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtendedZone[]> {
while (this.isUpdating) {
await new Promise(resolve => setTimeout(resolve, 100));
}
return this.childMap.get(zoneId) || [];
}
}
2 changes: 1 addition & 1 deletion utils/handleZoneAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4a5825a

Please sign in to comment.