diff --git a/apps/rowboat/app/projects/[projectId]/simulation/app.tsx b/apps/rowboat/app/projects/[projectId]/simulation/app.tsx index f1ec05b2..c1b1330c 100644 --- a/apps/rowboat/app/projects/[projectId]/simulation/app.tsx +++ b/apps/rowboat/app/projects/[projectId]/simulation/app.tsx @@ -196,14 +196,9 @@ export default function SimulationApp() { } ); - // Refresh scenarios list and update only the modified scenario + // Just refresh the scenarios list without setting selected scenario const updatedScenarios = await getScenarios(projectId as string); setScenarios(updatedScenarios); - - const refreshedScenario = updatedScenarios.find(s => s._id === updatedScenario._id); - if (refreshedScenario) { - setSelectedScenario(refreshedScenario); - } setIsEditing(false); }; diff --git a/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx b/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx index f6214960..61210e90 100644 --- a/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx +++ b/apps/rowboat/app/projects/[projectId]/simulation/components/ScenarioComponents.tsx @@ -1,11 +1,10 @@ 'use client'; -import { useState, useEffect } from 'react'; +import { useState, useEffect, useCallback, ChangeEvent } from 'react'; import { XMarkIcon } from '@heroicons/react/24/outline'; import { WithStringId } from '../../../../lib/types/types'; import { Scenario } from "../../../../lib/types/testing_types"; import { z } from 'zod'; -import { EditableField } from '../../../../lib/components/editable-field'; type ScenarioType = WithStringId>; @@ -17,73 +16,114 @@ interface ScenarioViewerProps { export function ScenarioViewer({ scenario, onSave, onClose }: ScenarioViewerProps) { const [editedScenario, setEditedScenario] = useState(scenario); + const [isDirty, setIsDirty] = useState(false); // Reset state when scenario changes useEffect(() => { setEditedScenario(scenario); + setIsDirty(false); }, [scenario]); - const handleFieldChange = (field: keyof ScenarioType) => (value: string) => { - const updatedScenario = { - ...editedScenario, + const handleChange = useCallback((field: keyof ScenarioType, event: ChangeEvent) => { + event.preventDefault(); + const value = event.target.value; + + setEditedScenario(prev => ({ + ...prev, [field]: value, - }; - setEditedScenario(updatedScenario); - onSave(updatedScenario); - }; + })); + setIsDirty(true); + }, []); + + const handleSave = useCallback(() => { + onSave(editedScenario); + onClose(); + }, [editedScenario, onSave, onClose]); + + const adjustTextareaHeight = useCallback((element: HTMLTextAreaElement) => { + element.style.height = 'auto'; + element.style.height = `${element.scrollHeight}px`; + }, []); return (

Scenario Details

- +
+ {isDirty && ( + + )} + +
- +
+
NAME
+ handleChange('name', e)} + 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" + autoComplete="off" + spellCheck="false" + /> +
- +
+
DESCRIPTION
+