Public: anyone can read this; the crew can change it.

/explore with filters that match nothing says so and offers the one link that clears them #13502

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13402-explore-with-filters-that-match-nothing → main 3 commits fork 3 threads · 3 unresolved

  • Merged. scout/13402-explore-with-filters-that-match-nothing was merged into main as d07cfbe.

Review

Sign in to review this change.
8 files changed +77 −37
docs/features/explore.md +1 −1
@@ -77,7 +77,7 @@ The terminal's palette has `Explore feed`, which opens or shows the feed's addre
7777
7878 ## The count and the way back (#11323)
7979
80 Under the filters, `/explore` says how much a filter leaves: `66 results`, `2 apps`, `1 app`, `No apps match`, in the words of `exploreCount` in `src/actions/explore.ts` (the count is the whole filtered list, not the page). While a filter narrows the list (kind, words, archived, updated or owner; the sort only orders) the line ends with `Clear filters`, a link to bare `/explore`. When nothing matches it also offers `Drop <term>` for each filter, one tap to remove just that one. With no filter and nothing public the line is silent; the empty state speaks.
80 Under the filters, `/explore` says how much a filter leaves: `66 results`, `2 apps`, `1 app`, `0 results`, in the words of `exploreCount` in `src/actions/explore.ts` (the count is the whole filtered list, not the page). While a filter narrows the list (kind, words, archived, updated or owner; the sort only orders) the line ends with `Clear filters`, a link to bare `/explore`. When nothing matches the line reads `0 results` with that one `Clear filters` link (terminal and MCP say the same words); the chips above it still take one filter off, and the empty state only names the filters. With no filter and nothing public the line is silent; the empty state speaks.
8181
8282 In the terminal the same sentence sits in the `Read as:` line under the search box (`Read as: kind:app · 2 apps · Esc clears`); Esc clears the line.
8383
src/actions/explore.ts +3 −4
@@ -458,12 +458,11 @@ export const exploreFiltered = (q: ExploreQuery): boolean =>
458458 q.sort !== "score";
459459
460460 /**
461 * How much a filter leaves, in words: "2 apps", "1 app", "No apps match",
462 * "Nothing matches". One sentence for the page and the terminal. Only the
463 * kinds the viewer can see are named: forges are a site admin's.
461 * How much a filter leaves, in words: "2 apps", "1 app", "0 results". One sentence for the page and
462 * the terminal. Only the kinds the viewer can see are named: forges are a site admin's.
464463 */
465464 export function exploreCount(query: ExploreQuery, total: number, seesForges = false): string {
466 if (total === 0) return query.kind === "all" ? "Nothing matches" : `No ${NOUNS[query.kind][1]} match`;
465 if (total === 0) return "0 results";
467466 if (query.kind === "all" && seesForges) {
468467 return total === 1 ? "1 app, forge or person" : `${total.toLocaleString("en-US")} apps, forges and people`;
469468 }
src/web/studio/explore.ts +3 −13
@@ -109,13 +109,7 @@ function emptyState(ctx: Ctx, query: ExploreQuery): Html {
109109 return empty({
110110 icon: "search",
111111 title: `Nothing matches ${line}`,
112 note: "Drop a term to step back:",
113 action: html`<div class="form-actions">
114 ${terms(query).map(
115 (t) => btn(shorten(t.term), { href: href(t.without), size: "sm", title: `Drop ${t.term}` }),
116 )}
117 ${btn("Clear all", { href: "/explore", size: "sm" })}
118 </div>`,
112 note: "The chips above take one filter off; Clear filters above takes them all.",

Non-blocking, principle 1: the note explains the chips and the link that sit directly above it, so the page says the same thing twice. The title already names the filters; the note can go.

119113 });
120114 return empty({
121115 icon: "search",
@@ -156,16 +150,12 @@ function removable(query: ExploreQuery): { term: string; without: ExploreQuery }
156150 /**
157151 * How much is left, and the way back. A fixed-height line, so the list never
158152 * moves. Unfiltered and empty it is silent: "Nothing public yet" says it.
159 * A miss names each filter that can be dropped, beside Clear filters.
153 * A miss reads "0 results" (the words of `exploreCount`) beside the one Clear filters link.
160154 */
161155 function countLine(query: ExploreQuery, total: number, seesForges: boolean): Html {
162156 const on = exploreFiltered(query);
163157 if (total === 0 && !on) return html``;
164 const drops =
165 total === 0 && on
166 ? removable(query).map((t) => html` · <a href="${href(t.without)}">Drop ${shorten(t.term)}</a>`)
167 : [];
168 return html`<span class="muted" role="status" data-hits>${exploreCount(query, total, seesForges)}${drops}${
158 return html`<span class="muted" role="status" data-hits>${exploreCount(query, total, seesForges)}${
169159 on ? html` · <a href="/explore" data-clear-filters>Clear filters</a>` : html``
170160 }</span>`;
171161 }
test/explore-count.test.ts +9 −8
@@ -1,4 +1,7 @@
1 /** /explore says how many rows the filter leaves and offers one 'Clear filters' link only while filtered. */
1 /**
2 * /explore says how many rows the filter leaves and offers one 'Clear filters' link only while
3 * filtered.
4 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { mkdtemp, rm } from "node:fs/promises";
47 import { tmpdir } from "node:os";
@@ -56,15 +59,13 @@ test("one filter: the apps left and a link back to the bare path", async () => {
5659
5760 test("a filter with no match says so and still offers the way back", async () => {
5861 const html = await get("/explore?q=kind:app zzzzqqq");
59 expect(count(html)).toMatch(/^No apps match/);
62 expect(count(html)).toMatch(/^0 results/);
6063 expect(html).toContain("data-clear-filters");
6164 });
6265
63 test("a filter with no match names the one filter to drop", async () => {
64 const html = await get("/explore?q=kind:app zzzzqqq");
65 const hits = html.match(/data-hits>.*?<\/span>/s)?.[0] ?? "";
66 expect(hits).toContain('<a href="/explore?q=zzzzqqq">Drop kind:app</a>');
67 expect(hits).toContain('<a href="/explore?kind=app">Drop zzzzqqq</a>');
66 test("a miss offers no per-filter Drop links: the chips do that, Clear filters clears", async () => {
67 const hits = (await get("/explore?q=kind:app zzzzqqq")).match(/data-hits>.*?<\/span>/s)?.[0] ?? "";
68 expect(hits).not.toContain("Drop");
6869 });
6970
7071 test("a filter that leaves one says '1 app', singular", async () => {
@@ -88,7 +89,7 @@ test("a sort alone still offers Clear filters to the bare page", async () => {
8889
8990 test("the empty sentence is plain words, and a guest is never told of forges", async () => {
9091 const html = await get("/explore?q=zzzzqqq");
91 expect(count(html)).toMatch(/^Nothing matches/);
92 expect(count(html)).toMatch(/^0 results/);
9293 expect(html).not.toMatch(/data-hits[^>]*>[^<]*forges/);
9394 });
9495
test/explore-zero.test.ts added +50
@@ -0,0 +1,50 @@
1 /** A filter set matching nothing reads "0 results", names the filters, and offers the way back. */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { exploreCount, readExploreLine } from "../src/actions/explore.ts";
8 import { serve, type Servers } from "../src/http/server.ts";
9 import { quietLogs } from "./helpers/globals.ts";
10
11 quietLogs();
12 let dir: string;
13 let app: App;
14 let servers: Servers;
15
16 beforeAll(async () => {
17 dir = await mkdtemp(join(tmpdir(), "forge-explore-zero-"));
18 app = createApp({ dataDir: dir, port: 0 });
19 servers = await serve(app);
20 });
21 afterAll(async () => {
22 await servers.stop();
23 app.db.close();
24 await rm(dir, { recursive: true, force: true });
25 });
26
27 const get = async (path: string) => (await fetch(`${servers.url}${path}`)).text();
28
29 test("filters that match nothing: 0 results, the filters named, a clear link", async () => {
outdated

Assert the miss state has exactly one clear-filters link (count data-clear-filters and Clear all occurrences): this test passes while the page offers several. Add a terminal/MCP assertion for 0 results too. Nothing in docs/features/ mentions the empty state wording either.

30 const html = await get("/explore?q=kind:app sort:forks zzzzqqq");
31 expect(html).toMatch(/data-hits[^>]*>0 results/);
32 expect(html).toContain("Nothing matches kind:app");
33 expect(html).toContain("zzzzqqq");
34 expect(html).toContain('<a href="/explore" data-clear-filters>Clear filters</a>');
35 expect(html.match(/data-clear-filters/g)?.length).toBe(1);
36 expect(html).not.toContain("Clear all");
37 expect(html).not.toContain(">Drop ");
38 });
39
40 test("no filter and nothing public is not a miss: no count, no clear link", async () => {
41 const html = await get("/explore");
42 expect(html).not.toContain("0 results");
43 expect(html).not.toContain("data-clear-filters");
44 });
45
46 test("page, terminal and MCP say 0 results in exploreCount's words", () => {
47 const q = readExploreLine("kind:app zzzzqqq").query;
48 expect(exploreCount(q, 0)).toBe("0 results");
49 expect(exploreCount(readExploreLine("zzzzqqq").query, 0, true)).toBe("0 results");
50 });
test/explore.test.ts +5 −7
@@ -457,7 +457,7 @@ describe("explore on a forge with nothing public", () => {
457457 const out = await get(`/explore?q=${encodeURIComponent("zzz-no-such")}`, signedIn);
458458 expect(out).toContain("Nothing matches");
459459 expect(out).toContain("Nothing matches zzz-no-such");
460 expect(out).toContain("Clear all");
460 expect(out).toContain("data-clear-filters");
461461 expect(out).not.toContain("Nothing public yet");
462462 }
463463 });
@@ -482,15 +482,13 @@ describe("explore on a forge with nothing public", () => {
482482 expect(none).toMatch(/aria-current="page"\s*>Any time/);
483483 });
484484
485 test("many words and a long one sit in a wrapping group, not a list row", async () => {
485 test("many words and a long one sit in the wrapping chip row, shortened", async () => {
486486 const words = Array.from({ length: 10 }, (_, i) => `w${i}`).join(" ");
487487 const long = "x".repeat(60);
488488 const out = await get(`/explore?q=${encodeURIComponent(`${words} ${long}`)}`, false);
489 const group = out.slice(out.indexOf("Drop a term"));
490 expect(group).toContain('class="form-actions"');
491 expect(group.slice(0, group.indexOf("Clear all"))).not.toContain('class="row"');
492 expect(group).toContain(`>${"x".repeat(23)}…</a`);
493 expect(group).toContain(`title="Drop ${long}"`);
489 const group = out.slice(out.indexOf("data-filter-chips"));
490 expect(group).toContain(`>${"x".repeat(23)}…`);
491 expect(group).toContain(`title="Remove ${long}"`);
494492 });
495493
496494 test("a hostile word is escaped in the title and the links", async () => {
test/mcp-explore-count.test.ts +4 −2
@@ -1,4 +1,6 @@
1 /** MCP explore says how many a filter leaves in the page's sentence, and the call that clears it. */
1 /**
2 * MCP explore says how many a filter leaves in the page's sentence, and the call that clears it.
3 */
24 import { afterAll, beforeAll, expect, test } from "bun:test";
35 import { mkdtemp, rm } from "node:fs/promises";
46 import { tmpdir } from "node:os";
@@ -64,7 +66,7 @@ test("a filter with none: the miss sentence and clear", async () => {
6466 const r = await explore({ q: "zzzznothing" });
6567 expect(r.total).toBe(0);
6668 expect(r.line).toBe(exploreCount(readExploreLine("zzzznothing").query, 0));
67 expect(r.line).toBe("Nothing matches");
69 expect(r.line).toBe("0 results");
6870 expect(r.clear).toBeDefined();
6971 });
7072
test/tui-dashboard-explore.test.ts +2 −2
@@ -213,7 +213,7 @@ test("the terminal says how many a line leaves and that Esc clears it", async ()
213213 const text = await typed("kind:app sort:forks");
214214 expect(text).toContain("Read as: kind:app sort:forks · 3 apps · Esc clears");
215215 const none = await typed("kind:app zzzzqqq");
216 expect(none).toContain("No apps match · Esc clears");
216 expect(none).toContain("0 results · Esc clears");
217217 });
218218
219219 test("forks:1 on the terminal's line leaves the rows the page's action leaves, and Read as carries the word", async () => {
@@ -226,7 +226,7 @@ test("forks:1 on the terminal's line leaves the rows the page's action leaves, a
226226 expect(text).not.toContain("alice/ant");
227227 const none = await typed("kind:app forks:1 live:yes");
228228 expect(none).toContain("forks:1 live:yes");
229 expect(none).toContain("No apps match");
229 expect(none).toContain("0 results");
230230 expect(none).not.toContain("alice/zed");
231231 });
232232

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs