From 726af0c49612db42eab76ce1137e14ecadf86a1b Mon Sep 17 00:00:00 2001 From: Andrew Alexander Date: Thu, 9 Jan 2025 17:16:01 -0500 Subject: [PATCH] Show running backfills for user --- .../service/persistence/BackfillRunQuery.kt | 6 ++ .../ui/components/DashboardPageLayout.kt | 89 +++++++++++-------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillRunQuery.kt b/service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillRunQuery.kt index 3d5ac3c1d..8ddbe8f90 100644 --- a/service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillRunQuery.kt +++ b/service/src/main/kotlin/app/cash/backfila/service/persistence/BackfillRunQuery.kt @@ -22,6 +22,12 @@ interface BackfillRunQuery : Query { @Constraint("state", Operator.NE) fun stateNot(state: BackfillState): BackfillRunQuery + @Constraint("created_by_user", Operator.EQ) + fun createdByUser(user: String): BackfillRunQuery + @Order("id", asc = false) fun orderByIdDesc(): BackfillRunQuery + + @Order("updated_at", asc = false) + fun orderByUpdatedAtDesc(): BackfillRunQuery } diff --git a/service/src/main/kotlin/app/cash/backfila/ui/components/DashboardPageLayout.kt b/service/src/main/kotlin/app/cash/backfila/ui/components/DashboardPageLayout.kt index ed66a2f9e..8e08b133d 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/components/DashboardPageLayout.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/components/DashboardPageLayout.kt @@ -1,6 +1,9 @@ package app.cash.backfila.ui.components import app.cash.backfila.dashboard.GetBackfillRunsAction +import app.cash.backfila.service.persistence.BackfilaDb +import app.cash.backfila.service.persistence.BackfillRunQuery +import app.cash.backfila.service.persistence.BackfillState import jakarta.inject.Inject import kotlinx.html.TagConsumer import kotlinx.html.div @@ -8,6 +11,9 @@ import kotlinx.html.main import kotlinx.html.script import misk.MiskCaller import misk.config.AppName +import misk.hibernate.Query +import misk.hibernate.Transacter +import misk.hibernate.newQuery import misk.hotwire.buildHtml import misk.scope.ActionScoped import misk.tailwind.Link @@ -34,6 +40,8 @@ class DashboardPageLayout @Inject constructor( private val deployment: Deployment, private val clientHttpCall: ActionScoped, private val getBackfillRunsAction: GetBackfillRunsAction, + @BackfilaDb private val transacter: Transacter, + private val queryFactory: Query.Factory, ) { private var newBuilder = false private var headBlock: TagConsumer<*>.() -> Unit = {} @@ -60,6 +68,8 @@ class DashboardPageLayout @Inject constructor( deployment = deployment, clientHttpCall = clientHttpCall, getBackfillRunsAction = getBackfillRunsAction, + transacter = transacter, + queryFactory = queryFactory, ).setNewBuilder() fun title(title: String) = apply { @@ -135,50 +145,53 @@ class DashboardPageLayout @Inject constructor( private fun buildMenuSections( currentPath: String, ): List { - val callerBackfills = getBackfillRunsAction.backfillRuns(serviceName, variant) + return transacter.transaction { session -> + val runningBackfills = queryFactory.newQuery() + .createdByUser(callerProvider.get()!!.user!!) + .state(BackfillState.RUNNING) + .orderByUpdatedAtDesc() + .list(session) - return listOf( - MenuSection( - title = "Backfila", - links = listOf( - Link( - label = "Services", - href = "/services/", - isSelected = currentPath.startsWith("/services/"), - ), - Link( - label = "Backfills", - href = "/backfills/", - isSelected = currentPath.startsWith("/backfills/"), + // TODO get services from REgistry for user || group backfills by service + + listOf( + MenuSection( + title = "Backfila", + links = listOf( + Link( + label = "Services", + href = "/services/", + isSelected = currentPath.startsWith("/services/"), + ), + Link( + label = "Backfills", + href = "/backfills/", + isSelected = currentPath.startsWith("/backfills/"), + ), ), ), - ), - MenuSection( - title = "Your Services", - links = listOf( - Link( - label = "Fine Dining", - href = "/services/?q=FineDining", - isSelected = currentPath.startsWith("/services/?q=FindDining"), + MenuSection( + title = "Your Services", + links = listOf( + Link( + label = "Fine Dining", + href = "/services/?q=FineDining", + isSelected = currentPath.startsWith("/services/?q=FindDining"), + ), ), ), - ), - MenuSection( - title = "Your Backfills", - links = listOf( - Link( - label = "FineDining #0034", - href = "/services/", - isSelected = currentPath.startsWith("/backfill/"), - ), - Link( - label = "FineDining #0067", - href = "/backfill/", - isSelected = currentPath.startsWith("/backfill/"), - ), + MenuSection( + title = "Your Backfills", + links = runningBackfills.map { backfill -> + Link( + label = backfill.service.registry_name + " #" + backfill.id, + href = "/backfills/${backfill.id}", + isSelected = currentPath.startsWith("/backfills/${backfill.id}"), + ) + }, ), - ), - ) + ) + } } companion object {