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

"Your repositories" in the user menu goes home (href "/"): give it a real, searchable list, and test every menu link #5872

Parked opened this in answer to
Closed without merging

scout/forge:scout/5844-your-repositories-in-the-user-menu-goes → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +274 −1
src/core/repos.ts +39
@@ -731,6 +731,45 @@ export function listReposWritableTo(
731731 return withCounts(db, rows);
732732 }
733733
734 /**
735 * Every repository a person owns or belongs to — their own, and every
736 * organization's they sit on a team in, any permission — most recently pushed
737 * first (a repository never pushed to sorts by when it was made). The
738 * "Your repositories" page: one list, not a page per owner. Archived ones
739 * stay; the row says so.
740 */
741 export function listReposOfMember(
742 db: Database,
743 user: User,
744 options: { query?: string; limit?: number } = {},
745 ): Repo[] {
746 const params: (string | number)[] = [user.id];
747 let where = `(repo.owner_id = ?1 OR repo.owner_id IN (
748 SELECT team.org_id FROM team
749 JOIN team_member ON team_member.team_id = team.id
750 WHERE team_member.user_id = ?1))`;
751 const query = options.query?.trim() ?? "";
752 if (query !== "") {
753 params.push(`%${likeEscape(query)}%`);
754 const p = params.length;
755 where += ` AND (repo.name LIKE ?${p} ESCAPE '\\' COLLATE NOCASE
756 OR user.username LIKE ?${p} ESCAPE '\\' COLLATE NOCASE
757 OR repo.description LIKE ?${p} ESCAPE '\\' COLLATE NOCASE)`;
758 }
759 params.push(Math.min(Math.max(options.limit ?? 500, 1), 500));
760 const rows = db
761 .query<RepoRow, (string | number)[]>(
762 `${SELECT} WHERE ${where}
763 ORDER BY COALESCE((SELECT MAX(event.created_at) FROM event
764 WHERE event.repo_id = repo.id AND event.kind = 'push'), repo.created_at) DESC,
765 repo.id DESC
766 LIMIT ?${params.length}`,
767 )
768 .all(...params)
769 .map(toRepo);
770 return withCounts(db, rows);
771 }
772
734773 /** Repos owned by one user or org, visible to the viewer. */
735774 export function listReposByOwner(
736775 db: Database,
src/http/server.ts +2
@@ -305,6 +305,7 @@ import {
305305 newAppPage,
306306 newAppSubmit,
307307 } from "../web/pages/apps.ts";
308 import { myReposPage } from "../web/pages/my-repos.ts";
308309 import {
309310 migratePage,
310311 migrateSubmit,
@@ -762,6 +763,7 @@ export function buildRouter(): Router<Handler> {
762763 router.add("POST", "/organizations/new", newOrgSubmit);
763764 // Apps and the crew (docs/APPS.md): the list, the golden path's first
764765 // step, and the short door to a run the proxy's "not running" page opens.
766 router.add("GET", "/repos", myReposPage);
765767 router.add("GET", "/apps", appsList);
766768 router.add("GET", "/apps/new", newAppPage);
767769 router.add("POST", "/apps/new", newAppSubmit);
src/web/layout.ts +2 −1
@@ -205,7 +205,7 @@ function userMenu(
205205 ): Html {
206206 const items: (MenuItem | Html)[] = [
207207 { label: "Your profile", href: `/${user.username}`, icon: "user" },
208 { label: "Your repositories", href: "/", icon: "repo" },
208 { label: "Your repositories", href: "/repos", icon: "repo" },
209209 { label: "Apps", href: "/apps", icon: "rocket" },
210210 { label: "Explore", href: "/explore", icon: "search" },
211211 { label: "Map", href: "/map", icon: "map" },
@@ -272,6 +272,7 @@ function searchBar(): Html {
272272 /** The palette's own verbs: where to go, what to make, what to set. */
273273 const STATIC_PALETTE: PaletteItem[] = [
274274 { t: "Home", h: "/", c: "Go to" },
275 { t: "Your repositories", h: "/repos", c: "Go to" },
275276 { t: "Apps", h: "/apps", c: "Go to" },
276277 { t: "Explore", h: "/explore", c: "Go to" },
277278 { t: "Map", h: "/map", c: "Go to" },
src/web/pages/my-repos.ts added +83
@@ -0,0 +1,83 @@
1 /**
2 * Your repositories: every repository you own or belong to through an
3 * organization, one list, most recently pushed first, with a search box that
4 * works as a plain GET form. The user menu's "Your repositories" opens it.
5 */
6
7 import { appsForRepos } from "../../core/apps.ts";
8 import { listReposOfMember, type Repo } from "../../core/repos.ts";
9 import type { Ctx } from "../../http/context.ts";
10 import { pageHead, signInFirst } from "../chrome.ts";
11 import { html, type Html } from "../html.ts";
12 import { icon } from "../icons.ts";
13 import { page } from "../layout.ts";
14 import { badge, btn, empty, listCard, repoCounts, row } from "../ui.ts";
15
16 function repoRow(repo: Repo, isApp: boolean): Html {
17 return row({
18 href: `/${repo.ownerName}/${repo.name}`,
19 lead: icon(isApp ? "rocket" : repo.forkParentId !== null ? "fork" : "repo"),
20 title: `${repo.ownerName}/${repo.name}`,
21 nav: true,
22 ...(repo.description !== "" ? { meta: html`${repo.description}` } : {}),
23 trail: html`${repoCounts({
24 openIssues: repo.counts?.openIssues,
25 openPulls: repo.counts?.openPulls,
26 })}${repo.archivedAt !== null ? badge("Archived", { variant: "secondary" }) : null}${repo.visibility ===
27 "private"
28 ? badge("Private", { icon: "lock", variant: "secondary" })
29 : badge("Public", { variant: "secondary" })}`,
30 });
31 }
32
33 // GET /repos
34 export function myReposPage(ctx: Ctx): Response {
35 const user = ctx.auth.user;
36 if (!user) return signInFirst(ctx);
37 const query = (ctx.url.searchParams.get("q") ?? "").slice(0, 100);
38 const repos = listReposOfMember(ctx.app.db, user, { query });
39 const apps = appsForRepos(
40 ctx.app.db,
41 repos.map((r) => r.id),
42 );
43 return page({
44 ctx,
45 title: "Your repositories",
46 body: html`<div class="narrow-wide">
47 ${pageHead("Your repositories", {
48 actions: btn("New repository", { href: "/new", variant: "primary" }),
49 sub: "Yours, and every organization's you are on a team in — most recently pushed first.",
50 })}
51 <div class="bar mt mb">
52 <form class="bar" method="get" action="/repos" role="search">
53 <input
54 class="input search"
55 type="search"
56 name="q"
57 value="${query}"
58 placeholder="Find a repository"
59 aria-label="Find a repository"
60 data-search-input
61 />
62 <button class="btn" data-size="sm" type="submit">Search</button>
63 </form>
64 </div>
65 ${repos.length === 0
66 ? empty({
67 icon: "repo",
68 title: query !== "" ? "No matches" : "No repositories yet",
69 note:
70 query !== ""
71 ? "Try a different search."
72 : "Create one, or migrate one in.",
73 })
74 : listCard(
75 repos.map((r) => repoRow(r, apps.has(r.id))),
76 {
77 head: html`${icon("repo")}
78 <h2>${repos.length} ${repos.length === 1 ? "repository" : "repositories"}</h2>`,
79 },
80 )}
81 </div>`,
82 });
83 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs