From 020eff9d5c15390a7d0866c667dd911be5c521d9 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Fri, 30 May 2025 01:27:19 -0600 Subject: [PATCH] Upgraded API Request Node --- .../Data Collection/Node_API_Request.jsx | 253 +++++++----------- 1 file changed, 101 insertions(+), 152 deletions(-) diff --git a/Data/Server/WebUI/src/nodes/Data Collection/Node_API_Request.jsx b/Data/Server/WebUI/src/nodes/Data Collection/Node_API_Request.jsx index eda504d..7af5bcb 100644 --- a/Data/Server/WebUI/src/nodes/Data Collection/Node_API_Request.jsx +++ b/Data/Server/WebUI/src/nodes/Data Collection/Node_API_Request.jsx @@ -1,67 +1,27 @@ ////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: /Data/WebUI/src/nodes/Data Collection/Node_API_Request.jsx - import React, { useState, useEffect, useRef } from "react"; import { Handle, Position, useReactFlow, useStore } from "reactflow"; +// API Request Node (Modern, Sidebar Config Enabled) const APIRequestNode = ({ id, data }) => { const { setNodes } = useReactFlow(); const edges = useStore((state) => state.edges); if (!window.BorealisValueBus) window.BorealisValueBus = {}; - const [url, setUrl] = useState(data?.url || "http://localhost:5000/health"); - const [editUrl, setEditUrl] = useState(data?.url || "http://localhost:5000/health"); - const [useProxy, setUseProxy] = useState(data?.useProxy ?? true); - const [body, setBody] = useState(data?.body || ""); - const [intervalSec, setIntervalSec] = useState(data?.intervalSec ?? 10); + // Use config values, but coerce types + const url = data?.url || "http://localhost:5000/health"; + // Note: Store useProxy as a string ("true"/"false"), convert to boolean for logic + const useProxy = (data?.useProxy ?? "true") === "true"; + const body = data?.body || ""; + const intervalSec = parseInt(data?.intervalSec || "10", 10) || 10; + + // Status State const [error, setError] = useState(null); const [statusCode, setStatusCode] = useState(null); const [statusText, setStatusText] = useState(""); const resultRef = useRef(null); - const handleUrlInputChange = (e) => setEditUrl(e.target.value); - const handleToggleProxy = (e) => { - const flag = e.target.checked; - setUseProxy(flag); - setNodes((nds) => - nds.map((n) => (n.id === id ? { ...n, data: { ...n.data, useProxy: flag } } : n)) - ); - }; - - const handleUpdateUrl = () => { - setUrl(editUrl); - setError(null); - setStatusCode(null); - setStatusText(""); - resultRef.current = null; - window.BorealisValueBus[id] = undefined; - setNodes((nds) => - nds.map((n) => - n.id === id - ? { ...n, data: { ...n.data, url: editUrl, result: undefined } } - : n - ) - ); - }; - - const handleBodyChange = (e) => { - const newBody = e.target.value; - setBody(newBody); - setNodes((nds) => - nds.map((n) => (n.id === id ? { ...n, data: { ...n.data, body: newBody } } : n)) - ); - }; - - const handleIntervalChange = (e) => { - const sec = parseInt(e.target.value, 10) || 1; - setIntervalSec(sec); - setNodes((nds) => - nds.map((n) => - n.id === id ? { ...n, data: { ...n.data, intervalSec: sec } } : n - ) - ); - }; - useEffect(() => { let cancelled = false; @@ -69,12 +29,9 @@ const APIRequestNode = ({ id, data }) => { try { setError(null); + // Allow dynamic URL override from upstream node (if present) const inputEdge = edges.find((e) => e.target === id); const upstreamUrl = inputEdge ? window.BorealisValueBus[inputEdge.source] : null; - if (upstreamUrl && upstreamUrl !== editUrl) { - setEditUrl(upstreamUrl); - } - const resolvedUrl = upstreamUrl || url; let target = useProxy ? `/api/proxy?url=${encodeURIComponent(resolvedUrl)}` : resolvedUrl; @@ -126,119 +83,111 @@ const APIRequestNode = ({ id, data }) => { }; }, [url, body, intervalSec, useProxy, id, setNodes, edges]); + // Upstream disables direct editing of URL in the UI const inputEdge = edges.find((e) => e.target === id); const hasUpstream = Boolean(inputEdge && inputEdge.source); + // -- Node Card Render (minimal: sidebar handles config) -- return (
-
API Request
-
- - - - -
- - -
- - -