|
| 1 | +import { |
| 2 | + Dialog, |
| 3 | + DialogContent, |
| 4 | + DialogDescription, |
| 5 | + DialogHeader, |
| 6 | + DialogTitle, |
| 7 | + DialogTrigger, |
| 8 | +} from "@/components/ui/dialog"; |
| 9 | +import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; |
| 10 | +import { |
| 11 | + Table, |
| 12 | + TableBody, |
| 13 | + TableCell, |
| 14 | + TableHead, |
| 15 | + TableHeader, |
| 16 | + TableRow, |
| 17 | +} from "@/components/ui/table"; |
| 18 | +import { Badge } from "@/components/ui/badge"; |
| 19 | +import { api } from "@/utils/api"; |
| 20 | + |
| 21 | +interface Props { |
| 22 | + containerId: string; |
| 23 | + serverId?: string; |
| 24 | +} |
| 25 | + |
| 26 | +interface Mount { |
| 27 | + Type: string; |
| 28 | + Source: string; |
| 29 | + Destination: string; |
| 30 | + Mode: string; |
| 31 | + RW: boolean; |
| 32 | + Propagation: string; |
| 33 | + Name?: string; |
| 34 | + Driver?: string; |
| 35 | +} |
| 36 | + |
| 37 | +export const ShowContainerMounts = ({ containerId, serverId }: Props) => { |
| 38 | + const { data } = api.docker.getConfig.useQuery( |
| 39 | + { |
| 40 | + containerId, |
| 41 | + serverId, |
| 42 | + }, |
| 43 | + { |
| 44 | + enabled: !!containerId, |
| 45 | + }, |
| 46 | + ); |
| 47 | + |
| 48 | + const mounts: Mount[] = data?.Mounts ?? []; |
| 49 | + |
| 50 | + return ( |
| 51 | + <Dialog> |
| 52 | + <DialogTrigger asChild> |
| 53 | + <DropdownMenuItem |
| 54 | + className="w-full cursor-pointer" |
| 55 | + onSelect={(e) => e.preventDefault()} |
| 56 | + > |
| 57 | + View Mounts |
| 58 | + </DropdownMenuItem> |
| 59 | + </DialogTrigger> |
| 60 | + <DialogContent className="w-full md:w-[70vw] min-w-[70vw]"> |
| 61 | + <DialogHeader> |
| 62 | + <DialogTitle>Container Mounts</DialogTitle> |
| 63 | + <DialogDescription> |
| 64 | + Volume and bind mounts for this container |
| 65 | + </DialogDescription> |
| 66 | + </DialogHeader> |
| 67 | + <div className="overflow-auto max-h-[70vh]"> |
| 68 | + {mounts.length === 0 ? ( |
| 69 | + <div className="text-center text-muted-foreground py-8"> |
| 70 | + No mounts found for this container. |
| 71 | + </div> |
| 72 | + ) : ( |
| 73 | + <Table> |
| 74 | + <TableHeader> |
| 75 | + <TableRow> |
| 76 | + <TableHead>Type</TableHead> |
| 77 | + <TableHead>Source</TableHead> |
| 78 | + <TableHead>Destination</TableHead> |
| 79 | + <TableHead>Mode</TableHead> |
| 80 | + <TableHead>Read/Write</TableHead> |
| 81 | + </TableRow> |
| 82 | + </TableHeader> |
| 83 | + <TableBody> |
| 84 | + {mounts.map((mount, index) => ( |
| 85 | + <TableRow key={index}> |
| 86 | + <TableCell> |
| 87 | + <Badge variant="outline">{mount.Type}</Badge> |
| 88 | + </TableCell> |
| 89 | + <TableCell className="font-mono text-xs max-w-[250px] truncate"> |
| 90 | + {mount.Name || mount.Source} |
| 91 | + </TableCell> |
| 92 | + <TableCell className="font-mono text-xs max-w-[250px] truncate"> |
| 93 | + {mount.Destination} |
| 94 | + </TableCell> |
| 95 | + <TableCell className="text-xs"> |
| 96 | + {mount.Mode || "-"} |
| 97 | + </TableCell> |
| 98 | + <TableCell> |
| 99 | + <Badge variant={mount.RW ? "default" : "secondary"}> |
| 100 | + {mount.RW ? "RW" : "RO"} |
| 101 | + </Badge> |
| 102 | + </TableCell> |
| 103 | + </TableRow> |
| 104 | + ))} |
| 105 | + </TableBody> |
| 106 | + </Table> |
| 107 | + )} |
| 108 | + </div> |
| 109 | + </DialogContent> |
| 110 | + </Dialog> |
| 111 | + ); |
| 112 | +}; |
0 commit comments