search: browse bounded recent items with kind-only queries

This commit is contained in:
2026-10-20 17:54:00 +01:00
parent cce7ea903a
commit 9cdfd9d9ab
12 changed files with 477 additions and 94 deletions
+27 -27
View File
@@ -12,7 +12,6 @@ import {
SEARCH_DEBOUNCE_MS,
SEARCH_KINDS,
SEARCH_SORTS,
SEARCH_TYPE_HELP,
parseSearchQuery,
SearchSequencer,
filterSearchResults,
@@ -87,9 +86,9 @@ function openSearch() {
state.searchFocusPending = true;
renderHeader();
renderSearch();
// Resume: the previous results show immediately, and a non-blank query is
// refreshed so the list is not stale.
if (searchQuerySendable(state.searchQuery)) {
// Resume: show previous results immediately, then refresh text or kind-only
// searches so the list is not stale.
if (searchQuerySendable(state.searchQuery, parsedSearch().kind)) {
state.searchLoading = true;
const sent = state.searchSequencer.begin(state.searchSequencer.edit(state.searchQuery));
if (sent) runSearch(sent);
@@ -134,16 +133,16 @@ function cancelSearchDebounce() {
}
/**
* A keystroke. A blank/whitespace query clears the results locally and sends
* nothing; otherwise the previous results stay visible, the request is marked in
* flight and the send is debounced `SEARCH_DEBOUNCE_MS` from the last keystroke.
* A keystroke. Blank text without a kind clears locally and sends nothing;
* kind-only searches browse recent items. Previous results stay visible while
* loading; sending is debounced `SEARCH_DEBOUNCE_MS` from the last keystroke.
* Recording the edit is itself enough to drop any older reply still in flight.
*/
function onSearchInput(value) {
state.searchQuery = value;
state.searchError = "";
cancelSearchDebounce();
if (!searchQuerySendable(value)) {
if (!searchQuerySendable(value, parsedSearch().kind)) {
state.searchSequencer.edit("");
state.searchResults = [];
state.searchLoading = false;
@@ -165,7 +164,7 @@ function onSearchInput(value) {
function sendSearchNow() {
const query = state.searchQuery;
cancelSearchDebounce();
if (!searchQuerySendable(query)) {
if (!searchQuerySendable(query, parsedSearch().kind)) {
state.searchSequencer.edit("");
state.searchResults = [];
state.searchLoading = false;
@@ -180,8 +179,8 @@ function sendSearchNow() {
/**
* A kind-filter change: the in-hand filter is re-applied immediately so the list
* always matches the control, and — when the query is non-blank — a fresh server
* request is sent with the new kind. A sort change never sends a request.
* always matches the control. Text or a valid kind sends a fresh server request;
* clearing both stays local. A sort change never sends a request.
*/
function setSearchKind(kind) {
state.searchQuery = parsedSearch().query;
@@ -204,15 +203,8 @@ function setSearchSort(sort) {
*/
async function runSearch(sent) {
const parsed = parseSearchQuery(sent.query, state.searchKind);
if (!parsed.query.trim()) {
state.searchResults = [];
state.searchLoading = false;
state.searchLoaded = false;
refreshSearch();
return;
}
try {
const reply = await repo.search(parsed.query, parsed.kind);
const reply = await repo.search(parsed.query.trim() ? parsed.query : "", parsed.kind);
if (!state.searchSequencer.accepts(sent.token)) return;
if (reply == null) {
state.searchLoading = false;
@@ -222,6 +214,7 @@ async function runSearch(sent) {
return;
}
state.searchResults = Array.isArray(reply.results) ? reply.results : [];
state.searchTruncated = Boolean(reply.truncated);
state.searchActiveIndex = 0;
state.searchLoading = false;
state.searchError = "";
@@ -315,7 +308,7 @@ function renderSearch() {
}
if (event.key === "Enter") {
event.preventDefault();
if (shown.length && !state.searchLoading && !state.searchError && parsedSearch().query.trim()) {
if (shown.length && !state.searchLoading && !state.searchError) {
routeSearchResult(shown[state.searchActiveIndex] ?? shown[0]);
} else sendSearchNow();
}
@@ -355,7 +348,7 @@ function renderSearch() {
"div",
{ id: "searchPanel", class: "search-panel", role: "dialog", "aria-modal": "true", "aria-label": "Search" },
h("div", { class: "search-modal", role: "search" }, fieldRow, controls,
h("p", { class: "muted", text: "Filter with t:pipeline or type:artifact (pipeline, run, step, field, artifact, version). Last type wins; choosing Kind replaces it. Quote tokens to search literally." }), area),
h("p", { class: "muted", text: "Filter with t:pipeline or type:artifact (pipeline, run, step, field, artifact, version). Type alone lists recent items. Last type wins; choosing Kind replaces it. Quote tokens to search literally." }), area),
);
// A spotlight: clicking the dimmed backdrop closes it (the modal itself stops).
panel.addEventListener("click", (event) => {
@@ -377,19 +370,20 @@ function renderSearch() {
*/
function fillSearchResults(area) {
const parsed = parsedSearch();
if (parsed.hasType && !parsed.query.trim()) {
area.replaceChildren(h("div", { class: "search-empty muted", text: SEARCH_TYPE_HELP }));
return;
}
const shown = sortSearchResults(
filterSearchResults(state.searchResults, parsed.kind),
state.searchSort,
);
const nodes = [];
if (searchPanelProgress(state)) {
const panelState = {
query: parsed.query, loading: state.searchLoading, loaded: state.searchLoaded,
error: state.searchError, results: state.searchResults,
truncated: state.searchTruncated,
};
if (searchPanelProgress(panelState)) {
nodes.push(h("div", { class: "search-progress", role: "progressbar", "aria-label": "Searching" }));
}
const body = searchPanelBody(state, shown, parsed.kind);
const body = searchPanelBody(panelState, shown, parsed.kind);
if (body.kind === "error") {
nodes.push(h("div", { class: "search-error", text: body.message }));
} else if (body.kind === "results") {
@@ -414,6 +408,12 @@ function fillSearchResults(area) {
} else if (body.kind === "empty") {
nodes.push(h("div", { class: "search-empty muted", text: body.message }));
}
if (body.kind === "results" && !state.searchLoading && parsed.kind && !parsed.query.trim()) {
nodes.push(h("div", {
class: "search-summary muted",
text: state.searchTruncated ? "Recent items · limited by the server's result or scan cap." : "Recent items",
}));
}
area.replaceChildren(...nodes);
}