Public: anyone can read this; the crew can change it.
/explore takes `updated:7d` (or 1d, 30d) in its one line, and a chip for each narrows to what moved in that window #5887
scout/forge:scout/5874-explore-takes-updated-7d-or-1d-30d-in-it → main 5 commits fork
4 files
changed +79
−3
src/actions/explore.ts +25 −1
| @@ -48,10 +48,19 @@ export interface ExploreQuery { | ||
| 48 | 48 | readonly text: string; |
| 49 | 49 | /** `archived:yes` — put-away repositories are in the list; off, they are not. */ |
| 50 | 50 | readonly archived: boolean; |
| 51 | /** `updated:1d|7d|30d` — only rows that moved within the window; `all` is no window. */ | |
| 52 | readonly updated: ExploreWindow; | |
| 51 | 53 | /** `owner:<name>` — only this account's apps, and the person themself. */ |
| 52 | 54 | readonly owner?: string; |
| 53 | 55 | } |
| 54 | 56 | |
| 57 | export type ExploreWindow = "all" | "1d" | "7d" | "30d"; | |
| 58 | const WINDOWS: Record<string, number> = { | |
| 59 | "1d": 86_400_000, | |
| 60 | "7d": 7 * 86_400_000, | |
| 61 | "30d": 30 * 86_400_000, | |
| 62 | }; | |
| 63 | ||
| 55 | 64 | const KINDS: Record<string, ExploreKind> = { |
| 56 | 65 | app: "app", |
| 57 | 66 | apps: "app", |
| @@ -82,6 +91,7 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 82 | 91 | let kind: ExploreKind | "all" = "all"; |
| 83 | 92 | let sort: ExploreSort = "score"; |
| 84 | 93 | let archived = false; |
| 94 | let updated: ExploreWindow = "all"; | |
| 85 | 95 | let owner: string | undefined; |
| 86 | 96 | const words: string[] = []; |
| 87 | 97 | for (const word of line |
| @@ -98,6 +108,8 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 98 | 108 | sort = value.toLowerCase() as ExploreSort; |
| 99 | 109 | else if (k === "archived" && ["yes", "no"].includes(value.toLowerCase())) |
| 100 | 110 | archived = value.toLowerCase() === "yes"; |
| 111 | else if (k === "updated" && value.toLowerCase() in WINDOWS) | |
| 112 | updated = value.toLowerCase() as ExploreWindow; | |
| 101 | 113 | else if (k === "owner" && isSafeName(value)) owner = value; |
| 102 | 114 | else if (k === "q" && value !== "") words.push(value); |
| 103 | 115 | else words.push(word); |
| @@ -107,6 +119,7 @@ export function parseExploreQuery(line: string): ExploreQuery { | ||
| 107 | 119 | sort, |
| 108 | 120 | text: words.join(" ").slice(0, 100), |
| 109 | 121 | archived, |
| 122 | updated, | |
| 110 | 123 | ...(owner === undefined ? {} : { owner }), |
| 111 | 124 | }; |
| 112 | 125 | } |
| @@ -117,6 +130,7 @@ export function exploreLine(query: ExploreQuery): string { | ||
| 117 | 130 | query.kind === "all" ? "" : `kind:${query.kind}`, |
| 118 | 131 | query.sort === "score" ? "" : `sort:${query.sort}`, |
| 119 | 132 | query.archived ? "archived:yes" : "", |
| 133 | query.updated === "all" ? "" : `updated:${query.updated}`, | |
| 120 | 134 | query.owner === undefined ? "" : `owner:${query.owner}`, |
| 121 | 135 | query.text, |
| 122 | 136 | ] |
| @@ -184,7 +198,8 @@ export async function explore( | ||
| 184 | 198 | |
| 185 | 199 | /** The forges this forge spawned, for a site admin asking for them. */ |
| 186 | 200 | async function forges(app: App, viewer: User | undefined, query: ExploreQuery): Promise<ExploreRow[]> { |
| 187 | if (query.owner !== undefined || viewer?.isAdmin !== true || (query.kind !== "all" && query.kind !== "forge")) return []; | |
| 201 | // A spawned forge carries no time, so a window leaves it out. | |
| 202 | if (query.updated !== "all" || query.owner !== undefined || viewer?.isAdmin !== true || (query.kind !== "all" && query.kind !== "forge")) return []; | |
| 188 | 203 | return (await listChildren(app)).map((child) => ({ |
| 189 | 204 | kind: "forge", |
| 190 | 205 | name: child.name, |
| @@ -314,6 +329,7 @@ function rank( | ||
| 314 | 329 | [...appRows, ...people.values()].map(freeze).filter( |
| 315 | 330 | (row) => |
| 316 | 331 | (query.kind === "all" || row.kind === query.kind) && |
| 332 | movedWithin(row, query, now) && | |
| 317 | 333 | (only === undefined || (row.repo?.owner ?? row.name).toLowerCase() === only) && |
| 318 | 334 | (text === "" || `${row.name} ${row.description}`.toLowerCase().includes(text)), |
| 319 | 335 | ), |
| @@ -321,6 +337,14 @@ function rank( | ||
| 321 | 337 | ); |
| 322 | 338 | } |
| 323 | 339 | |
| 340 | /** Whether the row's last push, release or profile change is inside the window. */ | |
| 341 | function movedWithin(row: ExploreRow, query: ExploreQuery, now: number): boolean { | |
| 342 | if (query.updated === "all") return true; | |
| 343 | if (row.shippedAt === null) return false; | |
| 344 | const at = Date.parse(row.shippedAt); | |
| 345 | return now - at <= WINDOWS[query.updated]!; | |
| 346 | } | |
| 347 | ||
| 324 | 348 | /** Rows sorted as the query says, in place. */ |
| 325 | 349 | function order(rows: ExploreRow[], query: ExploreQuery): ExploreRow[] { |
| 326 | 350 | const by: Record<ExploreSort, (r: ExploreRow) => number | string> = { |
src/http/mcp/tools/explore.ts +1 −1
| @@ -12,7 +12,7 @@ export const tool: Tool = { | ||
| 12 | 12 | query: { |
| 13 | 13 | type: "string", |
| 14 | 14 | maxLength: 200, |
| 15 | description: "Words; kind:, sort: filters.", | |
| 15 | description: "Words; kind: sort: updated:7d", | |
| 16 | 16 | }, |
| 17 | 17 | }, |
| 18 | 18 | }, |
src/web/studio/explore.ts +13 −1
| @@ -43,7 +43,7 @@ function numbers(row: ExploreRow): { apps: string; rest: string } { | ||
| 43 | 43 | function rowHtml(row: ExploreRow): Html { |
| 44 | 44 | const { apps, rest } = numbers(row); |
| 45 | 45 | // One tap from a person to their apps; with none, the count is plain text. |
| 46 | const theirs = href({ kind: "app", sort: "score", text: "", archived: false, owner: row.name }); | |
| 46 | const theirs = href({ kind: "app", sort: "score", text: "", archived: false, updated: "all", owner: row.name }); | |
| 47 | 47 | const count = apps === "" ? html`` : row.numbers.apps > 0 ? html`<a href="${theirs}">${apps}</a>` : html`${apps}`; |
| 48 | 48 | const parts = [ |
| 49 | 49 | row.description === "" ? html`` : html`${row.description}`, |
| @@ -140,6 +140,11 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 140 | 140 | { label: "Use", sort: "use" as const }, |
| 141 | 141 | { label: "Fresh", sort: "fresh" as const }, |
| 142 | 142 | ]; |
| 143 | const windows = [ | |
| 144 | { label: "Today", updated: "1d" as const }, | |
| 145 | { label: "This week", updated: "7d" as const }, | |
| 146 | { label: "This month", updated: "30d" as const }, | |
| 147 | ]; | |
| 143 | 148 | const body = html`${pageHead("Explore", { |
| 144 | 149 | sub: "Apps and their makers, ranked by forks, ships, use and how lately — the numbers on every row.", |
| 145 | 150 | })} |
| @@ -170,6 +175,13 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 170 | 175 | current: query.sort === s.sort, |
| 171 | 176 | })), |
| 172 | 177 | )} |
| 178 | ${seg( | |
| 179 | windows.map((w) => ({ | |
| 180 | label: w.label, | |
| 181 | href: href({ ...query, updated: w.updated }), | |
| 182 | current: query.updated === w.updated, | |
| 183 | })), | |
| 184 | )} | |
| 173 | 185 | <a |
| 174 | 186 | class="btn" data-size="sm" |
| 175 | 187 | href="${href({ ...query, archived: !query.archived })}" |
test/explore.test.ts +40
| @@ -31,23 +31,32 @@ describe("the one line", () => { | ||
| 31 | 31 | sort: "forks", |
| 32 | 32 | text: "garden", |
| 33 | 33 | archived: false, |
| 34 | updated: "all", | |
| 34 | 35 | }); |
| 35 | 36 | expect(parseExploreQuery("kind:people q:dungeon")).toEqual({ |
| 36 | 37 | kind: "person", |
| 37 | 38 | sort: "score", |
| 38 | 39 | text: "dungeon", |
| 39 | 40 | archived: false, |
| 41 | updated: "all", | |
| 40 | 42 | }); |
| 41 | 43 | expect(parseExploreQuery("kind:nonsense sort:nonsense")).toEqual({ |
| 42 | 44 | kind: "all", |
| 43 | 45 | sort: "score", |
| 44 | 46 | text: "sort:nonsense", |
| 45 | 47 | archived: false, |
| 48 | updated: "all", | |
| 46 | 49 | }); |
| 47 | 50 | expect(parseExploreQuery("archived:yes").archived).toBe(true); |
| 48 | 51 | expect(exploreLine(parseExploreQuery("archived:yes kind:app"))).toBe( |
| 49 | 52 | "kind:app archived:yes", |
| 50 | 53 | ); |
| 54 | expect(parseExploreQuery("updated:7d").updated).toBe("7d"); | |
| 55 | expect(parseExploreQuery("updated:2y").updated).toBe("all"); | |
| 56 | expect(parseExploreQuery("updated:2y").text).toBe("updated:2y"); | |
| 57 | expect(exploreLine(parseExploreQuery("updated:30d kind:app garden"))).toBe( | |
| 58 | "kind:app updated:30d garden", | |
| 59 | ); | |
| 51 | 60 | expect(exploreLine(parseExploreQuery(" sort:ships kind:app "))).toBe( |
| 52 | 61 | "kind:app sort:ships", |
| 53 | 62 | ); |
| @@ -302,6 +311,37 @@ describe("explore", () => { | ||
| 302 | 311 | ).text(); |
| 303 | 312 | expect(asAlice).not.toContain('href="/alice/loved/make-it-yours"'); |
| 304 | 313 | }); |
| 314 | ||
| 315 | test("updated: narrows to what moved in the window, on the API and the page chips", async () => { | |
| 316 | const ago = async (name: string, days: number) => { | |
| 317 | const repo = await appOf(alice, name); | |
| 318 | const issue = createIssue(app.db, { repoId: repo.id, authorId: alice.id, title: "c", kind: "pull" }); | |
| 319 | if (!issue.ok) throw new Error(issue.error); | |
| 320 | app.db | |
| 321 | .query( | |
| 322 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) | |
| 323 | VALUES (?1, 'main', 'b', '', '', ?2)`, | |
| 324 | ) | |
| 325 | .run(issue.value.id, new Date(Date.now() - days * 86_400_000).toISOString()); | |
| 326 | }; | |
| 327 | await ago("two-days", 2); | |
| 328 | await ago("twenty-days", 20); | |
| 329 | const inWindow = async (w: string) => | |
| 330 | names((await api(`kind:app updated:${w}`)).items); | |
| 331 | expect(await inWindow("1d")).not.toContain("alice/two-days"); | |
| 332 | expect(await inWindow("1d")).toContain("alice/loved"); | |
| 333 | expect(await inWindow("7d")).toContain("alice/two-days"); | |
| 334 | expect(await inWindow("7d")).not.toContain("alice/twenty-days"); | |
| 335 | expect(await inWindow("30d")).toContain("alice/twenty-days"); | |
| 336 | expect(await inWindow("30d")).not.toContain("alice/quiet"); | |
| 337 | expect((await api("updated:7d kind:app")).query).toBe("kind:app updated:7d"); | |
| 338 | ||
| 339 | const page = await (await fetch(`${base}/explore?q=${encodeURIComponent("updated:7d")}`)).text(); | |
| 340 | for (const [label, w] of [["Today", "1d"], ["This week", "7d"], ["This month", "30d"]]) | |
| 341 | expect(page).toContain(`href="/explore?q=updated%3A${w}"`), expect(page).toContain(label); | |
| 342 | expect(page).toMatch(/aria-current="page"\s*>This week/); | |
| 343 | }); | |
| 344 | ||
| 305 | 345 | }); |
| 306 | 346 | |
| 307 | 347 | describe("explore on a forge with nothing public", () => { |
new above
offline