From 80e8ce3239ca88be6901eb1bb8adeec356b0d1f0 Mon Sep 17 00:00:00 2001 From: Jon Petersson Date: Mon, 29 Apr 2024 14:49:37 +0200 Subject: [PATCH] Show custom lists even if no filter constraints match --- .../SelectLocation/CustomListLocationNodeBuilder.swift | 6 ++++-- .../SelectLocation/CustomListsDataSource.swift | 6 +++--- .../SelectLocation/LocationDataSource.swift | 7 ++----- .../SelectLocation/CustomListsDataSourceTests.swift | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift index 3f2e22a96f92..cef94576c353 100644 --- a/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift +++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListLocationNodeBuilder.swift @@ -19,7 +19,7 @@ struct CustomListLocationNodeBuilder { name: customList.name, code: customList.name, locations: customList.locations, - isActive: !customList.locations.isEmpty, + isActive: true, // Defaults to true, updated after children have been populated. customList: customList ) @@ -47,7 +47,9 @@ struct CustomListLocationNodeBuilder { } } + listNode.isActive = !listNode.children.isEmpty listNode.sort() + return listNode } } @@ -66,7 +68,7 @@ private extension CustomListLocationNode { }) .sorted(by: { $0.key < $1.key }) .reduce([]) { - return $0 + $1.value.sorted(by: { $0.name < $1.name }) + $0 + $1.value.sorted(by: { $0.name < $1.name }) } children = sortedChildren diff --git a/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift b/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift index 6d8f8989fab4..28f40e924af3 100644 --- a/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift +++ b/ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift @@ -25,8 +25,8 @@ class CustomListsDataSource: LocationDataSourceProtocol { /// Constructs a collection of node trees by copying each matching counterpart /// from the complete list of nodes created in ``AllLocationDataSource``. - func reload(allLocationNodes: [LocationNode], isFiltered: Bool) { - nodes = repository.fetchAll().compactMap { list in + func reload(allLocationNodes: [LocationNode]) { + nodes = repository.fetchAll().map { list in let customListWrapper = CustomListLocationNodeBuilder(customList: list, allLocations: allLocationNodes) let listNode = customListWrapper.customListLocationNode @@ -38,7 +38,7 @@ class CustomListsDataSource: LocationDataSourceProtocol { node.code = LocationNode.combineNodeCodes([listNode.code, node.code]) } - return (isFiltered && listNode.children.isEmpty) ? nil : listNode + return listNode } } diff --git a/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift b/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift index d6460343e04a..3aa69604e494 100644 --- a/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift +++ b/ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift @@ -18,7 +18,6 @@ final class LocationDataSource: private var currentSearchString = "" private var dataSources: [LocationDataSourceProtocol] = [] private var selectedItem: LocationCellViewModel? - private var hasFilter = false let tableView: UITableView let sections: [LocationSection] @@ -52,8 +51,6 @@ final class LocationDataSource: } func setRelays(_ response: REST.ServerRelaysResponse, selectedRelays: UserSelectedRelays?, filter: RelayFilter) { - hasFilter = filter.providers != .any || filter.ownership != .any - let allLocationsDataSource = dataSources.first(where: { $0 is AllLocationDataSource }) as? AllLocationDataSource @@ -65,7 +62,7 @@ final class LocationDataSource: } allLocationsDataSource?.reload(response, relays: relays) - customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter) + customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? []) mapSelectedItem(from: selectedRelays) filterRelays(by: currentSearchString) @@ -110,7 +107,7 @@ final class LocationDataSource: .filter { $0.showsChildren } // Reload data source with (possibly) updated custom lists. - customListsDataSource.reload(allLocationNodes: allLocationsDataSource.nodes, isFiltered: hasFilter) + customListsDataSource.reload(allLocationNodes: allLocationsDataSource.nodes) // Reapply current selection. mapSelectedItem(from: selectedRelays) diff --git a/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift b/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift index 33a97fffcd3c..15069391782b 100644 --- a/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift +++ b/ios/MullvadVPNTests/MullvadVPN/View controllers/SelectLocation/CustomListsDataSourceTests.swift @@ -75,7 +75,7 @@ class CustomListsDataSourceTests: XCTestCase { extension CustomListsDataSourceTests { private func setUpDataSource() { dataSource = CustomListsDataSource(repository: CustomListsRepositoryStub(customLists: customLists)) - dataSource.reload(allLocationNodes: allLocationNodes, isFiltered: false) + dataSource.reload(allLocationNodes: allLocationNodes) } private func createAllLocationNodes() {