From 0f8a202d9ffee8d3c3a161e37fa6ff4f0d236e2d Mon Sep 17 00:00:00 2001 From: Erik Nilsen Date: Mon, 15 Jun 2026 08:18:39 -0700 Subject: [PATCH] fix(recipe): close modal when canceling parameter form (#9195) Signed-off-by: Erik Nilsen Signed-off-by: Douwe M Osinga Co-authored-by: Douwe M Osinga --- ui/desktop/eslint.config.js | 1 + .../src/components/ParameterInputModal.tsx | 40 ++--- .../__tests__/ParameterInputModal.test.tsx | 161 ++++++++++++++++++ 3 files changed, 177 insertions(+), 25 deletions(-) create mode 100644 ui/desktop/src/components/__tests__/ParameterInputModal.test.tsx diff --git a/ui/desktop/eslint.config.js b/ui/desktop/eslint.config.js index 87968e311..5e6aa8cac 100644 --- a/ui/desktop/eslint.config.js +++ b/ui/desktop/eslint.config.js @@ -68,6 +68,7 @@ module.exports = [ CustomEvent: 'readonly', HTMLElement: 'readonly', HTMLInputElement: 'readonly', + HTMLSelectElement: 'readonly', HTMLTextAreaElement: 'readonly', HTMLButtonElement: 'readonly', HTMLDivElement: 'readonly', diff --git a/ui/desktop/src/components/ParameterInputModal.tsx b/ui/desktop/src/components/ParameterInputModal.tsx index c3fad93a0..c20a05c82 100644 --- a/ui/desktop/src/components/ParameterInputModal.tsx +++ b/ui/desktop/src/components/ParameterInputModal.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useId, useState, useEffect } from 'react'; import { Parameter } from '../recipe'; import { Button } from './ui/button'; import { defineMessages, useIntl } from '../i18n'; @@ -68,11 +68,12 @@ const ParameterInputModal: React.FC = ({ initialValues, }) => { const intl = useIntl(); + const fieldIdPrefix = useId(); + const fieldId = (key: string): string => `${fieldIdPrefix}-${key}`; const [inputValues, setInputValues] = useState>({}); const [validationErrors, setValidationErrors] = useState>({}); const [showCancelOptions, setShowCancelOptions] = useState(false); - // Pre-fill the form with default values from the recipe and initialValues from deeplink useEffect(() => { const defaultValues: Record = {}; parameters.forEach((param) => { @@ -90,10 +91,8 @@ const ParameterInputModal: React.FC = ({ }; const handleSubmit = (): void => { - // Clear previous validation errors setValidationErrors({}); - // Check if all *required* parameters are filled const requiredParams: Parameter[] = parameters.filter((p) => p.requirement === 'required'); const errors: Record = {}; @@ -113,7 +112,6 @@ const ParameterInputModal: React.FC = ({ }; const handleCancel = (): void => { - // Always show cancel options if recipe has any parameters (required or optional) const hasAnyParams = parameters.length > 0; if (hasAnyParams) { @@ -123,18 +121,9 @@ const ParameterInputModal: React.FC = ({ } }; - const handleCancelOption = (option: 'new-chat' | 'back-to-form'): void => { - if (option === 'new-chat') { - onClose(); - } else { - setShowCancelOptions(false); // Go back to the parameter form - } - }; - return (
{showCancelOptions ? ( - // Cancel options modal

{intl.formatMessage(i18n.cancelRecipeSetup)} @@ -142,25 +131,19 @@ const ParameterInputModal: React.FC = ({

{intl.formatMessage(i18n.whatToDo)}

-

) : ( - // Main parameter form

@@ -171,16 +154,19 @@ const ParameterInputModal: React.FC = ({
{parameters.map((param) => (
-