Reorganize Repository modal (GitDialog) into 3 sections

Section 1: Repository Info
- Git URL with save button
- Current Branch selector with New button
- Sync Status with Pull/Push buttons
- Merge Branch action

Section 2: Pull Requests
- Your Open PRs list (for non-Nostr repos)
- Create PR button

Section 3: Working Directory
- List of changed files with status badges
- Clean state message when no changes

All sections are now in a single card-based layout for better organization and clarity.
This commit is contained in:
shakespeare.diy committed 2025-10-14 23:59:42 -05:00
1 parent c88b4f1750
commit 74d42a926c
2 files changed
+327 -617

No files matched your search

+244 -267
View File
@@ -715,234 +715,223 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
<div className="flex-1 min-h-0 overflow-hidden px-6 pb-6">
<ScrollArea className="h-full">
<div className="space-y-4 pr-4">
{/* URL Configuration */}
{/* Section 1: Git URL, Current Branch, Sync Status, Merge Branch */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Git URL</CardTitle>
<CardTitle className="text-sm">Repository Info</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<div className="flex-1">
<Label htmlFor="origin-url" className="sr-only">
URL
</Label>
<CardContent className="space-y-4">
{/* Git URL */}
<div className="space-y-2">
<Label htmlFor="origin-url" className="text-xs font-medium text-muted-foreground">
Git URL
</Label>
<div className="flex gap-2">
<Input
id="origin-url"
placeholder="https://github.com/username/repository.git"
value={originUrl}
onChange={(e) => setOriginUrl(e.target.value)}
disabled={isSavingOrigin}
className="flex-1"
/>
<Button
onClick={handleSaveOrigin}
disabled={isSavingOrigin}
variant="outline"
size="sm"
className="h-10 shrink-0"
>
{isSavingOrigin ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Save className="h-4 w-4 mr-2" />
)}
{isSavingOrigin ? 'Saving...' : 'Save'}
</Button>
</div>
<Button
onClick={handleSaveOrigin}
disabled={isSavingOrigin}
variant="outline"
size="sm"
className="h-10 shrink-0"
>
{isSavingOrigin ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Save className="h-4 w-4 mr-2" />
)}
{isSavingOrigin ? 'Saving...' : 'Save'}
</Button>
{/* Credentials Warning */}
{gitStatus.remotes.length > 0 && (
(() => {
const remoteWithoutCredentials = gitStatus.remotes.find((remote) => !findCredentialsForRepo(remote.url, settings.credentials));
if (!remoteWithoutCredentials) return null;
let protocol = '';
let hostname = 'the remote host';
try {
const url = new URL(remoteWithoutCredentials.url);
protocol = url.protocol;
hostname = url.hostname;
} catch {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50 mt-2">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
Invalid URL format. Enter an https URL.
</AlertDescription>
</Alert>
);
}
if (protocol !== 'https:' && protocol !== 'nostr:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50 mt-2">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
The {protocol.replace(':', '')} URL type is not supported. Enter an https URL.
</AlertDescription>
</Alert>
);
}
if (protocol === 'nostr:' && !user) {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50 mt-2">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into Nostr. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/nostr')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
if (protocol === 'https:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50 mt-2">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into {hostname}. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/git')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
return null;
})()
)}
</div>
{/* Credentials Warning */}
{gitStatus.remotes.length > 0 && (
(() => {
const remoteWithoutCredentials = gitStatus.remotes.find((remote) => !findCredentialsForRepo(remote.url, settings.credentials));
if (!remoteWithoutCredentials) return null;
let protocol = '';
let hostname = 'the remote host';
try {
const url = new URL(remoteWithoutCredentials.url);
protocol = url.protocol;
hostname = url.hostname;
} catch {
// Invalid URL
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
Invalid URL format. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// Check for unsupported protocols
if (protocol !== 'https:' && protocol !== 'nostr:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
The {protocol.replace(':', '')} URL type is not supported. Enter an https URL.
</AlertDescription>
</Alert>
);
}
// For nostr protocol, only show warning if user is not logged in
if (protocol === 'nostr:' && !user) {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into Nostr. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/nostr')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
// For https protocol, show warning if no credentials
if (protocol === 'https:') {
return (
<Alert className="border-amber-200 bg-amber-50 dark:border-amber-800 dark:bg-amber-950/50">
<AlertTriangle className="h-4 w-4" />
<AlertDescription className="text-sm">
You are not logged into {hostname}. Push & pull might not work unless you{' '}
<button
onClick={() => navigate('/settings/git')}
className="underline hover:no-underline font-medium text-amber-700 dark:text-amber-300"
>
log in
</button>.
</AlertDescription>
</Alert>
);
}
return null;
})()
)}
</CardContent>
</Card>
)}
{/* Branch Selector */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Current Branch</CardTitle>
</CardHeader>
<CardContent className="space-y-3">
<div className="flex gap-2">
<Select
value={gitStatus.currentBranch}
onValueChange={handleSwitchBranch}
disabled={isSwitchingBranch || isLoadingBranches}
>
<SelectTrigger className="flex-1">
<SelectValue>
{isSwitchingBranch ? (
<span className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Switching...
</span>
) : (
<span className="flex items-center gap-2">
<GitBranch className="h-4 w-4" />
{gitStatus.currentBranch}
</span>
)}
</SelectValue>
</SelectTrigger>
<SelectContent>
{branches.map((branch) => (
<SelectItem key={branch} value={branch}>
<span className="flex items-center gap-2">
{branch === gitStatus.currentBranch && (
<CheckCircle className="h-4 w-4 text-primary" />
{/* Current Branch */}
{gitStatus.currentBranch && (
<div className="space-y-2">
<Label className="text-xs font-medium text-muted-foreground">
Current Branch
</Label>
<div className="flex gap-2">
<Select
value={gitStatus.currentBranch}
onValueChange={handleSwitchBranch}
disabled={isSwitchingBranch || isLoadingBranches}
>
<SelectTrigger className="flex-1">
<SelectValue>
{isSwitchingBranch ? (
<span className="flex items-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Switching...
</span>
) : (
<span className="flex items-center gap-2">
<GitBranch className="h-4 w-4" />
{gitStatus.currentBranch}
</span>
)}
{branch}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="outline"
size="sm"
className="shrink-0"
onClick={() => setIsCreateBranchDialogOpen(true)}
disabled={isSwitchingBranch}
>
<Plus className="h-4 w-4 mr-2" />
New
</Button>
</div>
</CardContent>
</Card>
)}
{/* Sync Status */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Sync Status</CardTitle>
</CardHeader>
<CardContent>
<div className="flex items-center gap-2 mb-4">
<syncStatus.icon className={cn("h-4 w-4", syncStatus.color)} />
<span className={cn("text-sm font-medium", syncStatus.color)}>
{syncStatus.text}
</span>
</div>
{gitStatus.remotes.length > 0 && (
<div className="flex gap-2">
<Button
onClick={handlePull}
disabled={isPulling || isPushing || isPushingToNostr}
variant="outline"
size="sm"
className="flex-1"
>
{isPulling ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Download className="h-4 w-4 mr-2" />
)}
{isPulling ? 'Pulling...' : 'Pull'}
</Button>
<Button
onClick={handlePush}
disabled={isPushing || isPulling || isPushingToNostr || gitStatus.ahead === 0}
variant="outline"
size="sm"
className="flex-1"
>
{isPushing ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Upload className="h-4 w-4 mr-2" />
)}
{isPushing ? 'Pushing...' : 'Push'}
</Button>
</SelectValue>
</SelectTrigger>
<SelectContent>
{branches.map((branch) => (
<SelectItem key={branch} value={branch}>
<span className="flex items-center gap-2">
{branch === gitStatus.currentBranch && (
<CheckCircle className="h-4 w-4 text-primary" />
)}
{branch}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="outline"
size="sm"
className="shrink-0"
onClick={() => setIsCreateBranchDialogOpen(true)}
disabled={isSwitchingBranch}
>
<Plus className="h-4 w-4 mr-2" />
New
</Button>
</div>
</div>
)}
{/* Push to Nostr button when no remote is configured and user is logged in */}
{gitStatus.remotes.length === 0 && user && (
<div className="flex gap-2">
{/* Sync Status */}
<div className="space-y-2">
<Label className="text-xs font-medium text-muted-foreground">
Sync Status
</Label>
<div className="flex items-center gap-2 mb-3">
<syncStatus.icon className={cn("h-4 w-4", syncStatus.color)} />
<span className={cn("text-sm font-medium", syncStatus.color)}>
{syncStatus.text}
</span>
</div>
{gitStatus.remotes.length > 0 && (
<div className="flex gap-2">
<Button
onClick={handlePull}
disabled={isPulling || isPushing || isPushingToNostr}
variant="outline"
size="sm"
className="flex-1"
>
{isPulling ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Download className="h-4 w-4 mr-2" />
)}
{isPulling ? 'Pulling...' : 'Pull'}
</Button>
<Button
onClick={handlePush}
disabled={isPushing || isPulling || isPushingToNostr || gitStatus.ahead === 0}
variant="outline"
size="sm"
className="flex-1"
>
{isPushing ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
) : (
<Upload className="h-4 w-4 mr-2" />
)}
{isPushing ? 'Pushing...' : 'Push'}
</Button>
</div>
)}
{gitStatus.remotes.length === 0 && user && (
<Button
onClick={handlePushToNostr}
disabled={isPushingToNostr || isPushing || isPulling}
variant="outline"
size="sm"
className="flex-1"
className="w-full"
>
{isPushingToNostr ? (
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
@@ -951,13 +940,24 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
)}
{isPushingToNostr ? 'Publishing to Nostr...' : 'Push to Nostr'}
</Button>
)}
</div>
{/* Merge Branch Action */}
{gitStatus.currentBranch && (
<div className="pt-2 border-t">
<MergeDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
onMergeComplete={() => refetchGitStatus()}
/>
</div>
)}
</CardContent>
</Card>
)}
{/* Pull Requests Card */}
{/* Section 2: Your Open PRs and Create PR Button */}
{gitStatus?.isGitRepo && gitStatus.remotes.length > 0 && originUrl && (
<Card>
<CardHeader className="pb-3">
@@ -972,7 +972,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
</CardDescription>
</CardHeader>
<CardContent className="space-y-3">
{/* Open Pull Requests List (only for non-Nostr repos) */}
{/* Open Pull Requests List */}
{!originUrl.startsWith('nostr://') && isLoadingPRs && (
<div className="flex items-center justify-center py-4 text-sm text-muted-foreground">
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
@@ -980,7 +980,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
</div>
)}
{!originUrl.startsWith('nostr://') && !isLoadingPRs && pullRequests && pullRequests.length > 0 && (
<div className="space-y-2">
<div className="space-y-2 mb-3">
<div className="text-xs font-medium text-muted-foreground mb-2">Your Open PRs</div>
{pullRequests.map((pr) => (
<div
key={pr.id}
@@ -1011,13 +1012,8 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
))}
</div>
)}
{!originUrl.startsWith('nostr://') && !isLoadingPRs && (!pullRequests || pullRequests.length === 0) && (
<div className="text-sm text-muted-foreground text-center py-2">
You have no open pull requests
</div>
)}
{/* Create PR Button - Works for all repo types */}
{/* Create PR Button */}
<PullRequestDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
@@ -1027,64 +1023,45 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
</Card>
)}
{/* Branch Operations */}
{gitStatus?.isGitRepo && gitStatus.currentBranch && (
{/* Section 3: Working Directory */}
{gitStatus?.isGitRepo && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Branch Operations</CardTitle>
</CardHeader>
<CardContent className="flex gap-2">
<MergeDialog
projectId={projectId}
currentBranch={gitStatus.currentBranch}
onMergeComplete={() => refetchGitStatus()}
/>
</CardContent>
</Card>
)}
{/* Working Directory Changes */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length > 0 && (
<Card>
<CardHeader className="pb-3">
<CardTitle className="text-sm">Working Directory Changes</CardTitle>
<CardDescription>
{gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes
</CardDescription>
<CardTitle className="text-sm">Working Directory</CardTitle>
{gitStatus.changedFiles.length > 0 && (
<CardDescription>
{gitStatus.changedFiles.length} file{gitStatus.changedFiles.length !== 1 ? 's' : ''} with changes
</CardDescription>
)}
</CardHeader>
<CardContent>
<div className="space-y-2">
{gitStatus.changedFiles.map((file, index) => (
<div
key={index}
className="flex items-center gap-2 p-2 rounded-md border bg-muted/20"
>
{getFileStatusIcon(file.status)}
<span className="font-mono text-sm flex-1 truncate">
{file.filepath}
</span>
<Badge
variant="outline"
className={cn("text-xs", getFileStatusColor(file.status))}
{gitStatus.changedFiles.length > 0 ? (
<div className="space-y-2">
{gitStatus.changedFiles.map((file, index) => (
<div
key={index}
className="flex items-center gap-2 p-2 rounded-md border bg-muted/20"
>
{file.status}
</Badge>
</div>
))}
</div>
</CardContent>
</Card>
)}
{/* Clean Working Directory */}
{gitStatus?.isGitRepo && gitStatus.changedFiles.length === 0 && (
<Card>
<CardContent className="py-6">
<div className="text-center text-muted-foreground">
<CheckCircle className="h-8 w-8 mx-auto mb-2 text-green-500" />
<p>Working directory is clean</p>
<p className="text-xs">No uncommitted changes</p>
</div>
{getFileStatusIcon(file.status)}
<span className="font-mono text-sm flex-1 truncate">
{file.filepath}
</span>
<Badge
variant="outline"
className={cn("text-xs", getFileStatusColor(file.status))}
>
{file.status}
</Badge>
</div>
))}
</div>
) : (
<div className="text-center text-muted-foreground py-6">
<CheckCircle className="h-8 w-8 mx-auto mb-2 text-green-500" />
<p>Working directory is clean</p>
<p className="text-xs">No uncommitted changes</p>
</div>
)}
</CardContent>
</Card>
)}
+83 -350
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback } from 'react';
import { useState } from 'react';
import {
Dialog,
DialogContent,
@@ -6,31 +6,21 @@ import {
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Separator } from '@/components/ui/separator';
import {
GitBranch,
GitMerge,
GitCompare,
Settings,
GitPullRequest,
ExternalLink,
Loader2,
RefreshCw,
CheckCircle,
XCircle,
Clock,
} from 'lucide-react';
import { BranchManager } from './BranchManager';
import { CompareView } from './CompareView';
import { DiffViewer } from './DiffViewer';
import { MergeDialog } from './MergeDialog';
import { PullRequestForm } from './PullRequestForm';
import { useGitStatus } from '@/hooks/useGitStatus';
import { useGit } from '@/hooks/useGit';
import { useGitSettings } from '@/hooks/useGitSettings';
import { useToast } from '@/hooks/useToast';
import { findCredentialsForRepo } from '@/lib/gitCredentials';
import { BranchManager } from './BranchManager';
import { useState, useEffect } from 'react';
interface GitManagementDialogProps {
projectId: string;
@@ -40,37 +30,16 @@ interface GitManagementDialogProps {
defaultTab?: string;
}
interface PullRequest {
number: number;
title: string;
state: 'open' | 'closed' | 'merged';
html_url: string;
created_at: string;
head: {
ref: string;
};
base: {
ref: string;
};
}
export function GitManagementDialog({
projectId,
children,
open,
onOpenChange,
defaultTab = 'branches',
}: GitManagementDialogProps) {
const [activeTab, setActiveTab] = useState(defaultTab);
const [remoteUrl, setRemoteUrl] = useState<string | null>(null);
const [isSyncing, setIsSyncing] = useState(false);
const [isMergeDialogOpen, setIsMergeDialogOpen] = useState(false);
const [showPRForm, setShowPRForm] = useState(false);
const [pullRequests, setPullRequests] = useState<PullRequest[]>([]);
const [isLoadingPRs, setIsLoadingPRs] = useState(false);
const [showBranchManager, setShowBranchManager] = useState(false);
const { git } = useGit();
const { settings } = useGitSettings();
const { toast } = useToast();
const projectPath = `/projects/${projectId}`;
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
@@ -89,140 +58,11 @@ export function GitManagementDialog({
}
}, [open, git, projectPath]);
const loadPullRequests = useCallback(async () => {
if (!remoteUrl) return;
setIsLoadingPRs(true);
try {
const credentials = findCredentialsForRepo(remoteUrl, settings.credentials);
if (!credentials) {
setPullRequests([]);
return;
}
// Parse GitHub/GitLab URL
let match;
let owner = '';
let repo = '';
let apiUrl = '';
const normalizedUrl = remoteUrl.replace(/\.git$/, '');
// GitHub
match = normalizedUrl.match(/git@github\.com:([^/]+)\/(.+)$/) ||
normalizedUrl.match(/https?:\/\/github\.com\/([^/]+)\/(.+)$/);
if (match) {
owner = match[1];
repo = match[2];
apiUrl = `https://api.github.com/repos/${owner}/${repo}/pulls`;
}
// GitLab
if (!match) {
match = normalizedUrl.match(/git@gitlab\.com:([^/]+)\/(.+)$/) ||
normalizedUrl.match(/https?:\/\/gitlab\.com\/([^/]+)\/(.+)$/);
if (match) {
owner = match[1];
repo = match[2];
apiUrl = `https://gitlab.com/api/v4/projects/${encodeURIComponent(`${owner}/${repo}`)}/merge_requests`;
}
}
if (!apiUrl) {
setPullRequests([]);
return;
}
// Get current user to filter PRs
const response = await fetch(`${apiUrl}?state=open`, {
headers: {
'Authorization': `token ${credentials.password}`,
},
});
if (!response.ok) {
throw new Error('Failed to fetch pull requests');
}
const data = await response.json();
// Filter PRs authored by current user (based on credentials username)
const userPRs = Array.isArray(data)
? data.filter((pr: any) =>
pr.user?.login === credentials.username ||
pr.author?.username === credentials.username
)
: [];
setPullRequests(userPRs);
} catch (err) {
console.error('Failed to load pull requests:', err);
setPullRequests([]);
} finally {
setIsLoadingPRs(false);
}
}, [remoteUrl, settings.credentials]);
useEffect(() => {
if (open && remoteUrl) {
loadPullRequests();
}
}, [open, remoteUrl, loadPullRequests]);
const handleSync = async () => {
setIsSyncing(true);
try {
const credentials = findCredentialsForRepo(remoteUrl || '', settings.credentials);
// Pull
await git.pull({
dir: projectPath,
author: {
name: credentials?.username || 'shakespeare.diy',
email: credentials?.email || '[email protected]',
},
onAuth: () => credentials || undefined,
});
// Push
await git.push({
dir: projectPath,
onAuth: () => credentials || undefined,
});
toast({
title: 'Sync successful',
description: 'Your changes have been synchronized',
});
refetchGitStatus();
} catch (err) {
toast({
title: 'Sync failed',
description: err instanceof Error ? err.message : 'Unknown error',
variant: 'destructive',
});
} finally {
setIsSyncing(false);
}
};
const handleBranchChange = () => {
// Refetch git status when branches change
refetchGitStatus();
};
const formatDate = (dateStr: string) => {
const date = new Date(dateStr);
const now = new Date();
const diffMs = now.getTime() - date.getTime();
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays === 0) return 'today';
if (diffDays === 1) return 'yesterday';
if (diffDays < 7) return `${diffDays} days ago`;
return date.toLocaleDateString();
};
return (
<>
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -232,201 +72,94 @@ export function GitManagementDialog({
<DialogHeader className="px-6 pt-6 pb-4 border-b shrink-0">
<DialogTitle className="flex items-center gap-2">
<GitBranch className="h-5 w-5" />
Repository
Git Management
</DialogTitle>
</DialogHeader>
<ScrollArea className="flex-1">
<div className="p-6 space-y-6">
{/* Section 1: Git URL, Current Branch, Sync Status, Merge Branch */}
<Card>
<CardHeader>
<CardTitle className="text-base">Repository Info</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{/* Git URL */}
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Git URL</div>
<div className="font-mono text-sm bg-muted/50 p-2 rounded break-all">
{remoteUrl || 'No remote configured'}
</div>
</div>
{/* Current Branch */}
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Current Branch</div>
<div className="flex items-center gap-2">
<Badge variant="outline" className="font-mono">
{gitStatus?.currentBranch || 'Unknown'}
</Badge>
<Button
variant="ghost"
size="sm"
onClick={() => setShowBranchManager(!showBranchManager)}
className="h-7 text-xs"
>
{showBranchManager ? 'Hide' : 'Manage'} Branches
</Button>
</div>
</div>
{/* Branch Manager (collapsible) */}
{showBranchManager && (
<div className="pt-2 border-t">
<BranchManager
projectId={projectId}
currentBranch={gitStatus?.currentBranch || null}
onBranchChange={handleBranchChange}
/>
</div>
)}
{/* Sync Status */}
{/* Tabs Container - takes remaining space */}
<div className="flex-1 flex flex-col min-h-0">
<Tabs value={activeTab} onValueChange={setActiveTab} className="flex-1 flex flex-col">
{/* Fixed Tab List */}
<div className="border-b px-6 shrink-0">
<TabsList className="h-auto p-0 bg-transparent">
<TabsTrigger
value="branches"
className="gap-2 data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none"
>
<GitBranch className="h-4 w-4" />
Branches
</TabsTrigger>
<TabsTrigger
value="changes"
className="gap-2 data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none"
>
<Settings className="h-4 w-4" />
Changes
</TabsTrigger>
<TabsTrigger
value="compare"
className="gap-2 data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none"
>
<GitCompare className="h-4 w-4" />
Compare
</TabsTrigger>
{remoteUrl && (
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Sync Status</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={handleSync}
disabled={isSyncing}
className="gap-2"
>
{isSyncing ? (
<>
<Loader2 className="h-4 w-4 animate-spin" />
Syncing...
</>
) : (
<>
<RefreshCw className="h-4 w-4" />
Sync
</>
)}
</Button>
{gitStatus && (
<div className="text-sm text-muted-foreground">
{gitStatus.modified + gitStatus.added + gitStatus.deleted > 0
? `${gitStatus.modified + gitStatus.added + gitStatus.deleted} changes`
: 'Up to date'}
</div>
)}
</div>
</div>
<TabsTrigger
value="pr"
className="gap-2 data-[state=active]:border-b-2 data-[state=active]:border-primary rounded-none"
>
<GitPullRequest className="h-4 w-4" />
Pull Request
</TabsTrigger>
)}
</TabsList>
</div>
{/* Merge Branch Action */}
<div className="pt-2 border-t">
<MergeDialog
{/* Scrollable Tab Content */}
<TabsContent value="branches" className="flex-1 m-0 data-[state=active]:flex data-[state=active]:flex-col">
<ScrollArea className="flex-1">
<div className="p-6">
<BranchManager
projectId={projectId}
currentBranch={gitStatus?.currentBranch || null}
open={isMergeDialogOpen}
onOpenChange={setIsMergeDialogOpen}
onMergeComplete={() => {
refetchGitStatus();
setIsMergeDialogOpen(false);
}}
onBranchChange={handleBranchChange}
/>
</div>
</CardContent>
</Card>
</ScrollArea>
</TabsContent>
{/* Section 2: Pull Requests */}
{remoteUrl && (
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-base">Pull Requests</CardTitle>
<Button
variant="outline"
size="sm"
onClick={() => setShowPRForm(!showPRForm)}
className="gap-2"
>
<GitPullRequest className="h-4 w-4" />
{showPRForm ? 'Hide Form' : 'Create PR'}
</Button>
</div>
</CardHeader>
<CardContent className="space-y-4">
{/* PR Form (collapsible) */}
{showPRForm && (
<div className="pb-4 border-b">
<PullRequestForm
projectId={projectId}
currentBranch={gitStatus?.currentBranch || null}
remoteUrl={remoteUrl}
/>
</div>
)}
{/* Your Open PRs */}
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Your Open PRs</div>
{isLoadingPRs ? (
<div className="flex items-center justify-center py-8">
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
</div>
) : pullRequests.length > 0 ? (
<div className="space-y-2">
{pullRequests.map((pr) => (
<div
key={pr.number}
className="flex items-start gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors"
>
<div className="mt-0.5">
{pr.state === 'open' && <GitPullRequest className="h-4 w-4 text-green-600" />}
{pr.state === 'merged' && <CheckCircle className="h-4 w-4 text-purple-600" />}
{pr.state === 'closed' && <XCircle className="h-4 w-4 text-red-600" />}
</div>
<div className="flex-1 min-w-0">
<div className="font-medium text-sm">{pr.title}</div>
<div className="flex items-center gap-2 mt-1 text-xs text-muted-foreground">
<span>#{pr.number}</span>
<span>•</span>
<span>{pr.head.ref} → {pr.base.ref}</span>
<span>•</span>
<span>{formatDate(pr.created_at)}</span>
</div>
</div>
<Button
variant="ghost"
size="sm"
className="h-7 gap-1 shrink-0"
onClick={() => window.open(pr.html_url, '_blank')}
>
View
<ExternalLink className="h-3 w-3" />
</Button>
</div>
))}
</div>
) : (
<div className="text-center py-8 text-muted-foreground">
<GitPullRequest className="h-12 w-12 mx-auto mb-2 opacity-50" />
<p className="text-sm">No open pull requests</p>
</div>
)}
</div>
</CardContent>
</Card>
)}
{/* Section 3: Working Directory */}
<Card>
<CardHeader>
<CardTitle className="text-base">Working Directory</CardTitle>
</CardHeader>
<CardContent className="p-0">
<TabsContent value="changes" className="flex-1 m-0 data-[state=active]:flex data-[state=active]:flex-col min-h-0">
<div className="flex-1 min-h-0">
<DiffViewer
projectId={projectId}
compareFrom="HEAD"
/>
</CardContent>
</Card>
</div>
</ScrollArea>
</div>
</TabsContent>
<TabsContent value="compare" className="flex-1 m-0 data-[state=active]:flex data-[state=active]:flex-col">
<ScrollArea className="flex-1">
<div className="p-6">
<CompareView projectId={projectId} />
</div>
</ScrollArea>
</TabsContent>
{remoteUrl && (
<TabsContent value="pr" className="flex-1 m-0 data-[state=active]:flex data-[state=active]:flex-col">
<ScrollArea className="flex-1">
<div className="p-6">
<PullRequestForm
projectId={projectId}
currentBranch={gitStatus?.currentBranch || null}
remoteUrl={remoteUrl}
/>
</div>
</ScrollArea>
</TabsContent>
)}
</Tabs>
</div>
</DialogContent>
</Dialog>
</>