From 0709f2f1ff45b7ed11b9d0596e67dc0863fcef4c Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 3 Apr 2025 15:37:52 +0200 Subject: [PATCH] Revert "feat(ui): Action playground config and parameter forms (#129)" This reverts commit 1eee5b5a326e50894da4aa3083b1bfa2b36aeb2f. --- webui/react-ui/src/App.jsx | 7 +- .../react-ui/src/pages/ActionsPlayground.jsx | 227 +++++++++++------- webui/react-ui/src/utils/api.js | 8 - 3 files changed, 141 insertions(+), 101 deletions(-) diff --git a/webui/react-ui/src/App.jsx b/webui/react-ui/src/App.jsx index decbba7..2aeb250 100644 --- a/webui/react-ui/src/App.jsx +++ b/webui/react-ui/src/App.jsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { Outlet, Link, useOutletContext } from 'react-router-dom' +import { Outlet, Link } from 'react-router-dom' import './App.css' function App() { @@ -19,9 +19,6 @@ function App() { setMobileMenuOpen(!mobileMenuOpen); }; - // Provide showToast to children - const context = { showToast }; - return (
{/* Navigation Menu */} @@ -113,7 +110,7 @@ function App() { {/* Main Content Area */}
- +
diff --git a/webui/react-ui/src/pages/ActionsPlayground.jsx b/webui/react-ui/src/pages/ActionsPlayground.jsx index c3ed28c..355338e 100644 --- a/webui/react-ui/src/pages/ActionsPlayground.jsx +++ b/webui/react-ui/src/pages/ActionsPlayground.jsx @@ -1,15 +1,14 @@ import { useState, useEffect } from 'react'; import { useOutletContext, useNavigate } from 'react-router-dom'; import { actionApi } from '../utils/api'; -import FormFieldDefinition from '../components/common/FormFieldDefinition'; function ActionsPlayground() { const { showToast } = useOutletContext(); + const navigate = useNavigate(); const [actions, setActions] = useState([]); const [selectedAction, setSelectedAction] = useState(''); - const [actionMeta, setActionMeta] = useState(null); - const [configValues, setConfigValues] = useState({}); - const [paramsValues, setParamsValues] = useState({}); + const [configJson, setConfigJson] = useState('{}'); + const [paramsJson, setParamsJson] = useState('{}'); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [loadingActions, setLoadingActions] = useState(true); @@ -25,29 +24,19 @@ function ActionsPlayground() { // Fetch available actions useEffect(() => { const fetchActions = async () => { - const response = await actionApi.listActions(); - setActions(response); - setLoadingActions(false); + try { + const response = await actionApi.listActions(); + setActions(response); + } catch (err) { + console.error('Error fetching actions:', err); + showToast('Failed to load actions', 'error'); + } finally { + setLoadingActions(false); + } }; fetchActions(); - }, []); - - // Fetch action metadata when an action is selected - useEffect(() => { - if (selectedAction) { - const fetchActionMeta = async () => { - const response = await actionApi.getAgentConfigMeta(); - const meta = response.actions.find(a => a.name === selectedAction); - setActionMeta(meta); - // Reset values when action changes - setConfigValues({}); - setParamsValues({}); - }; - - fetchActionMeta(); - } - }, [selectedAction]); + }, [showToast]); // Handle action selection const handleActionChange = (e) => { @@ -55,20 +44,13 @@ function ActionsPlayground() { setResult(null); }; - // Handle config field changes - const handleConfigChange = (fieldName, value) => { - setConfigValues(prev => ({ - ...prev, - [fieldName]: value - })); + // Handle JSON input changes + const handleConfigChange = (e) => { + setConfigJson(e.target.value); }; - // Handle params field changes - const handleParamsChange = (fieldName, value) => { - setParamsValues(prev => ({ - ...prev, - [fieldName]: value - })); + const handleParamsChange = (e) => { + setParamsJson(e.target.value); }; // Execute the selected action @@ -84,11 +66,31 @@ function ActionsPlayground() { setResult(null); try { + // Parse JSON inputs + let config = {}; + let params = {}; + + try { + config = JSON.parse(configJson); + } catch (err) { + showToast('Invalid configuration JSON', 'error'); + setLoading(false); + return; + } + + try { + params = JSON.parse(paramsJson); + } catch (err) { + showToast('Invalid parameters JSON', 'error'); + setLoading(false); + return; + } + // Prepare action data const actionData = { action: selectedAction, - config: configValues, - params: paramsValues + config: config, + params: params }; // Execute action @@ -96,65 +98,114 @@ function ActionsPlayground() { setResult(response); showToast('Action executed successfully', 'success'); } catch (err) { - showToast('Failed to execute action', 'error'); + console.error('Error executing action:', err); + showToast(`Failed to execute action: ${err.message}`, 'error'); } finally { setLoading(false); } }; return ( -
-

Actions Playground

+
+
+

Actions Playground

+

Test and execute actions directly from the UI

+
-
-
- - +
+
+

Select an Action

+ +
+ + +
- - {actionMeta && ( - <> -

Configuration

- - -

Parameters

- - + + {selectedAction && ( +
+

Action Configuration

+ + +
+ +