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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13402-explore-with-filters-that-match-nothing → main 3 commits fork 3 threads · 3 unresolved
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 | ||
| 77 | 77 | |
| 78 | 78 | ## The count and the way back (#11323) |
| 79 | 79 | |
| 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. | |
| 81 | 81 | |
| 82 | 82 | 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. |
| 83 | 83 |
src/actions/explore.ts +3 −4
| @@ -458,12 +458,11 @@ export const exploreFiltered = (q: ExploreQuery): boolean => | ||
| 458 | 458 | q.sort !== "score"; |
| 459 | 459 | |
| 460 | 460 | /** |
| 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. | |
| 464 | 463 | */ |
| 465 | 464 | 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"; | |
| 467 | 466 | if (query.kind === "all" && seesForges) { |
| 468 | 467 | return total === 1 ? "1 app, forge or person" : `${total.toLocaleString("en-US")} apps, forges and people`; |
| 469 | 468 | } |
src/web/studio/explore.ts +3 −13
| @@ -109,13 +109,7 @@ function emptyState(ctx: Ctx, query: ExploreQuery): Html { | ||
| 109 | 109 | return empty({ |
| 110 | 110 | icon: "search", |
| 111 | 111 | 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.", | |
| 119 | 113 | }); |
| 120 | 114 | return empty({ |
| 121 | 115 | icon: "search", |
| @@ -156,16 +150,12 @@ function removable(query: ExploreQuery): { term: string; without: ExploreQuery } | ||
| 156 | 150 | /** |
| 157 | 151 | * How much is left, and the way back. A fixed-height line, so the list never |
| 158 | 152 | * 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. | |
| 160 | 154 | */ |
| 161 | 155 | function countLine(query: ExploreQuery, total: number, seesForges: boolean): Html { |
| 162 | 156 | const on = exploreFiltered(query); |
| 163 | 157 | 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)}${ | |
| 169 | 159 | on ? html` · <a href="/explore" data-clear-filters>Clear filters</a>` : html`` |
| 170 | 160 | }</span>`; |
| 171 | 161 | } |
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 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -56,15 +59,13 @@ test("one filter: the apps left and a link back to the bare path", async () => { | ||
| 56 | 59 | |
| 57 | 60 | test("a filter with no match says so and still offers the way back", async () => { |
| 58 | 61 | const html = await get("/explore?q=kind:app zzzzqqq"); |
| 59 | expect(count(html)).toMatch(/^No apps match/); | |
| 62 | expect(count(html)).toMatch(/^0 results/); | |
| 60 | 63 | expect(html).toContain("data-clear-filters"); |
| 61 | 64 | }); |
| 62 | 65 | |
| 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"); | |
| 68 | 69 | }); |
| 69 | 70 | |
| 70 | 71 | 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 () => { | ||
| 88 | 89 | |
| 89 | 90 | test("the empty sentence is plain words, and a guest is never told of forges", async () => { |
| 90 | 91 | const html = await get("/explore?q=zzzzqqq"); |
| 91 | expect(count(html)).toMatch(/^Nothing matches/); | |
| 92 | expect(count(html)).toMatch(/^0 results/); | |
| 92 | 93 | expect(html).not.toMatch(/data-hits[^>]*>[^<]*forges/); |
| 93 | 94 | }); |
| 94 | 95 |
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", () => { | ||
| 457 | 457 | const out = await get(`/explore?q=${encodeURIComponent("zzz-no-such")}`, signedIn); |
| 458 | 458 | expect(out).toContain("Nothing matches"); |
| 459 | 459 | expect(out).toContain("Nothing matches zzz-no-such"); |
| 460 | expect(out).toContain("Clear all"); | |
| 460 | expect(out).toContain("data-clear-filters"); | |
| 461 | 461 | expect(out).not.toContain("Nothing public yet"); |
| 462 | 462 | } |
| 463 | 463 | }); |
| @@ -482,15 +482,13 @@ describe("explore on a forge with nothing public", () => { | ||
| 482 | 482 | expect(none).toMatch(/aria-current="page"\s*>Any time/); |
| 483 | 483 | }); |
| 484 | 484 | |
| 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 () => { | |
| 486 | 486 | const words = Array.from({ length: 10 }, (_, i) => `w${i}`).join(" "); |
| 487 | 487 | const long = "x".repeat(60); |
| 488 | 488 | 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}"`); | |
| 494 | 492 | }); |
| 495 | 493 | |
| 496 | 494 | 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 | */ | |
| 2 | 4 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 5 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 6 | import { tmpdir } from "node:os"; |
| @@ -64,7 +66,7 @@ test("a filter with none: the miss sentence and clear", async () => { | ||
| 64 | 66 | const r = await explore({ q: "zzzznothing" }); |
| 65 | 67 | expect(r.total).toBe(0); |
| 66 | 68 | expect(r.line).toBe(exploreCount(readExploreLine("zzzznothing").query, 0)); |
| 67 | expect(r.line).toBe("Nothing matches"); | |
| 69 | expect(r.line).toBe("0 results"); | |
| 68 | 70 | expect(r.clear).toBeDefined(); |
| 69 | 71 | }); |
| 70 | 72 |
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 () | ||
| 213 | 213 | const text = await typed("kind:app sort:forks"); |
| 214 | 214 | expect(text).toContain("Read as: kind:app sort:forks · 3 apps · Esc clears"); |
| 215 | 215 | const none = await typed("kind:app zzzzqqq"); |
| 216 | expect(none).toContain("No apps match · Esc clears"); | |
| 216 | expect(none).toContain("0 results · Esc clears"); | |
| 217 | 217 | }); |
| 218 | 218 | |
| 219 | 219 | 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 | ||
| 226 | 226 | expect(text).not.toContain("alice/ant"); |
| 227 | 227 | const none = await typed("kind:app forks:1 live:yes"); |
| 228 | 228 | expect(none).toContain("forks:1 live:yes"); |
| 229 | expect(none).toContain("No apps match"); | |
| 229 | expect(none).toContain("0 results"); | |
| 230 | 230 | expect(none).not.toContain("alice/zed"); |
| 231 | 231 | }); |
| 232 | 232 |
new above
offline
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.