Skip to content

Commit 6ca1714

Browse files
mojganiiJon Petersson
authored and
Jon Petersson
committed
Apply filtering on custom lists
1 parent 030d55d commit 6ca1714

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

ios/MullvadVPN/View controllers/SelectLocation/CustomListsDataSource.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class CustomListsDataSource: LocationDataSourceProtocol {
2525

2626
/// Constructs a collection of node trees by copying each matching counterpart
2727
/// from the complete list of nodes created in ``AllLocationDataSource``.
28-
func reload(allLocationNodes: [LocationNode]) {
29-
nodes = repository.fetchAll().map { list in
28+
func reload(allLocationNodes: [LocationNode], isFiltered: Bool) {
29+
nodes = repository.fetchAll().compactMap { customList in
3030
let listNode = CustomListLocationNode(
31-
name: list.name,
32-
code: list.name.lowercased(),
33-
locations: list.locations,
34-
customList: list
31+
name: customList.name,
32+
code: customList.name.lowercased(),
33+
locations: customList.locations,
34+
customList: customList
3535
)
3636

37-
listNode.children = list.locations.compactMap { location in
37+
listNode.children = customList.locations.compactMap { location in
3838
copy(location, from: allLocationNodes, withParent: listNode)
3939
}
4040

@@ -46,7 +46,7 @@ class CustomListsDataSource: LocationDataSourceProtocol {
4646
node.code = LocationNode.combineNodeCodes([listNode.code, node.code])
4747
}
4848

49-
return listNode
49+
return (isFiltered && listNode.children.isEmpty) ? nil : listNode
5050
}
5151
}
5252

ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class LocationDataSource: UITableViewDiffableDataSource<LocationSection, L
1717
private let tableView: UITableView
1818
private var dataSources: [LocationDataSourceProtocol] = []
1919
private var selectedItem: LocationCellViewModel?
20+
private var hasFilter = false
2021

2122
var didSelectRelayLocations: ((UserSelectedRelays) -> Void)?
2223
var didTapEditCustomLists: (() -> Void)?
@@ -47,6 +48,8 @@ final class LocationDataSource: UITableViewDiffableDataSource<LocationSection, L
4748
}
4849

4950
func setRelays(_ response: REST.ServerRelaysResponse, selectedRelays: UserSelectedRelays?, filter: RelayFilter) {
51+
hasFilter = filter.providers != .any || filter.ownership != .any
52+
5053
let allLocationsDataSource =
5154
dataSources.first(where: { $0 is AllLocationDataSource }) as? AllLocationDataSource
5255

@@ -58,7 +61,7 @@ final class LocationDataSource: UITableViewDiffableDataSource<LocationSection, L
5861
}
5962

6063
allLocationsDataSource?.reload(response, relays: relays)
61-
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [])
64+
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter)
6265

6366
mapSelectedItem(from: selectedRelays)
6467
filterRelays(by: currentSearchString)
@@ -101,7 +104,7 @@ final class LocationDataSource: UITableViewDiffableDataSource<LocationSection, L
101104
let customListsDataSource =
102105
dataSources.first(where: { $0 is CustomListsDataSource }) as? CustomListsDataSource
103106

104-
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [])
107+
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter)
105108

106109
mapSelectedItem(from: selectedRelays)
107110
filterRelays(by: currentSearchString, scrollToSelected: false)

ios/MullvadVPNTests/Location/CustomListsDataSourceTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CustomListsDataSourceTests: XCTestCase {
7575
extension CustomListsDataSourceTests {
7676
private func setUpDataSource() {
7777
dataSource = CustomListsDataSource(repository: CustomListsRepositoryStub(customLists: customLists))
78-
dataSource.reload(allLocationNodes: allLocationNodes)
78+
dataSource.reload(allLocationNodes: allLocationNodes, isFiltered: false)
7979
}
8080

8181
private func createAllLocationNodes() {

0 commit comments

Comments
 (0)