diff --git a/src/components/ai/GitHistoryDialog.test.tsx b/src/components/ai/GitHistoryDialog.test.tsx index c035fb75..dd6e730d 100644 --- a/src/components/ai/GitHistoryDialog.test.tsx +++ b/src/components/ai/GitHistoryDialog.test.tsx @@ -128,4 +128,48 @@ describe('GitHistoryDialog', () => { const rollbackButtons = screen.getAllByText('Rollback'); expect(rollbackButtons).toHaveLength(1); }); + + it('handles multi-line commit messages with expand/collapse', async () => { + const mockCommits = [ + { + oid: 'commit1', + commit: { + message: 'Add new feature\n\nThis commit adds a new feature with the following changes:\n- Added component A\n- Updated component B\n- Fixed bug in component C', + author: { name: 'User', email: 'user@example.com', timestamp: Math.floor(Date.now() / 1000), timezoneOffset: 0 }, + committer: { name: 'User', email: 'user@example.com', timestamp: Math.floor(Date.now() / 1000), timezoneOffset: 0 }, + parent: [], + tree: 'tree1', + }, + payload: '', + }, + ]; + + const git = await import('isomorphic-git'); + vi.mocked(git.default.log).mockResolvedValue(mockCommits); + + render( + + + + ); + + const historyButton = screen.getByRole('button', { name: /history/i }); + fireEvent.click(historyButton); + + await waitFor(() => { + expect(screen.getByText('Add new feature')).toBeInTheDocument(); + }); + + // Should show expand button for multi-line commit + const expandButton = screen.getByRole('button', { name: '' }); // ChevronDown button + expect(expandButton).toBeInTheDocument(); + + // Click to expand + fireEvent.click(expandButton); + + // Should show the expanded content + await waitFor(() => { + expect(screen.getByText(/This commit adds a new feature/)).toBeInTheDocument(); + }); + }); }); \ No newline at end of file diff --git a/src/components/ai/GitHistoryDialog.tsx b/src/components/ai/GitHistoryDialog.tsx index e474b864..674ee4fd 100644 --- a/src/components/ai/GitHistoryDialog.tsx +++ b/src/components/ai/GitHistoryDialog.tsx @@ -4,7 +4,7 @@ import { Button } from '@/components/ui/button'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Badge } from '@/components/ui/badge'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; -import { History, GitCommit, User, Calendar, Hash, RotateCcw, AlertTriangle } from 'lucide-react'; +import { History, GitCommit, RotateCcw, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react'; import { useFS } from '@/hooks/useFS'; import { useToast } from '@/hooks/useToast'; import git from 'isomorphic-git'; @@ -36,6 +36,7 @@ export function GitHistoryDialog({ projectId }: GitHistoryDialogProps) { const [error, setError] = useState(null); const [isOpen, setIsOpen] = useState(false); const [isRollingBack, setIsRollingBack] = useState(null); + const [expandedCommits, setExpandedCommits] = useState>(new Set()); const { fs } = useFS(); const { toast } = useToast(); @@ -234,10 +235,6 @@ ${commitsToRevert.map(c => `- ${c.oid.substring(0, 7)}: ${c.commit.message}`).jo } }, [isOpen, loadGitHistory]); - const formatDate = (timestamp: number) => { - return new Date(timestamp * 1000).toLocaleString(); - }; - const formatRelativeTime = (timestamp: number) => { const now = Date.now(); const commitTime = timestamp * 1000; @@ -256,6 +253,27 @@ ${commitsToRevert.map(c => `- ${c.oid.substring(0, 7)}: ${c.commit.message}`).jo } }; + const getCommitMessageLines = (message: string) => { + const lines = message.split('\n').filter(line => line.trim() !== ''); + return { + firstLine: lines[0] || '', + hasMoreLines: lines.length > 1, + fullMessage: message, + }; + }; + + const toggleCommitExpansion = (commitOid: string) => { + setExpandedCommits(prev => { + const newSet = new Set(prev); + if (newSet.has(commitOid)) { + newSet.delete(commitOid); + } else { + newSet.add(commitOid); + } + return newSet; + }); + }; + return ( @@ -309,108 +327,119 @@ ${commitsToRevert.map(c => `- ${c.oid.substring(0, 7)}: ${c.commit.message}`).jo ) : ( - - {commits.map((commit, index) => ( - - - - - + + {commits.map((commit, index) => { + const { firstLine, hasMoreLines, fullMessage } = getCommitMessageLines(commit.commit.message); + const isExpanded = expandedCommits.has(commit.oid); - - - - {commit.commit.message} - - - - - {commit.oid.substring(0, 7)} - - {index > 0 && ( // Don't show rollback for the most recent commit - - - - - Rollback - - - - - - - Confirm Rollback - - - - This will create a new commit that reverts the codebase back to: - - - {commit.commit.message} - - {commit.oid.substring(0, 7)} • {formatRelativeTime(commit.commit.author.timestamp)} - - - - This action will revert {index} commit(s) and cannot be undone easily. - A new commit will be created with the reverted changes. - - - - - Cancel - rollbackToCommit(commit)} - className="bg-destructive text-destructive-foreground hover:bg-destructive/90" - disabled={isRollingBack !== null} - > - {isRollingBack === commit.oid ? ( - <> - - Rolling back... - > - ) : ( - <> - - Rollback - > - )} - - - - + return ( + + + + + + + + {firstLine} + + + {commit.oid.substring(0, 7)} + + + + {isExpanded && hasMoreLines && ( + + {fullMessage.split('\n').slice(1).join('\n').trim()} + + )} + + + {hasMoreLines && ( + toggleCommitExpansion(commit.oid)} + > + {isExpanded ? ( + + ) : ( + + )} + )} - - - - - {commit.commit.author.name} - - - - - - {formatRelativeTime(commit.commit.author.timestamp)} - + + {commit.commit.author.name} + committed {formatRelativeTime(commit.commit.author.timestamp)} + + {index > 0 && ( // Don't show rollback for the most recent commit + + + + + + Rollback + + + + + + + Confirm Rollback + + + + This will create a new commit that reverts the codebase back to: + + + {firstLine} + + {commit.oid.substring(0, 7)} • {formatRelativeTime(commit.commit.author.timestamp)} + + + + This action will revert {index} commit(s) and cannot be undone easily. + A new commit will be created with the reverted changes. + + + + + Cancel + rollbackToCommit(commit)} + className="bg-destructive text-destructive-foreground hover:bg-destructive/90" + disabled={isRollingBack !== null} + > + {isRollingBack === commit.oid ? ( + <> + + Rolling back... + > + ) : ( + <> + + Rollback + > + )} + + + + + + )} - - {index < commits.length - 1 && ( - - - - )} - - ))} + ); + })} )}
- This will create a new commit that reverts the codebase back to: -
- This action will revert {index} commit(s) and cannot be undone easily. - A new commit will be created with the reverted changes. -
+ This will create a new commit that reverts the codebase back to: +
+ This action will revert {index} commit(s) and cannot be undone easily. + A new commit will be created with the reverted changes. +