Files
Dorod-Sky/skyvern-frontend/src/routes/tasks/running/RunningTasks.tsx

78 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-05-07 11:31:05 -07:00
import { getClient } from "@/api/AxiosClient";
2024-04-24 21:14:05 +03:00
import { TaskApiResponse } from "@/api/types";
import { useQuery } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
2024-04-01 21:34:52 +03:00
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { basicTimeFormat } from "@/util/timeFormat";
import { LatestScreenshot } from "./LatestScreenshot";
2024-05-07 11:31:05 -07:00
import { useCredentialGetter } from "@/hooks/useCredentialGetter";
2024-04-01 21:34:52 +03:00
function RunningTasks() {
const navigate = useNavigate();
2024-05-07 11:31:05 -07:00
const credentialGetter = useCredentialGetter();
2024-04-01 21:34:52 +03:00
2024-04-24 21:14:05 +03:00
const { data: runningTasks } = useQuery<Array<TaskApiResponse>>({
queryKey: ["tasks", "running"],
2024-04-01 21:34:52 +03:00
queryFn: async () => {
2024-05-07 11:31:05 -07:00
const client = await getClient(credentialGetter);
2024-04-01 21:34:52 +03:00
return client
.get("/tasks", {
params: {
2024-04-24 21:14:05 +03:00
task_status: "running",
2024-04-01 21:34:52 +03:00
},
})
.then((response) => response.data);
},
});
if (runningTasks?.length === 0) {
2024-04-01 21:34:52 +03:00
return <div>No running tasks</div>;
}
function handleNavigate(event: React.MouseEvent, id: string) {
if (event.ctrlKey || event.metaKey) {
window.open(
window.location.origin + `/tasks/${id}/actions`,
"_blank",
"noopener,noreferrer",
);
} else {
navigate(`/tasks/${id}/actions`);
}
}
return runningTasks?.map((task) => {
2024-04-01 21:34:52 +03:00
return (
<Card
key={task.task_id}
2024-05-10 08:35:00 -07:00
className="hover:bg-muted/50 cursor-pointer"
onClick={(event) => handleNavigate(event, task.task_id)}
2024-04-01 21:34:52 +03:00
>
<CardHeader>
<CardTitle className="overflow-hidden text-ellipsis whitespace-nowrap">
{task.task_id}
</CardTitle>
<CardDescription className="whitespace-nowrap overflow-hidden text-ellipsis">
{task.request.url}
</CardDescription>
2024-04-01 21:34:52 +03:00
</CardHeader>
<CardContent className="flex items-center justify-center">
<div className="w-40 h-40">
<LatestScreenshot id={task.task_id} />
</div>
</CardContent>
2024-04-01 21:34:52 +03:00
<CardFooter>Created: {basicTimeFormat(task.created_at)}</CardFooter>
</Card>
);
});
}
export { RunningTasks };