Skip to content
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
7 changes: 7 additions & 0 deletions service/src/main/kotlin/app/cash/backfila/ui/UiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ class UiModule : KAbstractModule() {
install(WebActionModule.create<BackfillShowButtonHandlerAction>())
}
}

/**
* Identifies the Misk dashboard for Backfila so dashboard links and other customization can be added.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class BackfilaDashboard
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import app.cash.backfila.service.BackfilaConfig
import app.cash.backfila.service.persistence.BackfilaDb
import app.cash.backfila.service.persistence.BackfillRunQuery
import app.cash.backfila.service.persistence.BackfillState
import app.cash.backfila.ui.BackfilaDashboard
import app.cash.backfila.ui.pages.IndexAction
import jakarta.inject.Inject
import kotlinx.html.TagConsumer
Expand All @@ -30,6 +31,7 @@ import misk.tailwind.pages.MenuSection
import misk.tailwind.pages.Navbar
import misk.web.HttpCall
import misk.web.ResponseBody
import misk.web.dashboard.DashboardTab
import misk.web.dashboard.HtmlLayout
import okio.BufferedSink
import wisp.deployment.Deployment
Expand All @@ -47,6 +49,7 @@ class DashboardPageLayout @Inject constructor(
private val getBackfillRunsAction: GetBackfillRunsAction,
@BackfilaDb private val transacter: Transacter,
private val queryFactory: Query.Factory,
private val allTabs: List<DashboardTab>,
) {
private var newBuilder = false
private var headBlock: TagConsumer<*>.() -> Unit = {}
Expand All @@ -57,6 +60,10 @@ class DashboardPageLayout @Inject constructor(
clientHttpCall.get().url.encodedPath
}

private val backfilaLinks by lazy {
allTabs.filter { it.dashboardAnnotationKClass == BackfilaDashboard::class }
}

private fun setNewBuilder() = apply { newBuilder = true }

fun newBuilder(): DashboardPageLayout = DashboardPageLayout(
Expand All @@ -67,6 +74,7 @@ class DashboardPageLayout @Inject constructor(
getBackfillRunsAction = getBackfillRunsAction,
transacter = transacter,
queryFactory = queryFactory,
allTabs = allTabs,
).setNewBuilder()

fun title(title: String) = apply {
Expand Down Expand Up @@ -181,9 +189,30 @@ class DashboardPageLayout @Inject constructor(
href = "/backfills/",
isSelected = currentPath == "/backfills/",
),
),
) + backfilaLinks.filter { it.menuCategory == "Backfila" }.map { tab ->
Link(
label = tab.menuLabel,
href = tab.menuUrl,
isSelected = currentPath.startsWith(tab.menuUrl),
)
},
),
) + if (services.isNotEmpty()) {
) + if (backfilaLinks.filterNot { it.menuCategory == "Backfila" }.isNotEmpty()) {
backfilaLinks.filterNot { it.menuCategory == "Backfila" }.groupBy { it.menuCategory }.map { (category, tabs) ->
MenuSection(
title = category,
links = tabs.map { tab ->
Link(
label = tab.menuLabel,
href = tab.menuUrl,
isSelected = currentPath.startsWith(tab.menuUrl),
)
},
)
}
} else {
listOf()
} + if (services.isNotEmpty()) {
listOf(
MenuSection(
title = "Your Services",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import app.cash.backfila.protos.clientservice.RunBatchResponse
import app.cash.backfila.service.BackfilaConfig
import app.cash.backfila.service.BackfilaServiceModule
import app.cash.backfila.service.persistence.DbBackfillRun
import app.cash.backfila.ui.BackfilaDashboard
import misk.MiskApplication
import misk.MiskRealServiceModule
import misk.audit.NoOpAuditClientModule
Expand All @@ -28,8 +29,10 @@ import misk.jdbc.DataSourceConfig
import misk.jdbc.DataSourceType
import misk.security.authz.FakeCallerAuthenticator
import misk.security.authz.MiskCallerAuthenticator
import misk.security.authz.Unauthenticated
import misk.web.MiskWebModule
import misk.web.WebConfig
import misk.web.dashboard.DashboardModule
import okio.ByteString.Companion.encodeUtf8
import wisp.deployment.Deployment

Expand All @@ -54,6 +57,22 @@ fun main(args: Array<String>) {
multibind<MiskCallerAuthenticator>().to<FakeCallerAuthenticator>()
bind<ViewLogsUrlProvider>().to<DevelopmentViewLogsUrlProvider>()

// Example custom link that shows up in navbar
install(
DashboardModule.createMenuLink<BackfilaDashboard, Unauthenticated>(
label = "Go to Repo",
url = "https://github.com/cashapp/backfila",
category = "Backfila",
),
)
install(
DashboardModule.createMenuLink<BackfilaDashboard, Unauthenticated>(
label = "Test other link",
url = "https://github.com/cashapp/backfila",
category = "Alpha",
),
)

newMapBinder<String, BackfilaCallbackConnectorProvider>(ForConnectors::class)
.permitDuplicates().addBinding("DEV")
.toInstance(object : BackfilaCallbackConnectorProvider {
Expand Down