Polish source control settings

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-05-02 14:23:00 -07:00
1 parent b133b0dbce
commit f4180a404f
7 files changed
+523 -200

No files matched your search

@@ -74,7 +74,6 @@ Logged in to github.com account juliusmarminge (keyring)
[
{ kind: "git", implemented: true, status: "available" },
{ kind: "jj", implemented: false, status: "missing" },
{ kind: "sapling", implemented: false, status: "missing" },
],
);
assert.deepStrictEqual(
@@ -63,14 +63,6 @@ const VCS_PROBES: ReadonlyArray<VcsProbe> = [
implemented: false,
installHint: "Install Jujutsu with `brew install jj` or from https://github.com/jj-vcs/jj.",
},
{
kind: "sapling",
label: "Sapling",
executable: "sl",
versionArgs: ["--version"],
implemented: false,
installHint: "Install Sapling (`sl`) from https://sapling-scm.com/.",
},
];
const SOURCE_CONTROL_PROVIDER_PROBES: ReadonlyArray<ProviderProbe> = [
@@ -11,17 +11,19 @@ import {
type DesktopUpdateState,
type LocalApi,
type ServerConfig,
type SourceControlDiscoveryResult,
} from "@t3tools/contracts";
import { DateTime } from "effect";
import { DateTime, Option } from "effect";
import { page } from "vitest/browser";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { render } from "vitest-browser-react";
import { __resetLocalApiForTests } from "../../localApi";
import { AppAtomRegistryProvider } from "../../rpc/atomRegistry";
import { AppAtomRegistryProvider, resetAppAtomRegistryForTests } from "../../rpc/atomRegistry";
import { resetServerStateForTests, setServerConfigSnapshot } from "../../rpc/serverState";
import { ConnectionsSettings } from "./ConnectionsSettings";
import { GeneralSettingsPanel } from "./SettingsPanels";
import { SourceControlSettingsPanel } from "./SourceControlSettings";
const authAccessHarness = vi.hoisted(() => {
type Snapshot = AuthAccessSnapshot;
@@ -723,3 +725,148 @@ describe("GeneralSettingsPanel observability", () => {
await expect.element(page.getByPlaceholder("Optional")).toBeInTheDocument();
});
});
describe("SourceControlSettingsPanel discovery states", () => {
let mounted:
| (Awaited<ReturnType<typeof render>> & {
cleanup?: () => Promise<void>;
unmount?: () => Promise<void>;
})
| null = null;
beforeEach(async () => {
resetAppAtomRegistryForTests();
await __resetLocalApiForTests();
document.body.innerHTML = "";
});
afterEach(async () => {
if (mounted) {
const teardown = mounted.cleanup ?? mounted.unmount;
await teardown?.call(mounted).catch(() => {});
}
mounted = null;
Reflect.deleteProperty(window, "nativeApi");
document.body.innerHTML = "";
await __resetLocalApiForTests();
resetAppAtomRegistryForTests();
});
function setSourceControlDiscoveryStub(
discoverSourceControl: () => Promise<SourceControlDiscoveryResult>,
) {
window.nativeApi = {
server: {
discoverSourceControl,
},
} as LocalApi;
}
it("shows skeleton sections while the first source control scan is pending", async () => {
setSourceControlDiscoveryStub(() => new Promise(() => {}));
mounted = await render(
<AppAtomRegistryProvider>
<SourceControlSettingsPanel />
</AppAtomRegistryProvider>,
);
await expect.element(page.getByText("Version Control")).toBeInTheDocument();
await expect.element(page.getByText("Source Control Providers")).toBeInTheDocument();
await expect
.element(page.getByRole("button", { name: "Scan source control tools" }))
.toBeDisabled();
await expect.element(page.getByText("No source control tools found")).not.toBeInTheDocument();
});
it("uses the shared empty state when discovery completes without tools", async () => {
setSourceControlDiscoveryStub(async () => ({
versionControlSystems: [],
sourceControlProviders: [],
}));
mounted = await render(
<AppAtomRegistryProvider>
<SourceControlSettingsPanel />
</AppAtomRegistryProvider>,
);
await expect.element(page.getByText("No source control tools found")).toBeInTheDocument();
await expect
.element(page.getByText("Install a supported Git or pull request CLI, then scan again."))
.toBeInTheDocument();
await expect.element(page.getByRole("button", { name: "Scan" })).toBeInTheDocument();
});
it("keeps discovered rows instead of showing the empty state", async () => {
setSourceControlDiscoveryStub(async () => ({
versionControlSystems: [
{
kind: "git",
label: "Git",
executable: "git",
implemented: true,
status: "available",
version: Option.some("git version 2.50.0"),
installHint: "Install Git.",
detail: Option.none(),
},
],
sourceControlProviders: [],
}));
mounted = await render(
<AppAtomRegistryProvider>
<SourceControlSettingsPanel />
</AppAtomRegistryProvider>,
);
await expect.element(page.getByRole("heading", { name: "Git" })).toBeInTheDocument();
await expect.element(page.getByText("No source control tools found")).not.toBeInTheDocument();
});
it("does not rescan on remount while the discovery atom is fresh", async () => {
let calls = 0;
setSourceControlDiscoveryStub(async () => {
calls += 1;
return {
versionControlSystems: [
{
kind: "git",
label: "Git",
executable: "git",
implemented: true,
status: "available",
version: Option.some("git version 2.50.0"),
installHint: "Install Git.",
detail: Option.none(),
},
],
sourceControlProviders: [],
};
});
mounted = await render(
<AppAtomRegistryProvider>
<SourceControlSettingsPanel />
</AppAtomRegistryProvider>,
);
await expect.element(page.getByRole("heading", { name: "Git" })).toBeInTheDocument();
expect(calls).toBe(1);
const teardown = mounted.cleanup ?? mounted.unmount;
await teardown?.call(mounted).catch(() => {});
mounted = null;
document.body.innerHTML = "";
mounted = await render(
<AppAtomRegistryProvider>
<SourceControlSettingsPanel />
</AppAtomRegistryProvider>,
);
await expect.element(page.getByRole("heading", { name: "Git" })).toBeInTheDocument();
expect(calls).toBe(1);
});
});
@@ -1,8 +1,8 @@
import { ChevronDownIcon, GitBranchIcon, GitPullRequestIcon, RefreshCwIcon } from "lucide-react";
import { GitPullRequestIcon, RefreshCwIcon } from "lucide-react";
import { Option } from "effect";
import { useMemo, useState } from "react";
import { type ReactNode, useId } from "react";
import type {
SourceControlDiscoveryItem,
SourceControlProviderKind,
SourceControlDiscoveryResult,
SourceControlProviderAuth,
SourceControlProviderDiscoveryItem,
@@ -16,8 +16,18 @@ import {
} from "../../lib/sourceControlDiscoveryState";
import { Badge } from "../ui/badge";
import { Button } from "../ui/button";
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
import {
Empty,
EmptyContent,
EmptyDescription,
EmptyHeader,
EmptyMedia,
EmptyTitle,
} from "../ui/empty";
import { Skeleton } from "../ui/skeleton";
import { Switch } from "../ui/switch";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { GitHubIcon, type Icon } from "../Icons";
import { RedactedSensitiveText } from "./RedactedSensitiveText";
import { SettingsPageContainer, SettingsSection } from "./settingsLayout";
@@ -26,6 +36,134 @@ const EMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult = {
sourceControlProviders: [],
};
const GitLabIcon: Icon = (props) => (
<svg {...props} viewBox="0 0 32 32" fill="none">
<path
d="m31.46 12.78-.04-.12-4.35-11.35A1.14 1.14 0 0 0 25.94.6c-.24 0-.47.1-.66.24-.19.15-.33.36-.39.6l-2.94 9h-11.9l-2.94-9A1.14 1.14 0 0 0 6.07.58a1.15 1.15 0 0 0-1.14.72L.58 12.68l-.05.11a8.1 8.1 0 0 0 2.68 9.34l.02.01.04.03 6.63 4.97 3.28 2.48 2 1.52a1.35 1.35 0 0 0 1.62 0l2-1.52 3.28-2.48 6.67-5h.02a8.09 8.09 0 0 0 2.7-9.36Z"
fill="#E24329"
/>
<path
d="m31.46 12.78-.04-.12a14.75 14.75 0 0 0-5.86 2.64l-9.55 7.24 6.09 4.6 6.67-5h.02a8.09 8.09 0 0 0 2.67-9.36Z"
fill="#FC6D26"
/>
<path
d="m9.9 27.14 3.28 2.48 2 1.52a1.35 1.35 0 0 0 1.62 0l2-1.52 3.28-2.48-6.1-4.6-6.07 4.6Z"
fill="#FCA326"
/>
<path
d="M6.44 15.3a14.71 14.71 0 0 0-5.86-2.63l-.05.12a8.1 8.1 0 0 0 2.68 9.34l.02.01.04.03 6.63 4.97 6.1-4.6-9.56-7.24Z"
fill="#FC6D26"
/>
</svg>
);
const AzureDevOpsIcon: Icon = (props) => {
const id = useId().replaceAll(":", "");
const gradientA = `${id}-azure-a`;
const gradientB = `${id}-azure-b`;
const gradientC = `${id}-azure-c`;
return (
<svg {...props} viewBox="0 0 96 96">
<defs>
<linearGradient
id={gradientA}
x1="-1032.17"
x2="-1059.21"
y1="145.31"
y2="65.43"
gradientTransform="matrix(1 0 0 -1 1075 158)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopColor="#114a8b" />
<stop offset="1" stopColor="#0669bc" />
</linearGradient>
<linearGradient
id={gradientB}
x1="-1023.73"
x2="-1029.98"
y1="108.08"
y2="105.97"
gradientTransform="matrix(1 0 0 -1 1075 158)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopOpacity=".3" />
<stop offset=".07" stopOpacity=".2" />
<stop offset=".32" stopOpacity=".1" />
<stop offset=".62" stopOpacity=".05" />
<stop offset="1" stopOpacity="0" />
</linearGradient>
<linearGradient
id={gradientC}
x1="-1027.16"
x2="-997.48"
y1="147.64"
y2="68.56"
gradientTransform="matrix(1 0 0 -1 1075 158)"
gradientUnits="userSpaceOnUse"
>
<stop offset="0" stopColor="#3ccbf4" />
<stop offset="1" stopColor="#2892df" />
</linearGradient>
</defs>
<path
fill={`url(#${gradientA})`}
d="M33.34 6.54h26.04l-27.03 80.1a4.15 4.15 0 0 1-3.94 2.81H8.15a4.14 4.14 0 0 1-3.93-5.47L29.4 9.38a4.15 4.15 0 0 1 3.94-2.83z"
/>
<path
fill="#0078d4"
d="M71.17 60.26H29.88a1.91 1.91 0 0 0-1.3 3.31l26.53 24.76a4.17 4.17 0 0 0 2.85 1.13h23.38z"
/>
<path
fill={`url(#${gradientB})`}
d="M33.34 6.54a4.12 4.12 0 0 0-3.95 2.88L4.25 83.92a4.14 4.14 0 0 0 3.91 5.54h20.79a4.44 4.44 0 0 0 3.4-2.9l5.02-14.78 17.91 16.7a4.24 4.24 0 0 0 2.67.97h23.29L71.02 60.26H41.24L59.47 6.55z"
/>
<path
fill={`url(#${gradientC})`}
d="M66.6 9.36a4.14 4.14 0 0 0-3.93-2.82H33.65a4.15 4.15 0 0 1 3.93 2.82l25.18 74.62a4.15 4.15 0 0 1-3.93 5.48h29.02a4.15 4.15 0 0 0 3.93-5.48z"
/>
</svg>
);
};
const BitbucketIcon: Icon = (props) => {
const id = useId().replaceAll(":", "");
const gradientId = `${id}-bitbucket-a`;
return (
<svg {...props} viewBox="8.4 14.39 2481.29 2231.21">
<path fill="none" d="M989.97,1493.09h518.05l125.04-730.04H852.22L989.97,1493.09z" />
<path
fill="#2684FF"
d="M88.92,14.4C45.02,13.83,8.97,48.96,8.41,92.86c-0.06,4.61,0.28,9.22,1.02,13.77l337.48,2048.72 c8.68,51.75,53.26,89.8,105.74,90.24h1619.03c39.38,0.5,73.19-27.9,79.49-66.78l337.49-2071.78c7.03-43.34-22.41-84.17-65.75-91.2 c-4.55-0.74-9.15-1.08-13.76-1.02L88.92,14.4z M1509.99,1495.09H993.24l-139.92-731h781.89L1509.99,1495.09z"
/>
<linearGradient
id={gradientId}
gradientUnits="userSpaceOnUse"
x1="945.1094"
y1="1524.8389"
x2="944.4923"
y2="1524.1893"
gradientTransform="matrix(1996.6343 0 0 -1480.3047 -1884485.625 2258195)"
>
<stop offset="0.18" stopColor="#0052CC" />
<stop offset="1" stopColor="#2684FF" />
</linearGradient>
<path
fill={`url(#${gradientId})`}
d="M2379.27,763.06h-745.5l-125.12,730.42H992.31l-609.67,723.67c19.32,16.71,43.96,26,69.5,26.21h1618.13 c39.35,0.51,73.14-27.88,79.44-66.72L2379.27,763.06z"
/>
</svg>
);
};
const SOURCE_CONTROL_PROVIDER_ICONS: Partial<Record<SourceControlProviderKind, Icon>> = {
github: GitHubIcon,
gitlab: GitLabIcon,
"azure-devops": AzureDevOpsIcon,
bitbucket: BitbucketIcon,
};
function optionLabel(value: Option.Option<string>): string | null {
return Option.getOrNull(value);
}
@@ -38,25 +176,15 @@ function isProviderDiscoveryItem(
function authPresentation(auth: SourceControlProviderAuth): {
readonly label: string;
readonly badge: "success" | "warning" | "outline";
readonly badge: "warning" | null;
} {
if (auth.status === "authenticated") {
return { label: "Signed in", badge: "success" };
return { label: "Signed in", badge: null };
}
if (auth.status === "unauthenticated") {
return { label: "Sign in", badge: "warning" };
}
return { label: "Auth unknown", badge: "outline" };
}
function authSummary(auth: SourceControlProviderAuth): string {
if (auth.status === "authenticated") {
return "Authenticated";
}
if (auth.status === "unauthenticated") {
return "Not authenticated";
}
return "Auth not checked";
return { label: "Sign in", badge: null };
}
function RedactedAccount(props: { readonly account: string | null }) {
@@ -70,57 +198,93 @@ function RedactedAccount(props: { readonly account: string | null }) {
);
}
function statusPresentation(item: SourceControlDiscoveryItem): {
readonly label: string;
readonly badge: "success" | "warning" | "outline";
readonly dot: string;
} {
if (item.implemented && item.status === "available") {
return {
label: "Ready",
badge: "success",
dot: "bg-success",
};
function itemStatusDot(item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem): string {
if (!item.implemented) return "bg-muted-foreground/35";
if (item.status !== "available") return "bg-warning";
if (isProviderDiscoveryItem(item) && item.auth.status !== "authenticated") return "bg-warning";
return "bg-success";
}
function SourceControlItemMark({
item,
}: {
readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;
}) {
const dotClassName = itemStatusDot(item);
const Icon = isProviderDiscoveryItem(item) ? SOURCE_CONTROL_PROVIDER_ICONS[item.kind] : null;
if (!Icon) {
return <span className={cn("size-2 shrink-0 rounded-full", dotClassName)} aria-hidden />;
}
if (item.implemented) {
return {
label: "CLI missing",
badge: "warning",
dot: "bg-warning",
};
return (
<span className="relative inline-flex size-5 shrink-0 items-center justify-center">
<Icon className="size-4.5 text-foreground/80" aria-hidden />
<span
className={cn(
"pointer-events-none absolute -left-0.5 -top-0.5 size-2 rounded-full ring-2 ring-background",
dotClassName,
)}
aria-hidden
/>
</span>
);
}
function itemSummary({
item,
auth,
authAccount,
}: {
readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;
readonly auth: SourceControlProviderAuth | null;
readonly authAccount: string | null;
}) {
if (!item.implemented) {
return <span>Support for {item.label} is coming soon.</span>;
}
if (item.status === "available") {
return {
label: "Detected",
badge: "outline",
dot: "bg-muted-foreground/60",
};
if (item.status !== "available") {
return <span>Not found - {item.installHint}</span>;
}
return {
label: "Placeholder",
badge: "outline",
dot: "bg-muted-foreground/40",
};
if (auth) {
if (auth.status === "authenticated") {
return (
<>
<span>Authenticated</span>
{authAccount ? (
<>
<span aria-hidden>as</span>
<RedactedAccount account={authAccount} />
</>
) : null}
</>
);
}
if (auth.status === "unauthenticated") {
return <span>Sign in with the {item.executable} CLI to enable pull request actions.</span>;
}
return (
<span>
Install and sign in with the {item.executable} CLI to enable pull request actions.
</span>
);
}
return <span>Available</span>;
}
function DiscoveryItemRow({
item,
expanded,
onExpandedChange,
}: {
readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;
readonly expanded: boolean;
readonly onExpandedChange: (expanded: boolean) => void;
}) {
const status = statusPresentation(item);
const version = optionLabel(item.version);
const detail = optionLabel(item.detail);
const enabled = item.implemented && item.status === "available";
const auth = isProviderDiscoveryItem(item) ? item.auth : null;
const authStatus = auth ? authPresentation(auth) : null;
const authAccount = auth ? optionLabel(auth.account) : null;
const authHost = auth ? optionLabel(auth.host) : null;
const authDetail = auth ? optionLabel(auth.detail) : null;
return (
<div
@@ -133,166 +297,175 @@ function DiscoveryItemRow({
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="min-w-0 flex-1 space-y-1">
<div className="flex min-w-0 flex-wrap items-center gap-2">
<span className={cn("size-2 rounded-full", status.dot)} aria-hidden />
<SourceControlItemMark item={item} />
<h3 className="truncate text-[13px] font-semibold tracking-[-0.01em] text-foreground">
{item.label}
</h3>
<Badge variant={status.badge} size="sm">
{status.label}
</Badge>
{version ? <code className="text-xs text-muted-foreground">{version}</code> : null}
{!item.implemented ? (
<Badge variant="outline" size="sm">
Not in this branch
<Badge variant="warning" size="sm">
Coming Soon
</Badge>
) : null}
{authStatus ? (
{authStatus?.badge ? (
<Badge variant={authStatus.badge} size="sm">
{authStatus.label}
</Badge>
) : null}
</div>
<p className="flex min-w-0 flex-wrap items-center gap-x-1 text-xs text-muted-foreground">
<span>CLI</span>
<code className="rounded-sm bg-muted px-1 py-0.5 font-mono text-[11px] text-foreground/80">
{item.executable}
</code>
{version ? <span>- {version}</span> : null}
{auth ? (
<>
<span aria-hidden>-</span>
<span>{authSummary(auth)}</span>
{authAccount ? <RedactedAccount account={authAccount} /> : null}
</>
) : null}
{itemSummary({ item, auth, authAccount })}
</p>
</div>
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
<Button
size="sm"
variant="ghost"
className="h-7 px-2 text-xs text-muted-foreground hover:text-foreground"
onClick={() => onExpandedChange(!expanded)}
aria-label={`Toggle ${item.label} details`}
>
<ChevronDownIcon
className={cn("size-3.5 transition-transform", expanded && "rotate-180")}
/>
</Button>
<Switch checked={enabled} disabled aria-label={`${item.label} availability`} />
{item.implemented ? (
<Switch checked={enabled} disabled aria-label={`${item.label} availability`} />
) : null}
</div>
</div>
</div>
<Collapsible open={expanded} onOpenChange={onExpandedChange}>
<CollapsibleContent>
<div className="border-t border-border/60 px-4 py-3 text-xs sm:px-5">
<dl className="grid gap-3 sm:grid-cols-[8rem_minmax(0,1fr)]">
<dt className="text-muted-foreground">Command</dt>
<dd className="min-w-0 font-mono text-foreground">{item.executable}</dd>
<dt className="text-muted-foreground">Version</dt>
<dd className="min-w-0 text-foreground">{version ?? "Not detected"}</dd>
{auth ? (
<>
<dt className="text-muted-foreground">Auth</dt>
<dd className="min-w-0 space-y-1 text-foreground">
<div className="flex min-w-0 flex-wrap items-center gap-1.5">
<span>{authSummary(auth)}</span>
{authAccount ? <RedactedAccount account={authAccount} /> : null}
{authHost ? (
<span className="text-muted-foreground">on {authHost}</span>
) : null}
</div>
{authDetail ? (
<div className="break-words text-muted-foreground">{authDetail}</div>
) : null}
</dd>
</>
) : null}
<dt className="text-muted-foreground">Install</dt>
<dd className="min-w-0 leading-relaxed text-foreground">{item.installHint}</dd>
<dt className="text-muted-foreground">Build</dt>
<dd className="min-w-0 leading-relaxed text-foreground">
{item.implemented
? "Enabled in this branch and available for repository routing when the CLI is present."
: "Placeholder only in this branch. The matching driver/provider PR enables this row."}
</dd>
{detail ? (
<>
<dt className="text-muted-foreground">Probe</dt>
<dd className="min-w-0 break-words text-muted-foreground">{detail}</dd>
</>
) : null}
</dl>
</div>
</CollapsibleContent>
</Collapsible>
</div>
);
}
function SourceControlSectionSkeleton({
title,
headerAction,
}: {
readonly title: string;
readonly headerAction?: ReactNode;
}) {
return (
<SettingsSection title={title} headerAction={headerAction}>
{Array.from({ length: 2 }, (_, index) => (
<div key={index} className="border-t border-border/60 px-4 py-3.5 first:border-t-0 sm:px-5">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="min-w-0 flex-1 space-y-2">
<div className="flex items-center gap-2">
<Skeleton className="size-2 rounded-full" />
<Skeleton className="h-4 w-28 rounded-full" />
<Skeleton className="h-5 w-14 rounded-full" />
</div>
<Skeleton className="h-3 w-full max-w-xs rounded-full" />
</div>
<div className="flex shrink-0 items-center gap-2">
<Skeleton className="size-7 rounded-md" />
<Skeleton className="h-5 w-9 rounded-full" />
</div>
</div>
</div>
))}
</SettingsSection>
);
}
function EmptySourceControlDiscovery({
error,
isPending,
onScan,
}: {
readonly error: string | null;
readonly isPending: boolean;
readonly onScan: () => void;
}) {
const hasError = error !== null;
return (
<SettingsSection title="Detected tools">
<Empty className="min-h-88">
<EmptyMedia variant="icon">
<GitPullRequestIcon />
</EmptyMedia>
<EmptyHeader>
<EmptyTitle>
{hasError ? "Could not scan source control" : "No source control tools found"}
</EmptyTitle>
<EmptyDescription>
{hasError ? error : "Install a supported Git or pull request CLI, then scan again."}
</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Button
size="sm"
variant="outline"
className="h-8 gap-1.5 px-3 text-xs"
onClick={onScan}
disabled={isPending}
>
<RefreshCwIcon className={cn("size-3.5", isPending && "animate-spin")} />
Scan
</Button>
</EmptyContent>
</Empty>
</SettingsSection>
);
}
export function SourceControlSettingsPanel() {
const discovery = useSourceControlDiscovery();
const [expanded, setExpanded] = useState<Readonly<Record<string, boolean>>>({});
const result = discovery.data ?? EMPTY_DISCOVERY_RESULT;
const statusText = useMemo(() => {
if (discovery.isPending) return "Scanning installed tools...";
if (discovery.error) return discovery.error;
return "Detected source control tools on this system.";
}, [discovery.error, discovery.isPending]);
const setItemExpanded = (key: string, value: boolean) => {
setExpanded((current) => ({ ...current, [key]: value }));
const hasDiscoveryItems =
result.versionControlSystems.length > 0 || result.sourceControlProviders.length > 0;
const isInitialScanPending = discovery.isPending && discovery.data === null;
const handleScan = () => {
void refreshSourceControlDiscovery();
};
const scanButton = (
<Tooltip>
<TooltipTrigger
render={
<Button
size="icon-xs"
variant="ghost"
className="size-5 rounded-sm p-0 text-muted-foreground hover:text-foreground"
onClick={handleScan}
disabled={discovery.isPending}
aria-label="Scan source control tools"
>
<RefreshCwIcon className={cn("size-3", discovery.isPending && "animate-spin")} />
</Button>
}
/>
<TooltipPopup side="top">Scan source control tools</TooltipPopup>
</Tooltip>
);
return (
<SettingsPageContainer>
<div className="space-y-1 px-1">
<h1 className="text-lg font-semibold tracking-[-0.01em] text-foreground">Source Control</h1>
<p className="text-sm text-muted-foreground">{statusText}</p>
</div>
{isInitialScanPending ? (
<>
<SourceControlSectionSkeleton title="Version Control" headerAction={scanButton} />
<SourceControlSectionSkeleton title="Source Control Providers" />
</>
) : hasDiscoveryItems ? (
<>
{result.versionControlSystems.length > 0 ? (
<SettingsSection title="Version Control" headerAction={scanButton}>
{result.versionControlSystems.map((item) => (
<DiscoveryItemRow key={`vcs:${item.kind}`} item={item} />
))}
</SettingsSection>
) : null}
<SettingsSection
title="Version Control"
icon={<GitBranchIcon className="size-3.5" />}
headerAction={
<Button
size="sm"
variant="ghost"
className="h-7 gap-1.5 px-2 text-xs"
onClick={() => {
void refreshSourceControlDiscovery();
}}
disabled={discovery.isPending}
>
<RefreshCwIcon className={cn("size-3.5", discovery.isPending && "animate-spin")} />
Scan
</Button>
}
>
{result.versionControlSystems.map((item) => (
<DiscoveryItemRow
key={`vcs:${item.kind}`}
item={item}
expanded={expanded[`vcs:${item.kind}`] ?? false}
onExpandedChange={(value) => setItemExpanded(`vcs:${item.kind}`, value)}
/>
))}
</SettingsSection>
<SettingsSection
title="Source Control Providers"
icon={<GitPullRequestIcon className="size-3.5" />}
>
{result.sourceControlProviders.map((item) => (
<DiscoveryItemRow
key={`provider:${item.kind}`}
item={item}
expanded={expanded[`provider:${item.kind}`] ?? false}
onExpandedChange={(value) => setItemExpanded(`provider:${item.kind}`, value)}
/>
))}
</SettingsSection>
{result.sourceControlProviders.length > 0 ? (
<SettingsSection
title="Source Control Providers"
headerAction={result.versionControlSystems.length === 0 ? scanButton : null}
>
{result.sourceControlProviders.map((item) => (
<DiscoveryItemRow key={`provider:${item.kind}`} item={item} />
))}
</SettingsSection>
) : null}
</>
) : (
<EmptySourceControlDiscovery
error={discovery.error}
isPending={discovery.isPending}
onScan={handleScan}
/>
)}
</SettingsPageContainer>
);
}
@@ -28,13 +28,13 @@ export function SettingsSection({
}) {
return (
<section className="space-y-2.5">
<div className="flex items-center justify-between px-1">
<div className="flex h-5 items-center justify-between px-1">
<h2 className="flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/50">
<span className="inline-block h-px w-3 bg-border" aria-hidden />
{icon}
{title}
</h2>
{headerAction}
<div className="flex h-5 min-w-5 items-center justify-end">{headerAction}</div>
</div>
<div className="relative overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-sm/4 not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:shadow-none dark:before:shadow-[0_-1px_--theme(--color-white/6%)]">
{children}
@@ -8,18 +8,32 @@ import {
sourceControlDiscoveryStateAtom,
} from "@t3tools/client-runtime";
import type { SourceControlDiscoveryResult } from "@t3tools/contracts";
import { useEffect } from "react";
import { Effect } from "effect";
import { Atom } from "effect/unstable/reactivity";
import { readLocalApi } from "../localApi";
import { appAtomRegistry } from "../rpc/atomRegistry";
const SOURCE_CONTROL_DISCOVERY_TARGET = { key: "primary" } as const;
const SOURCE_CONTROL_DISCOVERY_STALE_TIME_MS = 30_000;
const SOURCE_CONTROL_DISCOVERY_IDLE_TTL_MS = 5 * 60_000;
export const sourceControlDiscoveryManager = createSourceControlDiscoveryManager({
getRegistry: () => appAtomRegistry,
getClient: () => readLocalApi()?.server ?? null,
});
const sourceControlDiscoveryAutoRefreshAtom = Atom.make(() =>
Effect.promise(() => refreshSourceControlDiscovery()),
).pipe(
Atom.swr({
staleTime: SOURCE_CONTROL_DISCOVERY_STALE_TIME_MS,
revalidateOnMount: true,
}),
Atom.setIdleTTL(SOURCE_CONTROL_DISCOVERY_IDLE_TTL_MS),
Atom.withLabel("source-control-discovery:auto-refresh"),
);
export function refreshSourceControlDiscovery(): Promise<SourceControlDiscoveryResult | null> {
return sourceControlDiscoveryManager.refresh(SOURCE_CONTROL_DISCOVERY_TARGET);
}
@@ -31,9 +45,7 @@ export function resetSourceControlDiscoveryStateForTests(): void {
export function useSourceControlDiscovery(): SourceControlDiscoveryState {
const targetKey = getSourceControlDiscoveryTargetKey(SOURCE_CONTROL_DISCOVERY_TARGET);
useEffect(() => {
void sourceControlDiscoveryManager.refresh(SOURCE_CONTROL_DISCOVERY_TARGET);
}, []);
useAtomValue(sourceControlDiscoveryAutoRefreshAtom);
const state = useAtomValue(
targetKey !== null
+1 -1
View File
@@ -1,7 +1,7 @@
import { Schema } from "effect";
import { TrimmedNonEmptyString } from "./baseSchemas.ts";
export const VcsDriverKind = Schema.Literals(["git", "jj", "sapling", "unknown"]);
export const VcsDriverKind = Schema.Literals(["git", "jj", "unknown"]);
export type VcsDriverKind = typeof VcsDriverKind.Type;
export const VcsFreshnessSource = Schema.Literals([