Skip to content

Commit 17fcab0

Browse files
committed
Remove old TKRouter.modesToGroupInRequest
Should instead use `TKUIRoutingResultsCard.config.routingModeRequestGroupAdjuster` or `groupedModeIdentifiers` input to `multiFetchTrips`.
1 parent 9952bf3 commit 17fcab0

3 files changed

Lines changed: 3 additions & 49 deletions

File tree

Sources/TripKit/server/TKRouter.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ extension TKRouter {
244244

245245
let groupedIdentifier = groupedModeIdentifiers ?? TKTransportMode.groupModeIdentifiers(
246246
enabledModes,
247-
includeGroupForAll: true,
248-
alwaysGroupedModeIdentifierPrefixes: TKRouter.modesToGroupInRequest ?? []
247+
includeGroupForAll: true
249248
)
250249

251250
let tripRequest: TripRequest = try request.performAndWait {

Sources/TripKitAPI/TKRouter.swift

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ public class TKRouter: NSObject {
2424
/// Optional parameters to add to routing query. Only used by TripKit.
2525
public static var defaultParameters: [URLQueryItem]? = nil
2626

27-
/// Optional setting to group certain modes always in a single `routing.json` when sending a
28-
/// multi-fetch request.
29-
///
30-
/// If you're using `TKUIRoutingResultsCard`, prefer
31-
/// `TKUIRoutingResultsCard.config.routingModeRequestGroupAdjuster`.
32-
public static var modesToGroupInRequest: [String]? = nil
33-
3427
/// Optional server to use instead of ``TKServer/shared``.
3528
public var server: TKServer?
3629

@@ -104,8 +97,7 @@ extension TKRouter {
10497
} else {
10598
let groupedIdentifier = TKTransportMode.groupModeIdentifiers(
10699
request.modes,
107-
includeGroupForAll: true,
108-
alwaysGroupedModeIdentifierPrefixes: TKRouter.modesToGroupInRequest ?? []
100+
includeGroupForAll: true
109101
)
110102
guard !groupedIdentifier.isEmpty else {
111103
throw RoutingError.invalidRequest("No modes enabled")
@@ -265,11 +257,9 @@ extension TKTransportMode {
265257
/// - modes: A set of all the identifiers to be grouped
266258
/// - includeGroupForAll: If an extra group which has all the identifiers should be added
267259
/// - Returns: A set of a set of mode identifiers
268-
public static func groupModeIdentifiers(_ modes: Set<String>, includeGroupForAll: Bool, alwaysGroupedModeIdentifierPrefixes: [String] = []) -> Set<Set<String>> {
269-
let identifiersToAlwaysGroup = alwaysGroupedModeIdentifierPrefixes
260+
public static func groupModeIdentifiers(_ modes: Set<String>, includeGroupForAll: Bool) -> Set<Set<String>> {
270261
var result: Set<Set<String>> = []
271262
var processedModes: Set<String> = []
272-
var specialGroups: [String: Set<String>] = [:]
273263
var includesWalkOnly = false
274264

275265
for mode in modes {
@@ -279,10 +269,6 @@ extension TKTransportMode {
279269
continue // don't add flights by themselves
280270
} else if mode == TKTransportMode.walking.modeIdentifier || mode == TKTransportMode.wheelchair.modeIdentifier {
281271
includesWalkOnly = true
282-
} else if let forceGroup = identifiersToAlwaysGroup.first(where: { mode.hasPrefix($0) }) {
283-
specialGroups[forceGroup, default: []].insert(mode)
284-
processedModes.insert(mode)
285-
continue
286272
}
287273

288274
var group: Set<String> = [mode]
@@ -306,10 +292,6 @@ extension TKTransportMode {
306292
processedModes.formUnion(group)
307293
}
308294

309-
for specials in specialGroups.values {
310-
result.insert(specials)
311-
}
312-
313295
if includeGroupForAll, result.count > 1 + (includesWalkOnly ? 1 : 0) {
314296
result.insert(modes)
315297
}

Tests/TripKitTests/parsing/TKRegionManagerTest.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,4 @@ class TKRegionManagerTest: XCTestCase {
112112
])
113113
}
114114

115-
func testGroupingSchoolBusModes() {
116-
let inputModes: Set<String> = [
117-
"pt_pub",
118-
"pt_ltd_SCHOOLBUS_1",
119-
"pt_ltd_SCHOOLBUS_2",
120-
"pt_ltd_SCHOOLBUS_3",
121-
"wa_wal",
122-
"cy_bic"]
123-
124-
let groupedModes = TKTransportMode.groupModeIdentifiers(
125-
inputModes,
126-
includeGroupForAll: false,
127-
alwaysGroupedModeIdentifierPrefixes: ["pt_ltd_SCHOOLBUS"]
128-
)
129-
130-
let expectedGroups: Set<Set<String>> = [
131-
["pt_pub"],
132-
["pt_ltd_SCHOOLBUS_1",
133-
"pt_ltd_SCHOOLBUS_2",
134-
"pt_ltd_SCHOOLBUS_3"],
135-
["wa_wal"],
136-
["cy_bic"]
137-
]
138-
139-
XCTAssertEqual(groupedModes, expectedGroups, "The grouped modes are not correct")
140-
}
141-
142115
}

0 commit comments

Comments
 (0)