From 237cab58452b05e49320caf8ce6c3c250cff3c40 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 29 Aug 2025 12:54:36 -0500 Subject: [PATCH] Add ProjectInfoDialog --- package-lock.json | 2 +- package.json | 1 - src/components/ProjectInfoDialog.test.tsx | 96 +++++++++++ src/components/ProjectInfoDialog.tsx | 192 ++++++++++++++++++++++ src/pages/ProjectView.tsx | 32 +++- 5 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 src/components/ProjectInfoDialog.test.tsx create mode 100644 src/components/ProjectInfoDialog.tsx diff --git a/package-lock.json b/package-lock.json index 9863e66d..49fdd142 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,6 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.0.0", - "date-fns": "^3.6.0", "embla-carousel-react": "^8.3.0", "esbuild-wasm": "^0.25.8", "input-otp": "^1.2.4", @@ -5143,6 +5142,7 @@ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-3.6.0.tgz", "integrity": "sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==", "license": "MIT", + "peer": true, "funding": { "type": "github", "url": "https://github.com/sponsors/kossnocorp" diff --git a/package.json b/package.json index b2552af8..d93725ec 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cmdk": "^1.0.0", - "date-fns": "^3.6.0", "embla-carousel-react": "^8.3.0", "esbuild-wasm": "^0.25.8", "input-otp": "^1.2.4", diff --git a/src/components/ProjectInfoDialog.test.tsx b/src/components/ProjectInfoDialog.test.tsx new file mode 100644 index 00000000..acf04b50 --- /dev/null +++ b/src/components/ProjectInfoDialog.test.tsx @@ -0,0 +1,96 @@ +import { describe, it, expect, vi } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import { userEvent } from '@testing-library/user-event'; +import { TestApp } from '@/test/TestApp'; +import { ProjectInfoDialog } from './ProjectInfoDialog'; +import type { Project } from '@/lib/ProjectsManager'; + +// Mock the useProjectsManager hook +vi.mock('@/hooks/useProjectsManager', () => ({ + useProjectsManager: () => ({ + readFile: vi.fn().mockResolvedValue('{"description": "Test project", "version": "1.0.0"}'), + getNostrRepoAddress: vi.fn().mockResolvedValue(null), + listFiles: vi.fn().mockResolvedValue(['file1.js', 'file2.ts']), + }), +})); + +const mockProject: Project = { + id: 'test-project', + name: 'Test Project', + path: '/projects/test-project', + lastModified: new Date('2024-01-01T12:00:00Z'), +}; + +describe('ProjectInfoDialog', () => { + it('renders project information when open', async () => { + render( + + {}} + /> + + ); + + // Check if the dialog title is rendered + expect(screen.getByText('Test Project')).toBeInTheDocument(); + expect(screen.getByText('Project information and metadata')).toBeInTheDocument(); + + // Check for basic information section + expect(screen.getByText('Basic Information')).toBeInTheDocument(); + expect(screen.getByText('Project ID:')).toBeInTheDocument(); + expect(screen.getByText('test-project')).toBeInTheDocument(); + }); + + it('does not render when closed', () => { + render( + + {}} + /> + + ); + + // Dialog should not be visible when closed + expect(screen.queryByText('Test Project')).not.toBeInTheDocument(); + }); + + it('calls onOpenChange when dialog state changes', async () => { + const user = userEvent.setup(); + const onOpenChange = vi.fn(); + + render( + + + + ); + + // Click the close button (X) + const closeButton = screen.getByRole('button', { name: /close/i }); + await user.click(closeButton); + + expect(onOpenChange).toHaveBeenCalledWith(false); + }); + + it('shows loading state initially', () => { + render( + + {}} + /> + + ); + + // Should show loading skeleton initially + expect(document.querySelector('.animate-pulse')).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/src/components/ProjectInfoDialog.tsx b/src/components/ProjectInfoDialog.tsx new file mode 100644 index 00000000..59c20854 --- /dev/null +++ b/src/components/ProjectInfoDialog.tsx @@ -0,0 +1,192 @@ +import { useState, useEffect } from 'react'; +import { type Project } from '@/lib/ProjectsManager'; +import { useProjectsManager } from '@/hooks/useProjectsManager'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Badge } from '@/components/ui/badge'; +import { Separator } from '@/components/ui/separator'; +import { Calendar, Folder, GitBranch, Package, FileText } from 'lucide-react'; + +interface ProjectInfoDialogProps { + project: Project; + open: boolean; + onOpenChange: (open: boolean) => void; +} + +interface ProjectMetadata { + description?: string; + version?: string; + nostrRepoAddress?: string; + fileCount?: number; +} + +export function ProjectInfoDialog({ project, open, onOpenChange }: ProjectInfoDialogProps) { + const [metadata, setMetadata] = useState({}); + const [isLoading, setIsLoading] = useState(false); + const projectsManager = useProjectsManager(); + + useEffect(() => { + if (!open) return; + + const loadProjectMetadata = async () => { + setIsLoading(true); + try { + const meta: ProjectMetadata = {}; + + // Try to read package.json + try { + const packageJsonContent = await projectsManager.readFile(project.id, 'package.json'); + const packageJson = JSON.parse(packageJsonContent); + meta.description = packageJson.description; + meta.version = packageJson.version; + } catch { + // package.json doesn't exist or is invalid + } + + // Get Nostr repo address + try { + const repoAddress = await projectsManager.getNostrRepoAddress(project.id); + if (repoAddress) { + meta.nostrRepoAddress = repoAddress; + } + } catch { + // No Nostr repo configured + } + + // Calculate file count and size (simplified) + try { + const files = await projectsManager.listFiles(project.id); + meta.fileCount = files.length; + } catch { + // Can't read directory + } + + setMetadata(meta); + } catch (error) { + console.error('Failed to load project metadata:', error); + } finally { + setIsLoading(false); + } + }; + + loadProjectMetadata(); + }, [open, project.id, projectsManager]); + + const formatDate = (date: Date) => { + return new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: '2-digit', + minute: '2-digit', + }).format(date); + }; + + const formatDistanceToNow = (date: Date) => { + const now = new Date(); + const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); + + if (diffInSeconds < 60) return 'just now'; + if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)} minutes ago`; + if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)} hours ago`; + if (diffInSeconds < 2592000) return `${Math.floor(diffInSeconds / 86400)} days ago`; + if (diffInSeconds < 31536000) return `${Math.floor(diffInSeconds / 2592000)} months ago`; + return `${Math.floor(diffInSeconds / 31536000)} years ago`; + }; + + return ( + + + + + + {project.name} + + + Project information and metadata + + + + {isLoading ? ( +
+
+
+
+
+
+ ) : ( +
+ {/* Basic Information */} +
+

+ Basic Information +

+
+
+ + Project ID: + {project.id} +
+
+ + Last Modified: + {formatDistanceToNow(project.lastModified)} +
+ {metadata.version && ( +
+ + Version: + {metadata.version} +
+ )} + {metadata.fileCount !== undefined && ( +
+ + Files: + {metadata.fileCount} +
+ )} +
+
+ Created: + {formatDate(project.lastModified)} +
+ {metadata.description && ( +
+ Description: +

{metadata.description}

+
+ )} +
+ + {/* Nostr Information */} + {metadata.nostrRepoAddress && ( + <> + +
+

+ + Nostr Repository +

+
+ Repository Address: + + {metadata.nostrRepoAddress} + +
+
+ + )} + + +
+ )} +
+
+ ); +} \ No newline at end of file diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index d16ddf28..00321049 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -5,6 +5,7 @@ import { useProjectsManager } from '@/hooks/useProjectsManager'; import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane'; import { PreviewPane } from '@/components/Shakespeare/PreviewPane'; import { ProjectSidebar } from '@/components/ProjectSidebar'; +import { ProjectInfoDialog } from '@/components/ProjectInfoDialog'; import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable'; import { Button } from '@/components/ui/button'; import { ArrowLeft, MessageSquare, Eye, Code, Menu, Columns2 } from 'lucide-react'; @@ -29,6 +30,7 @@ export function ProjectView() { const [isBuildLoading, setIsBuildLoading] = useState(false); const [isDeployLoading, setIsDeployLoading] = useState(false); const [isAILoading, setIsAILoading] = useState(false); + const [isProjectInfoOpen, setIsProjectInfoOpen] = useState(false); const projectsManager = useProjectsManager(); const chatPaneRef = useRef(null); const navigate = useNavigate(); @@ -221,7 +223,13 @@ BASE_DOMAIN=nostrdeploy.com`);
-

{project.name}

+
@@ -321,6 +329,13 @@ BASE_DOMAIN=nostrdeploy.com`); + + {/* Project Info Dialog */} + ); } @@ -369,9 +384,13 @@ BASE_DOMAIN=nostrdeploy.com`); {/* Center - Project title */}
-

+

+
@@ -453,6 +472,13 @@ BASE_DOMAIN=nostrdeploy.com`);
+ + {/* Project Info Dialog */} + ); }