Skip to content

Commit d2cbe3b

Browse files
committed
Add new Service index browser client side search with variant support
1 parent 8a8821a commit d2cbe3b

File tree

8 files changed

+240
-192
lines changed

8 files changed

+240
-192
lines changed

service/src/main/kotlin/app/cash/backfila/ui/actions/ServiceAutocompleteAction.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class ServiceAutocompleteAction @Inject constructor(
2323
fun get(
2424
@QueryParam q: String?,
2525
): String {
26-
val services = getServicesAction.services().services
26+
val services = getFlattenedServices()
2727

2828
return buildHtml {
29-
services.flatMap { service ->
30-
service.variants.map { variant -> "${service.name}/$variant" to service }
31-
}.filter { (path, _) ->
29+
services.filter { (path, _) ->
3230
q.isNullOrBlank() || path.lowercase().contains(q.lowercase())
3331
}.map { (path, service) ->
3432
li("list-group-item cursor-default select-none px-4 py-2 text-left") {
@@ -43,6 +41,13 @@ class ServiceAutocompleteAction @Inject constructor(
4341
}
4442
}
4543

44+
fun getFlattenedServices(): Map<String, GetServicesAction.UiService> {
45+
val services = getServicesAction.services().services
46+
return services.flatMap { service ->
47+
service.variants.map { variant -> "${service.name}/$variant" to service }
48+
}.toMap()
49+
}
50+
4651
companion object {
4752
const val PATH = "/api/autocomplete/services"
4853
}

service/src/main/kotlin/app/cash/backfila/ui/components/DashboardLayout.kt

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import kotlinx.html.TagConsumer
44
import kotlinx.html.div
55
import kotlinx.html.main
66
import kotlinx.html.script
7+
import misk.tailwind.Link
8+
import misk.tailwind.pages.MenuSection
9+
import misk.tailwind.pages.Navbar
710
import misk.web.dashboard.HtmlLayout
11+
import wisp.deployment.getDeploymentFromEnvironmentVariable
812

913
fun TagConsumer<*>.DashboardLayout(
1014
title: String,
1115
path: String,
1216
block: TagConsumer<*>.() -> Unit = {},
1317
) {
18+
val deployment = getDeploymentFromEnvironmentVariable()
19+
1420
HtmlLayout(
1521
appRoot = "/",
1622
title = title,
@@ -22,19 +28,90 @@ fun TagConsumer<*>.DashboardLayout(
2228
type = "module"
2329
src = "/static/js/autocomplete_controller.js"
2430
}
31+
script {
32+
type = "module"
33+
src = "/static/js/search_bar_controller.js"
34+
}
2535
},
2636
) {
2737
div("min-h-full") {
28-
NavBar(path)
29-
div("py-10") {
30-
main {
31-
div("mx-auto max-w-7xl sm:px-6 lg:px-8") {
32-
// TODO remove when new UI is stable and preferred
33-
UseOldUIAlert()
34-
block()
38+
if (true) {
39+
// Uses Misk's Navbar with sidebar
40+
Navbar(
41+
appName = "Backfila",
42+
deployment = deployment,
43+
homeHref = "/",
44+
menuSections = buildMenuSections(
45+
currentPath = path,
46+
),
47+
) {
48+
div("py-10") {
49+
main {
50+
div("mx-auto max-w-7xl sm:px-6 lg:px-8") {
51+
// TODO remove when new UI is stable and preferred
52+
UseOldUIAlert()
53+
block()
54+
}
55+
}
56+
}
57+
}
58+
} else {
59+
NavBar(path)
60+
div("py-10") {
61+
main {
62+
div("mx-auto max-w-7xl sm:px-6 lg:px-8") {
63+
// TODO remove when new UI is stable and preferred
64+
UseOldUIAlert()
65+
block()
66+
}
3567
}
3668
}
3769
}
3870
}
3971
}
4072
}
73+
74+
private fun buildMenuSections(
75+
currentPath: String,
76+
) = listOf(
77+
MenuSection(
78+
title = "Backfila",
79+
links = listOf(
80+
Link(
81+
label = "Services",
82+
href = "/services/",
83+
isSelected = currentPath.startsWith("/services/"),
84+
),
85+
Link(
86+
label = "Backfills",
87+
href = "/backfills/",
88+
isSelected = currentPath.startsWith("/backfills/"),
89+
),
90+
),
91+
),
92+
MenuSection(
93+
title = "Your Services",
94+
links = listOf(
95+
Link(
96+
label = "Fine Dining",
97+
href = "/services/?q=FineDining",
98+
isSelected = currentPath.startsWith("/services/?q=FindDining"),
99+
),
100+
),
101+
),
102+
MenuSection(
103+
title = "Your Backfills",
104+
links = listOf(
105+
Link(
106+
label = "FineDining #0034",
107+
href = "/services/",
108+
isSelected = currentPath.startsWith("/backfill/"),
109+
),
110+
Link(
111+
label = "FineDining #0067",
112+
href = "/backfill/",
113+
isSelected = currentPath.startsWith("/backfill/"),
114+
),
115+
),
116+
),
117+
)

0 commit comments

Comments
 (0)