From 281ab2c9e74df1500edf7c55d48ba442a5b364b3 Mon Sep 17 00:00:00 2001 From: lintsinghua <1930438860@qq.com> Date: Mon, 27 Oct 2025 18:01:33 +0800 Subject: [PATCH] feat: add project management features including recycle bin and project editing - Introduced a new Recycle Bin page for managing deleted projects. - Implemented project editing functionality with a dialog for updating project details. - Added methods for retrieving deleted projects and restoring or permanently deleting them from the database. - Enhanced the Projects page with edit and delete options for better project management. --- src/app/routes.tsx | 7 + src/pages/ProjectDetail.tsx | 195 ++++++++++++++++- src/pages/Projects.tsx | 250 +++++++++++++++++++++- src/pages/RecycleBin.tsx | 322 +++++++++++++++++++++++++++++ src/shared/config/database.ts | 54 +++++ src/shared/config/localDatabase.ts | 37 ++++ 6 files changed, 857 insertions(+), 8 deletions(-) create mode 100644 src/pages/RecycleBin.tsx diff --git a/src/app/routes.tsx b/src/app/routes.tsx index 4a272b6..77a72b9 100644 --- a/src/app/routes.tsx +++ b/src/app/routes.tsx @@ -1,6 +1,7 @@ import Dashboard from "@/pages/Dashboard"; import Projects from "@/pages/Projects"; import ProjectDetail from "@/pages/ProjectDetail"; +import RecycleBin from "@/pages/RecycleBin"; import InstantAnalysis from "@/pages/InstantAnalysis"; import AuditTasks from "@/pages/AuditTasks"; import TaskDetail from "@/pages/TaskDetail"; @@ -57,6 +58,12 @@ const routes: RouteConfig[] = [ element: , visible: true, }, + { + name: "回收站", + path: "/recycle-bin", + element: , + visible: true, + }, ]; export default routes; \ No newline at end of file diff --git a/src/pages/ProjectDetail.tsx b/src/pages/ProjectDetail.tsx index f346fb8..292d51f 100644 --- a/src/pages/ProjectDetail.tsx +++ b/src/pages/ProjectDetail.tsx @@ -3,11 +3,16 @@ import { useParams, Link } from "react-router-dom"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Progress } from "@/components/ui/progress"; import { ArrowLeft, - Settings, + Edit, ExternalLink, Code, Shield, @@ -20,7 +25,7 @@ import { } from "lucide-react"; import { api } from "@/shared/config/database"; import { runRepositoryAudit } from "@/features/projects/services"; -import type { Project, AuditTask } from "@/shared/types"; +import type { Project, AuditTask, CreateProjectForm } from "@/shared/types"; import { toast } from "sonner"; import CreateTaskDialog from "@/components/audit/CreateTaskDialog"; import TerminalProgressDialog from "@/components/audit/TerminalProgressDialog"; @@ -34,6 +39,19 @@ export default function ProjectDetail() { const [showCreateTaskDialog, setShowCreateTaskDialog] = useState(false); const [showTerminalDialog, setShowTerminalDialog] = useState(false); const [currentTaskId, setCurrentTaskId] = useState(null); + const [showSettingsDialog, setShowSettingsDialog] = useState(false); + const [editForm, setEditForm] = useState({ + name: "", + description: "", + repository_url: "", + repository_type: "github", + default_branch: "main", + programming_languages: [] + }); + + const supportedLanguages = [ + 'JavaScript', 'TypeScript', 'Python', 'Java', 'Go', 'Rust', 'C++', 'C#', 'PHP', 'Ruby' + ]; useEffect(() => { if (id) { @@ -94,6 +112,50 @@ export default function ProjectDetail() { } }; + const handleOpenSettings = () => { + if (!project) return; + + // 初始化编辑表单 + setEditForm({ + name: project.name, + description: project.description || "", + repository_url: project.repository_url || "", + repository_type: project.repository_type || "github", + default_branch: project.default_branch || "main", + programming_languages: project.programming_languages ? JSON.parse(project.programming_languages) : [] + }); + + setShowSettingsDialog(true); + }; + + const handleSaveSettings = async () => { + if (!id) return; + + if (!editForm.name.trim()) { + toast.error("项目名称不能为空"); + return; + } + + try { + await api.updateProject(id, editForm); + toast.success("项目信息已保存"); + setShowSettingsDialog(false); + loadProjectData(); + } catch (error) { + console.error('Failed to update project:', error); + toast.error("保存失败"); + } + }; + + const handleToggleLanguage = (lang: string) => { + const currentLanguages = editForm.programming_languages || []; + const newLanguages = currentLanguages.includes(lang) + ? currentLanguages.filter(l => l !== lang) + : [...currentLanguages, lang]; + + setEditForm({ ...editForm, programming_languages: newLanguages }); + }; + const getStatusColor = (status: string) => { switch (status) { case 'completed': return 'bg-green-100 text-green-800'; @@ -187,9 +249,9 @@ export default function ProjectDetail() { {scanning ? '正在启动...' : '启动审计'} - @@ -470,8 +532,8 @@ export default function ProjectDetail() {
- -

项目设置

+ +

项目编辑

此功能正在开发中

@@ -492,6 +554,125 @@ export default function ProjectDetail() { taskId={currentTaskId} taskType="repository" /> + + {/* 项目编辑对话框 */} + + + + 编辑项目 + + +
+ {/* 基本信息 */} +
+
+ + setEditForm({ ...editForm, name: e.target.value })} + placeholder="输入项目名称" + /> +
+ +
+ +