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";
|
2024-04-07 21:52:59 +03:00
|
|
|
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);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-07 21:52:59 +03:00
|
|
|
if (runningTasks?.length === 0) {
|
2024-04-01 21:34:52 +03:00
|
|
|
return <div>No running tasks</div>;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-25 13:36:01 -07:00
|
|
|
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`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 21:52:59 +03:00
|
|
|
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"
|
2024-06-25 13:36:01 -07:00
|
|
|
onClick={(event) => handleNavigate(event, task.task_id)}
|
2024-04-01 21:34:52 +03:00
|
|
|
>
|
|
|
|
|
<CardHeader>
|
2024-05-20 08:27:36 -07:00
|
|
|
<CardTitle className="overflow-hidden text-ellipsis whitespace-nowrap">
|
|
|
|
|
{task.task_id}
|
|
|
|
|
</CardTitle>
|
2024-04-07 21:52:59 +03:00
|
|
|
<CardDescription className="whitespace-nowrap overflow-hidden text-ellipsis">
|
|
|
|
|
{task.request.url}
|
|
|
|
|
</CardDescription>
|
2024-04-01 21:34:52 +03:00
|
|
|
</CardHeader>
|
2024-05-31 19:27:26 +03:00
|
|
|
<CardContent className="flex items-center justify-center">
|
|
|
|
|
<div className="w-40 h-40">
|
2024-04-07 21:52:59 +03:00
|
|
|
<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 };
|