Skip to content
104 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar1import { Plus, Search } from "lucide-react";
2import { data, useSearchParams, type ShouldRevalidateFunctionArgs } from "react-router";
3
4import type { Team } from "@g1t/contracts";
5
6import type { Route } from "./+types/teams";
7import { page } from "../../lib/meta";
8import { TeamRow } from "../../components/teams";
9import { ButtonLink, EmptyState, notACredential } from "../../components/ui";
10import { filterTeams, splitTeams } from "../../lib/teams";
11import { identity } from "../../lib/services.server";
12import { getViewer, roleIn, unwrap } from "../../lib/session.server";
13
14export function meta({ params, ...args }: Route.MetaArgs) {
15 return page(args, { title: `Teams · ${params.owner} · g1t` });
16}
17
18export async function loader({ params, context }: Route.LoaderArgs) {
19 const viewer = getViewer(context);
20 // A workspace's teams are its members' business.
21 if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 });
22 const teams = unwrap(await identity.listTeams(viewer, params.owner));
23 return { teams, slug: params.owner.toLowerCase() };
24}
25
26/** Searching changes only the address: the list is already here. */
27export function shouldRevalidate({ currentUrl, nextUrl, formMethod, defaultShouldRevalidate }: ShouldRevalidateFunctionArgs) {
28 if (!formMethod && currentUrl.pathname === nextUrl.pathname) return false;
29 return defaultShouldRevalidate;
30}
31
32export default function WorkspaceTeams({ loaderData }: Route.ComponentProps) {
33 const { teams, slug } = loaderData;
34 const [params, setParams] = useSearchParams();
35 const query = params.get("q") ?? "";
36 const { mine, others } = splitTeams(filterTeams(teams, query));
37 const setQuery = (value: string) =>
38 setParams(
39 (current) => {
40 const next = new URLSearchParams(current);
41 if (value) next.set("q", value);
42 else next.delete("q");
43 return next;
44 },
45 { replace: true, preventScrollReset: true },
46 );
47
48 return (
49 <div className="space-y-8">
50 <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
51 <label className="relative block sm:w-72">
52 <span className="sr-only">Find a team</span>
53 <Search size={14} className="pointer-events-none absolute top-1/2 left-3 -translate-y-1/2 text-faint" />
54 <input
55 type="search"
56 value={query}
57 onChange={(event) => setQuery(event.target.value)}
58 placeholder="Find a team"
59 {...notACredential()}
60 className="w-full rounded-md border border-line bg-bg py-1.5 pr-3 pl-8 text-sm outline-none transition-colors placeholder:text-faint hover:border-line-strong focus:border-accent-dim"
61 />
62 </label>
63 <ButtonLink to={`/${slug}/-/teams/new`}>
64 <Plus size={15} />
65 New team
66 </ButtonLink>
67 </div>
68
69 {teams.length === 0 ? (
70 <EmptyState title="No teams yet">
71 A team gives a group of members a role on repositories at once. Mention it as{" "}
72 <span className="font-mono text-fg">@{slug}/team</span>, or ask it to review a pull request.
73 </EmptyState>
74 ) : mine.length + others.length === 0 ? (
75 <p className="rounded-xl border border-dashed border-line px-4 py-8 text-center text-sm text-muted">
76 No teams match.{" "}
77 <button type="button" className="text-accent hover:underline" onClick={() => setQuery("")}>
78 Show them all
79 </button>
80 </p>
81 ) : (
82 <>
83 {mine.length > 0 && <TeamList title="Your teams" teams={mine} />}
84 {others.length > 0 && <TeamList title={mine.length > 0 ? "Other teams" : "All teams"} teams={others} />}
85 </>
86 )}
87 </div>
88 );
89}
90
91function TeamList({ title, teams }: { title: string; teams: Team[] }) {
92 return (
93 <section aria-label={title}>
94 <h2 className="mb-3 text-sm font-medium text-muted">
95 {title} <span className="text-faint">{teams.length}</span>
96 </h2>
97 <ul className="divide-y divide-line overflow-hidden rounded-xl border border-line">
98 {teams.map((team) => (
99 <TeamRow key={team.id} team={team} />
100 ))}
101 </ul>
102 </section>
103 );
104}