From d8b494bb4e8e2b1694fd5f4275544be09a4c206a Mon Sep 17 00:00:00 2001 From: Ryan Hopper-Lowe <46546486+ryanhopperlowe@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:58:12 -0600 Subject: [PATCH] Fix: hide builtin tool actions (#1257) * fix: hide tool card actions for builtin tools * fix: prevent stale data from preventing tool polling --- .../tools/toolGrid/ToolCardActions.tsx | 2 ++ ui/admin/app/hooks/usePollSingleTool.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ui/admin/app/components/tools/toolGrid/ToolCardActions.tsx b/ui/admin/app/components/tools/toolGrid/ToolCardActions.tsx index 0175927a9..07c985f0e 100644 --- a/ui/admin/app/components/tools/toolGrid/ToolCardActions.tsx +++ b/ui/admin/app/components/tools/toolGrid/ToolCardActions.tsx @@ -28,6 +28,8 @@ export function ToolCardActions({ tool }: { tool: ToolReference }) { } ); + if (tool.builtin) return null; + return (
{(forceRefresh.isLoading || isPolling) && } diff --git a/ui/admin/app/hooks/usePollSingleTool.ts b/ui/admin/app/hooks/usePollSingleTool.ts index 1de5e7c76..c432ab626 100644 --- a/ui/admin/app/hooks/usePollSingleTool.ts +++ b/ui/admin/app/hooks/usePollSingleTool.ts @@ -1,10 +1,11 @@ -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import useSWR from "swr"; import { ToolReferenceService } from "~/lib/service/api/toolreferenceService"; export function usePollSingleTool(toolId: string) { const [isPolling, setIsPolling] = useState(false); + const isInitial = useRef(false); const { mutate: updateTools } = useSWR( isPolling ? ToolReferenceService.getToolReferences.key("tool") : null, @@ -20,6 +21,14 @@ export function usePollSingleTool(toolId: string) { ); useEffect(() => { + // skip initial poll in case data is stale + // stale data could give a false positive on the `resolved` property + // which would prematurely stop polling + if (isInitial.current) { + isInitial.current = false; + return; + } + if (!getTool.data) return; setIsPolling(!getTool.data.resolved); @@ -43,7 +52,10 @@ export function usePollSingleTool(toolId: string) { }, [getTool.data, updateTools, toolId]); return { - startPolling: () => setIsPolling(true), + startPolling: () => { + isInitial.current = true; + setIsPolling(true); + }, isPolling, }; }