android: share one LabelChip and drop the dead Run.artifacts flag
Consolidate the omni-search row type badge and the stage-type chip into a single ui/components/LabelChip composable, so the chip's shape, colour and type live in one place and a second copy cannot drift. Remove the unused SearchTarget.Run.artifacts field: an artifact hit and a step hit now resolve identically to the visit's stage pane, whose fixed section order already leads with the artifacts. Correct the SearchUiState.failed KDoc to describe how prior results are kept, and update OmniSearchResultsTest to the simplified target.
This commit is contained in:
@@ -161,15 +161,14 @@ sealed interface SearchTarget {
|
||||
|
||||
/**
|
||||
* Open the Runs destination at this run. [sequence] > 0 opens the recorded
|
||||
* visit, and [field]/[artifacts] name the section to reveal: a text match
|
||||
* opens the run-detail section holding the matched field, an artifact hit the
|
||||
* visit's stage pane (whose gallery leads), and a step hit the visit's pane.
|
||||
* visit's stage pane, whose fixed section order leads with the visit's
|
||||
* artifacts, so an artifact and a step hit resolve the same way. [field] names
|
||||
* the run-detail section holding a matched text field for a text match.
|
||||
*/
|
||||
data class Run(
|
||||
val runId: Long,
|
||||
val sequence: Int = 0,
|
||||
val field: String = "",
|
||||
val artifacts: Boolean = false,
|
||||
) : SearchTarget
|
||||
}
|
||||
|
||||
@@ -183,7 +182,7 @@ fun searchTarget(hit: SearchResult): SearchTarget? = when {
|
||||
hit.run != null -> SearchTarget.Run(hit.run.id)
|
||||
hit.step != null -> SearchTarget.Run(hit.step.runId, hit.step.sequence)
|
||||
hit.field != null -> SearchTarget.Run(hit.field.runId, hit.field.sequence, field = hit.field.field)
|
||||
hit.artifact != null -> SearchTarget.Run(hit.artifact.runId, hit.artifact.sequence, artifacts = true)
|
||||
hit.artifact != null -> SearchTarget.Run(hit.artifact.runId, hit.artifact.sequence)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -277,8 +276,10 @@ fun SearchUiState.loaded(response: SearchResponse): SearchUiState =
|
||||
copy(results = response.results, loading = false, error = null, loaded = true)
|
||||
|
||||
/**
|
||||
* A load failed: stop loading and record the reason, keeping any previous results
|
||||
* visible rather than blanking the panel.
|
||||
* A load failed: stop loading and record the reason. The previous results are
|
||||
* kept in the state (the panel shows the error in their place until the error
|
||||
* clears), so a later successful reply never has to re-fetch what was already
|
||||
* shown.
|
||||
*/
|
||||
fun SearchUiState.failed(message: String?): SearchUiState =
|
||||
copy(loading = false, error = message, loaded = true)
|
||||
|
||||
@@ -30,6 +30,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import net.awan.pipelines.data.protocol.SearchResult
|
||||
import net.awan.pipelines.ui.components.LabelChip
|
||||
import net.awan.pipelines.ui.theme.SEARCH_PROGRESS_DP
|
||||
import net.awan.pipelines.ui.theme.SPACING_L
|
||||
import net.awan.pipelines.ui.theme.SPACING_M
|
||||
@@ -152,7 +153,7 @@ private fun SearchResultRow(
|
||||
.padding(horizontal = SPACING_L, vertical = SPACING_M),
|
||||
horizontalArrangement = Arrangement.spacedBy(SPACING_M),
|
||||
) {
|
||||
TypeBadge(row.badge)
|
||||
LabelChip(row.badge, SPACING_S, SPACING_XXS)
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.spacedBy(SPACING_XXS),
|
||||
@@ -183,22 +184,6 @@ private fun SearchResultRow(
|
||||
}
|
||||
}
|
||||
|
||||
/** The row's type badge; its label carries the type, so it never relies on colour. */
|
||||
@Composable
|
||||
private fun TypeBadge(label: String) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(50),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = SPACING_S, vertical = SPACING_XXS),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Renders a snippet, emphasising the matched span with weight+underline (not colour). */
|
||||
private fun annotatedSnippet(spans: List<SnippetSpan>): AnnotatedString = buildAnnotatedString {
|
||||
spans.forEach { span ->
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.awan.pipelines.ui.components
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
|
||||
/**
|
||||
* A small rounded tonal chip whose label carries its meaning, so it never relies
|
||||
* on colour alone. One shape, colour and type across the app; a caller passes
|
||||
* only the padding its context needs (the search row's type badge is tighter than
|
||||
* the stage-type chip), so a second copy of the chip never appears.
|
||||
*/
|
||||
@Composable
|
||||
internal fun LabelChip(label: String, horizontalPadding: Dp, verticalPadding: Dp) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(50),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = horizontalPadding, vertical = verticalPadding),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
@@ -17,7 +16,6 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.PrimaryScrollableTabRow
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Tab
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
@@ -45,6 +43,7 @@ import net.awan.pipelines.ui.components.CodeBlock
|
||||
import net.awan.pipelines.ui.components.CollapsibleSectionBody
|
||||
import net.awan.pipelines.ui.components.DetailTabBody
|
||||
import net.awan.pipelines.ui.components.KeyValueRow
|
||||
import net.awan.pipelines.ui.components.LabelChip
|
||||
import net.awan.pipelines.ui.components.PaneIdentity
|
||||
import net.awan.pipelines.ui.components.SectionExpansionState
|
||||
import net.awan.pipelines.ui.components.SectionHeader
|
||||
@@ -615,17 +614,7 @@ internal fun StageFieldRow(field: StageField) {
|
||||
/** A small rounded chip naming the stage type (model / ntfy / …). */
|
||||
@Composable
|
||||
internal fun StageTypeChip(label: String) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(50),
|
||||
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSecondaryContainer,
|
||||
modifier = Modifier.padding(horizontal = STAGE_CHIP_PAD_H, vertical = SPACING_XS),
|
||||
)
|
||||
}
|
||||
LabelChip(label, STAGE_CHIP_PAD_H, SPACING_XS)
|
||||
}
|
||||
|
||||
/** A section key as its visible title ("definition" → "Definition"). */
|
||||
|
||||
@@ -108,7 +108,7 @@ class OmniSearchResultsTest {
|
||||
searchTarget(hit(Protocol.SEARCH_KIND_FIELD)),
|
||||
)
|
||||
assertEquals(
|
||||
SearchTarget.Run(11L, sequence = 4, artifacts = true),
|
||||
SearchTarget.Run(11L, sequence = 4),
|
||||
searchTarget(hit(Protocol.SEARCH_KIND_ARTIFACT)),
|
||||
)
|
||||
}
|
||||
@@ -155,7 +155,7 @@ class OmniSearchResultsTest {
|
||||
|
||||
@Test
|
||||
fun anArtifactTargetOpensTheVisitsStagePane() {
|
||||
val resolved = resolveRunTarget(SearchTarget.Run(11L, sequence = 2, artifacts = true), 11L, steps)
|
||||
val resolved = resolveRunTarget(SearchTarget.Run(11L, sequence = 2), 11L, steps)
|
||||
assertEquals(MasterPane.Stage, resolved.pane)
|
||||
assertEquals("builder", resolved.stageKey)
|
||||
assertEquals(0, resolved.stageVisit)
|
||||
|
||||
Reference in New Issue
Block a user