From ecea2842840ce5aaf479e2fd994ffd648baccc04 Mon Sep 17 00:00:00 2001 From: Kerem Yilmaz Date: Sat, 24 Aug 2024 00:19:04 +0300 Subject: [PATCH] Fix multiple artifact in action list (#722) --- .../src/routes/tasks/detail/JSONArtifact.tsx | 69 +++++++++++-------- .../src/routes/tasks/detail/StepArtifacts.tsx | 16 ++--- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx b/skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx index 6acf2dd9..e9ae291e 100644 --- a/skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx +++ b/skyvern-frontend/src/routes/tasks/detail/JSONArtifact.tsx @@ -2,45 +2,58 @@ import { artifactApiClient } from "@/api/AxiosClient"; import { ArtifactApiResponse } from "@/api/types"; import { Skeleton } from "@/components/ui/skeleton"; import { Textarea } from "@/components/ui/textarea"; -import { useQuery } from "@tanstack/react-query"; +import { useQueries } from "@tanstack/react-query"; import axios from "axios"; type Props = { - artifact: ArtifactApiResponse; + artifacts: Array; }; -function JSONArtifact({ artifact }: Props) { - const { data, isFetching, isError, error } = useQuery< - Record - >({ - queryKey: ["artifact", artifact.artifact_id], - queryFn: async () => { - if (artifact.uri.startsWith("file://")) { - return artifactApiClient - .get(`/artifact/json`, { - params: { - path: artifact.uri.slice(7), - }, - }) - .then((response) => response.data); - } - if (artifact.uri.startsWith("s3://") && artifact.signed_url) { - return axios.get(artifact.signed_url).then((response) => response.data); - } - }, +function JSONArtifact({ artifacts }: Props) { + function fetchArtifact(artifact: ArtifactApiResponse) { + if (artifact.uri.startsWith("file://")) { + return artifactApiClient + .get(`/artifact/json`, { + params: { + path: artifact.uri.slice(7), + }, + }) + .then((response) => response.data); + } + if (artifact.uri.startsWith("s3://") && artifact.signed_url) { + return axios.get(artifact.signed_url).then((response) => response.data); + } + } + + const results = useQueries({ + queries: + artifacts?.map((artifact) => { + return { + queryKey: ["artifact", artifact.artifact_id], + queryFn: () => fetchArtifact(artifact), + }; + }) ?? [], }); - if (isFetching) { + if (results.some((result) => result.isLoading)) { return ; } return ( -