'use client'; import { useState } from 'react'; import { updateExperiment } from '@/app/actions/experiment'; import { Experiment } from '@/lib/model/experiment'; interface EditableExperimentHeaderProps { experiment: Experiment; } const ANNOTATION_TOOLS = [ { value: 'quality-choice', label: 'Quality Choice' }, { value: 'binary', label: 'Binary' }, // Future tools can be added here ]; export default function EditableExperimentHeader({ experiment, }: EditableExperimentHeaderProps) { const [isEditing, setIsEditing] = useState(false); const [name, setName] = useState(experiment.name); const [description, setDescription] = useState(experiment.description || ''); const [annotationTool, setAnnotationTool] = useState(experiment.annotationTool || 'quality-choice'); const [published, setPublished] = useState(experiment.published || false); const [onboardingEnabled, setOnboardingEnabled] = useState(experiment.onboardingEnabled || false); const [calibrationEnabled, setCalibrationEnabled] = useState(experiment.calibrationEnabled || false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function handleSave() { if (!name.trim()) { setError('Experiment name cannot be empty'); return; } setLoading(true); setError(null); try { await updateExperiment(experiment.id, { name: name.trim(), description: description.trim() || undefined, annotationTool: annotationTool, published: published, onboardingEnabled: onboardingEnabled, calibrationEnabled: calibrationEnabled }); setIsEditing(false); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to update experiment'); } finally { setLoading(false); } } function handleCancel() { setName(experiment.name); setAnnotationTool(experiment.annotationTool || 'quality-choice'); setPublished(experiment.published || false); setDescription(experiment.description || ''); setOnboardingEnabled(experiment.onboardingEnabled || false); setCalibrationEnabled(experiment.calibrationEnabled || false); setError(null); setIsEditing(false); } return (
{isEditing ? (
setName(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 mb-4" disabled={loading} />