From af063dead735183feb89962603bc9b23699762c9 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Tue, 22 Jul 2025 21:45:48 +0200 Subject: [PATCH] Reuse modal for instance editing --- ui/src/App.tsx | 38 ++++++++++++++++++++-- ui/src/components/Header.tsx | 51 ++++++++++-------------------- ui/src/components/InstanceCard.tsx | 6 ++-- ui/src/components/InstanceList.tsx | 8 ++++- 4 files changed, 62 insertions(+), 41 deletions(-) diff --git a/ui/src/App.tsx b/ui/src/App.tsx index e6ef2fc..1820466 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -1,13 +1,47 @@ +import { useState } from 'react' import Header from '@/components/Header' import InstanceList from '@/components/InstanceList' +import InstanceModal from '@/components/InstanceModal' +import { CreateInstanceOptions, Instance } from '@/types/instance' function App() { + const [isModalOpen, setIsModalOpen] = useState(false) + const [editingInstance, setEditingInstance] = useState(undefined) + + const handleCreateInstance = () => { + setEditingInstance(undefined) + setIsModalOpen(true) + } + + const handleEditInstance = (instance: Instance) => { + setEditingInstance(instance) + setIsModalOpen(true) + } + + const handleSaveInstance = (name: string, options: CreateInstanceOptions) => { + if (editingInstance) { + // TODO: Implement API call to update instance + console.log('Updating instance:', { name, options }) + } else { + // TODO: Implement API call to create instance + console.log('Creating instance:', { name, options }) + } + // For now, just log the data - you'll implement the API call later + } + return (
-
+
- +
+ +
) } diff --git a/ui/src/components/Header.tsx b/ui/src/components/Header.tsx index 5b50c0c..83257c2 100644 --- a/ui/src/components/Header.tsx +++ b/ui/src/components/Header.tsx @@ -1,43 +1,24 @@ -import { useState } from 'react' import { Button } from '@/components/ui/button' -import InstanceModal from '@/components/InstanceModal' -import { CreateInstanceOptions } from '@/types/instance' -function Header() { - const [isModalOpen, setIsModalOpen] = useState(false) - - const handleCreateInstance = () => { - setIsModalOpen(true) - } - - const handleSaveInstance = (name: string, options: CreateInstanceOptions) => { - // TODO: Implement API call to create instance - console.log('Creating instance:', { name, options }) - // For now, just log the data - you'll implement the API call later - } +interface HeaderProps { + onCreateInstance: () => void +} +function Header({ onCreateInstance }: HeaderProps) { return ( - <> -
-
-
-

- LlamaCtl Dashboard -

- - -
+
+
+
+

+ LlamaCtl Dashboard +

+ +
-
- - - +
+
) } diff --git a/ui/src/components/InstanceCard.tsx b/ui/src/components/InstanceCard.tsx index ccc4d01..1028345 100644 --- a/ui/src/components/InstanceCard.tsx +++ b/ui/src/components/InstanceCard.tsx @@ -9,9 +9,10 @@ interface InstanceCardProps { startInstance: (name: string) => void stopInstance: (name: string) => void deleteInstance: (name: string) => void + editInstance: (instance: Instance) => void } -function InstanceCard({ instance, startInstance, stopInstance, deleteInstance }: InstanceCardProps) { +function InstanceCard({ instance, startInstance, stopInstance, deleteInstance, editInstance }: InstanceCardProps) { const handleStart = () => { startInstance(instance.name) @@ -28,8 +29,7 @@ function InstanceCard({ instance, startInstance, stopInstance, deleteInstance }: } const handleEdit = () => { - // Logic for editing the instance (e.g., open a modal) - console.log(`Edit instance: ${instance.name}`) + editInstance(instance) } const handleLogs = () => { diff --git a/ui/src/components/InstanceList.tsx b/ui/src/components/InstanceList.tsx index d0078a7..0aff605 100644 --- a/ui/src/components/InstanceList.tsx +++ b/ui/src/components/InstanceList.tsx @@ -1,7 +1,12 @@ import { useInstances } from '@/hooks/useInstances' import InstanceCard from '@/components/InstanceCard' +import { Instance } from '@/types/instance' -function InstanceList() { +interface InstanceListProps { + editInstance: (instance: Instance) => void +} + +function InstanceList({ editInstance }: InstanceListProps) { const { instances, loading, error, startInstance, stopInstance, deleteInstance } = useInstances() if (loading) { @@ -49,6 +54,7 @@ function InstanceList() { startInstance={startInstance} stopInstance={stopInstance} deleteInstance={deleteInstance} + editInstance={editInstance} /> ))}