Skip to content

Commit

Permalink
Fix: hide builtin tool actions (#1257)
Browse files Browse the repository at this point in the history
* fix: hide tool card actions for builtin tools

* fix: prevent stale data from preventing tool polling
  • Loading branch information
ryanhopperlowe authored Jan 14, 2025
1 parent 2b92aef commit d8b494b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ui/admin/app/components/tools/toolGrid/ToolCardActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function ToolCardActions({ tool }: { tool: ToolReference }) {
}
);

if (tool.builtin) return null;

return (
<div className="flex items-center gap-2">
{(forceRefresh.isLoading || isPolling) && <LoadingSpinner />}
Expand Down
16 changes: 14 additions & 2 deletions ui/admin/app/hooks/usePollSingleTool.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand All @@ -43,7 +52,10 @@ export function usePollSingleTool(toolId: string) {
}, [getTool.data, updateTools, toolId]);

return {
startPolling: () => setIsPolling(true),
startPolling: () => {
isInitial.current = true;
setIsPolling(true);
},
isPolling,
};
}

0 comments on commit d8b494b

Please sign in to comment.