mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-05 16:44:22 +00:00
Add Header, InstanceList, and InstanceCard components for instance management UI
This commit is contained in:
@@ -1,20 +1,13 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import Header from '@/components/Header'
|
||||
import InstanceList from '@/components/InstanceList'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="p-8">
|
||||
<h1 className="text-3xl font-bold mb-6">Llamactl Dashboard</h1>
|
||||
|
||||
<Card className="w-96">
|
||||
<CardHeader>
|
||||
<CardTitle>Sample Instance</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="mb-4">Status: Running</p>
|
||||
<Button>Stop Instance</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Header />
|
||||
<main className="container mx-auto max-w-4xl px-4 py-8">
|
||||
<InstanceList />
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
26
ui/src/components/Header.tsx
Normal file
26
ui/src/components/Header.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
function Header() {
|
||||
const handleCreateInstance = () => {
|
||||
// TODO: Open create instance dialog
|
||||
console.log('Create instance clicked')
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="bg-white border-b border-gray-200">
|
||||
<div className="container mx-auto max-w-4xl px-4 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold text-gray-900">
|
||||
LlamaCtl Dashboard
|
||||
</h1>
|
||||
|
||||
<Button onClick={handleCreateInstance}>
|
||||
Create Instance
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
export default Header
|
||||
74
ui/src/components/InstanceCard.tsx
Normal file
74
ui/src/components/InstanceCard.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Instance } from '@/types/instance'
|
||||
import { useInstances } from '@/hooks/useInstances'
|
||||
|
||||
interface InstanceCardProps {
|
||||
instance: Instance
|
||||
}
|
||||
|
||||
function InstanceCard({ instance }: InstanceCardProps) {
|
||||
const { startInstance, stopInstance, deleteInstance } = useInstances()
|
||||
|
||||
const handleStart = () => {
|
||||
startInstance(instance.name)
|
||||
}
|
||||
|
||||
const handleStop = () => {
|
||||
stopInstance(instance.name)
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
if (confirm(`Are you sure you want to delete instance "${instance.name}"?`)) {
|
||||
deleteInstance(instance.name)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-lg">{instance.name}</CardTitle>
|
||||
<Badge variant={instance.running ? "default" : "secondary"}>
|
||||
{instance.running ? "Running" : "Stopped"}
|
||||
</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<div className="flex gap-2">
|
||||
{!instance.running ? (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleStart}
|
||||
className="flex-1"
|
||||
>
|
||||
Start
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={handleStop}
|
||||
className="flex-1"
|
||||
>
|
||||
Stop
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={handleDelete}
|
||||
disabled={instance.running}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
export default InstanceCard
|
||||
56
ui/src/components/InstanceList.tsx
Normal file
56
ui/src/components/InstanceList.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { useInstances } from '@/hooks/useInstances'
|
||||
import InstanceCard from '@/components/InstanceCard'
|
||||
|
||||
function InstanceList() {
|
||||
const { instances, loading, error } = useInstances()
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-4"></div>
|
||||
<p className="text-gray-600">Loading instances...</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center py-12">
|
||||
<div className="text-red-600 mb-4">
|
||||
<p className="text-lg font-semibold">Error loading instances</p>
|
||||
<p className="text-sm">{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (instances.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-12">
|
||||
<p className="text-gray-600 text-lg mb-2">No instances found</p>
|
||||
<p className="text-gray-500 text-sm">Create your first instance to get started</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-xl font-semibold text-gray-900 mb-6">
|
||||
Instances ({instances.length})
|
||||
</h2>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{instances.map((instance) => (
|
||||
<InstanceCard
|
||||
key={instance.name}
|
||||
instance={instance}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default InstanceList
|
||||
46
ui/src/components/ui/badge.tsx
Normal file
46
ui/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
Reference in New Issue
Block a user