From 624befaec26d242cc797152414ca1d3b4e0a9055 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 27 Jan 2020 22:31:13 -0500 Subject: [PATCH] Alphabetically sort database and collection names Closes #1 --- .../View Controllers/DatabaseViewController.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MongoView/View Controllers/DatabaseViewController.swift b/MongoView/View Controllers/DatabaseViewController.swift index 15907f8..9d4f7d5 100644 --- a/MongoView/View Controllers/DatabaseViewController.swift +++ b/MongoView/View Controllers/DatabaseViewController.swift @@ -47,9 +47,11 @@ class DatabaseViewController: NSViewController { super.viewDidLoad() mongoController.client.listDatabaseNames().flatMap { (databaseNames) -> EventLoopFuture<[DatabaseCollections]> in - let futures = databaseNames.map { (name) in - self.mongoController.client.db(name).listCollectionNames().map { (collectionNames) in - DatabaseCollections(database: name, collections: collectionNames) + let futures = databaseNames.map { (name: String) -> EventLoopFuture in + let db = self.mongoController.client.db(name) + return db.listCollectionNames().map { (collectionNames: [String]) -> DatabaseCollections in + let sortedNames = collectionNames.sorted() + return DatabaseCollections(database: name, collections: sortedNames) } } return EventLoopFuture.whenAllSucceed(futures, on: futures.first!.eventLoop) @@ -58,7 +60,8 @@ class DatabaseViewController: NSViewController { switch res { case let .success(databaseCollections): - self.databaseCollections = databaseCollections + let sortedCollections = databaseCollections.sorted(by: { $0.database < $1.database }) + self.databaseCollections = sortedCollections DispatchQueue.main.async { self.collectionsOutlineView.reloadData() }