android: preserve run decision pill work

This commit is contained in:
2026-10-18 15:05:30 +01:00
parent b93eee234c
commit c78c6ca4ff
7 changed files with 177 additions and 32 deletions
@@ -185,11 +185,17 @@ fun PipelinesApp(
}
val search by vm.search.collectAsStateWithLifecycle()
// Whether the Chat destination currently shows an open conversation. The
// floating pill stands down only there (see [destinationPillVisible]); it is
// floating pill stands down there (see [destinationPillVisible]); it is
// read from the chat store, so it flips in the same recomposition that swaps
// the chat list for the conversation.
val conversationOpen by vm.conversationOpen.collectAsStateWithLifecycle()
val pillVisible = destinationPillVisible(currentRoute, conversationOpen)
// Whether a run's pending-decision surface — the decision sheet the operator
// opens from the run summary's Decide action — is currently open. It is a state
// of the run view (reported up by the run detail and its stage pane), not a
// destination, so the pill stands down for exactly as long as it is up and
// returns the moment the decision is answered or dismissed, with no navigation.
var decisionSurfaceOpen by remember { mutableStateOf(false) }
val pillVisible = destinationPillVisible(currentRoute, conversationOpen, decisionSurfaceOpen)
val searchKind by vm.searchKind.collectAsStateWithLifecycle()
val searchSort by vm.searchSort.collectAsStateWithLifecycle()
@@ -291,7 +297,8 @@ fun PipelinesApp(
// ([pillScrollInset], published through [LocalPillBottomInset]) is applied
// inside each scrollable screen's own scroll content, so scrolling to the end
// still reveals the last row clear of the pill, and while the pill is hidden
// (an open conversation, see [destinationPillVisible]) that clearance is zero
// (an open conversation or a run's open decision surface, see
// [destinationPillVisible]) that clearance is zero
// so a hidden pill leaves no empty band. See [contentPillPadding].
val bannerVisible = connectionState !is ConnectionState.Connected
// The live height of any bottom selector strip the current pane is showing. The
@@ -354,6 +361,7 @@ fun PipelinesApp(
listState = runListState,
decisionRequest = decisionRequest,
onDecisionRequestHandled = { decisionRequest = null },
onDecisionSurfaceChange = { decisionSurfaceOpen = it },
)
}
composable("chat") {
@@ -436,9 +444,10 @@ fun PipelinesApp(
onClick = { attentionOpen = true },
modifier = Modifier.align(Alignment.End).padding(bottom = SPACING_S),
)
// The pill stands down while a conversation is open; the search
// field it morphs into is unreachable there anyway (the field opens
// from the pill), so nothing is stranded by not drawing it.
// The pill stands down while a conversation is open, or while a
// run's pending-decision surface is up; the search field it morphs
// into is unreachable there anyway (the field opens from the pill),
// so nothing is stranded by not drawing it.
if (pillVisible) {
DestinationBar(
destinations = destinations,
@@ -497,15 +506,25 @@ private const val CHAT_ROUTE = "chat"
/**
* Whether the floating destination pill is drawn for [currentRoute]. The pill
* stands down only while the Chat destination is showing an open conversation —
* a session's transcript and composer — where it would sit over the composer and
* the newest message and compete with send/stop. The chat list and every other
* destination keep it exactly as before; the covered peek strip and Back still
* leave a conversation, so hiding the pill strands nothing. Pure, so the one
* stands down in the two places a deliberate bottom surface owns the foot of the
* screen and the pill would sit over it:
*
* - while the Chat destination is showing an open conversation — a session's
* transcript and composer — where it would compete with send/stop;
* - while a run's pending-decision surface is open ([decisionOpen], the sheet the
* operator answers from the run summary), where it would cover the options.
*
* Everything else keeps it: the chat list, a run being read, its stage pane, an
* artifact and the graph all draw it exactly as before, and the covered peek strip
* and Back still leave both hiding states, so hiding the pill strands nothing. The
* clearance and the drawn pill both key off this one predicate. Pure, so the one
* rule is unit-testable without a device.
*/
internal fun destinationPillVisible(currentRoute: String?, conversationOpen: Boolean): Boolean =
!(currentRoute == CHAT_ROUTE && conversationOpen)
internal fun destinationPillVisible(
currentRoute: String?,
conversationOpen: Boolean,
decisionOpen: Boolean,
): Boolean = !(currentRoute == CHAT_ROUTE && conversationOpen) && !decisionOpen
/**
* Where the bottom overlay — the destination pill and the attention chip above it
@@ -534,9 +553,10 @@ internal fun contentPillPadding(pillVisible: Boolean): Dp = 0.dp
* The trailing bottom space a scrollable screen keeps so its last row scrolls clear
* of the floating bottom stack — the destination pill and the attention chip above
* it — built from the named [DESTINATION_PILL_RESERVE] and [ATTENTION_CHIP_RESERVE]
* while the pill is drawn, and none while it is hidden (an open conversation, see
* [destinationPillVisible]) so a hidden pill leaves no empty band at the end of a
* list. Published to the content through `LocalPillBottomInset` and applied inside
* while the pill is drawn, and none while it is hidden (an open conversation or a
* run's open decision surface, see [destinationPillVisible]) so a hidden pill
* leaves no empty band at the end of a list. Published to the content through
* `LocalPillBottomInset` and applied inside
* each scrollable's own scroll content, never as layout padding on the content. It
* is derived from [pillVisible] alone, so the clearance and the drawn pill can
* never disagree into a frame with a drawn pill over content it does not clear, or
@@ -34,6 +34,7 @@ internal fun RunsDestination(
listState: LazyListState,
decisionRequest: Long? = null,
onDecisionRequestHandled: () -> Unit = {},
onDecisionSurfaceChange: (Boolean) -> Unit = {},
) {
val depth = selection.depth
val onBack: () -> Unit = { onSelectionChange(backFrom(selection)) }
@@ -103,6 +104,7 @@ internal fun RunsDestination(
covered = covered,
requestDecision = decisionRequest == itemId,
onDecisionRequestHandled = onDecisionRequestHandled,
onDecisionSurfaceChange = onDecisionSurfaceChange,
)
}
2 -> rememberPaneContent(
@@ -126,6 +128,7 @@ internal fun RunsDestination(
wide = wide,
modifier = paneModifier,
covered = covered,
onDecisionSurfaceChange = onDecisionSurfaceChange,
)
}
3 -> rememberPaneContent(
@@ -147,6 +150,7 @@ internal fun RunsDestination(
wide = wide,
modifier = paneModifier,
covered = covered,
onDecisionSurfaceChange = onDecisionSurfaceChange,
)
}
}
@@ -22,6 +22,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -60,6 +61,12 @@ import net.awan.pipelines.ui.theme.pipelinesText
* [onSend] performs the request; it reports the outcome through its callback so
* this component owns no networking and is unit-testable through the pure
* [DecisionDraft]/[decisionRefusalMessage] model.
*
* [onSurfaceOpenChange] reports whether the decision sheet — the run's pending
* decision surface — is currently open, so the host can tell the app shell to
* stand the floating destination pill down for exactly as long as the operator is
* answering. It is the host's job to route that to the pill (see
* `destinationPillVisible`); this component only says when its own surface is up.
*/
@Composable
fun DecisionPrompt(
@@ -68,6 +75,7 @@ fun DecisionPrompt(
modifier: Modifier = Modifier,
openRequest: Boolean = false,
onOpenRequestHandled: () -> Unit = {},
onSurfaceOpenChange: (Boolean) -> Unit = {},
) {
val shown = rememberPaneContent(decision)
var open by remember { mutableStateOf(false) }
@@ -75,6 +83,13 @@ fun DecisionPrompt(
var sending by remember { mutableStateOf(false) }
var error by remember { mutableStateOf<String?>(null) }
// The decision surface is up exactly while the sheet is open (it can outlive
// the decision, kept open to report a refusal), so the host is told on every
// change. It is cleared when the prompt leaves the composition, so a surface
// that closes with its pane can never leave the pill hidden behind it.
LaunchedEffect(open) { onSurfaceOpenChange(open) }
DisposableEffect(Unit) { onDispose { onSurfaceOpenChange(false) } }
// A notification's tap asks for the decision itself, not just the run:
// open the sheet once the waiting run's detail has loaded. The request is
// consumed here so a recomposition or a dismissal does not reopen it.
@@ -420,6 +420,7 @@ fun StageDetailPane(
runLabel: String? = null,
decision: PendingDecision? = null,
onDecide: (PendingDecision, String, String, (Result<RunDetail>) -> Unit) -> Unit = { _, _, _, _ -> },
onDecisionSurfaceChange: (Boolean) -> Unit = {},
) {
// A covered pane shows its compact identity only; the visit tab row and the
// stage body must never be drawn squeezed into the peek strip.
@@ -485,6 +486,7 @@ fun StageDetailPane(
runContext = runContext,
decision = decision,
onDecide = onDecide,
onDecisionSurfaceChange = onDecisionSurfaceChange,
modifier = Modifier.padding(padding),
)
}
@@ -505,6 +507,7 @@ private fun StageDetailBody(
runContext: Boolean,
decision: PendingDecision?,
onDecide: (PendingDecision, String, String, (Result<RunDetail>) -> Unit) -> Unit,
onDecisionSurfaceChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
) {
val text = pipelinesText()
@@ -536,7 +539,11 @@ private fun StageDetailBody(
// the stage screen: reaching the stage is enough. Rendered
// unconditionally so the open sheet survives a refusal (which clears the
// decision) and can report the server's reason.
DecisionPrompt(decision = decision, onSend = onDecide)
DecisionPrompt(
decision = decision,
onSend = onDecide,
onSurfaceOpenChange = onDecisionSurfaceChange,
)
// The stage's own name is the app bar's title, so the body does not
// repeat it: the pane leads with the stage's type and facts instead of
// a duplicated heading.
@@ -849,6 +856,7 @@ fun RunStagePane(
wide: Boolean,
modifier: Modifier = Modifier,
covered: Boolean = false,
onDecisionSurfaceChange: (Boolean) -> Unit = {},
) {
val state by vm.runDetail.collectAsStateWithLifecycle()
val configuredServerUrl by vm.configuredServerUrl.collectAsStateWithLifecycle()
@@ -884,6 +892,7 @@ fun RunStagePane(
onDecide = { pending, option, feedback, onResult ->
vm.decideRun(pending.runId, pending.stageKey, option, feedback, onResult)
},
onDecisionSurfaceChange = onDecisionSurfaceChange,
)
} else {
StageSectionPane(
@@ -69,6 +69,7 @@ fun RunDetailScreen(
covered: Boolean = false,
requestDecision: Boolean = false,
onDecisionRequestHandled: () -> Unit = {},
onDecisionSurfaceChange: (Boolean) -> Unit = {},
) {
val state by vm.runDetail.collectAsStateWithLifecycle()
val runsState by vm.runs.collectAsStateWithLifecycle()
@@ -217,6 +218,7 @@ fun RunDetailScreen(
modifier = Modifier.padding(horizontal = SPACING_L, vertical = SPACING_S),
openRequest = requestDecision,
onOpenRequestHandled = onDecisionRequestHandled,
onSurfaceOpenChange = onDecisionSurfaceChange,
)
StateCrossfade(
phase = detailLoadPhase(state.error, hasData = run != null),
@@ -83,17 +83,29 @@ class PipelinesNavTest {
}
@Test
fun thePillStandsDownOnlyWhileAConversationIsOpen() {
fun thePillStandsDownWhileAConversationOrARunDecisionSurfaceIsOpen() {
// An open conversation (the chat transcript and composer) hides the pill;
// the chat list keeps it, and so does every other destination.
assertFalse(destinationPillVisible("chat", conversationOpen = true))
assertTrue(destinationPillVisible("chat", conversationOpen = false))
assertFalse(destinationPillVisible("chat", conversationOpen = true, decisionOpen = false))
assertTrue(destinationPillVisible("chat", conversationOpen = false, decisionOpen = false))
for (route in listOf("pipelines", "runs", "settings", null)) {
assertTrue(destinationPillVisible(route, conversationOpen = false))
assertTrue(destinationPillVisible(route, conversationOpen = false, decisionOpen = false))
}
// A conversation only exists on the chat route; even if the flag were set
// elsewhere the pill stays, so a background chat never hides it.
assertTrue(destinationPillVisible("runs", conversationOpen = true))
assertTrue(destinationPillVisible("runs", conversationOpen = true, decisionOpen = false))
// A run's pending-decision surface (the decision sheet the operator opens
// from the run summary) hides the pill on the Runs destination, and only
// while it is open: the run being read, its stage pane, an artifact or a
// graph all keep it.
assertFalse(destinationPillVisible("runs", conversationOpen = false, decisionOpen = true))
assertTrue(destinationPillVisible("runs", conversationOpen = false, decisionOpen = false))
// The decision surface is a state of the run view, not a route, so the
// predicate hides it everywhere it were reported, exactly as for a
// conversation — and never for the chat list's own conversation flag.
for (route in listOf("pipelines", "runs", "chat", "settings", null)) {
assertFalse(destinationPillVisible(route, conversationOpen = false, decisionOpen = true))
}
}
@Test
@@ -120,16 +132,18 @@ class PipelinesNavTest {
// when hidden.
for (route in listOf("pipelines", "chat", "runs", "settings", null)) {
for (open in listOf(false, true)) {
val drawn = destinationPillVisible(route, open)
val inset = pillScrollInset(drawn)
assertTrue(
"scroll clearance held behind a hidden pill on $route (open=$open)",
drawn || inset.value == 0f,
)
assertTrue(
"list not cleared of a drawn pill on $route (open=$open)",
!drawn || inset.value == drawnInset.value,
)
for (deciding in listOf(false, true)) {
val drawn = destinationPillVisible(route, open, deciding)
val inset = pillScrollInset(drawn)
assertTrue(
"scroll clearance held behind a hidden pill on $route (open=$open, deciding=$deciding)",
drawn || inset.value == 0f,
)
assertTrue(
"list not cleared of a drawn pill on $route (open=$open, deciding=$deciding)",
!drawn || inset.value == drawnInset.value,
)
}
}
}
}