|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import { Dialog, DialogContent } from "@/components/ui/dialog"; |
| 3 | +import { X } from "lucide-react"; |
| 4 | + |
| 5 | +interface LicenseEntry { |
| 6 | + name: string; |
| 7 | + version: string; |
| 8 | + license: string; |
| 9 | + repository?: string; |
| 10 | + author?: string; |
| 11 | +} |
| 12 | + |
| 13 | +const PROJECT_LICENSES = [ |
| 14 | + { |
| 15 | + name: "sql-validator (core)", |
| 16 | + license: "GPL-3.0", |
| 17 | + description: "The core application is licensed under the GNU General Public License v3.0.", |
| 18 | + url: "https://github.com/Edwinexd/sql-validator?tab=GPL-3.0-1-ov-file", |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "ra-engine (Relational Algebra)", |
| 22 | + license: "BSL-1.1", |
| 23 | + description: "The relational algebra engine (src/ra-engine/) is licensed under the Business Source License 1.1, converting to GPL-3.0 on 2035-03-20.", |
| 24 | + url: "https://github.com/Edwinexd/sql-validator/blob/master/src/ra-engine/LICENSE.md", |
| 25 | + }, |
| 26 | +]; |
| 27 | + |
| 28 | +export default function LicenseDialog() { |
| 29 | + const [open, setOpen] = useState(false); |
| 30 | + const [deps, setDeps] = useState<LicenseEntry[]>([]); |
| 31 | + |
| 32 | + useEffect(() => { |
| 33 | + if (open && deps.length === 0) { |
| 34 | + fetch("/licenses.json") |
| 35 | + .then(r => r.json()) |
| 36 | + .then(setDeps) |
| 37 | + .catch(() => setDeps([])); |
| 38 | + } |
| 39 | + }, [open, deps.length]); |
| 40 | + |
| 41 | + return ( |
| 42 | + <> |
| 43 | + <button |
| 44 | + onClick={() => setOpen(true)} |
| 45 | + className="text-blue-600 dark:text-blue-400 hover:underline" |
| 46 | + > |
| 47 | + Licenses |
| 48 | + </button> |
| 49 | + <Dialog open={open} onOpenChange={setOpen}> |
| 50 | + <DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto p-0"> |
| 51 | + <div className="sticky top-0 bg-white dark:bg-slate-900 border-b border-gray-200 dark:border-slate-700 px-6 py-4 flex items-center justify-between z-10"> |
| 52 | + <h2 className="text-xl font-semibold">Licenses</h2> |
| 53 | + <button onClick={() => setOpen(false)} className="text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"> |
| 54 | + <X className="w-5 h-5" /> |
| 55 | + </button> |
| 56 | + </div> |
| 57 | + |
| 58 | + <div className="px-6 py-4 space-y-6"> |
| 59 | + <div> |
| 60 | + <h3 className="text-lg font-semibold mb-3">Project Licenses</h3> |
| 61 | + <div className="space-y-3"> |
| 62 | + {PROJECT_LICENSES.map(l => ( |
| 63 | + <div key={l.name} className="border border-gray-200 dark:border-slate-700 rounded-md p-3"> |
| 64 | + <div className="flex items-center justify-between"> |
| 65 | + <span className="font-medium">{l.name}</span> |
| 66 | + <a href={l.url} target="_blank" rel="noopener noreferrer" className="text-sm text-blue-600 dark:text-blue-400 hover:underline">{l.license}</a> |
| 67 | + </div> |
| 68 | + <p className="text-sm text-gray-600 dark:text-gray-400 mt-1">{l.description}</p> |
| 69 | + </div> |
| 70 | + ))} |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div> |
| 75 | + <h3 className="text-lg font-semibold mb-3">Third-Party Dependencies</h3> |
| 76 | + {deps.length === 0 ? ( |
| 77 | + <p className="text-sm text-gray-500">Loading...</p> |
| 78 | + ) : ( |
| 79 | + <div className="border border-gray-200 dark:border-slate-700 rounded-md overflow-hidden"> |
| 80 | + <table className="w-full text-sm"> |
| 81 | + <thead> |
| 82 | + <tr className="bg-gray-50 dark:bg-slate-800 text-left"> |
| 83 | + <th className="px-3 py-2 font-medium">Package</th> |
| 84 | + <th className="px-3 py-2 font-medium">Version</th> |
| 85 | + <th className="px-3 py-2 font-medium">License</th> |
| 86 | + </tr> |
| 87 | + </thead> |
| 88 | + <tbody> |
| 89 | + {deps.map(dep => ( |
| 90 | + <tr key={dep.name} className="border-t border-gray-100 dark:border-slate-700/50"> |
| 91 | + <td className="px-3 py-1.5"> |
| 92 | + {dep.repository ? ( |
| 93 | + <a href={dep.repository} target="_blank" rel="noopener noreferrer" className="text-blue-600 dark:text-blue-400 hover:underline">{dep.name}</a> |
| 94 | + ) : dep.name} |
| 95 | + </td> |
| 96 | + <td className="px-3 py-1.5 text-gray-500 dark:text-gray-400">{dep.version}</td> |
| 97 | + <td className="px-3 py-1.5">{dep.license}</td> |
| 98 | + </tr> |
| 99 | + ))} |
| 100 | + </tbody> |
| 101 | + </table> |
| 102 | + </div> |
| 103 | + )} |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </DialogContent> |
| 107 | + </Dialog> |
| 108 | + </> |
| 109 | + ); |
| 110 | +} |
0 commit comments