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

Revert "Verticals: Give flexibility by adding separate configure fuctions and reload mechanism (#408)" #411

Merged
merged 2 commits into from
Aug 7, 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
28 changes: 5 additions & 23 deletions CharcoalDemo/CharcoalDemo/DemoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,15 @@ extension DemoTableViewController: UITableViewDelegate {
charcoalViewController.freeTextFilterDataSource = self
charcoalViewController.freeTextFilterDelegate = self
charcoalViewController.searchLocationDataSource = searchLocationDataSource
if let setup = row.setup {
charcoalViewController.filterContainer = setup.filterContainer
charcoalViewController.configure(with: setup.verticals)
charcoalViewController.updateReloadVerticalsButton(isVisible: setup.showVerticalsReloadButton)
}
charcoalViewController.filterContainer = row.setup?.filterContainer
charcoalViewController.selectionDelegate = self
} else if let viewController = viewController as? DrawerPresentationViewController {
let charcoalViewController = viewController.charcoalViewController
charcoalViewController.selectionDelegate = self
charcoalViewController.freeTextFilterDataSource = self
charcoalViewController.freeTextFilterDelegate = self
charcoalViewController.searchLocationDataSource = searchLocationDataSource
if let setup = row.setup {
charcoalViewController.filterContainer = setup.filterContainer
charcoalViewController.configure(with: setup.verticals)
charcoalViewController.updateReloadVerticalsButton(isVisible: setup.showVerticalsReloadButton)
}
charcoalViewController.filterContainer = row.setup?.filterContainer
charcoalViewController.selectionDelegate = self

viewController.transitioningDelegate = viewController.transition
Expand All @@ -87,11 +79,10 @@ extension DemoTableViewController: CharcoalViewControllerSelectionDelegate {
return
}

if let subVertical = setup.verticals.first(where: { $0.id == vertical.id }) {
setup.current = subVertical
if let submarket = setup.markets.first(where: { $0.id == vertical.id }) {
setup.current = submarket
viewController.isLoading = true
viewController.filterContainer = setup.filterContainer
viewController.configure(with: setup.verticals)
viewController.isLoading = false
}
}
Expand All @@ -108,17 +99,8 @@ extension DemoTableViewController: CharcoalViewControllerSelectionDelegate {
print("🔥 Did select external filter with key '\(key)' and value '\(value ?? "nil")'")
}

func charcoalViewControllerDidSelectReloadVerticals(_ viewController: CharcoalViewController) {
let verticals: [DemoVertical] = .multiple
if let setup = currentRow?.setup {
setup.verticals = verticals
setup.current = verticals.first
}
viewController.updateReloadVerticalsButton(isVisible: false)
viewController.configure(with: verticals)
}

func charcoalViewController(_ viewController: CharcoalViewController, didChangeSelection selection: [URLQueryItem], origin: SelectionChangeOrigin) {}
func charcoalViewController(_ viewController: CharcoalViewController, didSelect selection: CharcoalViewController.MapSelection) {}
}

extension DemoTableViewController: CharcoalViewControllerTextEditingDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ extension FilterContainer {
rootFilters: [Filter] = defaultRootFilters(),
freeTextFilter: Filter? = .freeText,
inlineFilter: Filter? = defaultInlineFilter(),
numberOfResults: Int = 123
numberOfResults: Int = 123,
numberOfVerticals: Int = 4,
lastVerticalIsExternal: Bool = true
) -> FilterContainer {
FilterContainer(rootFilters: rootFilters, freeTextFilter: freeTextFilter, inlineFilter: inlineFilter, numberOfResults: numberOfResults)
let container = FilterContainer(rootFilters: rootFilters, freeTextFilter: freeTextFilter, inlineFilter: inlineFilter, numberOfResults: numberOfResults)
container.verticals = DemoVertical.create(numberOfVerticals, lastVerticalIsExternal: lastVerticalIsExternal)
return container
}

