Skip to content

Commit 21d7919

Browse files
authored
Improve search logic in feature inventory screen (#5232)
Task/Issue URL: https://app.asana.com/0/1198194956794324/1208633884628758/f ### Description Improve the (internal) feature flag inventory screen search logic: Before: * searches would filter feature flags that match the search text After: * searches filter feature flags that match the search text, but: * if match is a top-level features, all sub-features are also considered a match (even if their name doesn't match) * if match is a sub-feature, parent feature is also considered a match (even if its name doesn't match) ### Steps to test this PR _Test_ - [x] install from this branch, open app -> settings -> feature flag inventory - [x] search for a sub-feature by name - [x] verify sub-feature and its parent top-level feature are displayed - [x] search for a top-level feature by name (eg. autofill) - [x] verify the top-level feature and ALL its sub-features are displayed - [x] smoke test enable/disable features
1 parent 30f3827 commit 21d7919

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

feature-toggles/feature-toggles-api/src/main/java/com/duckduckgo/feature/toggles/api/FeatureToggles.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,17 @@ internal class ToggleImpl constructor(
306306
private val callback: FeatureTogglesCallback?,
307307
) : Toggle {
308308

309+
override fun equals(other: Any?): Boolean {
310+
if (other !is Toggle) {
311+
return false
312+
}
313+
return this.featureName() == other.featureName()
314+
}
315+
316+
override fun hashCode(): Int {
317+
return this.featureName().hashCode()
318+
}
319+
309320
private fun Toggle.State.evaluateTargetMatching(isExperiment: Boolean): Boolean {
310321
val variant = appVariantProvider.invoke()
311322
// no targets then consider always treated

feature-toggles/feature-toggles-internal/src/main/java/com/duckduckgo/examplefeature/internal/ui/FeatureToggleInventoryActivity.kt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,43 @@ class FeatureToggleInventoryActivity : DuckDuckGoActivity() {
117117
private suspend fun getFeatureViews(): List<View> = withContext(dispatcherProvider.io()) {
118118
val toggles = this@FeatureToggleInventoryActivity.toggles.await()
119119
val match = featureNameFilter.get().lowercase()
120-
val parentFeature = toggles
120+
val parentFeatures = toggles
121121
.filter { it.featureName().parentName == null }
122122
.sortedBy { it.featureName().name.lowercase() }
123123
val subFeatures = toggles
124124
.filter { it.featureName().parentName != null }
125125
.sortedBy { it.featureName().name.lowercase() }
126+
126127
val features = mutableListOf<Toggle>().apply {
127-
for (parent in parentFeature) {
128-
add(parent)
129-
addAll(subFeatures.filter { it.featureName().parentName == parent.featureName().name })
128+
// add parent features that match and all their sub-features
129+
parentFeatures.forEach { parentFeature ->
130+
if (match.isNotBlank()) {
131+
if (parentFeature.featureName().name.lowercase().contains(match)) {
132+
add(parentFeature)
133+
// add also all sub-features
134+
addAll(
135+
subFeatures.filter { it.featureName().parentName == parentFeature.featureName().name },
136+
)
137+
}
138+
} else {
139+
for (parent in parentFeatures) {
140+
add(parent)
141+
addAll(subFeatures.filter { it.featureName().parentName == parent.featureName().name })
142+
}
143+
}
130144
}
131-
}.filter {
132-
if (match.isNotBlank()) {
133-
// Apply search box filter if needed
134-
it.featureName().name.lowercase().contains(match)
135-
} else {
136-
true
145+
146+
// add sub-features that match and their parent feature
147+
subFeatures.forEach { feature ->
148+
if (match.isNotBlank() && feature.featureName().name.lowercase().contains(match)) {
149+
// add its parent too
150+
addAll(
151+
parentFeatures.filter { it.featureName().name == feature.featureName().parentName },
152+
)
153+
add(feature)
154+
}
137155
}
138-
}
156+
}.distinct() // de-dup
139157

140158
val views = features.map { feature ->
141159
OneLineListItem(this@FeatureToggleInventoryActivity).apply {

0 commit comments

Comments
 (0)