Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply filtering on custom lists #5980

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ 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]) {
nodes = repository.fetchAll().map { list in
func reload(allLocationNodes: [LocationNode], isFiltered: Bool) {
nodes = repository.fetchAll().compactMap { customList in
let listNode = CustomListLocationNode(
name: list.name,
code: list.name.lowercased(),
locations: list.locations,
customList: list
name: customList.name,
code: customList.name.lowercased(),
locations: customList.locations,
customList: customList
)

listNode.children = list.locations.compactMap { location in
listNode.children = customList.locations.compactMap { location in
copy(location, from: allLocationNodes, withParent: listNode)
}

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

return listNode
return (isFiltered && listNode.children.isEmpty) ? nil : listNode
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
private let tableView: UITableView
private var dataSources: [LocationDataSourceProtocol] = []
private var selectedItem: LocationCellViewModel?
private var hasFilter = false

var didSelectRelayLocations: ((UserSelectedRelays) -> Void)?
var didTapEditCustomLists: (() -> Void)?
Expand Down Expand Up @@ -47,6 +48,8 @@
}

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

Expand All @@ -58,7 +61,7 @@
}

allLocationsDataSource?.reload(response, relays: relays)
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [])
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter)

mapSelectedItem(from: selectedRelays)
filterRelays(by: currentSearchString)
Expand Down Expand Up @@ -101,7 +104,7 @@
let customListsDataSource =
dataSources.first(where: { $0 is CustomListsDataSource }) as? CustomListsDataSource

customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [])
customListsDataSource?.reload(allLocationNodes: allLocationsDataSource?.nodes ?? [], isFiltered: hasFilter)

mapSelectedItem(from: selectedRelays)
filterRelays(by: currentSearchString, scrollToSelected: false)
Expand Down Expand Up @@ -396,4 +399,4 @@
recursivelyRemoveSubNodes(from: node)
}
}
}

Check warning on line 402 in ios/MullvadVPN/View controllers/SelectLocation/LocationDataSource.swift

View workflow job for this annotation

GitHub Actions / End to end tests

File Length Violation: File should contain 400 lines or less: currently contains 402 (file_length)
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CustomListsDataSourceTests: XCTestCase {
extension CustomListsDataSourceTests {
private func setUpDataSource() {
dataSource = CustomListsDataSource(repository: CustomListsRepositoryStub(customLists: customLists))
dataSource.reload(allLocationNodes: allLocationNodes)
dataSource.reload(allLocationNodes: allLocationNodes, isFiltered: false)
}

private func createAllLocationNodes() {
Expand Down
Loading