diff --git a/apps/rowboat/app/projects/[projectId]/simulation/app.tsx b/apps/rowboat/app/projects/[projectId]/simulation/app.tsx index f119dc38..0196e59d 100644 --- a/apps/rowboat/app/projects/[projectId]/simulation/app.tsx +++ b/apps/rowboat/app/projects/[projectId]/simulation/app.tsx @@ -19,7 +19,7 @@ import { type WithStringId } from '../../../lib/types/types'; import { Scenario, SimulationRun, SimulationResult } from "../../../lib/types/testing_types"; import { z } from 'zod'; import { SimulationResultCard, ScenarioResultCard } from './components/RunComponents'; -import { ScenarioViewer, ScenarioEditor } from './components/ScenarioComponents'; +import { ScenarioViewer } from './components/ScenarioComponents'; type ScenarioType = WithStringId>; type SimulationRunType = WithStringId>; @@ -339,19 +339,11 @@ export default function SimulationApp() { {/* Main content */}
{selectedScenario ? ( - isEditing ? ( - setIsEditing(false)} - /> - ) : ( - setIsEditing(true)} - onClose={handleCloseScenario} - /> - ) + ) : (
diff --git a/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx b/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx index f1aa7b10..ebdd5080 100644 --- a/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx +++ b/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { PencilIcon, XMarkIcon, DocumentDuplicateIcon } from '@heroicons/react/24/outline'; import { WithStringId } from '../../../../lib/types/types'; import { Scenario } from "../../../../lib/types/testing_types"; @@ -10,77 +10,18 @@ type ScenarioType = WithStringId>; interface ScenarioViewerProps { scenario: ScenarioType; - onEdit: () => void; + onSave: (scenario: ScenarioType) => void; onClose: () => void; } -export function ScenarioViewer({ scenario, onEdit, onClose }: ScenarioViewerProps) { - return ( -
-
-

{scenario.name}

-
- - -
-
-
-
-
NAME
-
{scenario.name}
-
- -
- -
-
DESCRIPTION
-
{scenario.description}
-
- -
- -
-
CRITERIA
-
{scenario.criteria}
-
- -
- -
-
CONTEXT
-
{scenario.context}
-
-
-
- ); -} - -interface ScenarioEditorProps { - scenario: ScenarioType; - onSave: (scenario: ScenarioType) => void; - onCancel: () => void; -} - -export function ScenarioEditor({ scenario, onSave, onCancel }: ScenarioEditorProps) { +export function ScenarioViewer({ scenario, onSave, onClose }: ScenarioViewerProps) { const [name, setName] = useState(scenario.name); const [description, setDescription] = useState(scenario.description); const [criteria, setCriteria] = useState(scenario.criteria || ''); const [context, setContext] = useState(scenario.context || ''); - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); + // Save changes whenever any field changes + useEffect(() => { onSave({ ...scenario, name, @@ -88,80 +29,82 @@ export function ScenarioEditor({ scenario, onSave, onCancel }: ScenarioEditorPro criteria, context, }); - }; + }, [name, description, criteria, context]); return (
-

Edit Scenario

-
- - -
+

Scenario Details

+
-
-
+
+
NAME
setName(e.target.value)} - className="mt-1 block w-full rounded-md border-2 border-gray-300 shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 px-3 py-2" - placeholder="An identifiable scenario name" + className="text-base border border-gray-200 rounded px-2 py-1 hover:border-gray-300 focus:border-blue-500 focus:ring-1 focus:ring-blue-500" />
- +
- -
+ +
DESCRIPTION