feat(web): add custom file download button for runs output

This commit is contained in:
BennyKok
2023-12-20 23:14:01 +08:00
parent 8f67a136c3
commit ee68507755
10 changed files with 54 additions and 30 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ import { LoaderIcon } from "lucide-react";
import * as React from "react";
export function LoadingIcon() {
return <LoaderIcon size={14} className="ml-2 animate-spin" />;
return <LoaderIcon size={14} className="animate-spin" />;
}
+31
View File
@@ -0,0 +1,31 @@
'use client'
import { Download } from "lucide-react";
import { Button } from "@/components/ui/button";
import { getFileDownloadUrl } from "@/server/getFileDownloadUrl";
export function OutputRender(props: { run_id: string; filename: string; }) {
if (props.filename.endsWith(".png")) {
return (
<img
className="max-w-[200px]"
alt={props.filename}
src={`/api/view?file=${encodeURIComponent(
`outputs/runs/${props.run_id}/${props.filename}`
)}`} />
);
} else {
return <Button className="gap-2" onClick={async () => {
const url = await getFileDownloadUrl(`outputs/runs/${props.run_id}/${props.filename}`);
const a = document.createElement('a');
a.href = url;
a.download = props.filename;
a.target = '_blank'; // Add this line
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}}>Download <Download size={14} /></Button>;
}
}
+1 -14
View File
@@ -1,3 +1,4 @@
import { RunInputs } from "@/components/RunInputs";
import { LiveStatus } from "./LiveStatus";
import { RunOutputs } from "@/components/RunOutputs";
@@ -51,17 +52,3 @@ export async function RunDisplay({
</Dialog>
);
}
export function OutputRender(props: { run_id: string; filename: string }) {
if (props.filename.endsWith(".png")) {
return (
<img
className="max-w-[200px]"
alt={props.filename}
src={`/api/view?file=${encodeURIComponent(
`outputs/runs/${props.run_id}/${props.filename}`
)}`}
/>
);
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
import { OutputRender } from "./RunDisplay";
import { OutputRender } from "./OutputRender";
import { CodeBlock } from "@/components/CodeBlock";
import {
Table,
+1 -1
View File
@@ -1,4 +1,4 @@
import { OutputRender } from "./RunDisplay";
import { OutputRender } from "./OutputRender";
import { CodeBlock } from "@/components/CodeBlock";
import {
Table,
+2 -2
View File
@@ -128,7 +128,7 @@ export function RunWorkflowButton({
}
}}
>
Run <Play size={14} /> {isLoading && <LoadingIcon />}
Run {isLoading ? <LoadingIcon /> : <Play size={14} />}
</Button>
);
}
@@ -155,7 +155,7 @@ export function CreateDeploymentButton({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="gap-2" disabled={isLoading} variant="outline">
Deploy <MoreVertical size={14} /> {isLoading && <LoadingIcon />}
Deploy {isLoading ? <LoadingIcon /> : <MoreVertical size={14} /> }
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">