Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export as csv in tasks and workflow runs #1361

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions skyvern-frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export type WorkflowRunApiResponse = {
webhook_callback_url: string;
created_at: string;
modified_at: string;
failure_reason: string | null;
};

export type WorkflowRunStatusApiResponse = {
Expand Down
45 changes: 40 additions & 5 deletions skyvern-frontend/src/routes/tasks/list/TaskHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { useState } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { TaskActions } from "./TaskActions";
import { TaskListSkeletonRows } from "./TaskListSkeletonRows";
import { Button } from "@/components/ui/button";
import { DownloadIcon } from "@radix-ui/react-icons";
import { downloadBlob } from "@/util/downloadBlob";

type StatusDropdownItem = {
label: string;
Expand Down Expand Up @@ -115,15 +118,47 @@ function TaskHistory() {
}
}

function handleExport() {
if (!tasks) {
return; // should never happen
}
const data = ["id,url,status,created,failure_reason"];
tasks.forEach((task) => {
const row = [
task.task_id,
task.request.url,
task.status,
task.created_at,
task.failure_reason ?? "",
];
data.push(
row
.map(String) // convert every value to String
.map((v) => v.replace(new RegExp('"', "g"), '""')) // escape double quotes
.map((v) => `"${v}"`) // quote it
.join(","), // comma-separated
);
});
const contents = data.join("\r\n");

downloadBlob(contents, "export.csv", "data:text/csv;charset=utf-8;");
}

return (
<div className="space-y-4">
<header className="flex items-center justify-between">
<h1 className="text-2xl">Task Runs</h1>
<StatusFilterDropdown
values={statusFilters}
onChange={setStatusFilters}
options={statusDropdownItems}
/>
<div className="flex gap-2">
<StatusFilterDropdown
values={statusFilters}
onChange={setStatusFilters}
options={statusDropdownItems}
/>
<Button variant="secondary" onClick={handleExport}>
<DownloadIcon className="mr-2" />
Export CSV
</Button>
</div>
</header>
<div className="rounded-md border">
<Table>
Expand Down
Loading
Loading