JobButtons
handles onPress
What can be done with a job: queue it again (retryJob), once it's done, failed or cancelled; cancel it
(cancelJob), while it's queued.
import { refresh } from "#codebase/tcmts/react"; import { toasts } from "#codebase/tcmts/share"; import { cancelJob, retryJob } from "#codebase/tcmts/studio"; import { Button } from "react-aria-components"; export function JobButtons({ id, status }: { id: string; status: string }) { const act = async (f: (id: string) => Promise<void>, said: string) => { try { await f(id); toasts.add({ title: said, tone: "ok" }, { timeout: 3000 }); refresh(); } catch (e) { toasts.add({ title: "Couldn't", description: (e as Error).message, tone: "bad" }); } }; return ( <span className="actions"> {status === "queued" && ( <Button className="btn small" onPress={() => act(cancelJob, "Cancelled")}> Cancel </Button> )} {["failed", "done", "cancelled"].includes(status) && ( <Button className="btn small" onPress={() => act(retryJob, "Queued again")}> {status === "failed" ? "Retry" : "Run again"} </Button> )} </span> ); }