mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add ProjectInfoDialog
This commit is contained in:
5 files changed
+318
-5
No files matched your search
Generated
+1
-1
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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(
|
||||
<TestApp>
|
||||
<ProjectInfoDialog
|
||||
project={mockProject}
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// 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(
|
||||
<TestApp>
|
||||
<ProjectInfoDialog
|
||||
project={mockProject}
|
||||
open={false}
|
||||
onOpenChange={() => {}}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// 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(
|
||||
<TestApp>
|
||||
<ProjectInfoDialog
|
||||
project={mockProject}
|
||||
open={true}
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// 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(
|
||||
<TestApp>
|
||||
<ProjectInfoDialog
|
||||
project={mockProject}
|
||||
open={true}
|
||||
onOpenChange={() => {}}
|
||||
/>
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// Should show loading skeleton initially
|
||||
expect(document.querySelector('.animate-pulse')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -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<ProjectMetadata>({});
|
||||
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 (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Folder className="h-5 w-5" />
|
||||
{project.name}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Project information and metadata
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="space-y-4">
|
||||
<div className="animate-pulse">
|
||||
<div className="h-4 bg-muted rounded w-3/4 mb-2"></div>
|
||||
<div className="h-4 bg-muted rounded w-1/2"></div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{/* Basic Information */}
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
||||
Basic Information
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 gap-4 text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Folder className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Project ID:</span>
|
||||
<code className="bg-muted px-1.5 py-0.5 rounded text-xs">{project.id}</code>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Calendar className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Last Modified:</span>
|
||||
<span>{formatDistanceToNow(project.lastModified)}</span>
|
||||
</div>
|
||||
{metadata.version && (
|
||||
<div className="flex items-center gap-2">
|
||||
<Package className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Version:</span>
|
||||
<Badge variant="secondary">{metadata.version}</Badge>
|
||||
</div>
|
||||
)}
|
||||
{metadata.fileCount !== undefined && (
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-muted-foreground">Files:</span>
|
||||
<span>{metadata.fileCount}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
<span className="text-muted-foreground">Created:</span>
|
||||
<span className="ml-2">{formatDate(project.lastModified)}</span>
|
||||
</div>
|
||||
{metadata.description && (
|
||||
<div className="text-sm">
|
||||
<span className="text-muted-foreground">Description:</span>
|
||||
<p className="mt-1 text-foreground">{metadata.description}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Nostr Information */}
|
||||
{metadata.nostrRepoAddress && (
|
||||
<>
|
||||
<Separator />
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-2">
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Nostr Repository
|
||||
</h3>
|
||||
<div className="text-sm">
|
||||
<span className="text-muted-foreground">Repository Address:</span>
|
||||
<code className="ml-2 bg-muted px-1.5 py-0.5 rounded text-xs break-all">
|
||||
{metadata.nostrRepoAddress}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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<ChatPaneRef>(null);
|
||||
const navigate = useNavigate();
|
||||
@@ -221,7 +223,13 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
</Button>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className="text-sm font-semibold truncate">{project.name}</h1>
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="p-0 h-auto text-sm font-semibold truncate hover:bg-transparent hover:text-primary"
|
||||
onClick={() => setIsProjectInfoOpen(true)}
|
||||
>
|
||||
{project.name}
|
||||
</Button>
|
||||
<GitStatusIndicator projectId={project.id} />
|
||||
</div>
|
||||
</div>
|
||||
@@ -321,6 +329,13 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Info Dialog */}
|
||||
<ProjectInfoDialog
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -369,9 +384,13 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
{/* Center - Project title */}
|
||||
<div className="flex-1 min-w-0 ml-2 px-4">
|
||||
<div className="flex items-center justify-center md:justify-start gap-2">
|
||||
<h2 className="font-semibold text-lg truncate">
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="p-0 h-auto font-semibold text-lg truncate hover:bg-transparent hover:text-primary"
|
||||
onClick={() => setIsProjectInfoOpen(true)}
|
||||
>
|
||||
{project.name}
|
||||
</h2>
|
||||
</Button>
|
||||
<div className="ml-auto">
|
||||
<GitStatusIndicator projectId={project.id} />
|
||||
</div>
|
||||
@@ -453,6 +472,13 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
</ResizablePanelGroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Info Dialog */}
|
||||
<ProjectInfoDialog
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user