From 853588157ce51b03f74129f40e55c6542efcbea0 Mon Sep 17 00:00:00 2001 From: Maxwell Lin <28914712+maxwellmlin@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:51:40 -0400 Subject: [PATCH] Address PR --- .../src/CallServicePanel.tsx | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/foxglove/extensions/call-service-panel/src/CallServicePanel.tsx b/foxglove/extensions/call-service-panel/src/CallServicePanel.tsx index bf22c0350..dec6f623c 100644 --- a/foxglove/extensions/call-service-panel/src/CallServicePanel.tsx +++ b/foxglove/extensions/call-service-panel/src/CallServicePanel.tsx @@ -1,7 +1,7 @@ import { Immutable, PanelExtensionContext, RenderState } from "@foxglove/studio"; import Alert from "@mui/material/Alert"; import { JsonViewer } from "@textea/json-viewer"; -import { useCallback, useEffect, useLayoutEffect, useState } from "react"; +import { useEffect, useLayoutEffect, useState } from "react"; import { JSX } from "react/jsx-runtime"; import { createRoot } from "react-dom/client"; @@ -30,27 +30,28 @@ function CallServicePanel({ context }: { context: PanelExtensionContext }): JSX. renderDone?.(); }, [renderDone]); - const callService = useCallback( - async (serviceName: string, request: string) => { - if (!context.callService) { - return; - } + const callService = async (serviceName: string, request: string) => { + if (!context.callService) { + return; + } - try { - const response = await context.callService(serviceName, JSON.parse(request)); - JSON.stringify(response); // Attempt serializing the response, to throw an error on failure - setState((oldState) => ({ - ...oldState, - response, - error: undefined, - })); - } catch (error) { - setState((oldState) => ({ ...oldState, error: error as Error })); - console.error(error); - } - }, - [context], - ); + try { + const response = await context.callService(serviceName, JSON.parse(request)); + JSON.stringify(response); // Attempt serializing the response, to throw an error on failure + setState((oldState) => ({ + ...oldState, + response, + error: undefined, + })); + } catch (error) { + setState((oldState) => ({ ...oldState, error: error as Error })); + console.error(error); + } + }; + + const callServiceWithRequest = () => { + void callService(state.serviceName, state.request); + }; return (