|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { Badge } from "@/components/ui/badge"; |
| 4 | +import { Button } from "@/components/ui/button"; |
| 5 | +import { |
| 6 | + Dialog, |
| 7 | + DialogContent, |
| 8 | + DialogDescription, |
| 9 | + DialogHeader, |
| 10 | + DialogTitle, |
| 11 | + DialogTrigger, |
| 12 | +} from "@/components/ui/dialog"; |
| 13 | +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; |
| 14 | +import { TaskDataOrNull, TaskErrorOrNull } from "@/packages/mongodb-pipeline-ts/Task"; |
| 15 | +import type { CNRepo } from "@/src/CNRepos"; |
| 16 | +import { Info } from "lucide-react"; |
| 17 | +import { useState } from "react"; |
| 18 | +import yaml from "yaml"; |
| 19 | + |
| 20 | +interface CNReposTableClientProps { |
| 21 | + repos: Array<CNRepo & { _id?: any }>; |
| 22 | +} |
| 23 | + |
| 24 | +export function CNReposTableClient({ repos }: CNReposTableClientProps) { |
| 25 | + return ( |
| 26 | + <Table className="text-sm"> |
| 27 | + <TableHeader> |
| 28 | + <TableRow className="h-8"> |
| 29 | + <TableHead className="w-12 px-2 py-1">Status</TableHead> |
| 30 | + <TableHead className="px-2 py-1">Repository</TableHead> |
| 31 | + <TableHead className="w-20 text-center px-2 py-1">Registry</TableHead> |
| 32 | + <TableHead className="w-28 text-center px-2 py-1">ComfyUI-Manager</TableHead> |
| 33 | + <TableHead className="w-20 text-center px-2 py-1">Candidate</TableHead> |
| 34 | + <TableHead className="px-2 py-1">Pull Requests</TableHead> |
| 35 | + <TableHead className="w-20 px-2 py-1">Info</TableHead> |
| 36 | + </TableRow> |
| 37 | + </TableHeader> |
| 38 | + <TableBody> |
| 39 | + {repos.map((repo) => ( |
| 40 | + <CNRepoRow key={repo._id?.toString()} repo={repo} /> |
| 41 | + ))} |
| 42 | + </TableBody> |
| 43 | + </Table> |
| 44 | + ); |
| 45 | +} |
| 46 | + |
| 47 | +function CNRepoRow({ repo }: { repo: CNRepo & { _id?: any } }) { |
| 48 | + const [isOpen, setIsOpen] = useState(false); |
| 49 | + |
| 50 | + const getStatusIcon = () => { |
| 51 | + if (!repo.cr && !repo.cm) return "🫗"; |
| 52 | + if (!!repo.cr && !!repo.cm && repo.crPulls?.state === "ok") return "✅"; |
| 53 | + if (!!repo.cr && !!repo.cm) return "☑️"; |
| 54 | + if (!!repo.cr && !repo.cm) return "✔️"; |
| 55 | + if (!repo.crPulls) return "🧪"; |
| 56 | + if (repo.crPulls.state === "ok") return "👀"; |
| 57 | + if (TaskErrorOrNull(repo.crPulls)) return "❗"; |
| 58 | + return "❓"; |
| 59 | + }; |
| 60 | + |
| 61 | + const getStatusDescription = () => { |
| 62 | + const icon = getStatusIcon(); |
| 63 | + const descriptions = { |
| 64 | + "🫗": "Repository not listed in ComfyUI-Manager or Registry", |
| 65 | + "✅": "Listed in both Registry and ComfyUI-Manager (PR successful)", |
| 66 | + "☑️": "Listed in both Registry and ComfyUI-Manager", |
| 67 | + "✔️": "Listed in Registry only", |
| 68 | + "🧪": "Ready to create PR", |
| 69 | + "👀": "Pull request pending review", |
| 70 | + "❗": "Error occurred during processing", |
| 71 | + "❓": "Unknown status", |
| 72 | + }; |
| 73 | + return descriptions[icon as keyof typeof descriptions] || "Unknown status"; |
| 74 | + }; |
| 75 | + |
| 76 | + const getRepoName = (url: string) => { |
| 77 | + return url.replace(/^https:\/\/github\.com\//, ""); |
| 78 | + }; |
| 79 | + |
| 80 | + return ( |
| 81 | + <TableRow className="h-10"> |
| 82 | + <TableCell className="text-center text-base px-2 py-1" title={getStatusDescription()}> |
| 83 | + {getStatusIcon()} |
| 84 | + </TableCell> |
| 85 | + <TableCell className="px-2 py-1"> |
| 86 | + <a |
| 87 | + href={repo.repository} |
| 88 | + target="_blank" |
| 89 | + rel="noreferrer" |
| 90 | + className="text-primary hover:underline font-mono text-xs transition-colors" |
| 91 | + > |
| 92 | + {getRepoName(repo.repository)} |
| 93 | + </a> |
| 94 | + </TableCell> |
| 95 | + <TableCell className="text-center px-2 py-1"> |
| 96 | + {repo.cr_ids?.length || repo.cr ? ( |
| 97 | + <Badge variant="secondary" className="text-xs px-1 py-0"> |
| 98 | + ✓ |
| 99 | + </Badge> |
| 100 | + ) : ( |
| 101 | + <span className="text-muted-foreground">-</span> |
| 102 | + )} |
| 103 | + </TableCell> |
| 104 | + <TableCell className="text-center px-2 py-1"> |
| 105 | + {repo.cm_ids?.length || repo.cm ? ( |
| 106 | + <Badge variant="secondary" className="text-xs px-1 py-0"> |
| 107 | + ✓ |
| 108 | + </Badge> |
| 109 | + ) : ( |
| 110 | + <span className="text-muted-foreground">-</span> |
| 111 | + )} |
| 112 | + </TableCell> |
| 113 | + <TableCell className="text-center px-2 py-1"> |
| 114 | + {TaskDataOrNull(repo.candidate) ? ( |
| 115 | + <Badge variant="outline" className="text-xs px-1 py-0"> |
| 116 | + ✓ |
| 117 | + </Badge> |
| 118 | + ) : ( |
| 119 | + <span className="text-muted-foreground">-</span> |
| 120 | + )} |
| 121 | + </TableCell> |
| 122 | + <TableCell className="px-2 py-1"> |
| 123 | + <div className="space-y-0.5"> |
| 124 | + {TaskDataOrNull(repo.crPulls)?.map((pull, idx) => ( |
| 125 | + <div key={idx} className="text-xs"> |
| 126 | + {pull.pull?.html_url ? ( |
| 127 | + <a |
| 128 | + href={pull.pull.html_url} |
| 129 | + target="_blank" |
| 130 | + rel="noreferrer" |
| 131 | + className="text-primary hover:underline transition-colors" |
| 132 | + > |
| 133 | + #{pull.pull.html_url.split("/").pop()} ({pull.type}) |
| 134 | + </a> |
| 135 | + ) : ( |
| 136 | + <span className="text-muted-foreground">Pending</span> |
| 137 | + )} |
| 138 | + </div> |
| 139 | + ))} |
| 140 | + {TaskErrorOrNull(repo.crPulls) && ( |
| 141 | + <Badge variant="destructive" className="text-xs" title={TaskErrorOrNull(repo.crPulls) || ""}> |
| 142 | + Error |
| 143 | + </Badge> |
| 144 | + )} |
| 145 | + </div> |
| 146 | + </TableCell> |
| 147 | + <TableCell className="px-2 py-1"> |
| 148 | + <Dialog open={isOpen} onOpenChange={setIsOpen}> |
| 149 | + <DialogTrigger asChild> |
| 150 | + <Button variant="ghost" size="sm" className="h-7 px-2"> |
| 151 | + <Info className="h-4 w-4" /> |
| 152 | + </Button> |
| 153 | + </DialogTrigger> |
| 154 | + <DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto"> |
| 155 | + <DialogHeader> |
| 156 | + <DialogTitle className="font-mono text-sm">{getRepoName(repo.repository)}</DialogTitle> |
| 157 | + <DialogDescription>Repository details and metadata</DialogDescription> |
| 158 | + </DialogHeader> |
| 159 | + <div className="mt-4"> |
| 160 | + <pre className="p-4 bg-muted rounded-lg text-xs overflow-auto font-mono"> |
| 161 | + {yaml.stringify({ |
| 162 | + repository: repo.repository, |
| 163 | + status: getStatusDescription(), |
| 164 | + cr_ids: repo.cr_ids?.length || 0, |
| 165 | + cm_ids: repo.cm_ids?.length || 0, |
| 166 | + candidate: TaskDataOrNull(repo.candidate), |
| 167 | + info: TaskDataOrNull(repo.info) |
| 168 | + ? { |
| 169 | + archived: TaskDataOrNull(repo.info)?.archived, |
| 170 | + private: TaskDataOrNull(repo.info)?.private, |
| 171 | + default_branch: TaskDataOrNull(repo.info)?.default_branch, |
| 172 | + html_url: TaskDataOrNull(repo.info)?.html_url, |
| 173 | + } |
| 174 | + : null, |
| 175 | + pulls_count: TaskDataOrNull(repo.pulls)?.length || 0, |
| 176 | + crPulls: TaskDataOrNull(repo.crPulls)?.map((pull) => ({ |
| 177 | + type: pull.type, |
| 178 | + url: pull.pull?.html_url, |
| 179 | + state: pull.pull?.prState, |
| 180 | + })), |
| 181 | + crPulls_state: repo.crPulls?.state, |
| 182 | + error: TaskErrorOrNull(repo.crPulls), |
| 183 | + })} |
| 184 | + </pre> |
| 185 | + </div> |
| 186 | + </DialogContent> |
| 187 | + </Dialog> |
| 188 | + </TableCell> |
| 189 | + </TableRow> |
| 190 | + ); |
| 191 | +} |
0 commit comments