/** * @license * SPDX-License-Identifier: Apache-2.0 */ /* tslint:disable */ import React, {useEffect, useState} from 'react'; interface ParametersPanelProps { currentLength: number; onUpdateHistoryLength: (newLength: number) => void; // Renamed for clarity onClosePanel: () => void; isStatefulnessEnabled: boolean; onSetStatefulness: (enabled: boolean) => void; // Changed to accept a boolean } export const ParametersPanel: React.FC = ({ currentLength, onUpdateHistoryLength, onClosePanel, isStatefulnessEnabled, onSetStatefulness, }) => { // Local state for pending changes const [localHistoryLengthInput, setLocalHistoryLengthInput] = useState(currentLength.toString()); const [localStatefulnessChecked, setLocalStatefulnessChecked] = useState(isStatefulnessEnabled); // Update local state if props change (e.g., panel re-opened) useEffect(() => { setLocalHistoryLengthInput(currentLength.toString()); }, [currentLength]); useEffect(() => { setLocalStatefulnessChecked(isStatefulnessEnabled); }, [isStatefulnessEnabled]); const handleHistoryLengthInputChange = ( event: React.ChangeEvent, ) => { setLocalHistoryLengthInput(event.target.value); }; const handleStatefulnessCheckboxChange = ( event: React.ChangeEvent, ) => { setLocalStatefulnessChecked(event.target.checked); }; const handleApplyParameters = () => { // Apply history length const newLength = parseInt(localHistoryLengthInput, 10); if (!isNaN(newLength) && newLength >= 0 && newLength <= 10) { onUpdateHistoryLength(newLength); } else { alert('Please enter a number between 0 and 10 for history length.'); setLocalHistoryLengthInput(currentLength.toString()); // Revert local input to original prop on error return; // Do not proceed to close if there's an error } // Apply statefulness if it has changed if (localStatefulnessChecked !== isStatefulnessEnabled) { onSetStatefulness(localStatefulnessChecked); } onClosePanel(); // Close the panel after applying settings }; const handleClose = () => { // Reset local state to reflect original props before closing, ensuring no pending changes carry over visually if panel is quickly reopened setLocalHistoryLengthInput(currentLength.toString()); setLocalStatefulnessChecked(isStatefulnessEnabled); onClosePanel(); }; return (
{/* Interaction History Row */}
{/* Statefulness Row */}
{/* Action Buttons */}
{' '} {/* Changed pt-2 to mt-6, justify-end to justify-start */}
); };