diff --git a/android/README.md b/android/README.md index f7845240..39189cc4 100644 --- a/android/README.md +++ b/android/README.md @@ -4424,6 +4424,92 @@ and a selection navigating (the visual review owns the device, per the brief's device policy); the panel's pure logic is exercised by the unit tests and the compile only. +## Search type icons, a kind filter and sorting (17 Oct 2026) + +The omni-search results panel replaces each row's text type badge with a glyph and +gains the runs list's filter and sort controls. `android/` only; no new dependency +(the glyphs and the `FilterList`/`Sort` menu icons are from the already-declared +`material-icons-extended`), no Pipelines server/Go/installer/Docker file touched, +no run started from the app, and the operator's phone was never used. + +- **Type glyph per result.** `OmniSearchResults.searchResultIcon` maps a hit to a + glyph: pipeline → the app's pipeline icon (`AccountTree`), run → `History`, + version → `Commit`, step → `Segment`, field → `Subject` (text lines, distinct + from the gallery's `Description` document glyph), and an unknown kind → + `HelpOutline`. An artifact reuses the gallery's own + classification (`artifactKind`/`artifactIcon` in `ui/graph/ArtifactType.kt`) + rather than a second mapping, so a search artifact and a gallery tile never + disagree. The glyph replaces the `LabelChip` badge (the chip is removed); the + payload decides the branch exactly as `searchRow` does. +- **Kind in words.** The glyph's `contentDescription` is `searchResultKindLabel` + ("Pipeline", "Run", "Pipeline version", "Step", "Field", or " + artifact", e.g. "PDF artifact" via the new `artifactKindLabel`), so a screen + reader hears the type the icon alone cannot carry. The row and the filter use + the same kind vocabulary ("Fields"). +- **Kind filter, narrowing server-side.** `SearchKindFilter` lists the filter + options - All kinds, Pipelines, Runs, Steps, Fields, Artifacts, Versions - and + each carries the server's own `SearchRequest.kind` value, sent verbatim + (`PipelinesRepository.search(query, kind)`). There is deliberately no "Prompts" + option: the server's search kinds are pipeline/version/run/step/field/artifact + only (`internal/protocol/search.go`), so a prompts filter could never match and + would visibly do nothing. +- **Sort, honest about its reach.** `SearchSort` offers Relevance (the server's + own score/recency/tie-break order, left untouched), Newest first (by `recency`) + and Name (by the displayed title). The server's search command takes no sort, so + Newest and Name order the results already in hand; the sort menu carries a + "Sort results in hand" caption, the collapsed summary appends " (in hand)" for + those two orders, and the icon's description reads "Sort results in hand". A + server-side sort would need a `sort` field on `SearchRequest`/the search + command. +- **Shared controls, remembered choice.** The panel header uses the same + `FilterMenu` and `SortMenu` the runs list uses (no new pattern), plus a one-line + `searchControlsSummary` ("All kinds · Relevance") so the collapsed controls show + the active choice. The header row carries a top inset so the filter's count badge + stays inside the panel's rounded surface. The kind and order persist as `search_filter_kind`/ + `search_sort` in `SettingsRepository`, so they survive a query change, the + results streaming in, and a restart. +- **Tests.** `OmniSearchResultsTest` now covers the glyph per kind and per + artifact content type (checked against the gallery's + `artifactIcon(artifactKind(...))`), the kind-in-words label, the kind filter + narrowing a mixed list, the Relevance/Newest/Name ordering including a recency + tie and a title tie, the in-hand summary suffix, the filter-aware empty-state + line (`searchPanelEmptyMessage`, which replaced the panel's now-orphaned + `isEmptyResult` and names the active kind filter), and the stored-value + fallbacks; `ArtifactTypeTest` covers `artifactKindLabel`. + +Evidence (macOS, JDK 17 from Homebrew `openjdk@17`, +`ANDROID_HOME=/Users/alan/Library/Android/sdk`, Gradle 8.11.1 from the wrapper +cache, every command `--no-daemon --offline --console=plain`; this build includes +the visual-review fixes: the header's badge inset, the visible in-hand sort +caption/summary, and the consistent "Field" vocabulary with a distinct glyph): + +- `gradle :app:testDebugUnitTest --rerun` → `BUILD SUCCESSFUL`; the 47 result XMLs + aggregate to **433 tests, 0 failures, 0 errors, 0 skipped** + (`OmniSearchResultsTest` 28, `ArtifactTypeTest` 7). +- `gradle :app:assembleDebug` → `BUILD SUCCESSFUL`; + `app/build/outputs/apk/debug/app-debug.apk` is **18,715,466 bytes**, sha256 + `f4cee0d4949ac587601f01a96733b3d865431bd5376ac6d7d182222a40999bf5`. +- **APK publish.** Copied to + `~/.local/share/pipelines/data/artifacts/231/4/pipelines-debug-wip-f31f150.apk` + (`f31f150` = `git rev-parse --short HEAD`). The LAN URL + `http://10.0.0.75:8080/artifacts/231/4/pipelines-debug-wip-f31f150.apk` returned + `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`, + `Content-Length: 18715466`, and the downloaded bytes' sha256 + `f4cee0d4949ac587601f01a96733b3d865431bd5376ac6d7d182222a40999bf5` matched the + local file. +- `gradle :app:lintDebug` fails on two pre-existing `NewApi` errors + (`res/values{,-night}/themes.xml`: `windowLightNavigationBar` requires API 27, + min is 26), unrelated to and not introduced by this change; the report names no + file touched by this change. +- No packaged template and no packaged authoring skill reference + (`internal/author/skill/references/*`, `internal/author/install.go`'s inventory) + documents the app's search panel - the only "omni search" reference describes + the TUI - so none needed updating. + +Not verified in this pass: device frames of the panel and the open controls (the +visual review owns the device, per the brief's device policy); the pure logic is +exercised by the unit tests and the compile only. + ## Chat destination and multiple conversations (16 Oct 2026) The first Chat slice: the destination, the server session list and several diff --git a/android/app/src/main/java/net/awan/pipelines/data/PipelinesRepository.kt b/android/app/src/main/java/net/awan/pipelines/data/PipelinesRepository.kt index a06126ef..6feff8ec 100644 --- a/android/app/src/main/java/net/awan/pipelines/data/PipelinesRepository.kt +++ b/android/app/src/main/java/net/awan/pipelines/data/PipelinesRepository.kt @@ -174,13 +174,13 @@ class PipelinesRepository( /** * Sends one omni-search query over the shared transport and returns the raw - * reply envelope. The server command is still landing, so the reply is - * classified by its envelope type: [Protocol.SEARCH_RESULTS] is the accepted - * search, and any other type is an unexpected reply the caller reports rather - * than parsing. The typed result payload is added with the results item. + * reply envelope. [kind] narrows the server-side scan to one SearchKind (see + * SearchKindFilter); a blank kind searches every kind. The reply is classified + * by its envelope type: [Protocol.SEARCH_RESULTS] is the accepted search, and + * any other type is an unexpected reply the caller reports rather than parsing. */ - suspend fun search(query: String): Message = - client.call(Message(type = Protocol.SEARCH, search = SearchRequest(query = query.trim()))) + suspend fun search(query: String, kind: String = ""): Message = + client.call(Message(type = Protocol.SEARCH, search = SearchRequest(query = query.trim(), kind = kind))) /** Fetches an artifact's bytes (image preview) over the shared HTTP client. */ suspend fun fetchArtifactBytes(url: String): ByteArray = client.fetchBytes(url) diff --git a/android/app/src/main/java/net/awan/pipelines/data/SettingsRepository.kt b/android/app/src/main/java/net/awan/pipelines/data/SettingsRepository.kt index 7daffe17..49164171 100644 --- a/android/app/src/main/java/net/awan/pipelines/data/SettingsRepository.kt +++ b/android/app/src/main/java/net/awan/pipelines/data/SettingsRepository.kt @@ -77,6 +77,13 @@ class SettingsRepository(context: Context) { private val _notificationPermissionAsked = MutableStateFlow(prefs.getBoolean(KEY_NOTIFICATION_PERMISSION_ASKED, false)) val notificationPermissionAsked: StateFlow = _notificationPermissionAsked.asStateFlow() + // The omni-search kind narrowing (a server kind, "" = every kind) and the + // search order, stored as their stable values and resolved by the UI. + private val _searchFilterKind = MutableStateFlow(prefs.getString(KEY_SEARCH_FILTER_KIND, "").orEmpty()) + val searchFilterKind: StateFlow = _searchFilterKind.asStateFlow() + + private val _searchSort = MutableStateFlow(prefs.getString(KEY_SEARCH_SORT, "").orEmpty()) + val searchSort: StateFlow = _searchSort.asStateFlow() fun setServerUrl(value: String) { val trimmed = value.trim() @@ -155,6 +162,16 @@ class SettingsRepository(context: Context) { prefs.edit().putBoolean(KEY_NOTIFICATION_PERMISSION_ASKED, asked).apply() } + fun setSearchFilterKind(value: String) { + _searchFilterKind.value = value + prefs.edit().putString(KEY_SEARCH_FILTER_KIND, value).apply() + } + + fun setSearchSort(value: String) { + _searchSort.value = value + prefs.edit().putString(KEY_SEARCH_SORT, value).apply() + } + /** True only when the user has explicitly supplied both required values. */ fun isConfigured(): Boolean = _serverUrl.value.isNotBlank() && _workspace.value.isNotBlank() @@ -173,5 +190,7 @@ class SettingsRepository(context: Context) { const val KEY_CHAT_SEEN = "chat_seen" const val KEY_ATTENTION = "attention" const val KEY_NOTIFICATION_PERMISSION_ASKED = "notification_permission_asked" + const val KEY_SEARCH_FILTER_KIND = "search_filter_kind" + const val KEY_SEARCH_SORT = "search_sort" } } diff --git a/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt b/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt index d338999a..dafe2157 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/AppViewModel.kt @@ -83,6 +83,10 @@ class AppViewModel( val pipelineFilterRunStatuses: StateFlow = settings.pipelineFilterRunStatuses val pipelineFilterName: StateFlow = settings.pipelineFilterName + /** The stored omni-search kind narrowing (a server kind, "" = every kind) and order. */ + val searchKind: StateFlow = settings.searchFilterKind + val searchSort: StateFlow = settings.searchSort + private val _serverUrlDraft = MutableStateFlow(settings.serverUrl.value) val serverUrlDraft: StateFlow = _serverUrlDraft.asStateFlow() @@ -685,6 +689,19 @@ class AppViewModel( fun setPipelineFilterName(value: String) = settings.setPipelineFilterName(value) + /** + * Narrows the search to a server kind (see SearchKindFilter). The kind is a + * request parameter, so a narrowed search re-issues the live query at once + * rather than waiting for the next keystroke. + */ + fun setSearchKind(serverKind: String) { + settings.setSearchFilterKind(serverKind) + rerunSearchImmediately() + } + + /** Records the search order; it orders the results already in hand, so no refetch. */ + fun setSearchSort(storageKey: String) = settings.setSearchSort(storageKey) + private fun awaitConnected() { viewModelScope.launch { val connected = withTimeoutOrNull(CONNECT_TIMEOUT_MILLIS) { @@ -803,7 +820,13 @@ class AppViewModel( } /** Runs the current query immediately (the IME's search action), skipping the debounce. */ - fun searchNow() { + fun searchNow() = rerunSearchImmediately() + + /** + * Re-issues the live query at once, cancelling any pending debounce: the IME + * search action and a kind-filter change both want the newest request now. + */ + private fun rerunSearchImmediately() { val query = _search.value.query if (query.isBlank()) return val edit = searchSequencer.edit(query) @@ -821,7 +844,10 @@ class AppViewModel( private suspend fun runSearch(request: SentSearch) { _search.value = _search.value.copy(loading = true, error = null) try { - val reply = repository.search(request.query) + // The active kind filter is a request parameter; resolve it from the + // stored value (a blank/stale one falls back to every kind). + val kind = SearchKindFilter.fromStorage(settings.searchFilterKind.value).serverKind + val reply = repository.search(request.query, kind) // A reply for a superseded query must never land: the sequencer only // accepts the newest sent token. if (!searchSequencer.accepts(request.token)) return diff --git a/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt b/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt index 2533772c..2bbc9553 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/OmniSearchResults.kt @@ -1,6 +1,15 @@ package net.awan.pipelines.ui +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.HelpOutline +import androidx.compose.material.icons.automirrored.filled.Segment +import androidx.compose.material.icons.automirrored.filled.Subject +import androidx.compose.material.icons.filled.AccountTree +import androidx.compose.material.icons.filled.Commit +import androidx.compose.material.icons.filled.History import androidx.compose.runtime.Immutable +import androidx.compose.ui.graphics.vector.ImageVector +import java.time.OffsetDateTime import net.awan.pipelines.data.protocol.Protocol import net.awan.pipelines.data.protocol.RunStep import net.awan.pipelines.data.protocol.SearchArtifact @@ -11,22 +20,50 @@ import net.awan.pipelines.data.protocol.SearchResult import net.awan.pipelines.data.protocol.SearchRun import net.awan.pipelines.data.protocol.SearchStep import net.awan.pipelines.data.protocol.SearchVersion +import net.awan.pipelines.ui.graph.artifactIcon +import net.awan.pipelines.ui.graph.artifactKind +import net.awan.pipelines.ui.graph.artifactKindLabel import net.awan.pipelines.ui.screens.runTimeline // --------------------------------------------------------------------------- -// Row model: the badge, title and secondary line of one result. Pure (no +// Row model: the glyph, title and secondary line of one result. Pure (no // Compose, no coroutines), so the mapping for every kind is unit-testable. // --------------------------------------------------------------------------- -/** The short mixed-list type badge for a result kind. */ -fun searchBadge(kind: String): String = when (kind) { - Protocol.SEARCH_KIND_PIPELINE, Protocol.SEARCH_KIND_VERSION -> "pipeline" - Protocol.SEARCH_KIND_RUN -> "run" - Protocol.SEARCH_KIND_STEP -> "step" - Protocol.SEARCH_KIND_ARTIFACT -> "artifact" - // A text ("field") match and an unknown kind both read as a generic match; - // the unknown one is additionally labelled read-only by [searchRow]. - else -> "match" +/** + * The glyph that names one result's type at a glance: the result's kind, and for + * an artifact the file type its content resolves to. The artifact mapping is the + * gallery's own ([artifactKind]/[artifactIcon]) rather than a second copy, so the + * two surfaces can never disagree about a file. The payload decides the branch, + * exactly as [searchRow] does, so a known payload with an unknown kind string + * still gets the right glyph and an unrecognised result falls back to a neutral + * mark instead of vanishing. + */ +fun searchResultIcon(hit: SearchResult): ImageVector = when { + hit.pipeline != null -> Icons.Filled.AccountTree + hit.version != null -> Icons.Filled.Commit + hit.run != null -> Icons.Filled.History + hit.step != null -> Icons.AutoMirrored.Filled.Segment + hit.field != null -> Icons.AutoMirrored.Filled.Subject + hit.artifact != null -> artifactIcon(artifactKind(hit.artifact.contentType, hit.artifact.name)) + else -> Icons.AutoMirrored.Filled.HelpOutline +} + +/** + * The kind in words for a row's accessible description, so a screen reader hears + * what the row is even though the glyph alone carries no text. An artifact is + * named by its own content type ("Image artifact", "JSON artifact"), from the + * same gallery classification [searchResultIcon] uses. + */ +fun searchResultKindLabel(hit: SearchResult): String = when { + hit.pipeline != null -> "Pipeline" + hit.version != null -> "Pipeline version" + hit.run != null -> "Run" + hit.step != null -> "Step" + hit.field != null -> "Field" + hit.artifact != null -> + "${artifactKindLabel(artifactKind(hit.artifact.contentType, hit.artifact.name))} artifact" + else -> "Unrecognised result" } /** @@ -38,13 +75,12 @@ fun searchBadge(kind: String): String = when (kind) { data class SnippetSpan(val text: String, val matched: Boolean) /** - * One rendered search row: its type badge, a title and a secondary line. [snippet] - * is non-null only for a text ("field") match and carries the snippet split so the - * matched span is distinguishable without colour. + * One rendered search row: its title and a secondary line. [snippet] is non-null + * only for a text ("field") match and carries the snippet split so the matched + * span is distinguishable without colour. */ @Immutable data class SearchRow( - val badge: String, val title: String, val secondary: String, val snippet: List? = null, @@ -56,7 +92,6 @@ data class SearchRow( * renders its stable target (or a placeholder) and a `read-only` note. */ fun searchRow(hit: SearchResult, query: String): SearchRow { - val badge = searchBadge(hit.kind) val pipeline: SearchPipeline? = hit.pipeline val version: SearchVersion? = hit.version val run: SearchRun? = hit.run @@ -65,12 +100,10 @@ fun searchRow(hit: SearchResult, query: String): SearchRow { val artifact: SearchArtifact? = hit.artifact return when { pipeline != null -> SearchRow( - badge, pipeline.name.ifBlank { "pipeline ${pipeline.id}" }, "pipeline ${pipeline.id} · v${pipeline.version} · ${stageCountText(pipeline.stages)}", ) version != null -> SearchRow( - badge, "pipeline ${version.pipelineId} · v${version.version}", listOfNotNull( version.contentHash.takeIf { it.isNotBlank() }?.let { "content $it" }, @@ -78,7 +111,6 @@ fun searchRow(hit: SearchResult, query: String): SearchRow { ).joinToString(" · "), ) run != null -> SearchRow( - badge, "run #${run.id}" + run.pipelineName.takeIf { it.isNotBlank() }?.let { " · $it" }.orEmpty(), listOfNotNull( run.status.takeIf { it.isNotBlank() }, @@ -87,18 +119,15 @@ fun searchRow(hit: SearchResult, query: String): SearchRow { ).joinToString(" · "), ) step != null -> SearchRow( - badge, "run #${step.runId} · ${step.stage.ifBlank { "step" }} visit ${step.visit}", stepSecondary(step), ) field != null -> SearchRow( - badge, "run #${field.runId} · step ${field.sequence} · ${field.field.ifBlank { "field" }}", field.snippet, snippetSpans(field.snippet, query), ) artifact != null -> SearchRow( - badge, artifact.name.ifBlank { "artifact" }, listOfNotNull( "run #${artifact.runId}", @@ -108,7 +137,6 @@ fun searchRow(hit: SearchResult, query: String): SearchRow { ).joinToString(" · "), ) else -> SearchRow( - badge, hit.target.ifBlank { "Unrecognised result" }, if (hit.kind.isBlank()) "read-only" else "kind \"${hit.kind}\" · read-only", ) @@ -145,6 +173,92 @@ fun snippetSpans(snippet: String, query: String): List { } } +// --------------------------------------------------------------------------- +// Narrowing and ordering: the filter/sort control's pure model. Pure (no +// Compose), so the kind narrowing and each order are unit-testable. +// --------------------------------------------------------------------------- + +/** + * The kind narrowing the search filter control offers. [serverKind] is exactly the + * server's SearchRequest kind vocabulary (internal/protocol/search.go), sent and + * stored verbatim; [All] is the empty kind. + * + * There is deliberately no "prompts" entry: the server has no such kind (its + * kinds are pipeline, version, run, step, field and artifact), so a filter that + * could only ever match nothing is not offered. + */ +enum class SearchKindFilter(val label: String, val serverKind: String) { + All("All kinds", ""), + Pipelines("Pipelines", Protocol.SEARCH_KIND_PIPELINE), + Runs("Runs", Protocol.SEARCH_KIND_RUN), + Steps("Steps", Protocol.SEARCH_KIND_STEP), + Fields("Fields", Protocol.SEARCH_KIND_FIELD), + Artifacts("Artifacts", Protocol.SEARCH_KIND_ARTIFACT), + Versions("Versions", Protocol.SEARCH_KIND_VERSION); + + companion object { + val Default = All + + /** Resolves a stored kind, tolerating a blank/stale value by returning [Default]. */ + fun fromStorage(value: String?): SearchKindFilter = + entries.firstOrNull { it.serverKind == value } ?: Default + } +} + +/** + * The orders the search sort control offers. [Relevance] keeps the server's own + * ranking (score, then recency, then a stable kind/target tie-break). [Newest] + * and [Name] cannot be asked of the server - its search command takes only a + * query, an optional kind and a limit - so they order the results already in + * hand, and the control says so. + */ +enum class SearchSort(val label: String, val storageKey: String) { + Relevance("Relevance", "relevance"), + Newest("Newest first", "newest"), + Name("Name", "name"); + + companion object { + val Default = Relevance + + /** Resolves a stored order, tolerating a blank/stale value by returning [Default]. */ + fun fromStorage(value: String?): SearchSort = + entries.firstOrNull { it.storageKey == value } ?: Default + } +} + +/** The one-line summary of the active filter and sort the collapsed control shows. */ +fun searchControlsSummary(kind: SearchKindFilter, sort: SearchSort): String { + // Only Relevance is the server's own ranking; the other orders run on the + // results in hand, so the summary says so even when the menu is closed. + val reach = if (sort == SearchSort.Relevance) "" else " (in hand)" + return "${kind.label} · ${sort.label}$reach" +} + +/** + * Narrows [results] to [filter]'s kind. The filter is also sent to the server + * (SearchRequest.kind), so this only re-narrows the results already in hand, + * keeping the panel honest while a narrowed request loads. + */ +fun filterSearchResults(results: List, filter: SearchKindFilter): List = + if (filter == SearchKindFilter.All) results else results.filter { it.kind == filter.serverKind } + +/** + * Orders [results] by [sort]. [Relevance] leaves the server's ranking untouched; + * [Newest] and [Name] sort the results in hand (the server has no sort). The + * sorts are stable, so two results that tie keep the server's order rather than + * swapping arbitrarily. + */ +fun sortSearchResults(results: List, sort: SearchSort): List = when (sort) { + SearchSort.Relevance -> results + SearchSort.Newest -> results.sortedWith( + compareByDescending { parseInstant(it.recency.orEmpty()) ?: OffsetDateTime.MIN }, + ) + SearchSort.Name -> results + .map { it to searchRow(it, "").title } + .sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.second }) + .map { it.first } +} + // --------------------------------------------------------------------------- // Navigation: the destination a result resolves to. Pure, so the mapping for // every kind is unit-testable. @@ -284,6 +398,22 @@ fun SearchUiState.loaded(response: SearchResponse): SearchUiState = fun SearchUiState.failed(message: String?): SearchUiState = copy(loading = false, error = message, loaded = true) -/** Whether the panel shows the explicit, query-naming empty state. */ -fun SearchUiState.isEmptyResult(): Boolean = - error == null && !loading && loaded && results.isEmpty() && query.isNotBlank() +/** + * The empty-state line the panel shows when it has no rows to render for [query] + * under [kind], or null when it is showing rows, progress or nothing at all. + * [shown] is the filtered and sorted list actually displayed, so a filter that + * empties the list reports itself ("No runs match …") rather than the generic + * line. Pure, so the empty state is unit-testable without a device. + */ +fun searchPanelEmptyMessage( + state: SearchUiState, + shown: List, + kind: SearchKindFilter, +): String? = when { + state.error != null -> null + shown.isNotEmpty() -> null + state.loading -> null + state.query.isBlank() -> null + kind == SearchKindFilter.All -> "No matches for \"${state.query}\"." + else -> "No ${kind.label.lowercase()} match \"${state.query}\"." +} diff --git a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt index ae1a60d1..da010126 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/PipelinesApp.kt @@ -179,6 +179,8 @@ fun PipelinesApp( // the chat list for the conversation. val conversationOpen by vm.conversationOpen.collectAsStateWithLifecycle() val pillVisible = destinationPillVisible(currentRoute, conversationOpen) + val searchKind by vm.searchKind.collectAsStateWithLifecycle() + val searchSort by vm.searchSort.collectAsStateWithLifecycle() /** Back/scrim/close and a selection all dismiss the morph and clear the panel. */ val dismissSearch: () -> Unit = { @@ -376,9 +378,13 @@ fun PipelinesApp( verticalArrangement = Arrangement.Bottom, horizontalAlignment = Alignment.End, ) { - if (searchState.open && searchState.query.isNotBlank()) { + if (searchState.open) { SearchResultsPanel( state = search, + kind = SearchKindFilter.fromStorage(searchKind), + sort = SearchSort.fromStorage(searchSort), + onKind = { vm.setSearchKind(it.serverKind) }, + onSort = { vm.setSearchSort(it.storageKey) }, onSelect = onSelectResult, modifier = Modifier .fillMaxWidth() diff --git a/android/app/src/main/java/net/awan/pipelines/ui/SearchResultsPanel.kt b/android/app/src/main/java/net/awan/pipelines/ui/SearchResultsPanel.kt index 4190d851..3e97dbef 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/SearchResultsPanel.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/SearchResultsPanel.kt @@ -12,6 +12,7 @@ import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -30,31 +31,47 @@ 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.components.FilterCheckItem +import net.awan.pipelines.ui.components.FilterMenu +import net.awan.pipelines.ui.components.SortMenu +import net.awan.pipelines.ui.theme.ICON_LIST_DP 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 import net.awan.pipelines.ui.theme.SPACING_S -import net.awan.pipelines.ui.theme.SPACING_XXS import net.awan.pipelines.ui.theme.SPACING_XL +import net.awan.pipelines.ui.theme.SPACING_XS +import net.awan.pipelines.ui.theme.SPACING_XXS import net.awan.pipelines.ui.theme.pipelinesText /** * The omni-search results panel: one scrolling surface that sits above the search - * field. It renders the last accepted results, and while a newer query loads it - * keeps those results and adds a thin progress bar rather than blanking; a - * failure is reported without discarding what is already shown. Its height is - * bounded by the caller (the window's IME/navigation-bar insets), so it scrolls - * inside the remainder instead of running under the keyboard. + * field. It leads with the filter and sort controls (the same shared menu + * controls the runs list uses), then renders the last accepted results; while a + * newer query loads it keeps those results and adds a thin progress bar rather + * than blanking, and a failure is reported without discarding what is already + * shown. Its height is bounded by the caller (the window's IME/navigation-bar + * insets), so it scrolls inside the remainder instead of running under the + * keyboard. */ @Composable internal fun SearchResultsPanel( state: SearchUiState, + kind: SearchKindFilter, + sort: SearchSort, + onKind: (SearchKindFilter) -> Unit, + onSort: (SearchSort) -> Unit, onSelect: (SearchResult) -> Unit, modifier: Modifier = Modifier, ) { val scheme = MaterialTheme.colorScheme val error = state.error + // The filter and sort are applied to the results in hand as well as being sent + // to the server (the kind) or held client-side (the order), so the list always + // matches the active control, even for the moment a narrowed request loads. + val shown = remember(state.results, kind, sort) { + sortSearchResults(filterSearchResults(state.results, kind), sort) + } Surface( modifier = modifier, shape = RoundedCornerShape(SPACING_XL), @@ -63,6 +80,8 @@ internal fun SearchResultsPanel( shadowElevation = 6.dp, ) { Column(Modifier.fillMaxWidth()) { + SearchControls(kind = kind, sort = sort, onKind = onKind, onSort = onSort) + HorizontalDivider(color = scheme.outlineVariant) // A refresh of an already-populated panel shows progress without // replacing the results; the first load shows the searching row below. if (state.loading && state.results.isNotEmpty()) { @@ -70,14 +89,68 @@ internal fun SearchResultsPanel( } when { error != null -> PanelMessage(error, isError = true) - state.isEmptyResult() -> PanelMessage("No matches for \"${state.query}\".", isError = false) + shown.isNotEmpty() -> SearchResultList(shown, state.query, onSelect) state.loading && state.results.isEmpty() -> SearchingRow() - state.results.isNotEmpty() -> SearchResultList(state.results, state.query, onSelect) + else -> searchPanelEmptyMessage(state, shown, kind)?.let { PanelMessage(it, isError = false) } } } } } +/** + * The search surface's filter and sort control, the same shared [FilterMenu] and + * [SortMenu] the runs list uses rather than a new pattern, plus the one-line + * summary of the active choice so the collapsed controls are legible. The kind + * filter narrows server-side; the sort orders the results in hand. + */ +@Composable +private fun SearchControls( + kind: SearchKindFilter, + sort: SearchSort, + onKind: (SearchKindFilter) -> Unit, + onSort: (SearchSort) -> Unit, +) { + Row( + // The top inset leaves room for the filter badge, which is drawn above the + // icon button; without it the badge spills over the panel's rounded edge. + modifier = Modifier + .fillMaxWidth() + .padding(start = SPACING_S, end = SPACING_XS, top = SPACING_S, bottom = SPACING_XS), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(SPACING_XS), + ) { + FilterMenu( + activeCount = if (kind == SearchKindFilter.All) 0 else 1, + contentDescription = "Filter results", + resetLabel = "Clear filter", + onReset = { onKind(SearchKindFilter.Default) }, + ) { dismiss -> + SearchKindFilter.entries.forEach { option -> + FilterCheckItem(option.label, option == kind) { + onKind(option) + dismiss() + } + } + } + SortMenu( + options = SearchSort.entries, + selected = sort, + label = { it.label }, + header = "Sort results in hand", + contentDescription = "Sort results in hand", + onSelect = onSort, + onReset = { onSort(SearchSort.Default) }, + ) + Text( + text = searchControlsSummary(kind, sort), + style = pipelinesText().meta, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.weight(1f).padding(start = SPACING_S), + ) + } +} + @Composable private fun PanelMessage(message: String, isError: Boolean) { Text( @@ -127,10 +200,12 @@ private fun SearchResultList( } /** - * One result row: its type badge, a title and a secondary line. A text match's - * secondary line is its snippet with the matched span rendered bold+underlined, - * so the match is distinguishable without relying on colour. A result with no - * navigation target (an unknown kind) is shown read-only and is not clickable. + * One result row: the type glyph (its kind, or an artifact's content type), a + * title and a secondary line. The glyph carries the kind in words as its + * content description, since the mark alone is not readable, and the matched span + * of a text match is rendered bold+underlined, so the match is distinguishable + * without relying on colour. A result with no navigation target (an unknown kind) + * is shown read-only and is not clickable. */ @Composable private fun SearchResultRow( @@ -151,9 +226,15 @@ private fun SearchResultRow( }, ) .padding(horizontal = SPACING_L, vertical = SPACING_M), + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(SPACING_M), ) { - LabelChip(row.badge, SPACING_S, SPACING_XXS) + Icon( + imageVector = searchResultIcon(hit), + contentDescription = searchResultKindLabel(hit), + tint = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.size(ICON_LIST_DP), + ) Column( modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(SPACING_XXS), diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/FilterMenu.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/FilterMenu.kt index e3d60ca4..ddf2e7a5 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/FilterMenu.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/FilterMenu.kt @@ -179,7 +179,7 @@ fun FilterCheckItem( ) } -/** A small section caption inside a filter menu (Status/Pipeline/Time range). */ +/** A small section caption inside a menu (a filter facet or a sort's reach). */ @Composable fun FilterSectionHeader(label: String) { Text( diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/LabelChip.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/LabelChip.kt deleted file mode 100644 index 1652e6d2..00000000 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/LabelChip.kt +++ /dev/null @@ -1,31 +0,0 @@ -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), - ) - } -} diff --git a/android/app/src/main/java/net/awan/pipelines/ui/components/SortMenu.kt b/android/app/src/main/java/net/awan/pipelines/ui/components/SortMenu.kt index 9f3b5436..47f3ff2d 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/components/SortMenu.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/components/SortMenu.kt @@ -25,7 +25,9 @@ import androidx.compose.ui.Modifier * icon and works at both window widths (it is not width-dependent geometry). * * [selected] draws a leading check on its row, so the active choice is conveyed - * by a glyph as well as by text, never by colour alone. + * by a glyph as well as by text, never by colour alone. An optional [header] + * captions the menu, e.g. to say that an order applies to the results in hand + * rather than server-side. */ @Composable fun SortMenu( @@ -36,6 +38,7 @@ fun SortMenu( onSelect: (T) -> Unit, onReset: () -> Unit, modifier: Modifier = Modifier, + header: String? = null, ) { var expanded by remember { mutableStateOf(false) } Box(modifier) { @@ -43,6 +46,7 @@ fun SortMenu( Icon(Icons.AutoMirrored.Filled.Sort, contentDescription = contentDescription) } DropdownMenu(expanded = expanded, onDismissRequest = { expanded = false }) { + header?.let { FilterSectionHeader(it) } options.forEach { option -> DropdownMenuItem( text = { Text(label(option)) }, diff --git a/android/app/src/main/java/net/awan/pipelines/ui/graph/ArtifactType.kt b/android/app/src/main/java/net/awan/pipelines/ui/graph/ArtifactType.kt index 15037562..76b89093 100644 --- a/android/app/src/main/java/net/awan/pipelines/ui/graph/ArtifactType.kt +++ b/android/app/src/main/java/net/awan/pipelines/ui/graph/ArtifactType.kt @@ -82,6 +82,26 @@ internal fun artifactIcon(kind: ArtifactKind): ImageVector = when (kind) { ArtifactKind.Other -> Icons.AutoMirrored.Filled.InsertDriveFile } +/** + * The word that names [kind] where a surface shows the type glyph but must also + * say the type in prose (a screen reader cannot read an icon). It is the same + * classification [artifactIcon] draws from, so the glyph and the word never + * disagree. Pure, so the mapping is unit-tested. + */ +internal fun artifactKindLabel(kind: ArtifactKind): String = when (kind) { + ArtifactKind.Image -> "Image" + ArtifactKind.Video -> "Video" + ArtifactKind.Audio -> "Audio" + ArtifactKind.Pdf -> "PDF" + ArtifactKind.Json -> "JSON" + ArtifactKind.Archive -> "Archive" + ArtifactKind.Spreadsheet -> "Spreadsheet" + ArtifactKind.Log -> "Log" + ArtifactKind.Code -> "Code" + ArtifactKind.Document -> "Document" + ArtifactKind.Other -> "File" +} + private val ARCHIVE_EXTENSIONS = setOf("zip", "tar", "gz", "tgz", "bz2", "xz", "rar", "7z", "jar", "war") diff --git a/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt index ddb081c6..2bd8b23d 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/OmniSearchResultsTest.kt @@ -1,5 +1,19 @@ package net.awan.pipelines.ui +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.HelpOutline +import androidx.compose.material.icons.automirrored.filled.InsertDriveFile +import androidx.compose.material.icons.automirrored.filled.Segment +import androidx.compose.material.icons.automirrored.filled.Subject +import androidx.compose.material.icons.filled.AccountTree +import androidx.compose.material.icons.filled.Code +import androidx.compose.material.icons.filled.Commit +import androidx.compose.material.icons.filled.DataObject +import androidx.compose.material.icons.filled.Description +import androidx.compose.material.icons.filled.History +import androidx.compose.material.icons.filled.Image +import androidx.compose.material.icons.filled.PictureAsPdf +import androidx.compose.ui.graphics.vector.ImageVector import net.awan.pipelines.data.protocol.Protocol import net.awan.pipelines.data.protocol.RunStep import net.awan.pipelines.data.protocol.SearchArtifact @@ -10,6 +24,8 @@ import net.awan.pipelines.data.protocol.SearchResult import net.awan.pipelines.data.protocol.SearchRun import net.awan.pipelines.data.protocol.SearchStep import net.awan.pipelines.data.protocol.SearchVersion +import net.awan.pipelines.ui.graph.artifactIcon +import net.awan.pipelines.ui.graph.artifactKind import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -19,26 +35,77 @@ import org.junit.Test class OmniSearchResultsTest { - // ---- Badges and rows --------------------------------------------------- + // ---- Type glyphs and rows ---------------------------------------------- @Test - fun everyKindMapsToItsBadge() { - assertEquals("pipeline", searchBadge(Protocol.SEARCH_KIND_PIPELINE)) - assertEquals("pipeline", searchBadge(Protocol.SEARCH_KIND_VERSION)) - assertEquals("run", searchBadge(Protocol.SEARCH_KIND_RUN)) - assertEquals("step", searchBadge(Protocol.SEARCH_KIND_STEP)) - assertEquals("artifact", searchBadge(Protocol.SEARCH_KIND_ARTIFACT)) - assertEquals("match", searchBadge(Protocol.SEARCH_KIND_FIELD)) - // A kind the client does not know still gets a badge and is shown. - assertEquals("match", searchBadge("future_kind")) - assertEquals("match", searchBadge("")) + fun everyKindMapsToItsOwnGlyph() { + assertEquals(Icons.Filled.AccountTree, searchResultIcon(hit(Protocol.SEARCH_KIND_PIPELINE))) + assertEquals(Icons.Filled.Commit, searchResultIcon(hit(Protocol.SEARCH_KIND_VERSION))) + assertEquals(Icons.Filled.History, searchResultIcon(hit(Protocol.SEARCH_KIND_RUN))) + assertEquals(Icons.AutoMirrored.Filled.Segment, searchResultIcon(hit(Protocol.SEARCH_KIND_STEP))) + assertEquals(Icons.AutoMirrored.Filled.Subject, searchResultIcon(hit(Protocol.SEARCH_KIND_FIELD))) + // An artifact shows its content type's glyph; an unknown kind gets a neutral + // mark rather than none, and no two kinds share a glyph. + assertEquals(Icons.Filled.Description, searchResultIcon(hit(Protocol.SEARCH_KIND_ARTIFACT))) + assertEquals(Icons.AutoMirrored.Filled.HelpOutline, searchResultIcon(hit("future_kind"))) + val glyphs = listOf( + Protocol.SEARCH_KIND_PIPELINE, + Protocol.SEARCH_KIND_VERSION, + Protocol.SEARCH_KIND_RUN, + Protocol.SEARCH_KIND_STEP, + Protocol.SEARCH_KIND_FIELD, + Protocol.SEARCH_KIND_ARTIFACT, + "future_kind", + ).map { searchResultIcon(hit(it)) } + assertEquals(glyphs.size, glyphs.toSet().size) } @Test - fun eachRowCarriesABadgeTitleAndSecondaryLine() { + fun anArtifactGlyphIsTheGallerysContentTypeMapping() { + // Every artifact reuses artifactIcon(artifactKind(...)) rather than a second + // mapping, so the search surface and the gallery can never disagree. + val cases = listOf( + "image/png" to "shot.png", + "application/pdf" to "report.pdf", + "application/json" to "run.json", + "text/markdown" to "notes.md", + "application/xml" to "graph.xml", + "text/plain" to "readme.txt", + "application/octet-stream" to "blob", + ) + cases.forEach { (contentType, name) -> + assertEquals( + "artifact $contentType", + artifactIcon(artifactKind(contentType, name)), + artifactGlyph(contentType, name), + ) + } + // Spot-check the concrete glyphs the brief names. + assertEquals(Icons.Filled.Image, artifactGlyph("image/png", "shot.png")) + assertEquals(Icons.Filled.PictureAsPdf, artifactGlyph("application/pdf", "report.pdf")) + assertEquals(Icons.Filled.DataObject, artifactGlyph("application/json", "run.json")) + assertEquals(Icons.Filled.Code, artifactGlyph("application/xml", "graph.xml")) + assertEquals(Icons.Filled.Description, artifactGlyph("text/plain", "readme.txt")) + assertEquals(Icons.AutoMirrored.Filled.InsertDriveFile, artifactGlyph("application/octet-stream", "blob")) + } + + @Test + fun everyKindCarriesItsKindInWords() { + assertEquals("Pipeline", searchResultKindLabel(hit(Protocol.SEARCH_KIND_PIPELINE))) + assertEquals("Pipeline version", searchResultKindLabel(hit(Protocol.SEARCH_KIND_VERSION))) + assertEquals("Run", searchResultKindLabel(hit(Protocol.SEARCH_KIND_RUN))) + assertEquals("Step", searchResultKindLabel(hit(Protocol.SEARCH_KIND_STEP))) + assertEquals("Field", searchResultKindLabel(hit(Protocol.SEARCH_KIND_FIELD))) + // The default artifact fixture is a markdown file; an image names itself. + assertEquals("Document artifact", searchResultKindLabel(hit(Protocol.SEARCH_KIND_ARTIFACT))) + assertEquals("Image artifact", searchResultKindLabel(artifactHit("image/png", "shot.png"))) + assertEquals("Unrecognised result", searchResultKindLabel(hit("future_kind"))) + } + + @Test + fun eachRowCarriesATitleAndSecondaryLine() { results().forEach { hit -> val row = searchRow(hit, "release") - assertTrue("badge for ${hit.kind}", row.badge.isNotBlank()) assertTrue("title for ${hit.kind}", row.title.isNotBlank()) assertTrue("secondary for ${hit.kind}", row.secondary.isNotBlank()) } @@ -62,6 +129,91 @@ class OmniSearchResultsTest { assertNull("an unknown kind is not navigable", searchTarget(unknown)) } + // ---- Kind filter ------------------------------------------------------- + + @Test + fun everyFilterCarriesTheServerKindAndResolvesFromStorage() { + assertEquals("", SearchKindFilter.All.serverKind) + assertEquals(Protocol.SEARCH_KIND_PIPELINE, SearchKindFilter.Pipelines.serverKind) + assertEquals(Protocol.SEARCH_KIND_VERSION, SearchKindFilter.Versions.serverKind) + assertEquals(SearchKindFilter.All, SearchKindFilter.fromStorage("")) + assertEquals(SearchKindFilter.Runs, SearchKindFilter.fromStorage("run")) + // A stale/unknown stored value falls back to every kind; "prompts" is not a + // server kind, so it is deliberately not an option. + assertEquals(SearchKindFilter.All, SearchKindFilter.fromStorage("prompts")) + } + + @Test + fun theKindFilterNarrowsTheListToThatKind() { + val mixed = listOf( + hit(Protocol.SEARCH_KIND_PIPELINE), + hit(Protocol.SEARCH_KIND_RUN), + hit(Protocol.SEARCH_KIND_STEP), + hit(Protocol.SEARCH_KIND_FIELD), + hit(Protocol.SEARCH_KIND_ARTIFACT), + hit(Protocol.SEARCH_KIND_VERSION), + ) + assertEquals(mixed, filterSearchResults(mixed, SearchKindFilter.All)) + assertEquals(listOf(hit(Protocol.SEARCH_KIND_RUN)), filterSearchResults(mixed, SearchKindFilter.Runs)) + assertEquals(listOf(hit(Protocol.SEARCH_KIND_ARTIFACT)), filterSearchResults(mixed, SearchKindFilter.Artifacts)) + assertEquals( + listOf(hit(Protocol.SEARCH_KIND_VERSION)), + filterSearchResults(mixed, SearchKindFilter.Versions), + ) + } + + // ---- Sort ordering ----------------------------------------------------- + + @Test + fun relevanceKeepsTheServersRanking() { + val ordered = listOf( + hitWithRecency(Protocol.SEARCH_KIND_RUN, "2026-01-01T00:00:00Z"), + hitWithRecency(Protocol.SEARCH_KIND_PIPELINE, "2026-03-01T00:00:00Z"), + ) + assertEquals(ordered, sortSearchResults(ordered, SearchSort.Relevance)) + } + + @Test + fun newestFirstOrdersByRecencyDescending() { + val older = hitWithRecency(Protocol.SEARCH_KIND_RUN, "2026-01-01T00:00:00Z") + val newer = hitWithRecency(Protocol.SEARCH_KIND_PIPELINE, "2026-03-01T00:00:00Z") + assertEquals(listOf(newer, older), sortSearchResults(listOf(older, newer), SearchSort.Newest)) + } + + @Test + fun aRecencyTieKeepsTheServersOrder() { + val first = hitWithRecency(Protocol.SEARCH_KIND_RUN, "2026-01-01T00:00:00Z") + val second = hitWithRecency(Protocol.SEARCH_KIND_PIPELINE, "2026-01-01T00:00:00Z") + assertEquals(listOf(first, second), sortSearchResults(listOf(first, second), SearchSort.Newest)) + } + + @Test + fun aMissingRecencySortsLast() { + val dated = hitWithRecency(Protocol.SEARCH_KIND_RUN, "2026-01-01T00:00:00Z") + val undated = SearchResult(kind = Protocol.SEARCH_KIND_RUN, recency = null) + assertEquals(listOf(dated, undated), sortSearchResults(listOf(undated, dated), SearchSort.Newest)) + } + + @Test + fun nameOrdersByTheDisplayedTitleAndATieKeepsItsOrder() { + val alpha1 = SearchResult(kind = Protocol.SEARCH_KIND_PIPELINE, pipeline = SearchPipeline(id = 1, name = "alpha")) + val beta = SearchResult(kind = Protocol.SEARCH_KIND_PIPELINE, pipeline = SearchPipeline(id = 2, name = "beta")) + val alpha2 = SearchResult(kind = Protocol.SEARCH_KIND_PIPELINE, pipeline = SearchPipeline(id = 3, name = "alpha")) + // The two "alpha" rows tie and keep their input order; "beta" moves last. + assertEquals(listOf(alpha1, alpha2, beta), sortSearchResults(listOf(beta, alpha1, alpha2), SearchSort.Name)) + } + + @Test + fun theStoredSortAndTheControlSummaryResolve() { + assertEquals(SearchSort.Relevance, SearchSort.fromStorage("")) + assertEquals(SearchSort.Name, SearchSort.fromStorage("name")) + assertEquals(SearchSort.Relevance, SearchSort.fromStorage("bogus")) + assertEquals("All kinds · Relevance", searchControlsSummary(SearchKindFilter.All, SearchSort.Relevance)) + // An order that runs on the fetched results says so in the collapsed summary. + assertEquals("Runs · Newest first (in hand)", searchControlsSummary(SearchKindFilter.Runs, SearchSort.Newest)) + assertEquals("Fields · Name (in hand)", searchControlsSummary(SearchKindFilter.Fields, SearchSort.Name)) + } + // ---- Snippet highlighting --------------------------------------------- @Test @@ -220,13 +372,25 @@ class OmniSearchResultsTest { } @Test - fun theEmptyStateNamesTheQueryAndOnlyAppearsWhenLoaded() { + fun theEmptyStateNamesTheQueryAndTheActiveFilter() { val empty = SearchUiState(query = "release").loaded(SearchResponse(results = emptyList())) - assertTrue(empty.isEmptyResult()) - // Still loading: not the empty state. - assertFalse(empty.editing("release2").isEmptyResult()) - // A failure is an error, not an empty result. - assertFalse(SearchUiState(query = "release").failed("boom").isEmptyResult()) + assertEquals( + "No matches for \"release\".", + searchPanelEmptyMessage(empty, emptyList(), SearchKindFilter.All), + ) + // A filter that empties the list names itself rather than the generic line. + val pipelineOnly = empty.copy(results = listOf(hit(Protocol.SEARCH_KIND_PIPELINE))) + assertEquals( + "No runs match \"release\".", + searchPanelEmptyMessage(pipelineOnly, emptyList(), SearchKindFilter.Runs), + ) + // Rows shown: no message. Still loading, blank query or an error: no message + // (the panel shows progress, nothing, or the error respectively). + val shown = listOf(hit(Protocol.SEARCH_KIND_RUN)) + assertNull(searchPanelEmptyMessage(empty.copy(results = shown), shown, SearchKindFilter.All)) + assertNull(searchPanelEmptyMessage(empty.editing("release2"), emptyList(), SearchKindFilter.All)) + assertNull(searchPanelEmptyMessage(SearchUiState(query = ""), emptyList(), SearchKindFilter.All)) + assertNull(searchPanelEmptyMessage(empty.failed("boom"), emptyList(), SearchKindFilter.All)) } // ---- Fixtures ---------------------------------------------------------- @@ -265,6 +429,17 @@ class OmniSearchResultsTest { else -> SearchResult(kind = kind, target = "") } + private fun hitWithRecency(kind: String, recency: String?): SearchResult = + hit(kind).copy(recency = recency) + + private fun artifactHit(contentType: String, name: String): SearchResult = SearchResult( + kind = Protocol.SEARCH_KIND_ARTIFACT, + artifact = SearchArtifact(name = name, contentType = contentType), + ) + + private fun artifactGlyph(contentType: String, name: String): ImageVector = + searchResultIcon(artifactHit(contentType, name)) + private fun results(): List = listOf( Protocol.SEARCH_KIND_PIPELINE, Protocol.SEARCH_KIND_VERSION, diff --git a/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactTypeTest.kt b/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactTypeTest.kt index 57060c12..a6274e23 100644 --- a/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactTypeTest.kt +++ b/android/app/src/test/java/net/awan/pipelines/ui/graph/ArtifactTypeTest.kt @@ -74,4 +74,17 @@ class ArtifactTypeTest { val glyphs = ArtifactKind.entries.map { artifactIcon(it) } assertEquals(ArtifactKind.entries.size, glyphs.toSet().size) } + + @Test + fun everyKindHasAWordThatNamesIt() { + // The search surface names an artifact by this word for a screen reader; + // it must exist for every kind and be distinct. + assertEquals("Image", artifactKindLabel(ArtifactKind.Image)) + assertEquals("PDF", artifactKindLabel(ArtifactKind.Pdf)) + assertEquals("JSON", artifactKindLabel(ArtifactKind.Json)) + assertEquals("Document", artifactKindLabel(ArtifactKind.Document)) + assertEquals("File", artifactKindLabel(ArtifactKind.Other)) + val labels = ArtifactKind.entries.map { artifactKindLabel(it) } + assertEquals(ArtifactKind.entries.size, labels.toSet().size) + } }