Skip to content

Commit 9748b42

Browse files
committed
Update deep search
1 parent 5628222 commit 9748b42

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fix an issue with `isAutomaticConnectionEnabled` not starting the browser the first time it's enabled
88
- Fix crash when exporting HAR file by @rounak in https://github.com/kean/Pulse/pull/299
99
- Fix concurrency issue in `StoreDetailsViewModel` by @ejensen in https://github.com/kean/Pulse/pull/302
10+
- Update the deep search. It will now show all search scopes found and only one match per scope. You can tap on a match to see the scope with a prepopulated search query to see the remaining items.
1011

1112
## Pulse 5.1.1
1213

Sources/PulseUI/Features/Search/Views/ConsoleSearchResultsSectionView.swift

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Combine
1212
@available(iOS 16, visionOS 1, macOS 13, *)
1313
struct ConsoleSearchResultView: View {
1414
let viewModel: ConsoleSearchResultViewModel
15-
var limit: Int = 4
1615
var isSeparatorNeeded = false
1716

1817
@ScaledMetric(relativeTo: .body) private var fontMultiplier = 1.0
@@ -21,42 +20,26 @@ struct ConsoleSearchResultView: View {
2120

2221
var body: some View {
2322
ConsoleEntityCell(entity: viewModel.entity)
24-
let occurrences = Array(viewModel.occurrences).filter { $0.scope.isDisplayedInResults }
25-
ForEach(occurrences.prefix(limit)) { item in
26-
NavigationLink(destination: ConsoleSearchResultView.makeDestination(for: item, entity: viewModel.entity).injecting(environment)) {
23+
ForEach(makeMatches(from: viewModel.occurrences)) { item in
24+
NavigationLink(destination: ConsoleSearchResultView.makeDestination(for: item.occurrence, entity: viewModel.entity).injecting(environment)) {
2725
makeCell(for: item)
2826
}
2927
}
30-
if occurrences.count > limit {
31-
let total = occurrences.count > ConsoleSearchMatch.limit ? "\(ConsoleSearchMatch.limit)+" : "\(occurrences.count)"
32-
NavigationLink(destination: ConsoleSearchResultDetailsView(viewModel: viewModel).injecting(environment)) {
33-
Text("Total Results: ")
34-
.font(.callout) +
35-
Text(total)
36-
.font(.callout)
37-
.foregroundColor(.secondary)
38-
}
39-
}
4028
if isSeparatorNeeded {
4129
PlainListGroupSeparator()
4230
}
4331
}
4432

4533
@ViewBuilder
46-
private func makeCell(for occurrence: ConsoleSearchOccurrence) -> some View {
47-
let contents = VStack(alignment: .leading, spacing: 4) {
48-
Text(occurrence.preview)
49-
.font(contentFont)
50-
.lineLimit(3)
51-
Text(occurrence.scope.title + " (\(occurrence.line):\(occurrence.range.lowerBound + 1))")
34+
private func makeCell(for item: ConsoleSearchResultsItem) -> some View {
35+
VStack(alignment: .leading, spacing: 4) {
36+
Text(item.title)
5237
.font(detailsFont)
5338
.foregroundColor(.secondary)
54-
}
55-
if #unavailable(iOS 16) {
56-
contents.padding(.vertical, 4)
57-
} else {
58-
contents
59-
}
39+
Text(item.occurrence.preview)
40+
.font(contentFont)
41+
.lineLimit(3)
42+
}.padding(.vertical, 4)
6043
}
6144

6245
@ViewBuilder
@@ -101,16 +84,48 @@ struct ConsoleSearchResultView: View {
10184
}
10285

10386
@available(iOS 16, visionOS 1, *)
104-
struct ConsoleSearchResultDetailsView: View {
105-
let viewModel: ConsoleSearchResultViewModel
87+
private func makeMatches(from occurrences: [ConsoleSearchOccurrence]) -> [ConsoleSearchResultsItem] {
88+
var items: [ConsoleSearchResultsItem] = []
89+
var index = 0
90+
while index < occurrences.endIndex {
91+
let occurrence = occurrences[index]
92+
93+
if !occurrence.scope.isDisplayedInResults {
94+
index += 1
95+
continue // Skip
96+
}
10697

107-
var body: some View {
108-
List {
109-
ConsoleSearchResultView(viewModel: viewModel, limit: Int.max)
98+
// Count all occurences in this scope and skip to the end
99+
var counter = 1 // Already found one
100+
while (index+1) < occurrences.endIndex && occurrences[index+1].scope == occurrence.scope {
101+
counter += 1
102+
index += 1 // Consume next
103+
}
104+
105+
let item = ConsoleSearchResultsItem(totalCount: counter, occurrence: occurrence)
106+
items.append(item)
107+
index += 1
108+
}
109+
return items
110+
}
111+
112+
@available(iOS 16, visionOS 1, *)
113+
struct ConsoleSearchResultsItem: Identifiable {
114+
var id: ConsoleSearchOccurrence { occurrence }
115+
let totalCount: Int
116+
let occurrence: ConsoleSearchOccurrence
117+
118+
var title: String {
119+
let suffix: String
120+
if totalCount == 1 {
121+
suffix = ""
122+
} else if totalCount < ConsoleSearchMatch.limit {
123+
suffix = " (\(totalCount) matches)"
124+
} else {
125+
// we know there is 6, showin
126+
suffix = " (\(ConsoleSearchMatch.limit-1)+ matches)"
110127
}
111-
.listStyle(.plain)
112-
.environment(\.defaultMinListRowHeight, 0)
113-
.inlineNavigationTitle("Search Results")
128+
return "\(occurrence.scope.title)\(suffix)"
114129
}
115130
}
116131

0 commit comments

Comments
 (0)