fix: restore legacy GitHub launch compatibility (#1962)
This commit is contained in:
@@ -9,6 +9,36 @@ import { useToast } from "@/components/toast-provider";
|
||||
import { fetchGitHubCLIAccounts, setGitHubWorkspaceConnection } from "@/lib/api/domains/github-api";
|
||||
import type { GitHubCLIAccount } from "@/lib/types/github";
|
||||
|
||||
function GitHubCLIAccountNotice({
|
||||
loadError,
|
||||
loading,
|
||||
hasAccounts,
|
||||
}: {
|
||||
loadError: string | null;
|
||||
loading: boolean;
|
||||
hasAccounts: boolean;
|
||||
}) {
|
||||
if (loading || hasAccounts) return null;
|
||||
if (loadError) {
|
||||
return (
|
||||
<p role="alert" className="text-xs text-destructive">
|
||||
Could not load GitHub CLI accounts. {loadError}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sign in with <code>gh auth login</code>, then reopen this dialog.
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
function accountPlaceholder(loading: boolean, loadError: string | null) {
|
||||
if (loading) return "Loading accounts...";
|
||||
if (loadError) return "Accounts unavailable";
|
||||
return "No gh accounts found";
|
||||
}
|
||||
|
||||
export function GitHubCLIForm({
|
||||
workspaceId,
|
||||
onSaved,
|
||||
@@ -18,6 +48,7 @@ export function GitHubCLIForm({
|
||||
}) {
|
||||
const [accounts, setAccounts] = useState<GitHubCLIAccount[]>([]);
|
||||
const [selected, setSelected] = useState("");
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const { toast } = useToast();
|
||||
@@ -26,6 +57,7 @@ export function GitHubCLIForm({
|
||||
let current = true;
|
||||
setAccounts([]);
|
||||
setSelected("");
|
||||
setLoadError(null);
|
||||
setLoading(true);
|
||||
setSaving(false);
|
||||
fetchGitHubCLIAccounts(workspaceId, { cache: "no-store" })
|
||||
@@ -36,7 +68,13 @@ export function GitHubCLIForm({
|
||||
items.find((item) => item.selected) ?? items.find((item) => item.active) ?? items[0];
|
||||
setSelected(preferred ? `${preferred.host}\n${preferred.login}` : "");
|
||||
})
|
||||
.catch(() => current && setAccounts([]))
|
||||
.catch((error) => {
|
||||
if (!current) return;
|
||||
setAccounts([]);
|
||||
setLoadError(
|
||||
error instanceof Error ? error.message : "Unexpected response from the server",
|
||||
);
|
||||
})
|
||||
.finally(() => current && setLoading(false));
|
||||
return () => {
|
||||
current = false;
|
||||
@@ -80,7 +118,7 @@ export function GitHubCLIForm({
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-stretch">
|
||||
<Select value={selected} onValueChange={setSelected} disabled={loading || !accounts.length}>
|
||||
<SelectTrigger id="github-cli-account" className="min-h-11 min-w-0 flex-1">
|
||||
<SelectValue placeholder={loading ? "Loading accounts..." : "No gh accounts found"} />
|
||||
<SelectValue placeholder={accountPlaceholder(loading, loadError)} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{accounts.map((item) => (
|
||||
@@ -95,11 +133,11 @@ export function GitHubCLIForm({
|
||||
Use account
|
||||
</Button>
|
||||
</div>
|
||||
{!accounts.length && !loading && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sign in with <code>gh auth login</code>, then reopen this dialog.
|
||||
</p>
|
||||
)}
|
||||
<GitHubCLIAccountNotice
|
||||
loadError={loadError}
|
||||
loading={loading}
|
||||
hasAccounts={accounts.length > 0}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user