Skip to content

Commit

Permalink
added loading state for variant logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bekossy committed May 21, 2024
1 parent 868a39b commit 5b483ca
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const ViewNavigation: React.FC<Props> = ({
const stopperRef = useRef<Function | null>(null)
const [isDelayed, setIsDelayed] = useState(false)
const [loading, setLoading] = useState(false)
const [isLogsLoading, setIsLogsLoading] = useState(false)

let prevKey = ""
const showNotification = (config: Parameters<typeof notification.open>[0]) => {
Expand Down Expand Up @@ -123,9 +124,22 @@ const ViewNavigation: React.FC<Props> = ({
}

if (isError) {
setLoading(false)
const getLogs = async () => {
const logs = await fetchVariantLogs(variant.variantId)
setVariantErrorLogs(logs)
try {
setIsLogsLoading(true)
const logs = await fetchVariantLogs(variant.variantId)
setVariantErrorLogs(logs)
} catch (error) {
console.error(error)
showNotification({
type: "error",
message: "Variant logs unreachable",
description: `Unable to fetch variant logs.`,
})
} finally {
setIsLogsLoading(false)
}
}
getLogs()
}
Expand Down Expand Up @@ -215,7 +229,11 @@ const ViewNavigation: React.FC<Props> = ({
const apiAddress = `${containerURI}/openapi.json`
return (
<div>
{error ? (
{!error ? null : isLogsLoading ? (
<div className="grid place-items-center mt-10">
<Spin />
</div>
) : (
<div>
<p>
Error connecting to the variant {variant.variantName}.{" "}
Expand Down Expand Up @@ -276,7 +294,7 @@ const ViewNavigation: React.FC<Props> = ({
</Tooltip>
</Button>
</div>
) : null}
)}
</div>
)
}
Expand Down

0 comments on commit 5b483ca

Please sign in to comment.