diff --git a/atomizer-dashboard/frontend/src/components/canvas/panels/ConfigImporter.tsx b/atomizer-dashboard/frontend/src/components/canvas/panels/ConfigImporter.tsx index f87a1d05..7e7e35bf 100644 --- a/atomizer-dashboard/frontend/src/components/canvas/panels/ConfigImporter.tsx +++ b/atomizer-dashboard/frontend/src/components/canvas/panels/ConfigImporter.tsx @@ -7,16 +7,18 @@ * - Load from study directory */ -import { useState, useRef } from 'react'; +import { useState, useRef, useEffect } from 'react'; +import { FolderOpen } from 'lucide-react'; import { useCanvasStore, OptimizationConfig } from '../../../hooks/useCanvasStore'; interface ConfigImporterProps { isOpen: boolean; onClose: () => void; onImport: (source: string) => void; + currentStudyId?: string; // Auto-load this study when provided } -export function ConfigImporter({ isOpen, onClose, onImport }: ConfigImporterProps) { +export function ConfigImporter({ isOpen, onClose, onImport, currentStudyId }: ConfigImporterProps) { const [tab, setTab] = useState<'file' | 'paste' | 'study'>('file'); const [jsonText, setJsonText] = useState(''); const [studyPath, setStudyPath] = useState(''); @@ -26,6 +28,14 @@ export function ConfigImporter({ isOpen, onClose, onImport }: ConfigImporterProp const { loadFromConfig } = useCanvasStore(); + // Set study path from current study when provided + useEffect(() => { + if (currentStudyId) { + setStudyPath(currentStudyId); + setTab('study'); + } + }, [currentStudyId, isOpen]); + if (!isOpen) return null; const handleFileSelect = async (e: React.ChangeEvent) => { @@ -69,13 +79,14 @@ export function ConfigImporter({ isOpen, onClose, onImport }: ConfigImporterProp try { // Call backend API to load study config - const response = await fetch(`/api/studies/${encodeURIComponent(studyPath)}/config`); + const response = await fetch(`/api/optimization/studies/${encodeURIComponent(studyPath)}/config`); if (!response.ok) { throw new Error(`Study not found: ${studyPath}`); } - const config = await response.json() as OptimizationConfig; + const data = await response.json(); + const config = data.config as OptimizationConfig; validateConfig(config); loadFromConfig(config); onImport(`Study: ${studyPath}`); @@ -165,7 +176,7 @@ export function ConfigImporter({ isOpen, onClose, onImport }: ConfigImporterProp disabled={isLoading} className="w-full py-8 border-2 border-dashed border-dark-600 rounded-lg hover:border-primary-500/50 hover:bg-dark-800 transition-colors flex flex-col items-center gap-2" > - 📁 + {isLoading ? 'Loading...' : 'Click to select file'} diff --git a/atomizer-dashboard/frontend/src/pages/Setup.tsx b/atomizer-dashboard/frontend/src/pages/Setup.tsx index 604c34ed..111dc259 100644 --- a/atomizer-dashboard/frontend/src/pages/Setup.tsx +++ b/atomizer-dashboard/frontend/src/pages/Setup.tsx @@ -28,6 +28,8 @@ import { Card } from '../components/common/Card'; import { Button } from '../components/common/Button'; import { apiClient, ModelFile } from '../api/client'; import { AtomizerCanvas } from '../components/canvas/AtomizerCanvas'; +import { ConfigImporter } from '../components/canvas/panels/ConfigImporter'; +import { useCanvasStore } from '../hooks/useCanvasStore'; interface StudyConfig { study_name: string; @@ -88,6 +90,9 @@ export default function Setup() { ); const [modelFiles, setModelFiles] = useState([]); const [modelDir, setModelDir] = useState(''); + const [showImporter, setShowImporter] = useState(false); + const [canvasNotification, setCanvasNotification] = useState(null); + const { nodes } = useCanvasStore(); // Redirect if no study selected useEffect(() => { @@ -256,6 +261,11 @@ export default function Setup() { // Canvas tab - full height and full width if (activeTab === 'canvas') { + const handleImport = (source: string) => { + setCanvasNotification(`Loaded: ${source}`); + setTimeout(() => setCanvasNotification(null), 3000); + }; + return (
{/* Tab Bar */} @@ -275,6 +285,15 @@ export default function Setup() { Canvas Builder
+ {nodes.length === 0 && ( + + )} {selectedStudy?.name || 'Study'} @@ -283,6 +302,21 @@ export default function Setup() {
+ + {/* Config Importer Modal */} + setShowImporter(false)} + onImport={handleImport} + currentStudyId={selectedStudy?.id} + /> + + {/* Notification Toast */} + {canvasNotification && ( +
+ {canvasNotification} +
+ )}
); }