static func defaultRootFilters(isContextFilters: Bool = false, includePolygonSearch: Bool = true) -> [Filter] {
Expand Down
11 changes: 7 additions & 4 deletions CharcoalDemo/CharcoalDemo/Models/DemoSections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ enum DemoSections: CaseIterable {
]
case .verticals:
return [
Row(title: "Single vertical", filterContainer: .standard, verticals: .none),
Row(title: "Multiple verticals", filterContainer: .standard, verticals: .multiple),
Row(title: "Failed to load verticals", filterContainer: .standard, verticals: .none, showVerticalsReloadButton: true)
Row(title: "Single vertical", filterContainer: .singleVertical),
Row(title: "Multiple verticals", filterContainer: .multipleVerticals),
]
case .misc:
return [
Expand All @@ -45,7 +44,11 @@ enum DemoSections: CaseIterable {
}

extension FilterContainer {
static var standard: FilterContainer {
static var singleVertical: FilterContainer {
create(numberOfVerticals: 0)
}

static var multipleVerticals: FilterContainer {
create()
}

Expand Down
12 changes: 1 addition & 11 deletions CharcoalDemo/CharcoalDemo/Models/DemoVertical.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ class DemoVertical: Vertical {
self.isCurrent = isCurrent
self.isExternal = isExternal
}
}

extension Array where Element == DemoVertical {
static var none: [DemoVertical] {
create(0)
}

static var multiple: [DemoVertical] {
create(4)
}

static func create(_ count: Int = 4, lastVerticalIsExternal: Bool = true) -> [DemoVertical] {
static func create(_ count: Int, lastVerticalIsExternal: Bool) -> [DemoVertical] {
guard count >= 1 else { return [] }
return (1 ... count).map {
let isExternal = lastVerticalIsExternal && count > 1 && ($0 % count == 0)
Expand Down
15 changes: 2 additions & 13 deletions CharcoalDemo/CharcoalDemo/Models/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@ struct Row {
self.usingBottomSheet = usingBottomSheet
}

init(
title: String,
type: UIViewController.Type = CharcoalViewController.self,
filterContainer: FilterContainer,
verticals: [DemoVertical] = .multiple,
showVerticalsReloadButton: Bool = false
) {
self.init(
title: title,
type: type,
setup: Setup(filterContainer: filterContainer, verticals: verticals, showVerticalsReloadButton: showVerticalsReloadButton),
usingBottomSheet: true
)
init(title: String, type: UIViewController.Type = CharcoalViewController.self, filterContainer: FilterContainer) {
self.init(title: title, type: type, setup: Setup(filterContainer: filterContainer), usingBottomSheet: true)
}
}
10 changes: 4 additions & 6 deletions CharcoalDemo/CharcoalDemo/Setup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import UIKit

class Setup {
var filterContainer: FilterContainer
var verticals: [DemoVertical]
let showVerticalsReloadButton: Bool
let markets: [DemoVertical]

var current: DemoVertical? {
didSet {
Expand All @@ -17,10 +16,9 @@ class Setup {
}
}

init(filterContainer: FilterContainer, verticals: [DemoVertical], showVerticalsReloadButton: Bool = false) {
defer { current = verticals.first }
init(filterContainer: FilterContainer) {
defer { current = markets.first }
self.filterContainer = filterContainer
self.verticals = verticals
self.showVerticalsReloadButton = showVerticalsReloadButton
markets = (filterContainer.verticals as? [DemoVertical]) ?? []
}
}
18 changes: 3 additions & 15 deletions CharcoalDemo/SnapshotTests/FilterContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@ class FilterContainerTests: XCTestCase {

private func snapshot(
_ filterContainer: FilterContainer,
verticals: [DemoVertical] = .multiple,
showReloadVerticalsButton: Bool = false,
record recording: Bool = false,
testName: String = #function
) {
assertSnapshots(
matching: filterContainer,
verticals: verticals,
showReloadVerticalsButton: showReloadVerticalsButton,
delay: 0.1,
record: recording,
testName: testName
)
assertSnapshots(matching: filterContainer, delay: 0.1, record: recording, testName: testName)
}

override func setUp() {
Expand All @@ -32,13 +23,10 @@ class FilterContainerTests: XCTestCase {
// MARK: - Tests

func testSingleVertical() {
snapshot(.standard, verticals: .none)
snapshot(.singleVertical)
}
func testMultipleVerticals() {
snapshot(.standard, verticals: .multiple)
}
func testFailedToLoadVerticals() {
snapshot(.standard, verticals: .none, showReloadVerticalsButton: true)
snapshot(.multipleVerticals)
}
func testContextFilter() {
snapshot(.contextFilter)
Expand Down
12 changes: 2 additions & 10 deletions CharcoalDemo/SnapshotTests/XCTestCaseExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ extension XCTestCase {

func assertSnapshots(
matching filterContainer: FilterContainer,
verticals: [DemoVertical],
showReloadVerticalsButton: Bool = false,
includeIPad: Bool = true,
delay: TimeInterval? = nil,
record recording: Bool = false,
file: StaticString = #file,
testName: String = #function
) {
let viewController = getViewController(for: filterContainer, verticals: verticals, showReloadVerticalsButton: showReloadVerticalsButton)
let viewController = getViewController(for: filterContainer)
assertSnapshots(
matching: viewController,
device: .iPhone,
Expand All @@ -59,15 +57,9 @@ extension XCTestCase {
}
}

private func getViewController(
for filterContainer: FilterContainer,
verticals: [DemoVertical],
showReloadVerticalsButton: Bool
) -> UIViewController {
private func getViewController(for filterContainer: FilterContainer) -> UIViewController {
let viewController = CharcoalViewController()
viewController.filterContainer = filterContainer
viewController.configure(with: verticals)
viewController.updateReloadVerticalsButton(isVisible: showReloadVerticalsButton)
return viewController
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 14 additions & 24 deletions Sources/Charcoal/CharcoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public protocol CharcoalViewControllerSelectionDelegate: AnyObject {
func charcoalViewController(_ viewController: CharcoalViewController,
didChangeSelection selection: [URLQueryItem],
origin: SelectionChangeOrigin)
func charcoalViewControllerDidSelectReloadVerticals(_ viewController: CharcoalViewController)
func charcoalViewController(_ viewController: CharcoalViewController,
didSelect selection: CharcoalViewController.MapSelection)
}

public protocol CharcoalViewControllerMapDelegate: AnyObject {
Expand Down Expand Up @@ -53,6 +54,12 @@ public final class CharcoalViewController: UINavigationController {
selectedFilters(in: filterContainer?.allFilters)
}

public enum MapSelection {
case openPolygonSearch
case openRadiusSearch
case initialArea
}

// MARK: - Private properties

private var selectionHasChanged = false
Expand All @@ -65,9 +72,8 @@ public final class CharcoalViewController: UINavigationController {
}()

private var rootFilterViewController: RootFilterViewController?

private var calloutOverlay: CalloutOverlay?
private var verticals: [Vertical]?
private var isReloadVerticalsButtonVisible: Bool?

// MARK: - Lifecycle

Expand Down Expand Up @@ -128,17 +134,6 @@ public final class CharcoalViewController: UINavigationController {
}
}

public func configure(with verticals: [Vertical]) {
self.verticals = verticals
updateReloadVerticalsButton(isVisible: false)
rootFilterViewController?.configure(with: verticals)
}

public func updateReloadVerticalsButton(isVisible: Bool) {
isReloadVerticalsButtonVisible = isVisible
rootFilterViewController?.updateReloadVerticalsButton(isVisible: isVisible)
}

// MARK: - Private

private func configure(with filterContainer: FilterContainer?) {
Expand All @@ -156,12 +151,6 @@ public final class CharcoalViewController: UINavigationController {
rootFilterViewController?.rootDelegate = self
rootFilterViewController?.freeTextFilterDataSource = freeTextFilterDataSource
rootFilterViewController?.freeTextFilterDelegate = freeTextFilterDelegate
if let verticals {
rootFilterViewController?.configure(with: verticals)
}
if let isReloadVerticalsButtonVisible {
rootFilterViewController?.updateReloadVerticalsButton(isVisible: isReloadVerticalsButtonVisible)
}
setViewControllers([rootFilterViewController].compactMap({ $0 }), animated: false)
}
}
Expand Down Expand Up @@ -230,10 +219,6 @@ extension CharcoalViewController: RootFilterViewControllerDelegate {
selectionDelegate?.charcoalViewController(self, didSelect: vertical)
}

func rootFilterViewControllerDidSelectReloadVerticals(_ viewController: RootFilterViewController) {
selectionDelegate?.charcoalViewControllerDidSelectReloadVerticals(self)
}

private func handleFilterSelectionChange(from origin: SelectionChangeOrigin) {
if let filterContainer = filterContainer {
let queryItems = selectionStore.queryItems(for: filterContainer)
Expand Down Expand Up @@ -379,6 +364,11 @@ extension CharcoalViewController: MapFilterViewControllerDelegate {
public func mapFilterViewControllerDidDismiss(_ mapFilterViewController: MapFilterViewController) {
mapDelegate?.charcoalViewControllerDidDismissMapSearch(self)
}

public func mapFilterViewController(_ mapFilterViewController: MapFilterViewController,
didSelect selection: CharcoalViewController.MapSelection) {
selectionDelegate?.charcoalViewController(self, didSelect: selection)
}
}

// MARK: - CalloutOverlayDelegate
Expand Down
10 changes: 10 additions & 0 deletions Sources/Charcoal/Filters/Map/MapFilterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import UIKit

public protocol MapFilterViewControllerDelegate: AnyObject {
func mapFilterViewController(_ mapFilterViewController: MapFilterViewController,
didSelect selection: CharcoalViewController.MapSelection)
func mapFilterViewControllerDidDismiss(_ mapFilterViewController: MapFilterViewController)
}

Expand Down Expand Up @@ -175,6 +177,10 @@ public class MapFilterViewController: FilterViewController {
mapPolygonFilterViewController : mapRadiusFilterViewController
display(selectedViewController)
updateToggleButtonLabel()

let openedSearch: CharcoalViewController.MapSelection =
selectedViewController == mapRadiusFilterViewController ? .openRadiusSearch : .openPolygonSearch
mapFilterDelegate?.mapFilterViewController(self, didSelect: openedSearch)
}

private func updateToggleButtonLabel() {
Expand Down Expand Up @@ -216,6 +222,10 @@ extension MapFilterViewController: MapPolygonFilterViewControllerDelegate {
delegate?.filterViewControllerWillEndTextEditing(self)
}

func mapPolygonFilterViewControllerDidSelectInitialArea(_ mapPolygonFilterViewController: MapPolygonFilterViewController) {
mapFilterDelegate?.mapFilterViewController(self, didSelect: .initialArea)
}

func mapPolygonFilterViewControllerDidSelectFilter(_ mapPolygonFilterViewController: MapPolygonFilterViewController) {
mapRadiusFilterViewController.resetFilterValues()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import UIKit

protocol MapPolygonFilterViewControllerDelegate: AnyObject {
func mapPolygonFilterViewControllerDidSelectFilter(_ mapPolygonFilterViewController: MapPolygonFilterViewController)
func mapPolygonFilterViewControllerDidSelectInitialArea(_ mapPolygonFilterViewController: MapPolygonFilterViewController)
func mapPolygonFilterViewController(_ mapPolygonFilterViewController: MapPolygonFilterViewController, searchIsEnabled: Bool)
func mapPolygonFilterViewControllerWillBeginTextEditing(_ mapPolygonFilterViewController: MapPolygonFilterViewController)
func mapPolygonFilterViewControllerWillEndTextEditing(_ mapPolygonFilterViewController: MapPolygonFilterViewController)
Expand Down Expand Up @@ -545,6 +546,7 @@ extension MapPolygonFilterViewController: MapPolygonFilterViewDelegate {
mapPolygonFilterView.drawPolygon(with: annotations)
mapPolygonFilterView.configure(for: .polygonSelection)
updateFilterValues()
delegate?.mapPolygonFilterViewControllerDidSelectInitialArea(self)
}

func mapPolygonFilterViewDidSelectLocationButton(_ mapPolygonFilterView: MapPolygonFilterView) {
Expand Down
Loading