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

Show custom lists even if no filter constraints match #6195

Merged
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 @@ -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
)

Expand Down Expand Up @@ -47,7 +47,9 @@ struct CustomListLocationNodeBuilder {
}
}

listNode.isActive = !listNode.children.isEmpty
listNode.sort()

return listNode
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
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, isFiltered: false)
dataSource.reload(allLocationNodes: allLocationNodes)
}

private func createAllLocationNodes() {
Expand Down
Loading