mirror of
https://github.com/coder/coder.git
synced 2026-11-04 23:29:17 +08:00
Add the ability to pause a running task and resume a paused task directly from the TaskPage. This includes showing contextual messages when a task is paused (manual vs timeout) and proper error handling with dialogs for API errors. - Extract task action logic into reusable mutations (api/queries/tasks.ts) - Move TaskActionButton to modules/tasks for better organization - Add pause button to TaskStartingAgent component - Show appropriate state messages for transitioning states (pausing, canceling, deleting)
65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
import { Button } from "components/Button/Button";
|
|
import { Spinner } from "components/Spinner/Spinner";
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "components/Tooltip/Tooltip";
|
|
import { PauseIcon, PlayIcon } from "lucide-react";
|
|
import type { FC } from "react";
|
|
|
|
type TaskActionButtonProps = {
|
|
action: "pause" | "resume";
|
|
disabled?: boolean;
|
|
loading?: boolean;
|
|
onClick: () => void;
|
|
};
|
|
|
|
const actionConfig = {
|
|
pause: {
|
|
icon: PauseIcon,
|
|
label: "Pause task",
|
|
tooltip: "Pause the task to save resources. You can resume later.",
|
|
},
|
|
resume: {
|
|
icon: PlayIcon,
|
|
label: "Resume task",
|
|
tooltip: "Resuming takes time while the workspace starts.",
|
|
},
|
|
} as const;
|
|
|
|
export const TaskActionButton: FC<TaskActionButtonProps> = ({
|
|
action,
|
|
disabled,
|
|
loading,
|
|
onClick,
|
|
}) => {
|
|
const config = actionConfig[action];
|
|
const Icon = config.icon;
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
size="icon-lg"
|
|
variant="outline"
|
|
disabled={disabled || loading}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
onClick();
|
|
}}
|
|
>
|
|
<Spinner loading={loading}>
|
|
<Icon aria-hidden="true" />
|
|
</Spinner>
|
|
<span className="sr-only">{config.label}</span>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{config.tooltip}</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
);
|
|
};
|